From c4a68ab10ca8a791d493813ab5428237153049ae Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Tue, 4 Dec 2012 18:49:37 -0800 Subject: [PATCH] CSPACE-5727: Event listener now logs on movement record creates and updates. Bundle files have been updated with correct package name. --- .../nuxeo/nuxeo-platform-listener/build.xml | 1 - .../updateobjectlocationonmove/pom.xml | 9 +- .../listener/UpdateObjectLocationOnMove.java | 40 ++++++ .../listener/UpdateRelationsOnDelete.java | 119 ------------------ .../src/main/resources/META-INF/MANIFEST.MF | 6 +- .../resources/OSGI-INF/core-types-contrib.xml | 2 +- .../OSGI-INF/default-life-cycle-contrib.xml | 2 +- .../resources/OSGI-INF/ecm-types-contrib.xml | 11 +- .../resources/OSGI-INF/layouts-contrib.xml | 2 +- 9 files changed, 59 insertions(+), 133 deletions(-) create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java delete mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/build.xml b/3rdparty/nuxeo/nuxeo-platform-listener/build.xml index 10dc369ba..74e81ee56 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/build.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/build.xml @@ -8,7 +8,6 @@ - diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml index 56cdc3dc8..2fed52dab 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml @@ -15,13 +15,18 @@ org.collectionspace.services.listener.updateobjectlocationonmove http://maven.apache.org - - + + org.collectionspace.services org.collectionspace.services.common ${project.version} + + org.collectionspace.services + org.collectionspace.services.movement.service + ${project.version} + diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java new file mode 100644 index 000000000..14f160c49 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java @@ -0,0 +1,40 @@ +package org.collectionspace.services.listener; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.collectionspace.services.movement.nuxeo.MovementConstants; +import org.nuxeo.ecm.core.api.ClientException; +import org.nuxeo.ecm.core.api.CoreSession; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.nuxeo.ecm.core.api.impl.LifeCycleFilter; +import org.nuxeo.ecm.core.event.Event; +import org.nuxeo.ecm.core.event.EventContext; +import org.nuxeo.ecm.core.event.EventListener; +import org.nuxeo.ecm.core.event.impl.DocumentEventContext; + +public class UpdateObjectLocationOnMove implements EventListener { + + // FIXME: We might experiment here with using log4j instead of Apache Commons Logging; + // am using the latter to follow Ray's pattern for now + final Log logger = LogFactory.getLog(UpdateObjectLocationOnMove.class); + + @Override + public void handleEvent(Event event) throws ClientException { + + logger.info("In handleEvent in UpdateObjectLocationOnMove ..."); + + EventContext eventContext = event.getContext(); + if (eventContext == null) { + return; + } + DocumentEventContext docEventContext = (DocumentEventContext) eventContext; + DocumentModel docModel = docEventContext.getSourceDocument(); + logger.debug("docType=" + docModel.getType()); + if (docModel.getType().startsWith(MovementConstants.NUXEO_DOCTYPE)) { + logger.info("A create or update event for a Movement document was received by UpdateObjectLocationOnMove ..."); + } + } +} diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java deleted file mode 100644 index 8efc9c120..000000000 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.collectionspace.services.listener; - -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuxeo.ecm.core.api.ClientException; -import org.nuxeo.ecm.core.api.CoreSession; -import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.impl.LifeCycleFilter; -import org.nuxeo.ecm.core.event.Event; -import org.nuxeo.ecm.core.event.EventContext; -import org.nuxeo.ecm.core.event.EventListener; -import org.nuxeo.ecm.core.event.impl.DocumentEventContext; - -public class UpdateRelationsOnDelete implements EventListener { - - // FIXME: Consider adding the following constant to - // org.collectionspace.services.common.workflow.jaxb.WorkflowJAXBSchema - // and referencing it from there. - private static final String WORKFLOWTRANSITION_TO = "to"; - // FIXME: Consider substituting existing constant WorkflowClient.WORKFLOWSTATE_DELETED - private static final String WORKFLOWSTATE_DELETED = "deleted"; - // FIXME: Consider substituting existing constant WorkflowClient.WORKFLOWSTATE_LOCKED - private static final String WORKFLOWSTATE_LOCKED = "locked"; - // FIXME: Consider substituting existing constant WorkflowClient.WORKFLOWTRANSITION_DELETE - private static final String WORKFLOWTRANSITION_DELETE = "delete"; - - // FIXME: We might experiment here with using log4j instead of Apache Commons Logging; - // am using the latter to follow Ray's pattern for now - final Log logger = LogFactory.getLog(UpdateRelationsOnDelete.class); - - @Override - public void handleEvent(Event event) throws ClientException { - logger.info("In handleEvent in UpdateRelationsOnDelete ..."); - - EventContext eventContext = event.getContext(); - - if (isDocumentSoftDeletedEvent(eventContext)) { - - DocumentEventContext docContext = (DocumentEventContext) eventContext; - DocumentModel docModel = docContext.getSourceDocument(); - - // Retrieve a list of relation records, where the soft deleted - // document provided in the context of the current event is - // either the subject or object of any relation - - // Build a query string - String csid = docModel.getName(); - StringBuilder queryString = new StringBuilder(""); - queryString.append("SELECT * FROM Relation WHERE "); - // FIXME: Obtain and add tenant ID to the query here - // queryString.append("collectionspace_core:tenantId = 1 "); - // queryString.append(" AND "); - // queryString.append("ecm:currentLifeCycleState <> 'deleted' "); - queryString.append("ecm:isProxy = 0 "); - queryString.append(" AND "); - queryString.append("("); - queryString.append("relations_common:subjectCsid = "); - queryString.append("'"); - queryString.append(csid); - queryString.append("'"); - queryString.append(" OR "); - queryString.append("relations_common:objectCsid = "); - queryString.append("'"); - queryString.append(csid); - queryString.append("'"); - queryString.append(")"); - - // Create a filter to exclude from the list results any records - // that have already been soft deleted or are locked - List workflowStatesToFilter = new ArrayList(); - workflowStatesToFilter.add(WORKFLOWSTATE_DELETED); - workflowStatesToFilter.add(WORKFLOWSTATE_LOCKED); - LifeCycleFilter workflowStateFilter = new LifeCycleFilter(null, workflowStatesToFilter); - - // Perform the filtered query - CoreSession session = docModel.getCoreSession(); - DocumentModelList matchingDocuments; - try { - matchingDocuments = session.query(queryString.toString(), workflowStateFilter); - } catch (ClientException ce) { - logger.warn("Error attempting to retrieve relation records where " - + "record of type '" + docModel.getType() + "' with CSID " + csid - + " is the subject or object of any relation: " + ce.getMessage()); - throw ce; - } - - // Cycle through the list results, soft deleting each matching relation record - logger.trace("Attempting to soft delete " + matchingDocuments.size() + " relation records."); - for (DocumentModel doc : matchingDocuments) { - doc.followTransition(WORKFLOWTRANSITION_DELETE); - } - - } - - } - - /** - * Identifies whether a supplied event concerns a document that has - * been transitioned to the 'deleted' workflow state. - * - * @param eventContext an event context - * - * @return true if this event concerns a document that has - * been transitioned to the 'deleted' workflow state. - */ - private boolean isDocumentSoftDeletedEvent(EventContext eventContext) { - boolean isSoftDeletedEvent = false; - if (eventContext instanceof DocumentEventContext) { - if (eventContext.getProperties().containsKey(WORKFLOWTRANSITION_TO) - && eventContext.getProperties().get(WORKFLOWTRANSITION_TO).equals(WORKFLOWSTATE_DELETED)) { - isSoftDeletedEvent = true; - } - } - return isSoftDeletedEvent; - } -} diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF index 4fae07ad7..8afea5901 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 1 -Bundle-Name: org.collectionspace.nuxeo.listener.relation -Bundle-SymbolicName: org.collectionspace.nuxeo.listener.relation;singleton:=true +Bundle-Name: org.collectionspace.services.listener.updateobjectlocationonmove +Bundle-SymbolicName: org.collectionspace.services.listener.updateobjectlocationonmove;singleton:=true Bundle-Version: 1.0.0 Bundle-Localization: plugin Bundle-Vendor: Nuxeo @@ -9,7 +9,7 @@ Require-Bundle: org.nuxeo.runtime, org.nuxeo.ecm.core.api, org.nuxeo.ecm.core, org.nuxeo.ecm.webapp.core -Provide-Package: org.collectionspace.nuxeo.listener.relation +Provide-Package: org.collectionspace.services.listener.updateobjectlocationonmove Nuxeo-Component: OSGI-INF/core-types-contrib.xml, OSGI-INF/default-life-cycle-contrib.xml, OSGI-INF/ecm-types-contrib.xml, diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml index 8cedf8009..a5b94d22e 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -1,4 +1,4 @@ - + diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml index 08d595182..bdd1e2912 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -1,4 +1,4 @@ - + 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 d25de03a7..612dde8fe 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 @@ -1,11 +1,12 @@ - + - - lifecycle_transition_event + + documentCreated + documentModified - + diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml index 91f74f30b..ef82a7ac1 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -1,4 +1,4 @@ - + -- 2.47.3