- added service for retrieving all "associatied" FieldUnits for a taxon
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / IOccurrenceService.java
index 55cd5244b36d5b2fdf532b04f6bcbb237bca4b1c..7375b123957b4e18d9bdd81b46c16a638d7837a0 100644 (file)
 package eu.etaxonomy.cdm.api.service;\r
 \r
 import java.io.IOException;\r
+import java.util.Collection;\r
 import java.util.List;\r
 import java.util.Set;\r
+import java.util.UUID;\r
 \r
 import org.apache.lucene.index.CorruptIndexException;\r
 import org.apache.lucene.queryParser.ParseException;\r
@@ -20,6 +22,7 @@ import org.hibernate.search.spatial.impl.Rectangle;
 \r
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;\r
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;\r
+import eu.etaxonomy.cdm.api.service.dto.DerivateHierarchyDTO;\r
 import eu.etaxonomy.cdm.api.service.pager.Pager;\r
 import eu.etaxonomy.cdm.api.service.search.SearchResult;\r
 import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;\r
@@ -28,19 +31,21 @@ import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;\r
 import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
-import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;\r
+import eu.etaxonomy.cdm.model.location.Country;\r
 import eu.etaxonomy.cdm.model.media.Media;\r
+import eu.etaxonomy.cdm.model.molecular.DnaSample;\r
+import eu.etaxonomy.cdm.model.molecular.Sequence;\r
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;\r
 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
-import eu.etaxonomy.cdm.model.occurrence.FieldObservation;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;\r
-import eu.etaxonomy.cdm.persistence.dao.IBeanInitializer;\r
+import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;\r
 import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
 \r
 /**\r
@@ -49,9 +54,9 @@ import eu.etaxonomy.cdm.persistence.query.OrderHint;
  */\r
 public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenOrObservationBase> {\r
 \r
-    public WaterbodyOrCountry getCountryByIso(String iso639);\r
+    public Country getCountryByIso(String iso639);\r
 \r
-    public List<WaterbodyOrCountry> getWaterbodyOrCountryByName(String name);\r
+    public List<Country> getCountryByName(String name);\r
 \r
     /**\r
      * Returns a paged list of occurrences that have been determined to belong\r
@@ -97,6 +102,15 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
      */\r
     public Pager<Media> getMedia(SpecimenOrObservationBase occurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths);\r
 \r
+    /**\r
+     * Returns a count of determinations that have been made for a given occurence and for a given taxon concept\r
+     *\r
+     * @param occurence the occurence associated with these determinations (can be null for all occurrences)\r
+     * @param taxonbase the taxon concept associated with these determinations (can be null for all taxon concepts)\r
+     * @return a count of determination events\r
+     */\r
+    public int countDeterminations(SpecimenOrObservationBase occurence,TaxonBase taxonbase);\r
+\r
     /**\r
      * Returns a List of determinations that have been made for a given occurence\r
      *\r
@@ -136,8 +150,18 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
     @Override\r
     public Pager<SpecimenOrObservationBase> search(Class<? extends SpecimenOrObservationBase> clazz, String query, Integer pageSize,Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths);\r
 \r
-    public List<UuidAndTitleCache<FieldObservation>> getFieldObservationUuidAndTitleCache();\r
+    /**\r
+     * Retrieves the {@link UUID} and the string representation (title cache) of all\r
+     * {@link FieldUnit}s found in the data base.\r
+     * @return a list of {@link UuidAndTitleCache}\r
+     */\r
+    public List<UuidAndTitleCache<FieldUnit>> getFieldUnitUuidAndTitleCache();\r
 \r
+    /**\r
+     * Retrieves the {@link UUID} and the string representation (title cache) of all\r
+     * {@link DerivedUnit}s found in the data base.\r
+     * @return a list of {@link UuidAndTitleCache}\r
+     */\r
     public List<UuidAndTitleCache<DerivedUnit>> getDerivedUnitUuidAndTitleCache();\r
 \r
     public DerivedUnitFacade getDerivedUnitFacade(DerivedUnit derivedUnit, List<String> propertyPaths) throws DerivedUnitFacadeNotSupportedException;\r
@@ -178,6 +202,58 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
     public <T extends SpecimenOrObservationBase> List<T> listByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,\r
             Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);\r
 \r
+    /**\r
+     * Lists all instances of {@link FieldUnit} which are\r
+     * associated <b>directly or indirectly</b>with the <code>taxon</code> specified\r
+     * as parameter. "Indirectly" means that a sub derivate of the FieldUnit is\r
+     * directly associated with the given taxon.\r
+     * SpecimenOrObservationBase instances can be associated to taxa in multiple\r
+     * ways, all these possible relations are taken into account:\r
+     * <ul>\r
+     * <li>The {@link IndividualsAssociation} elements in a\r
+     * {@link TaxonDescription} contain {@link DerivedUnit}s</li>\r
+     * <li>{@link SpecimenTypeDesignation}s may be associated with any\r
+     * {@link HomotypicalGroup} related to the specific {@link Taxon}.</li>\r
+     * <li>A {@link Taxon} may be referenced by the {@link DeterminationEvent}\r
+     * of the {@link SpecimenOrObservationBase}</li>\r
+     * </ul>\r
+     * Further more there also can be taxa which are associated with the taxon\r
+     * in question (parameter associatedTaxon) by {@link TaxonRelationship}s. If\r
+     * the parameter <code>includeRelationships</code> is containing elements,\r
+     * these according {@TaxonRelationshipType}s and\r
+     * directional information will be used to collect further\r
+     * {@link SpecimenOrObservationBase} instances found this way.\r
+     *\r
+     * @param <T>\r
+     * @param type\r
+     * @param associatedTaxon\r
+     * @param Set<TaxonRelationshipVector> includeRelationships. TaxonRelationships will not be taken into account if this is <code>NULL</code>.\r
+     * @param maxDepth TODO\r
+     * @param pageSize\r
+     * @param pageNumber\r
+     * @param orderHints\r
+     * @param propertyPaths\r
+     * @return\r
+     */\r
+    public Collection<FieldUnit> listFieldUnitsByAssociatedTaxon(Set<TaxonRelationshipEdge> includeRelationships,\r
+            Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);\r
+\r
+    /**\r
+     * Assembles a {@link DerivateHierarchyDTO} for each "associated" {@link FieldUnit} found for the given {@link Taxon}.<br>\r
+     * <br>\r
+     * See also {@link #listFieldUnitsByAssociatedTaxon(Set, Taxon, Integer, Integer, Integer, List, List)}\r
+     * @param includeRelationships\r
+     * @param associatedTaxon\r
+     * @param maxDepth\r
+     * @param pageSize\r
+     * @param pageNumber\r
+     * @param orderHints\r
+     * @param propertyPaths\r
+     * @return\r
+     */\r
+    public Collection<DerivateHierarchyDTO> listDerivateHierarchyDTOsByAssociatedTaxon(Set<TaxonRelationshipEdge> includeRelationships,\r
+            Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);\r
+\r
     /**\r
      * See {@link #listByAssociatedTaxon(Class, Set, Taxon, Integer, Integer, Integer, List, List)}\r
      *\r
@@ -194,6 +270,14 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
     public <T extends SpecimenOrObservationBase> Pager<T> pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,\r
             Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);\r
 \r
+    /**\r
+     * Retrieves all {@link FieldUnit}s for the {@link SpecimenOrObservationBase} with the given {@link UUID}.<br>\r
+     * @param specimenUuid the UUID of the specimen\r
+     * @return either a collection of FieldUnits this specimen was derived from, the FieldUnit itself\r
+     * if this was a FieldUnit or an empty collection if no FieldUnits were found\r
+     */\r
+    public Collection<FieldUnit> getFieldUnits(UUID specimenUuid);\r
+\r
     /**\r
      * @param clazz\r
      * @param queryString\r
@@ -212,6 +296,38 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
             String queryString, Rectangle boundingBox, List<Language> languages, boolean highlightFragments, Integer pageSize,\r
             Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws CorruptIndexException,\r
             IOException, ParseException;\r
+    /**\r
+     * See {@link #listByAssociatedTaxon(Class, Set, String, Integer, Integer, Integer, List, List)}\r
+     *\r
+     * @param type\r
+     * @param includeRelationships\r
+     * @param associatedTaxon\r
+     * @param maxDepth\r
+     * @param pageSize\r
+     * @param pageNumber\r
+     * @param orderHints\r
+     * @param propertyPaths\r
+     * @return a Pager\r
+     */\r
+    public <T extends SpecimenOrObservationBase> Pager<T>  pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,\r
+            String taxonUUID, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);\r
 \r
+    /**\r
+     * Moves the given {@link Sequence} from one {@link DnaSample} to another\r
+     * @param from the DnaSample from which the sequence will be removed\r
+     * @param to the DnaSample which to which the sequence will be added\r
+     * @param sequence the Sequence to move\r
+     * @return <code>true</code> if successfully moved, <code>false</code> otherwise\r
+     */\r
+    public boolean moveSequence(DnaSample from, DnaSample to, Sequence sequence);\r
+\r
+    /**\r
+     * Moves the given {@link DerivedUnit} from one {@link SpecimenOrObservationBase} to another.\r
+     * @param from the SpecimenOrObservationBase from which the DerivedUnit will be removed\r
+     * @param to the SpecimenOrObservationBase to which the DerivedUnit will be added\r
+     * @param derivate the DerivedUnit to move\r
+     * @return <code>true</code> if successfully moved, <code>false</code> otherwise\r
+     */\r
+    public boolean moveDerivate(SpecimenOrObservationBase<?> from, SpecimenOrObservationBase<?> to, DerivedUnit derivate);\r
 \r
 }\r