ref #1445: fix helper methods for pesi merging
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / ITaxonService.java
index 0634b25921243d01faba2d48c65e6f5903cb0c3b..18719bf01caf7a8f3271207d1752fbf2b74eb043 100644 (file)
@@ -23,6 +23,7 @@ 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;
@@ -30,16 +31,16 @@ 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.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.name.HomotypicalGroup;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonName;
@@ -52,6 +53,8 @@ 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.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;
@@ -59,7 +62,16 @@ import eu.etaxonomy.cdm.persistence.query.OrderHint;
 import eu.etaxonomy.cdm.persistence.query.TaxonTitleType;
 
 
-public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
+public interface ITaxonService
+             extends IIdentifiableEntityService<TaxonBase>, IPublishableService<TaxonBase>{
+
+    /**
+     * {@inheritDoc}
+     * <BR><BR>
+     * NOTE: Also taxa with <code>publish=false</code> are returned.
+     */
+    @Override
+    public TaxonBase load(UUID uuid, List<String> propertyPaths);
 
     /**
      * Returns a list of taxa that matches the name string and the sec reference
@@ -67,7 +79,7 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * @param sec the taxons sec reference
      * @return a list of taxa matching the name and the sec reference
      */
-    public List<TaxonBase> searchTaxaByName(String name, Reference sec);
+    public List<TaxonBase> searchByName(String name, boolean includeUnpublished, Reference sec);
 
     /**
      * Swaps given synonym and accepted taxon.
@@ -81,9 +93,10 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @param synonym
      * @param acceptedTaxon
+     * @param setNameInSource
      * @return
      */
-    public UpdateResult swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon);
+    public UpdateResult swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon, boolean setNameInSource);
 
     /**
      * Changes a synonym into an accepted taxon and removes
@@ -253,13 +266,15 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @param taxon The taxon that is relatedTo
      * @param type The type of TaxonRelationship (can be null)
+     * @param includeUnpublished should unpublished related taxa also be returned?
      * @param pageSize The maximum number of relationships returned (can be null for all relationships)
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @param orderHints Properties to order by
      * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link IBeanInitializer#initialize(Object, List)}
      * @return a List of TaxonRelationship instances
      */
-    public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+    public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
 
     /**
@@ -268,13 +283,15 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @param taxon The taxon that is relatedTo
      * @param type The type of TaxonRelationship (can be null)
+     * @param includeUnpublished should unpublished related taxa also be returned?
      * @param pageSize The maximum number of relationships returned (can be null for all relationships)
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @param orderHints Properties to order by
      * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link IBeanInitializer#initialize(Object, List)}
      * @return a Pager of TaxonRelationship instances
      */
-    public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+    public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
     /**
      * Returns the TaxonRelationships (of where relationship.type == type, if this argument is supplied)
@@ -282,13 +299,15 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @param taxon The taxon that is relatedFrom
      * @param type The type of TaxonRelationship (can be null)
+     * @param includeUnpublished should unpublished related taxa also be returned?
      * @param pageSize The maximum number of relationships returned (can be null for all relationships)
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @param orderHints Properties to order by
      * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link IBeanInitializer#initialize(Object, List)}
      * @return a List of TaxonRelationship instances
      */
-    public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+    public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
 
     /**
@@ -297,13 +316,15 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @param taxon The taxon that is relatedFrom
      * @param type The type of TaxonRelationship (can be null)
+     * @param includeUnpublished should unpublished related taxa also be returned?
      * @param pageSize The maximum number of relationships returned (can be null for all relationships)
      * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
      * @param orderHints Properties to order by
      * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link IBeanInitializer#initialize(Object, List)}
      * @return a Pager of TaxonRelationship instances
      */
-    public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+    public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
     /**
      * lists all taxa which are related to the <code>taxon</code> given as
@@ -320,7 +341,7 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * @return
      */
     public Set<Taxon> listRelatedTaxa(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships, Integer maxDepth,
-            Integer limit, Integer start, List<String> propertyPaths);
+            boolean includeUnpublished, Integer limit, Integer start, List<String> propertyPaths);
 
 
     /**
@@ -329,13 +350,13 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *
      * @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}
@@ -520,7 +541,7 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      */
     @Deprecated
     public Pager<SearchResult<TaxonBase>> findByEverythingFullText(String queryString,
-            Classification classification, 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;
 
     /**
@@ -565,9 +586,12 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * @throws IOException
      * @throws LuceneParseException
      */
-    public Pager<SearchResult<TaxonBase>> findByFullText(Class<? extends TaxonBase> clazz, String queryString, Classification classification,
-            List<Language> languages, boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
-            List<String> propertyPaths) throws IOException, LuceneParseException;
+    public Pager<SearchResult<TaxonBase>> findByFullText(Class<? extends TaxonBase> clazz, String queryString,
+            Classification classification, TaxonNode subtree,
+            boolean includeUnpublished, List<Language> languages,
+            boolean highlightFragments, Integer pageSize, Integer pageNumber,
+            List<OrderHint> orderHints, List<String> propertyPaths)
+                    throws IOException, LuceneParseException;
 
 
     /**
@@ -596,8 +620,9 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * @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;
 
@@ -616,7 +641,9 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *            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
@@ -648,7 +675,8 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      */
     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;
 
@@ -664,14 +692,18 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      *            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
@@ -695,23 +727,8 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * @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;
-
-
-    /**
-     *
-     * @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);
-
+    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;
 
     /**
      * Lists all Media found in an any TaxonDescription associated with this
@@ -774,11 +791,11 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      * an accepted taxon are counted
      * @return the number of synonyms
      */
-    public int countSynonyms(boolean onlyAttachedToTaxon);
+    public long countSynonyms(boolean onlyAttachedToTaxon);
 
     public List<TaxonName> findIdenticalTaxonNames(List<String> propertyPath);
 
-    public List<TaxonName> findIdenticalTaxonNameIds(List<String> propertyPath);
+    public List<UUID> findIdenticalTaxonNameIds(List<String> propertyPath);
 //
 //    public String getPhylumName(TaxonName name);
 
@@ -842,9 +859,9 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
 
     public Taxon findBestMatchingTaxon(MatchingTaxonConfigurator config);
 
-    public Synonym findBestMatchingSynonym(String taxonName);
+    public Synonym findBestMatchingSynonym(String taxonName, boolean includeUnpublished);
 
-     public List<UuidAndTitleCache<IdentifiableEntity>> findTaxaAndNamesForEditor(IFindTaxaAndNamesConfigurator configurator);
+     public List<UuidAndTitleCache<? extends IdentifiableEntity>> findTaxaAndNamesForEditor(IFindTaxaAndNamesConfigurator configurator);
 
     /**
      * Creates the specified inferred synonyms for the taxon in the classification, but do not insert it to the database
@@ -863,7 +880,8 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
      */
     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);
 
@@ -910,9 +928,10 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
     /**
      * @param synonymUUid
      * @param acceptedTaxonUuid
+     * @param setNameInSource
      * @return
      */
-    public UpdateResult swapSynonymAndAcceptedTaxon(UUID synonymUUid, UUID acceptedTaxonUuid);
+    public UpdateResult swapSynonymAndAcceptedTaxon(UUID synonymUUid, UUID acceptedTaxonUuid, boolean setNameInSource);
 
     /**
      * @param taxonUuid
@@ -949,6 +968,35 @@ public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
     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.
+     * @param taxonUuid
+     * @param directTypes
+     * @param inversTypes
+     * @param direction
+     * @param groupMisapplications
+     * @param includeUnpublished
+     * @param pageSize
+     * @param pageNumber
+     * @return
+     */
+    public TaxonRelationshipsDTO listTaxonRelationships(UUID taxonUuid,
+            Set<TaxonRelationshipType> directTypes,
+            Set<TaxonRelationshipType> inversTypes, Direction direction, boolean groupMisapplications,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber);
+
+    /**
+     * @param clazz
+     * @param restrictions
+     * @param pageSize
+     * @param pageIndex
+     * @param orderHints
+     * @param propertyPaths
+     * @param includeUnpublished
+     * @return
+     */
+    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);