#4313 relationship type as additinal filter option for TaxonNodeAgentRelation services
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 18 Nov 2015 09:55:18 +0000 (10:55 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 18 Nov 2015 09:56:08 +0000 (10:56 +0100)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonNodeDaoHibernateImpl.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonNodeDao.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/AgentController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/AgentPortalController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonController.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonNodeService.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java

index 33f36707c51f6e5a99c8d734294de1a8bc2a9821..a6a7039ee731cf4d33f450fe4d7cbafd860fcff7 100644 (file)
@@ -152,10 +152,10 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
      */\r
     @Override\r
     public List<TaxonNodeAgentRelation> listTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid,\r
-            UUID agentUuid, UUID rankUuid, Integer start, Integer limit, List<String> propertyPaths) {\r
+            UUID agentUuid, UUID rankUuid, UUID relTypeUuid, Integer start, Integer limit, List<String> propertyPaths) {\r
 \r
 \r
-        StringBuilder hql = prepareListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, false);\r
+        StringBuilder hql = prepareListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, relTypeUuid, false);\r
 \r
         Query query =  getSession().createQuery(hql.toString());\r
 \r
@@ -166,7 +166,7 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
             }\r
         }\r
 \r
-        setParamsForListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, query);\r
+        setParamsForListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, relTypeUuid, query);\r
 \r
         List<TaxonNodeAgentRelation> records = query.list();\r
 \r
@@ -179,12 +179,12 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
      * {@inheritDoc}\r
      */\r
     @Override\r
-    public long countTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid) {\r
+    public long countTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid, UUID relTypeUuid) {\r
 \r
-        StringBuilder hql = prepareListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, true);\r
+        StringBuilder hql = prepareListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, relTypeUuid, true);\r
         Query query =  getSession().createQuery(hql.toString());\r
 \r
-        setParamsForListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, query);\r
+        setParamsForListTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, relTypeUuid, query);\r
 \r
         Long count = Long.parseLong(query.uniqueResult().toString());\r
 \r
@@ -194,12 +194,13 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
      * @param taxonUuid\r
      * @param classificationUuid\r
      * @param agentUuid\r
+     * @param relTypeUuid TODO\r
+     * @param doCount TODO\r
      * @param rankId\r
      *     limit to taxa having this rank, only applies if <code>taxonUuid = null</code>\r
-     * @param doCount TODO\r
      * @return\r
      */\r
-    private StringBuilder prepareListTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid, boolean doCount) {\r
+    private StringBuilder prepareListTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid, UUID relTypeUuid, boolean doCount) {\r
 \r
         StringBuilder hql = new StringBuilder();\r
 \r
@@ -224,13 +225,18 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
         hql.append(" join tn.classification as c ");\r
         if(agentUuid != null) {\r
             // agentUuid is search filter, do not fetch it\r
-            hql.append(" join tnar.agent as a ");\r
+//            hql.append(" join tnar.agent as a ");\r
+            hql.append(join_fetch_mode).append(" tnar.agent as a ");\r
         } else {\r
             hql.append(join_fetch_mode).append(" tnar.agent as a ");\r
         }\r
 \r
         hql.append(" where 1 = 1 ");\r
 \r
+        if(relTypeUuid != null) {\r
+            hql.append(" and tnar.type.uuid = :relTypeUuid ");\r
+        }\r
+\r
         if(taxonUuid != null) {\r
             hql.append(" and t.uuid = :taxonUuid ");\r
         } else {\r
@@ -252,11 +258,12 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
      * @param taxonUuid\r
      * @param classificationUuid\r
      * @param agentUuid\r
-     * @param rankId TODO\r
+     * @param relTypeUuid TODO\r
      * @param query\r
+     * @param rankId TODO\r
      */\r
     private void setParamsForListTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid,\r
-            UUID rankUuid, Query query) {\r
+            UUID rankUuid, UUID relTypeUuid, Query query) {\r
 \r
         if(taxonUuid != null) {\r
             query.setParameter("taxonUuid", taxonUuid);\r
@@ -271,6 +278,9 @@ public class TaxonNodeDaoHibernateImpl extends AnnotatableDaoImpl<TaxonNode>
         if(agentUuid != null) {\r
             query.setParameter("agentUuid", agentUuid);\r
         }\r
+        if(relTypeUuid != null) {\r
+            query.setParameter("relTypeUuid", relTypeUuid);\r
+        }\r
     }\r
 \r
 }\r
index ef7d4282da2526d2f657ef85846f62defbb8e74d..dd1a8a00175a6b24eccd610e7d3c115e73cc7b4d 100644 (file)
@@ -47,15 +47,16 @@ public interface ITaxonNodeDao extends IAnnotatableDao<TaxonNode> {
      *\r
      * @param taxonUuid\r
      * @param agentUuid TODO\r
-     * @param rankId TODO\r
+     * @param relTypeUuid TODO\r
      * @param start\r
      * @param limit\r
      * @param propertyPaths\r
+     * @param rankId TODO\r
      * @param classification\r
      * @return\r
      */\r
     public List<TaxonNodeAgentRelation> listTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid,\r
-            UUID agentUuid, UUID rankUuid, Integer start, Integer limit, List<String> propertyPaths);\r
+            UUID agentUuid, UUID rankUuid, UUID relTypeUuid, Integer start, Integer limit, List<String> propertyPaths);\r
 \r
     /**\r
      * Returns the number of TaxonNodeAgentRelation entities which are associated with the TaxonNode for the\r
@@ -63,11 +64,12 @@ public interface ITaxonNodeDao extends IAnnotatableDao<TaxonNode> {
      *\r
      * @param taxonUuid\r
      * @param agentUuid TODO\r
+     * @param relTypeUuid TODO\r
      * @param rankId TODO\r
      * @param classification\r
      * @return\r
      */\r
-    public long countTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid);\r
+    public long countTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid, UUID agentUuid, UUID rankUuid, UUID relTypeUuid);\r
 \r
 \r
 }\r
index e86b3609ef021c361ba9cbe29f5a9b32baf2e47a..5de663e7c9329aeebff9e91a5c704243a4fefe0f 100644 (file)
@@ -79,9 +79,13 @@ public class AgentController extends BaseController<AgentBase, IAgentService>
     private static final List<String> TAXONNODEAGENTRELATIONS_INIT_STRATEGY = Arrays.asList(new String[]{\r
             // NOTE: all other cases are covered in the TaxonNodeDaoHibernateImpl method\r
             // which is using join fetches\r
-            "taxonNode.taxon.name.nomenclaturalReference"\r
+            "taxonNode.taxon.name.nomenclaturalReference",\r
             });\r
 \r
+    public List<String> getTaxonNodeAgentRelationsInitStrategy() {\r
+        return TAXONNODEAGENTRELATIONS_INIT_STRATEGY;\r
+    }\r
+\r
     @Autowired\r
     private ITaxonNodeService nodeService;\r
 \r
@@ -144,6 +148,8 @@ public class AgentController extends BaseController<AgentBase, IAgentService>
     public Pager<TaxonNodeAgentRelation>  doGetTaxonNodeAgentRelations(\r
             @PathVariable("uuid") UUID uuid,\r
             @RequestParam(value = "classification_uuid" , required = false) UUID classificationUuid,\r
+            @RequestParam(value = "taxon_uuid" , required = false) UUID taxonUuid,\r
+            @RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,\r
             @RequestParam(value = "rank" , required = false) Rank rank,\r
             @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
             @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
@@ -157,8 +163,8 @@ public class AgentController extends BaseController<AgentBase, IAgentService>
         if(rank != null) {\r
             rankUuid = rank.getUuid();\r
         }\r
-        Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(null, classificationUuid, uuid,\r
-                rankUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), TAXONNODEAGENTRELATIONS_INIT_STRATEGY);\r
+        Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(taxonUuid, classificationUuid, uuid,\r
+                rankUuid, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), getTaxonNodeAgentRelationsInitStrategy());\r
         return pager;\r
     }\r
 \r
index 22f0dedf0f2c4c6291149c1058249842713953d6..4e04e5f6e0222a071986cbe48ff4dd20d0bf15f1 100644 (file)
@@ -28,18 +28,35 @@ import com.wordnik.swagger.annotations.Api;
 public class AgentPortalController extends AgentController {
 
     private static final List<String> TEAM_OR_PERSON_BASE_INIT_STRATEGY = Arrays.asList(new String[]{
+            // NOTE: all other cases are covered in the TaxonNodeDaoHibernateImpl method
+            // which is using join fetches
             // AgentBase
-//            "contact.urls",
-//            "contact#phoneNumbers",
-//            "contact#addresses",
-//            "contact#faxNumbers",
-//            "contact#emailAddresses",
+            "contact.*",
             // Person
             "institutionalMemberships.$",
+            "institutionalMemberships.institute.contact.*",
             // Team
             "teamMembers.$"
     });
 
+    private static final List<String> TAXONNODEAGENTRELATIONS_INIT_STRATEGY = Arrays.asList(new String[]{
+            // NOTE: all other cases are covered in the TaxonNodeDaoHibernateImpl method
+            // which is using join fetches
+            "taxonNode.taxon.name.nomenclaturalReference",
+            // AgentBase
+            "agent.contact.*",
+            // Person
+            "agent.institutionalMemberships.$",
+            "agent.institutionalMemberships.institute.contact.*",
+            // Team
+            "agent.teamMembers.$"
+            });
+
+    @Override
+    public List<String> getTaxonNodeAgentRelationsInitStrategy() {
+        return TAXONNODEAGENTRELATIONS_INIT_STRATEGY;
+    }
+
     /**
     *
     */
index 55c5eaee596d87510d50603116050b7c89af9ce3..d8e7f7eeb6ac52d352763cd0334b3ac3f85815ad 100644 (file)
@@ -207,6 +207,7 @@ public class TaxonController extends BaseController<TaxonBase, ITaxonService>
     public Pager<TaxonNodeAgentRelation>  doGetTaxonNodeAgentRelations(\r
             @PathVariable("uuid") UUID uuid,\r
             @PathVariable("classification_uuid") UUID classificationUuid,\r
+            @RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,\r
             @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
             @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
             HttpServletRequest request,\r
@@ -216,7 +217,7 @@ public class TaxonController extends BaseController<TaxonBase, ITaxonService>
         pagerParams.normalizeAndValidate(response);\r
 \r
         Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(uuid, classificationUuid,\r
-                null, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), null);\r
+                null, null, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), null);\r
         return pager;\r
     }\r
 \r
index 5863916b1940f73baab587a4968cba3997a6b3c0..9b0946b9bc72c0cdf5058a969eb617f6a8a1c2fb 100644 (file)
@@ -146,11 +146,12 @@ public interface ITaxonNodeService extends IAnnotatableService<TaxonNode>{
      * @param taxonUuid
      * @param agentUuid TODO
      * @param rankUuid TODO
+     * @param relTypeUuid TODO
      * @param classification
      * @return
      */
     public Pager<TaxonNodeAgentRelation> pageTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid,
-            UUID agentUuid, UUID rankUuid, Integer pageSize, Integer pageIndex, List<String> propertyPaths);
+            UUID agentUuid, UUID rankUuid, UUID relTypeUuid, Integer pageSize, Integer pageIndex, List<String> propertyPaths);
 
 
 }
index 336aafc82217484689bc64e8d0b50a28b085e038..c6abe2ab20bf81027ebb666b68a1b23dda8eb73a 100644 (file)
@@ -552,15 +552,15 @@ public class TaxonNodeServiceImpl extends AnnotatableServiceBase<TaxonNode, ITax
 
     @Override
     public Pager<TaxonNodeAgentRelation> pageTaxonNodeAgentRelations(UUID taxonUuid, UUID classificationUuid,
-            UUID agentUuid, UUID rankUuid, Integer pageSize, Integer pageIndex, List<String> propertyPaths) {
+            UUID agentUuid, UUID rankUuid, UUID relTypeUuid, Integer pageSize, Integer pageIndex, List<String> propertyPaths) {
 
 
         List<TaxonNodeAgentRelation> records = null;
 
-        long count = dao.countTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid);
+        long count = dao.countTaxonNodeAgentRelations(taxonUuid, classificationUuid, agentUuid, rankUuid, relTypeUuid);
         if(PagerUtils.hasResultsInRange(count, pageIndex, pageSize)) {
             records = dao.listTaxonNodeAgentRelations(taxonUuid, classificationUuid,
-                    agentUuid, rankUuid, PagerUtils.startFor(pageSize, pageIndex), PagerUtils.limitFor(pageSize), propertyPaths);
+                    agentUuid, rankUuid, relTypeUuid, PagerUtils.startFor(pageSize, pageIndex), PagerUtils.limitFor(pageSize), propertyPaths);
         }
 
         Pager<TaxonNodeAgentRelation> pager = new DefaultPagerImpl<TaxonNodeAgentRelation>(pageIndex, count, pageSize, records);