]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CC-1302: Service binding parameter values not handled correctly for Nuxeo exent liste...
authorRichard Millet <remillet@yahoo.com>
Mon, 3 Aug 2020 16:37:00 +0000 (09:37 -0700)
committerRichard Millet <remillet@yahoo.com>
Wed, 5 Aug 2020 20:48:41 +0000 (13:48 -0700)
3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java
3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationAndCrateOnMove.java
3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml
services/common/src/main/java/org/collectionspace/services/nuxeo/listener/AbstractCSEventListenerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/listener/CSEventListener.java

index 696a4c081be259a26084b232eafc400c7b52f722..9df47d654e2074ae4bb2f58c82b28ec956401b01 100644 (file)
@@ -87,7 +87,7 @@ public abstract class AbstractUpdateObjectLocationValues extends AbstractCSEvent
         DocumentModel eventDocModel = docEventContext.getSourceDocument();        
         String eventType = event.getName();
         boolean isAboutToBeRemovedEvent = eventType.equals(DocumentEventTypes.ABOUT_TO_REMOVE);
-        
+
         //
         // Ensure this event relates to a relationship record (between cataloging and movement records) or a movement record.  If so, get the CSID
         // of the corresponding movement record.  Otherwise, exit.
index 7a40b9b166eeb23765fc2c33a5961f9a25c739f7..46a9c84c17304249d05c9de058a9051680fd9c49 100644 (file)
@@ -17,10 +17,10 @@ public class UpdateObjectLocationAndCrateOnMove extends UpdateObjectLocationOnMo
     private static final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationAndCrateOnMove.class);
     
     // FIXME: Get values below from external constants
-    private final static String COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA = "collectionobjects_anthropology";
-    private final static String MOVEMENTS_ANTHROPOLOGY_SCHEMA = "movements_anthropology";
-    private final static String CRATE_PROPERTY = "crate";
+    private final static String TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY = "TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY"; // For this listener, this is the key value to find the Nuxeo document schema name for the CollectionObject document from the tenant binding's parameter list.
     private final static String COMPUTED_CRATE_PROPERTY = "computedCrate";
+    private final static String TENANT_MOVEMENTS_SCHEMANAME_KEY = "TENANT_MOVEMENTS_SCHEMANAME_KEY"; // For this listener, this is the key value to find the Nuxeo document schema name for the Movement document from the tenant binding's parameter list.
+    private final static String CRATE_PROPERTY = "crate";
 
     @Override
     protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
@@ -35,10 +35,10 @@ public class UpdateObjectLocationAndCrateOnMove extends UpdateObjectLocationOnMo
     private DocumentModel updateComputedCrateValue(DocumentModel collectionObjectDocModel,
             DocumentModel movementDocModel)
             throws ClientException {
-        
+
         // Get the current crate value from the Movement (the "new" value)
-        String crateRefName =
-                (String) movementDocModel.getProperty(MOVEMENTS_ANTHROPOLOGY_SCHEMA, CRATE_PROPERTY);
+        String crateRefName = (String) movementDocModel.getProperty(getParamValue(TENANT_MOVEMENTS_SCHEMANAME_KEY),
+                               CRATE_PROPERTY);
 
         // Check that the value returned, which is expected to be a
         // reference (refName) to an authority term:
@@ -57,8 +57,7 @@ public class UpdateObjectLocationAndCrateOnMove extends UpdateObjectLocationOnMo
         }
         // Get the computed crate value of the CollectionObject
         // (the "existing" value)
-        String existingCrateRefName =
-                (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+        String existingCrateRefName = (String) collectionObjectDocModel.getProperty(getParamValue(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY),
                 COMPUTED_CRATE_PROPERTY);
         if (logger.isTraceEnabled()) {
             logger.trace("Existing crate refName=" + existingCrateRefName);
@@ -67,7 +66,7 @@ public class UpdateObjectLocationAndCrateOnMove extends UpdateObjectLocationOnMo
         // If the new value is blank, any non-blank existing value should always
         // be overwritten ('nulled out') with a blank value.
         if (Tools.isBlank(crateRefName) && Tools.notBlank(existingCrateRefName)) {
-            collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+            collectionObjectDocModel.setProperty(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY,
                     COMPUTED_CRATE_PROPERTY, (Serializable) null);
             // Otherwise, if the new value is not blank, and
             // * the existing value is blank, or
@@ -80,7 +79,7 @@ public class UpdateObjectLocationAndCrateOnMove extends UpdateObjectLocationOnMo
             }
             // ... update the existing value in the CollectionObject with the
             // new value from the Movement.
-            collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_ANTHROPOLOGY_SCHEMA,
+            collectionObjectDocModel.setProperty(TENANT_COLLECTIONOBJECTS_SCHEMANAME_KEY,
                     COMPUTED_CRATE_PROPERTY, crateRefName);
         } else {
             if (logger.isTraceEnabled()) {
index a6e2876a31f27cb217ff1f0f8d4b693b145553e3..94d909aafb756c670c8c1b7910546a15cdede383 100644 (file)
             <event>aboutToRemove</event>
         </listener>
     </extension>
+    
+    <extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener">
+        <listener name="updateobjectlocationonandcrateonmovelistener" async="true" postCommit="true"
+                  class="org.collectionspace.services.listener.UpdateObjectLocationAndCrateOnMove">
+            <event>documentCreated</event>
+            <event>documentModified</event>
+            <event>lifecycle_transition_event</event>
+            <event>aboutToRemove</event>
+        </listener>
+    </extension>
 
 </component>
index f52eb347fc9dd85696a15360b33947b7677ba64e..3d7ad65e305a506d21b4a77268e28b37fa8f2fde 100644 (file)
@@ -35,6 +35,7 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener {
             "AND (ecm:currentLifeCycleState <> 'deleted') "
             + NONVERSIONED_NONPROXY_DOCUMENT_WHERE_CLAUSE_FRAGMENT;
     static final String DOCMODEL_CONTEXT_PROPERTY_PREFIX = ScopeType.DEFAULT.getScopePrefix();
+       private String currentRepositoryName;
 
        public AbstractCSEventListenerImpl() {
                // Intentionally left blank
@@ -53,6 +54,16 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener {
 
                return result;
        }
+       
+       @Override
+       public void setCurrentRepository(Event event) {
+               currentRepositoryName = event.getContext().getRepositoryName();
+       }
+
+       @Override
+       public String getCurrentRepository() {
+               return currentRepositoryName;
+       }
 
        /*
         * This method is meant to be the bottleneck for handling a Nuxeo document event.
@@ -64,6 +75,7 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener {
 
                try {
                        if (isRegistered && shouldHandleEvent(event)) {
+                               setCurrentRepository(event);
                                handleCSEvent(event);
                                getLogger().debug(String.format("Eventlistener '%s' accepted '%s' event.",
                                                getClass().getName(), event.getName()));
@@ -163,10 +175,6 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener {
                return result;
        }
 
-       protected void setName(String repositoryName, String eventListenerName) {
-               nameMap.put(repositoryName, eventListenerName);
-       }
-
        @Override
        public Map<String, String> getParams(Event event) {
                Map<String, String> result = null;
@@ -178,10 +186,34 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener {
                }
                return result;
        }
+       
+       @Override
+       public String getParamValue(String key) {
+               String result = null;
+
+               
+               Map<String, Map<String, Map<String, String>>> allTenantallListenerParamMaps = getEventListenerParamsMap();
+               if (allTenantallListenerParamMaps != null && !allTenantallListenerParamMaps.isEmpty()) {
+                       Map<String, Map<String, String>> allListenersParamsMap = allTenantallListenerParamMaps.get(getCurrentRepository());
+                       if (allListenersParamsMap != null && !allListenersParamsMap.isEmpty()) {
+                               Map<String, String> paramsMap = allListenersParamsMap.get(getName(getCurrentRepository()));
+                               if (paramsMap != null && !paramsMap.isEmpty()) {
+                                       result = paramsMap.get(key);
+                               }
+                       }
+               }
+
+               return result;
+       }
+
+       @Override
+       public void setName(String repositoryName, String eventListenerName) {
+               nameMap.put(repositoryName + "." + this.getClass().getSimpleName(), eventListenerName);
+       }
 
        @Override
        public String getName(String repositoryName) {
-               return nameMap.get(repositoryName);
+               return nameMap.get(repositoryName + "." + this.getClass().getSimpleName());
        }
 
        //
index c3da8464d164f3f57e5918cb2512140170799abb..b63ee6ee920f1da306bc4225debbfc7879f933aa 100644 (file)
@@ -62,5 +62,30 @@ public interface CSEventListener {
         * Returns the name of the event listener as defined during registration -see register() method.
         * @return
         */
-       String getName(String repositoryName);  
+       String getName(String repositoryName);
+       
+       /*
+        * Used to set the name of the current repository at setup to event handling
+        */
+       void setCurrentRepository(Event event);
+       
+       /*
+        * Returns the name of the event's current repository -see method setCurrentRepository()
+        */
+       String getCurrentRepository();
+
+       /**
+        * Returns a parameter value for the given key for the given repository/tenant
+        * @param key
+        * @return
+        */
+       String getParamValue(String key);
+
+       /**
+        * For a given repository/tenant, set the name of the listener as defined in the tenant bindings.
+        * 
+        * @param repositoryName
+        * @param eventListenerName
+        */
+       void setName(String repositoryName, String eventListenerName);
 }