ref #9222 ref #6581 adapting web services to single sourced classes
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 9 Sep 2020 08:07:32 +0000 (10:07 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 9 Sep 2020 08:07:32 +0000 (10:07 +0200)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/initializer/EntityInitStrategy.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/NameController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/NamePortalController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/NomenclaturalStatusController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonPortalController.java
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml

index 2763d91c579b2887c138c7751c63405a677fca4e..6c65dff98744d7d33e85f7b79eb2c2b9ae59d381 100644 (file)
@@ -11,6 +11,7 @@ package eu.etaxonomy.cdm.persistence.dao.initializer;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang3.StringUtils;
 
@@ -43,20 +44,32 @@ public class EntityInitStrategy {
     }
 
     /**
-     * Extends the property base bath by all property definitions in the <code>extensions</code>.
+     * Extends the property base bath by all property definitions in the
+     * <code>extensions</code> and adds the resulting property path to the
+     * EntityInitStrategy.
+     * <p>
+     * Potential duplicate property paths de-duplicated.
      *
-     * @param basePath can be NUll or empty to just append the extensions to the init strategies.
+     * @param basePath
+     *            can be NUll or empty to just append the extensions to the init
+     *            strategies.
      * @param extensions
      * @param basePathIsCollection
      */
-    public EntityInitStrategy extend(String basePath, EntityInitStrategy extensions, boolean basePathIsCollection){
+    public EntityInitStrategy extend(String basePath, EntityInitStrategy extensions, boolean basePathIsCollection) {
         return extend(basePath, extensions.getPropertyPaths(), basePathIsCollection);
     }
 
     /**
-     * Extends the property base bath by all property definitions in the <code>extensions</code>.
+     * Extends the property base bath by all property definitions in the
+     * <code>extensions</code> and adds the resulting property path to the
+     * EntityInitStrategy.
+     * <p>
+     * Potential duplicate property paths de-duplicated.
      *
-     * @param basePath can be NUll or empty to just append the extensions to the init strategies.
+     * @param basePath
+     *            can be NUll or empty to just add the extensions to the init
+     *            strategies.
      * @param extensions
      * @param basePathIsCollection
      */
@@ -73,6 +86,7 @@ public class EntityInitStrategy {
                 propertyPaths.add(appendix);
             }
         }
+        propertyPaths = propertyPaths.stream().distinct().collect(Collectors.toList());
         return this;
     }
 
index 7b18d14dfee3c71ffa8ebf1d8bc024fd494d5779..cde5f7b1212992f6b45480045e90f4bcb268ad68 100644 (file)
@@ -77,6 +77,7 @@ public class NameController extends AbstractIdentifiableController<TaxonName, IN
 \r
     public static final EntityInitStrategy NAME_RELATIONS_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{\r
             "$",\r
+            "source.citation",\r
             "relationsFromThisName.$",\r
             "relationsFromThisName.toName.registrations",\r
             "relationsToThisName.$",\r
index 408eea213d11ba6315b135a1518585345f65b030..2af5a24a210ee0a6c744b8a0cb5f73eb4a6449e8 100644 (file)
@@ -15,6 +15,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -70,6 +71,8 @@ public class NamePortalController extends BaseController<TaxonName, INameService
 
     private static final Logger logger = Logger.getLogger(NamePortalController.class);
 
+    private static final EntityInitStrategy DEFAULT_INIT_STRATEGY =  new EntityInitStrategy("$", "nomenclaturalSource.citation");
+
     private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = TypeDesignationPortalController.DEFAULT_INIT_STRATEGY;
 
 
@@ -88,9 +91,6 @@ public class NamePortalController extends BaseController<TaxonName, INameService
 
     private static EntityInitStrategy nameRelationsInitStrategy = null;
 
-    /**
-     * @return the nameRelationsInitStrategy
-     */
     public static EntityInitStrategy getNameRelationsInitStrategy() {
         if(nameRelationsInitStrategy == null){
             nameRelationsInitStrategy = extendNameRelationsInitStrategies(NameController.NAME_RELATIONS_INIT_STRATEGY.getPropertyPaths(), true);
@@ -98,6 +98,9 @@ public class NamePortalController extends BaseController<TaxonName, INameService
         return nameRelationsInitStrategy;
     }
 
+    public NamePortalController() {
+        setInitializationStrategy(DEFAULT_INIT_STRATEGY.getPropertyPaths());
+    }
 
     @Override
     protected <CDM_BASE extends CdmBase> List<String> complementInitStrategy(Class<CDM_BASE> clazz,
@@ -106,16 +109,10 @@ public class NamePortalController extends BaseController<TaxonName, INameService
         if(pathProperties == null){
             return pathProperties;
         }
-
         EntityInitStrategy initStrategy = extendNameRelationsInitStrategies(pathProperties, false);
-
         return initStrategy.getPropertyPaths();
     }
 
-    /**
-     * @param pathProperties
-     * @return
-     */
     static EntityInitStrategy extendNameRelationsInitStrategies(List<String> pathProperties, boolean addNomrefInitStrategy) {
 
         EntityInitStrategy initStrategy = new EntityInitStrategy(pathProperties);
@@ -127,27 +124,30 @@ public class NamePortalController extends BaseController<TaxonName, INameService
             nameRelInitExtendet.extend("fromName", NOMREF_INIT_STRATEGY.getPropertyPaths(), false);
         }
 
-        if(pathProperties.contains("nameRelations")){
+        List<String> transtientNameRelationsInitstrategies = initStrategy.getPropertyPaths()
+                .stream()
+                .filter(s -> s.startsWith("nameRelations"))
+                .collect(Collectors.toList());
+        if(!transtientNameRelationsInitstrategies.isEmpty()){
             // nameRelations is a transient property! replace it by relationsFromThisName and relationsToThisName
-            initStrategy.getPropertyPaths().remove("nameRelations");
+            for(String remove : transtientNameRelationsInitstrategies) {
+                initStrategy.getPropertyPaths().remove(remove);
+            }
             initStrategy.extend("relationsFromThisName", nameRelInitExtendet.getPropertyPaths(), true);
             initStrategy.extend("relationsToThisName", nameRelInitExtendet.getPropertyPaths(), true);
         } else {
-            if(pathProperties.contains("relationsFromThisName")){
-                initStrategy.getPropertyPaths().remove("relationsFromThisName");
+            if(pathProperties.stream().anyMatch(s -> s.startsWith("relationsFromThisName"))){
+                initStrategy.getPropertyPaths().remove("relationsFromThisName"); // remove the very simple one
                 initStrategy.extend("relationsFromThisName", nameRelInitExtendet.getPropertyPaths(), true);
             }
-            if(pathProperties.contains("relationsToThisName")){
-                initStrategy.getPropertyPaths().remove("relationsToThisName");
+            if(pathProperties.stream().anyMatch(s -> s.startsWith("relationsToThisName"))){
+                initStrategy.getPropertyPaths().remove("relationsToThisName"); // remove the very simple one
                 initStrategy.extend("relationsToThisName", nameRelInitExtendet.getPropertyPaths(), true);
             }
         }
         return initStrategy;
     }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
-     */
     @Autowired
     @Override
     public void setService(INameService service) {
index 0d91f436c57bc7bdf92d9967f0cb00ceaf0ee0ac..c8c8ee578743990875eec04fbe22bb7754d49658 100644 (file)
@@ -61,7 +61,7 @@ public class NomenclaturalStatusController extends AbstractController<TaxonName,
 
         logger.info("doGet() - " + requestPathAndQuery(request));
 
-        NomenclaturalStatus nomstatus = service.loadNomenclaturalStatus(uuid, Arrays.asList("$", "citation.inReference"));
+        NomenclaturalStatus nomstatus = service.loadNomenclaturalStatus(uuid, Arrays.asList("$", "source.citation.inReference"));
         if(nomstatus == null){
             HttpStatusMessage.UUID_NOT_FOUND.send(response);
         }
index dfb1d37045ceb899f89727f45bf0787b9683c6e0..e4f1cb51e44a81bb34a3452886d83815afb28a1f 100644 (file)
@@ -121,6 +121,7 @@ public class TaxonPortalController extends TaxonController{
             "name.nomenclaturalSource.citation.inReference",
             "name.rank.representations",
             "name.status.type.representations",
+            "name.status.source.citation",
             "sec.authorship"
 //            "descriptions" // TODO remove
 
@@ -138,6 +139,7 @@ public class TaxonPortalController extends TaxonController{
             "name.$",
             "name.rank.representations",
             "name.status.type.representations",
+            "name.status.source.citation",
             "name.nomenclaturalSource.citation.authorship",
             "name.nomenclaturalSource.citation.inReference.authorship",
             "taxonNodes.classification",
@@ -148,6 +150,7 @@ public class TaxonPortalController extends TaxonController{
             // initialize homotypical and heterotypical groups; needs synonyms
             "synonyms.$",
             "synonyms.name.status.type.representations",
+            "synonyms.name.status.source.citation",
             "synonyms.name.nomenclaturalSource.citation.authorship",
             "synonyms.name.nomenclaturalSource.citation.inReference",
 //            "synonyms.name.homotypicalGroup.typifiedNames.$",
@@ -176,7 +179,7 @@ public class TaxonPortalController extends TaxonController{
     public static final EntityInitStrategy NAMERELATIONSHIP_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
             "$",
             "type.inverseRepresentations",
-            "citation",
+            "source.citation",
             "toName.$",
             "toName.nomenclaturalSource.citation.authorship",
             "toName.nomenclaturalSource.citation.inReference",
index e3ccd1822ab4d7095a005b2cd4392776b57519c7..7a3c21bb699d75c5f7509ce93a98b1a44691aefd 100644 (file)
@@ -25,7 +25,8 @@
              <value>TermNode.children</value>
              <value>TermNode.feature</value>
 
-            <value>NomenclaturalStatus.citation</value>
+             <value>NomenclaturalStatus.source</value>
+             <value>DescriptionElementSource.citation</value>
 
              <value>TreeNode.data</value>
              <value>TreeNode.data</value>