ref #3560 fix includeUnpublished for taxon relationships and correct includePublished...
authorAndreas Müller <a.mueller@bgbm.org>
Thu, 14 Jun 2018 20:35:46 +0000 (22:35 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 14 Jun 2018 20:36:12 +0000 (22:36 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/RelationshipBase.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonDao.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonPortalController.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonService.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java

index 9772f60b6e148479b1ec6c64f5c9387fc9911b78..17ee5cabc480c6197a4a54200ace98da63e8200b 100644 (file)
@@ -48,7 +48,10 @@ import eu.etaxonomy.cdm.model.reference.Reference;
 @XmlRootElement(name = "RelationshipBase")
 @MappedSuperclass
 @Audited
-public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase> extends ReferencedEntityBase implements Cloneable {
+public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelated, TYPE extends RelationshipTermBase>
+        extends ReferencedEntityBase
+        implements Cloneable {
+
     private static final long serialVersionUID = -5030154633820061997L;
     @SuppressWarnings("unused")
     private static final Logger logger = Logger.getLogger(RelationshipBase.class);
@@ -69,7 +72,11 @@ public abstract class RelationshipBase<FROM extends IRelated, TO extends IRelate
         @XmlEnumValue("relatedFrom")
         relatedFrom,
         @XmlEnumValue("relatedTo")
-        relatedTo
+        relatedTo;
+
+        public Direction invers(){
+            return (this == relatedFrom)? relatedTo: relatedFrom;
+        }
     }
 
     protected RelationshipBase(){
index d7772ae4939e6dfd9e99f76f7e50869c2a56d4ce..4b5d96678d0756b0ec89ef20f91ef48a69183328 100755 (executable)
@@ -984,17 +984,17 @@ public class TaxonDaoHibernateImpl
 
     @Override
     public long countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Direction direction) {
+            boolean includeUnpublished, Direction direction) {
         AuditEvent auditEvent = getAuditEventFromContext();
         if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
 
-            String queryString = prepareTaxonRelationshipQuery(type, includePublished, direction, true);
+            String queryString = prepareTaxonRelationshipQuery(type, includeUnpublished, direction, true);
             Query query = getSession().createQuery(queryString);
             query.setParameter("relatedTaxon", taxon);
             if(type != null) {
                 query.setParameter("type",type);
             }
-            if(! includePublished) {
+            if(! includeUnpublished) {
                 query.setBoolean("publish",Boolean.TRUE);
             }
 
@@ -1027,12 +1027,12 @@ public class TaxonDaoHibernateImpl
 
     /**
      * @param type
-     * @param includePublished
+     * @param includeUnpublished
      * @param direction
      * @param b
      * @return
      */
-    private String prepareTaxonRelationshipQuery(TaxonRelationshipType type, boolean includePublished,
+    private String prepareTaxonRelationshipQuery(TaxonRelationshipType type, boolean includeUnpublished,
             Direction direction, boolean isCount) {
         String selectStr = isCount? " count(rel) as n ":" rel ";
         String result = "SELECT " + selectStr +
@@ -1041,21 +1041,21 @@ public class TaxonDaoHibernateImpl
         if (type != null){
             result += " AND rel.type = :type ";
         }
-        if(! includePublished) {
-            result += " AND rel."+direction+".publish = :publish";
+        if(! includeUnpublished) {
+            result += " AND rel."+direction.invers()+".publish = :publish";
         }
         return result;
     }
 
     @Override
     public List<TaxonRelationship> getTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
             List<String> propertyPaths, Direction direction) {
 
         AuditEvent auditEvent = getAuditEventFromContext();
         if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
 
-            String queryString = prepareTaxonRelationshipQuery(type, includePublished, direction, false);
+            String queryString = prepareTaxonRelationshipQuery(type, includeUnpublished, direction, false);
 
             queryString += orderByClause("rel", orderHints);
 
@@ -1064,7 +1064,7 @@ public class TaxonDaoHibernateImpl
             if(type != null) {
                 query.setParameter("type",type);
             }
-            if(! includePublished) {
+            if(! includeUnpublished) {
                 query.setBoolean("publish",Boolean.TRUE);
             }
             setPagingParameter(query, pageSize, pageNumber);
index 7dffdf908e5c4ae943fc4aa692706af0231514f8..7afecbf8908868292db095ebfa1f42b1573e89a0 100644 (file)
@@ -303,7 +303,7 @@ public interface ITaxonDao
      * @return the number of TaxonRelationship instances
      */
     public long countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Direction direction);
+            boolean includeUnpublished, Direction direction);
 
     /**
      * Returns the TaxonRelationships (of where relationship.type == type, if
@@ -332,7 +332,7 @@ public interface ITaxonDao
      * @return a List of TaxonRelationship instances
      */
     public List<TaxonRelationship> getTaxonRelationships(Taxon taxon,
-            TaxonRelationshipType type, boolean includePublished,
+            TaxonRelationshipType type, boolean includeUnpublished,
             Integer pageSize, Integer pageNumber,
             List<OrderHint> orderHints, List<String> propertyPaths,
             Direction direction);
index 7d5683ef9e9a18e03906cf7475d60199cede98f3..5bd1ea2e0dcc79080d928cbbdfc3aed5b7924174 100644 (file)
@@ -379,15 +379,15 @@ public class TaxonPortalController extends TaxonController{
     public List<TaxonRelationship> doGetTaxonRelations(@PathVariable("uuid") UUID uuid,
             HttpServletRequest request, HttpServletResponse response)throws IOException {
 
-        boolean includePublished = NO_UNPUBLISHED;
+        boolean includeUnpublished = NO_UNPUBLISHED;
         logger.info("doGetTaxonRelations()" + requestPathAndQuery(request));
         Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
-        taxon = checkExistsAndAccess(taxon, includePublished, response);
+        taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
 
         List<TaxonRelationship> toRelationships = service.listToTaxonRelationships(taxon, null,
-                includePublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
+                includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
         List<TaxonRelationship> fromRelationships = service.listFromTaxonRelationships(taxon, null,
-                includePublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
+                includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);
 
         List<TaxonRelationship> allRelationships = new ArrayList<>(toRelationships.size() + fromRelationships.size());
         allRelationships.addAll(toRelationships);
index 5e70248fa00627f4d1c42dff6bd1fce00b2df0a9..3121360836cd9f50266781549da5f28210ec2f18 100644 (file)
@@ -262,7 +262,7 @@ public interface ITaxonService
      *
      * @param taxon The taxon that is relatedTo
      * @param type The type of TaxonRelationship (can be null)
-     * @param includePublished should unpublished related taxa also be returned?
+     * @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
@@ -270,7 +270,7 @@ public interface ITaxonService
      * @return a List of TaxonRelationship instances
      */
     public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
 
     /**
@@ -279,7 +279,7 @@ public interface ITaxonService
      *
      * @param taxon The taxon that is relatedTo
      * @param type The type of TaxonRelationship (can be null)
-     * @param includePublished should unpublished related taxa also be returned?
+     * @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
@@ -287,7 +287,7 @@ public interface ITaxonService
      * @return a Pager of TaxonRelationship instances
      */
     public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+            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)
@@ -295,7 +295,7 @@ public interface ITaxonService
      *
      * @param taxon The taxon that is relatedFrom
      * @param type The type of TaxonRelationship (can be null)
-     * @param includePublished should unpublished related taxa also be returned?
+     * @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
@@ -303,7 +303,7 @@ public interface ITaxonService
      * @return a List of TaxonRelationship instances
      */
     public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
 
 
     /**
@@ -312,7 +312,7 @@ public interface ITaxonService
      *
      * @param taxon The taxon that is relatedFrom
      * @param type The type of TaxonRelationship (can be null)
-     * @param includePublished should unpublished related taxa also be returned?
+     * @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
@@ -320,7 +320,7 @@ public interface ITaxonService
      * @return a Pager of TaxonRelationship instances
      */
     public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
+            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
index c95293526c7db7ab0c4b785c4363d967fe565ba2..676fdbdea5c5dc6c2f1b423fbec8fefe5fa030f0 100644 (file)
@@ -441,48 +441,48 @@ public class TaxonServiceImpl
 
     @Override
     public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
-        long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedTo);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
+        long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedTo);
 
         List<TaxonRelationship> results = new ArrayList<>();
         if(numberOfResults > 0) { // no point checking again
-            results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
+            results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
         }
         return results;
     }
 
     @Override
     public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
-        long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedTo);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+        long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedTo);
 
         List<TaxonRelationship> results = new ArrayList<>();
         if(numberOfResults > 0) { // no point checking again
-            results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
+            results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedTo);
         }
         return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
     }
 
     @Override
     public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
-        long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedFrom);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
+        long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedFrom);
 
         List<TaxonRelationship> results = new ArrayList<>();
         if(numberOfResults > 0) { // no point checking again
-            results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
+            results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
         }
         return results;
     }
 
     @Override
     public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
-            boolean includePublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
-        long numberOfResults = dao.countTaxonRelationships(taxon, type, includePublished, TaxonRelationship.Direction.relatedFrom);
+            boolean includeUnpublished, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
+        long numberOfResults = dao.countTaxonRelationships(taxon, type, includeUnpublished, TaxonRelationship.Direction.relatedFrom);
 
         List<TaxonRelationship> results = new ArrayList<>();
         if(numberOfResults > 0) { // no point checking again
-            results = dao.getTaxonRelationships(taxon, type, includePublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
+            results = dao.getTaxonRelationships(taxon, type, includeUnpublished, pageSize, pageNumber, orderHints, propertyPaths, TaxonRelationship.Direction.relatedFrom);
         }
         return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
     }