Add new service method listDerminationEvents to occurrence service which
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 17 Nov 2015 15:32:20 +0000 (16:32 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 17 Nov 2015 15:32:35 +0000 (16:32 +0100)
lists all determination events that contain the given specimen

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/occurrence/OccurrenceDaoHibernateImpl.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/occurrence/IOccurrenceDao.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java

index 338077bbda510eb02c1db753820ce8aa1aae0524..78ba2fb224edef1249678c2db3c934a031f130d8 100644 (file)
@@ -674,6 +674,39 @@ public class OccurrenceDaoHibernateImpl extends IdentifiableDaoBase<SpecimenOrOb
         return results;\r
     }\r
 \r
+    @Override\r
+    public Collection<DeterminationEvent> listDeterminationEvents(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {\r
+        String queryString = "FROM DeterminationEvent determination WHERE determination.identifiedUnit = :specimen";\r
+\r
+        if(orderHints != null && orderHints.size() > 0){\r
+            queryString += " order by ";\r
+            String orderStr = "";\r
+            for(OrderHint orderHint : orderHints){\r
+                if(orderStr.length() > 0){\r
+                    orderStr += ", ";\r
+                }\r
+                queryString += "determination." + orderHint.getPropertyName() + " " + orderHint.getSortOrder().toHql();\r
+            }\r
+            queryString += orderStr;\r
+        }\r
+\r
+        Query query = getSession().createQuery(queryString);\r
+        query.setParameter("specimen", specimen);\r
+\r
+        if(limit != null) {\r
+            if(start != null) {\r
+                query.setFirstResult(start);\r
+            } else {\r
+                query.setFirstResult(0);\r
+            }\r
+            query.setMaxResults(limit);\r
+        }\r
+\r
+        List results = query.list();\r
+        defaultBeanInitializer.initializeAll(results, propertyPaths);\r
+        return results;\r
+    }\r
+\r
     @Override\r
     public Collection<SpecimenTypeDesignation> listTypeDesignations(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {\r
         String queryString = "FROM SpecimenTypeDesignation designations WHERE designations.typeSpecimen = :specimen";\r
index 3401b1429f1886c61449d4a6f87972b72ebca1c7..f034f5b45862fbb61463e79dfe0110803bd39f86 100644 (file)
@@ -288,6 +288,27 @@ public interface IOccurrenceDao extends IIdentifiableDao<SpecimenOrObservationBa
      */\r
        public Collection<IndividualsAssociation> listIndividualsAssociations(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
 \r
+       /**\r
+        * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimen as a type specimen.\r
+        * @param specimen the type specimen\r
+        * @param limit\r
+        * @param start\r
+        * @param orderHints\r
+        * @param propertyPaths\r
+        * @return collection of all designations with the given type specimen\r
+        */\r
+\r
+       /**\r
+     * Retrieves all {@link DeterminationEvent}s which have the given specimen set as identified unit.\r
+        * @param specimen\r
+        * @param limit\r
+        * @param start\r
+        * @param orderHints\r
+        * @param propertyPaths\r
+        * @return collection of all determinations with the given specimen\r
+        */\r
+    public Collection<DeterminationEvent> listDeterminationEvents(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
+\r
     /**\r
      * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimen as a type specimen.\r
      * @param specimen the type specimen\r
index 3cb381a696a47c4d84c3a306124ac299738e7dc8..3ec0bba705f0e45ce410934d47191f4109c7b684 100644 (file)
@@ -459,6 +459,17 @@ public interface IOccurrenceService extends IIdentifiableEntityService<SpecimenO
      */\r
     public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
 \r
+    /**\r
+     * Retrieves all {@link DeterminationEvent}s which have the given specimen set as identified unit.\r
+     * @param specimen the type specimen\r
+     * @param limit\r
+     * @param start\r
+     * @param orderHints\r
+     * @param propertyPaths\r
+     * @return collection of all designations with the given type specimen\r
+     */\r
+    public Collection<DeterminationEvent> listDeterminationEvents(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);\r
+\r
     /**\r
      * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimen as a type specimen.\r
      * @param specimen the type specimen\r
index c2fc33f921fe101fadff0f08f38031243fd24b72..dc8d46d7da2268b7a985d70e03e6216bc6772519 100644 (file)
@@ -1270,12 +1270,15 @@ public class OccurrenceServiceImpl extends IdentifiableServiceBase<SpecimenOrObs
     @Override
     public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start,
             List<OrderHint> orderHints, List<String> propertyPaths) {
-        //individuals associations
         Collection<TaxonBase<?>> associatedTaxa = new HashSet<TaxonBase<?>>();
+
+        //individuals associations
         for (IndividualsAssociation individualsAssociation : listIndividualsAssociations(specimen, limit, start, orderHints, propertyPaths)) {
             if(individualsAssociation.getInDescription().isInstanceOf(TaxonDescription.class)){
                 TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(individualsAssociation.getInDescription(), TaxonDescription.class);
-                associatedTaxa.add(taxonDescription.getTaxon());
+                if(taxonDescription.getTaxon()!=null){
+                    associatedTaxa.add(taxonDescription.getTaxon());
+                }
             }
         }
         //type designation
@@ -1288,9 +1291,28 @@ public class OccurrenceServiceImpl extends IdentifiableServiceBase<SpecimenOrObs
                 }
             }
         }
+        //determinations
+        Collection<DeterminationEvent> determinationEvents = new HashSet<DeterminationEvent>();
+        for (DeterminationEvent determinationEvent : listDeterminationEvents(specimen, limit, start, orderHints, propertyPaths)) {
+            if(determinationEvent.getIdentifiedUnit().equals(specimen)){
+                if(determinationEvent.getTaxon()!=null){
+                    associatedTaxa.add(determinationEvent.getTaxon());
+                }
+                if(determinationEvent.getTaxonName()!=null){
+                    associatedTaxa.addAll(determinationEvent.getTaxonName().getTaxonBases());
+                }
+            }
+        }
+
         return associatedTaxa;
     }
 
+    @Override
+    public Collection<DeterminationEvent> listDeterminationEvents(SpecimenOrObservationBase<?> specimen,
+            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
+        return dao.listDeterminationEvents(specimen, limit, start, orderHints, propertyPaths);
+    }
+
     @Override
     public Collection<SpecimenTypeDesignation> listTypeDesignations(SpecimenOrObservationBase<?> specimen,
             Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {