From 68d616452882a489c3415dc43c7d060c8f7c09f9 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 3 Aug 2020 09:37:00 -0700 Subject: [PATCH] CC-1302: Service binding parameter values not handled correctly for Nuxeo exent listeners. --- .../AbstractUpdateObjectLocationValues.java | 2 +- .../UpdateObjectLocationAndCrateOnMove.java | 19 ++++----- .../resources/OSGI-INF/ecm-types-contrib.xml | 10 +++++ .../listener/AbstractCSEventListenerImpl.java | 42 ++++++++++++++++--- .../nuxeo/listener/CSEventListener.java | 27 +++++++++++- 5 files changed, 83 insertions(+), 17 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java index 696a4c081..9df47d654 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java @@ -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. diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationAndCrateOnMove.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationAndCrateOnMove.java index 7a40b9b16..46a9c84c1 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationAndCrateOnMove.java +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationAndCrateOnMove.java @@ -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()) { diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml index a6e2876a3..94d909aaf 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -10,5 +10,15 @@ aboutToRemove + + + + documentCreated + documentModified + lifecycle_transition_event + aboutToRemove + + diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/AbstractCSEventListenerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/AbstractCSEventListenerImpl.java index f52eb347f..3d7ad65e3 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/AbstractCSEventListenerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/AbstractCSEventListenerImpl.java @@ -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 getParams(Event event) { Map result = null; @@ -178,10 +186,34 @@ public abstract class AbstractCSEventListenerImpl implements CSEventListener { } return result; } + + @Override + public String getParamValue(String key) { + String result = null; + + + Map>> allTenantallListenerParamMaps = getEventListenerParamsMap(); + if (allTenantallListenerParamMaps != null && !allTenantallListenerParamMaps.isEmpty()) { + Map> allListenersParamsMap = allTenantallListenerParamMaps.get(getCurrentRepository()); + if (allListenersParamsMap != null && !allListenersParamsMap.isEmpty()) { + Map 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()); } // diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/CSEventListener.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/CSEventListener.java index c3da8464d..b63ee6ee9 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/CSEventListener.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/listener/CSEventListener.java @@ -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); } -- 2.47.3