ref #10334 further handle include unpublished in webservices
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / ITaxonService.java
index 4fb711c110ae7d3f19370920e42845f49c7f8aac..2cb2bb8c106ec40917427c9eb0a082038b71ecd2 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.cdm.api.service;
 import java.io.IOException;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
@@ -23,23 +24,26 @@ import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
 import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
 import eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO;
+import eu.etaxonomy.cdm.api.service.dto.TaxonRelationshipsDTO;
 import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
 import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.api.service.search.LuceneMultiSearchException;
 import eu.etaxonomy.cdm.api.service.search.LuceneParseException;
 import eu.etaxonomy.cdm.api.service.search.SearchResult;
-import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
-import eu.etaxonomy.cdm.model.common.DefinedTerm;
+import eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge;
+import eu.etaxonomy.cdm.exception.UnpublishedException;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.media.MediaRepresentation;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingSwapEnum;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonName;
@@ -52,6 +56,9 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
+import eu.etaxonomy.cdm.model.term.DefinedTerm;
+import eu.etaxonomy.cdm.model.term.IdentifierType;
+import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
 import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
@@ -90,9 +97,12 @@ public interface ITaxonService
      *
      * @param synonym
      * @param acceptedTaxon
+     * @param setNameInSource
      * @return
      */
-    public UpdateResult swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon);
+    public UpdateResult swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean setNameInSource, boolean newUuidForAcceptedTaxon, SecReferenceHandlingSwapEnum secHandling, Reference secRefAcc, Reference secRefSyn);
+
+    public UpdateResult swapSynonymAndAcceptedTaxon(UUID synonymUUid, UUID acceptedTaxonUuid, boolean setNameInSource, boolean newUuidForAcceptedTaxon, SecReferenceHandlingSwapEnum secHandling, UUID newSecAcc, UUID newSecSyn);
 
     /**
      * Changes a synonym into an accepted taxon and removes
@@ -125,7 +135,7 @@ public interface ITaxonService
      *          in the homotypic group. It is up to the implementing class to
      *          handle this situation via an exception or in another way.
      */
-    public UpdateResult changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean deleteSynonym) throws HomotypicalGroupChangeException;
+    public UpdateResult changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon,Reference newSecRef, String microRef, SecReferenceHandlingEnum secHandling, boolean deleteSynonym) throws HomotypicalGroupChangeException;
 
     /**
      * @param synonymUuid
@@ -135,7 +145,7 @@ public interface ITaxonService
      * @return
      * @throws HomotypicalGroupChangeException
      */
-    public UpdateResult changeSynonymToAcceptedTaxon(UUID synonymUuid, UUID acceptedTaxonUuid, UUID newParentNodeUuid,
+    public UpdateResult changeSynonymToAcceptedTaxon(UUID synonymUuid, UUID acceptedTaxonUuid, UUID newParentNodeUuid, UUID newSecRef, String microRef, SecReferenceHandlingEnum secHandling,
             boolean deleteSynonym)
             throws HomotypicalGroupChangeException;
 
@@ -208,7 +218,6 @@ public interface ITaxonService
     public UpdateResult moveSynonymToAnotherTaxon(Synonym oldSynonym, Taxon newTaxon, boolean moveHomotypicGroup,
             SynonymType newSynonymType) throws HomotypicalGroupChangeException;
 
-
     /**
      * Moves a synonym to another taxon and removes the old synonym relationship.
      *
@@ -233,27 +242,16 @@ public interface ITaxonService
      *                 (2) synonym is in homotypic group with other synonyms and <code>moveHomotypicGroup</code> is false
      */
     public UpdateResult moveSynonymToAnotherTaxon(Synonym oldSynonym, Taxon newTaxon, boolean moveHomotypicGroup,
-            SynonymType newSynonymType, Reference newSecundum,
+            SynonymType newSynonymType, UUID newSecundumUuid,
             String newSecundumDetail, boolean keepSecundumIfUndefined) throws HomotypicalGroupChangeException;
 
-
     /**
-     * @param oldSynonym
-     * @param newTaxonUUID
-     * @param moveHomotypicGroup
-     * @param newSynonymType
-     * @param reference
-     * @param referenceDetail
-     * @param keepReference
-     * @return
-     * @throws HomotypicalGroupChangeException
-     *
      * @see {@link #moveSynonymToAnotherTaxon(Synonym, Taxon, boolean, SynonymType, Reference, String, boolean)}
      */
     public UpdateResult moveSynonymToAnotherTaxon(Synonym oldSynonym,
             UUID newTaxonUUID, boolean moveHomotypicGroup,
             SynonymType newSynonymType,
-            Reference newSecundum, String newSecundumDetail, boolean keepSecundumIfUndefined)
+            UUID newSecundumUuid, String newSecundumDetail, boolean keepSecundumIfUndefined)
             throws HomotypicalGroupChangeException;
 
     /**
@@ -346,13 +344,13 @@ public interface ITaxonService
      *
      * @param types The taxon relationship type filter, if <code>null</code> no filter is set, if empty the result will also be empty
      * @param pageSize the page size
-     * @param pageStart the number of the start page
+     * @param pageStart the number of the page
      * @param orderHints the order hints
      * @param propertyPaths the property path to initialize the resulting objects
      * @return list of taxon relationships matching the filter criteria
      */
     public List<TaxonRelationship> listTaxonRelationships(Set<TaxonRelationshipType> types,
-            Integer pageSize, Integer pageStart, List<OrderHint> orderHints, List<String> propertyPaths);
+            Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
     /**
      * Lists all classifications the given taxon/synonym is used in{@link Synonym}
@@ -464,7 +462,8 @@ public interface ITaxonService
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @return a list of TaxonBase instances
      */
-    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize, Integer pageNumber);
+    public <T extends TaxonBase>  Pager<T> findTaxaByName(Class<T> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
+            String infraspecificEpithet, String authorshipCache, Rank rank, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
 
     /**
      * Returns a list of TaxonBase instances where the
@@ -477,17 +476,20 @@ public interface ITaxonService
      * @param specificEpithet
      * @param infraspecificEpithet
      * @param rank
+     * @param authorshipCache
      * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @return a List of TaxonBase instances
      */
-    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize, Integer pageNumber);
+    public <T extends TaxonBase> List<T> listTaxaByName(Class<T> clazz, String uninomial, String infragenericEpithet, String specificEpithet,
+            String infraspecificEpithet, String authorshipCache, Rank rank, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
 
     /**
      * Returns a list of IdentifiableEntity instances (in particular, TaxonName and TaxonBase instances)
      * that match the properties specified in the configurator.
-     * @param configurator
-     * @return
+     *
+     * Note: The search result includes a search on titleCache (with {@link MatchMode#BEGINNING} or {@link MatchMode#ANYWHERE} )
+     * for all records with protected titleCache (see #9561). Maybe this should be parameterized in future.
      */
     public Pager<IdentifiableEntity> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator);
 
@@ -537,7 +539,7 @@ public interface ITaxonService
      */
     @Deprecated
     public Pager<SearchResult<TaxonBase>> findByEverythingFullText(String queryString,
-            Classification classification, boolean includeUnpublished, List<Language> languages, boolean highlightFragments,
+            Classification classification, TaxonNode subtree, boolean includeUnpublished, List<Language> languages, boolean highlightFragments,
             Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException, LuceneMultiSearchException;
 
     /**
@@ -583,9 +585,11 @@ public interface ITaxonService
      * @throws LuceneParseException
      */
     public Pager<SearchResult<TaxonBase>> findByFullText(Class<? extends TaxonBase> clazz, String queryString,
-            Classification classification, boolean includeUnpublished, List<Language> languages,
-            boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
-            List<String> propertyPaths) throws IOException, LuceneParseException;
+            Classification classification, TaxonNode subtree,
+            boolean includeUnpublished, List<Language> languages,
+            boolean highlightFragments, Integer pageSize, Integer pageNumber,
+            List<OrderHint> orderHints, List<String> propertyPaths)
+                    throws IOException, LuceneParseException;
 
 
     /**
@@ -614,8 +618,9 @@ public interface ITaxonService
      * @throws IOException
      * @throws LuceneParseException
      */
+    //TODO needed? currently only used in test
     public Pager<SearchResult<TaxonBase>> findByDistribution(List<NamedArea> areaFilter, List<PresenceAbsenceTerm> statusFilter,
-            Classification classification,
+            Classification classification, TaxonNode subtree,
             Integer pageSize, Integer pageNumber,
             List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException;
 
@@ -634,7 +639,9 @@ public interface ITaxonService
      *            Additional filter criterion: If a taxonomic classification
      *            three is specified here the result set will only contain taxa
      *            of the given classification
+     * @param subtree
      * @param namedAreas
+     * @param distributionStatus
      * @param languages
      *            Additional filter criterion: Search only in these languages.
      *            Not all text fields in the cdm model are multilingual, thus
@@ -666,7 +673,8 @@ public interface ITaxonService
      */
     public Pager<SearchResult<TaxonBase>> findTaxaAndNamesByFullText(
             EnumSet<TaxaAndNamesSearchMode> searchModes,
-            String queryString, Classification classification, Set<NamedArea> namedAreas, Set<PresenceAbsenceTerm> distributionStatus,
+            String queryString, Classification classification, TaxonNode subtree,
+            Set<NamedArea> namedAreas, Set<PresenceAbsenceTerm> distributionStatus,
             List<Language> languages, boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
             List<String> propertyPaths) throws IOException, LuceneParseException, LuceneMultiSearchException;
 
@@ -682,14 +690,18 @@ public interface ITaxonService
      *            the query string to filter by
      * @param classification
      *            Additional filter criterion: If a taxonomic classification
-     *            three is specified here the result set will only contain taxa
+     *            tree is specified here the result set will only contain taxa
      *            of the given classification
+     * @param subtree
+     *            Additional filter criterion: If a taxonomic classification
+     *            subtree is specified here the result set will only contain taxa
+     *            of the given subtree
      * @param features
      *            TODO
      * @param languages
      *            Additional filter criterion: Search only in these languages.
-     *            Not all text fields in the cdm model are multilingual, thus
-     *            this setting will only apply to the multilingiual fields.
+     *            Not all text fields in the CDM model are multi-lingual, thus
+     *            this setting will only apply to the multi-lingual fields.
      *            Other fields are searched nevertheless if this parameter is
      *            set or not.
      * @param highlightFragments
@@ -713,43 +725,10 @@ public interface ITaxonService
      * @throws LuceneCorruptIndexException
      * @throws LuceneParseException
      */
-    public Pager<SearchResult<TaxonBase>> findByDescriptionElementFullText(Class<? extends DescriptionElementBase> clazz, String queryString, Classification classification, List<Feature> features, List<Language> languages, boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException;
-
+    public Pager<SearchResult<TaxonBase>> findByDescriptionElementFullText(Class<? extends DescriptionElementBase> clazz,
+            String queryString, Classification classification, TaxonNode subtree, List<Feature> features, List<Language> languages, boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException;
 
-    /**
-     *
-     * @param taxon
-     * @param size
-     * @param height
-     * @param widthOrDuration
-     * @param mimeTypes
-     * @return
-     *
-     * @deprecated use {@link #listMedia(Taxon, Set, boolean, boolean, List)} instead
-     */
-    @Deprecated
-    public List<MediaRepresentation> getAllMedia(Taxon taxon, int size, int height, int widthOrDuration, String[] mimeTypes);
-
-
-    /**
-     * Lists all Media found in an any TaxonDescription associated with this
-     * taxon.
-     *
-     * @param taxon
-     * @param includeRelationships
-     *            the given list of TaxonRelationshipEdges will be taken into
-     *            account when retrieving media associated with the given taxon.
-     *            Can be NULL.
-     * @param limitToGalleries
-     *            whether to take only TaxonDescription into account which are
-     *            marked as gallery
-     * @return
-     * @deprecated use {@link #listMedia(Taxon, Set, boolean, boolean, List)} instead
-     */
-    @Deprecated
-    public List<Media> listTaxonDescriptionMedia(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships, boolean limitToGalleries, List<String> propertyPath);
-
-    /**
+     /**
      * Lists all Media found in an any TaxonDescription, NameDescription,
      * SpecimenOrObservationBase, DnaSample Chromatograms, etc. associated with this taxon.
      *
@@ -764,15 +743,17 @@ public interface ITaxonService
      * @param includeTaxonDescriptions
      *            whether to take TaxonDescriptions into account, can be NULL
      * @param includeOccurrences
-     *          whether to take TaxonDescriptions into account, can be NULL
+     *          whether to take SpecimenDescriptions into account, can be NULL
+     * @param includeOriginals
+     *          whether to take SpecimenDescriptions of the originals of associated derived units into account, can be NULL
      * @param includeTaxonNameDescriptions
      *       whether to take TaxonNameDescriptions into account, can be NULL
      * @param propertyPath
      * @return
      */
     public List<Media> listMedia(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships,
-            Boolean limitToGalleries, Boolean includeTaxonDescriptions, Boolean includeOccurrences,
-            Boolean includeTaxonNameDescriptions, List<String> propertyPath);
+            Boolean limitToGalleries, Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeOriginals,
+            Boolean includeTaxonNameDescriptions, boolean includeUnpublished, List<String> propertyPath);
 
     public List<TaxonBase> findTaxaByID(Set<Integer> listOfIDs);
 
@@ -792,13 +773,15 @@ public interface ITaxonService
      * an accepted taxon are counted
      * @return the number of synonyms
      */
-    public int countSynonyms(boolean onlyAttachedToTaxon);
-
-    public List<TaxonName> findIdenticalTaxonNames(List<String> propertyPath);
+    public long countSynonyms(boolean onlyAttachedToTaxon);
 
-    public List<TaxonName> findIdenticalTaxonNameIds(List<String> propertyPath);
-//
-//    public String getPhylumName(TaxonName name);
+    /**
+     * Returns a map of taxon names that have identical name caches but derive from different sources.
+     * The sources are defined via the sources reference uuid.
+     *
+     * @return map of nameCaches and taxon name maps where the key is the UUID of the according sourceRefUuid
+     */
+    public Map<String, Map<UUID,Set<TaxonName>>> findIdenticalTaxonNames(List<UUID> sourceRefUuids, List<String> propertyPaths);
 
     /**
      * Returns all {@link Taxon taxa} which are {@link TaxonRelationshipType#CONGRUENT_TO() congruent} or
@@ -836,7 +819,6 @@ public interface ITaxonService
      * @param synonym
      * @param removeNameIfPossible
      * @return deleteResult
-     *
      */
     public DeleteResult deleteSynonym(Synonym synonym, SynonymDeletionConfigurator config);
 
@@ -852,10 +834,6 @@ public interface ITaxonService
      */
     public DeleteResult deleteSynonym(UUID synonymUuid, SynonymDeletionConfigurator config);
 
-    /**
-     * @param tnb
-     * @return
-     */
     public Taxon findBestMatchingTaxon(String taxonName);
 
     public Taxon findBestMatchingTaxon(MatchingTaxonConfigurator config);
@@ -881,11 +859,11 @@ public interface ITaxonService
      */
     public List<Synonym>  createAllInferredSynonyms(Taxon taxon, Classification tree, boolean doWithMisappliedNames);
 
-    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid, List<String> propertyPaths);
+    public Taxon findAcceptedTaxonFor(UUID synonymUuid, UUID classificationUuid, boolean includeUnpublished,
+            List<String> propertyPaths) throws UnpublishedException;
 
     public List<TaxonBase> findTaxaByName(MatchingTaxonConfigurator config);
 
-
     /**
      * @param clazz the optional {@link TaxonBase} subclass
      * @param identifier the identifier string
@@ -900,7 +878,7 @@ public interface ITaxonService
      * @see IIdentifiableEntityService#findByIdentifier(Class, String, DefinedTerm, MatchMode, boolean, Integer, Integer, List)
      */
     public <S extends TaxonBase> Pager<IdentifiedEntityDTO<S>> findByIdentifier(
-                       Class<S> clazz, String identifier, DefinedTerm identifierType, TaxonNode subtreeFilter,
+                       Class<S> clazz, String identifier, IdentifierType identifierType, TaxonNode subtreeFilter,
                        MatchMode matchmode, boolean includeEntity, Integer pageSize,
                        Integer pageNumber,     List<String> propertyPaths);
 
@@ -925,50 +903,26 @@ public interface ITaxonService
             TaxonNode subtreeFilter, boolean includeEntity, TaxonTitleType titleType,
             Integer pageSize, Integer pageNumber, List<String> propertyPaths);
 
-    /**
-     * @param synonymUUid
-     * @param acceptedTaxonUuid
-     * @return
-     */
-    public UpdateResult swapSynonymAndAcceptedTaxon(UUID synonymUUid, UUID acceptedTaxonUuid);
-
-    /**
-     * @param taxonUuid
-     * @param config
-     * @param classificationUuid
-     * @return
-     */
     public DeleteResult deleteTaxon(UUID taxonUuid, TaxonDeletionConfigurator config, UUID classificationUuid);
 
-
        public UpdateResult moveFactualDateToAnotherTaxon(UUID fromTaxonUuid,
                        UUID toTaxonUuid);
 
-
-    /**
-     * @param synonymUuid
-     * @param toTaxonUuid
-     * @param taxonRelationshipType
-     * @param citation
-     * @param microcitation
-     * @return
-     */
     public UpdateResult changeSynonymToRelatedTaxon(UUID synonymUuid, UUID toTaxonUuid, TaxonRelationshipType taxonRelationshipType,
             Reference citation, String microcitation);
 
-    /**
-     * @param fromTaxonUuid
-     * @param toTaxonUuid
-     * @param oldRelationshipType
-     * @param synonymType
-     * @return
-     * @throws DataChangeNoRollbackException
-     */
     public UpdateResult changeRelatedTaxonToSynonym(UUID fromTaxonUuid, UUID toTaxonUuid,
             TaxonRelationshipType oldRelationshipType, SynonymType synonymType) throws DataChangeNoRollbackException;
 
+    /**
+     * Returns a list of taxon relationships for a given taxon as DTO.
+     */
+    public TaxonRelationshipsDTO listTaxonRelationships(UUID taxonUuid,
+            Set<TaxonRelationshipType> directTypes,
+            Set<TaxonRelationshipType> inversTypes, Direction direction, boolean groupMisapplications,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber);
 
-
-
+    public <S extends TaxonBase> Pager<S> page(Class<S> clazz, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex,
+            List<OrderHint> orderHints, List<String> propertyPaths, boolean includeUnpublished);
 
 }