From 03e2d757ba104654101605bc15ce7b21b62c9d93 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Tue, 4 Dec 2012 11:38:45 -0800 Subject: [PATCH] CSPACE-5727: Initial directory structure for an 'update object location on move' event listener. Cloned from the 'delete relations on soft delete' event listener, and still needs updates in several files to reflect the new module/package name. --- .../build.properties | 1 + .../updateobjectlocationonmove/build.xml | 104 +++++++++++++++ .../updateobjectlocationonmove/pom.xml | 51 ++++++++ .../listener/UpdateRelationsOnDelete.java | 119 ++++++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 16 +++ .../resources/OSGI-INF/core-types-contrib.xml | 4 + .../OSGI-INF/default-life-cycle-contrib.xml | 4 + .../OSGI-INF/deployment-fragment.xml | 10 ++ .../resources/OSGI-INF/ecm-types-contrib.xml | 11 ++ .../resources/OSGI-INF/layouts-contrib.xml | 4 + 10 files changed, 324 insertions(+) create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.properties create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.properties b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.properties new file mode 100644 index 000000000..9f857e71d --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.properties @@ -0,0 +1 @@ +listener.module.name=updateobjectlocationonmove diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.xml new file mode 100644 index 000000000..2933eb2e7 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/build.xml @@ -0,0 +1,104 @@ + + + CollectionSpace Nuxeo listener component type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml new file mode 100644 index 000000000..56cdc3dc8 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.collectionspace.services.3rdparty.nuxeo.listener + org.collectionspace.services + 3.2-SNAPSHOT + + + UTF-8 + + org.collectionspace.services.listener.updateobjectlocationonmove + org.collectionspace.services.listener.updateobjectlocationonmove + http://maven.apache.org + + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + 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 new file mode 100644 index 000000000..8efc9c120 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateRelationsOnDelete.java @@ -0,0 +1,119 @@ +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 new file mode 100644 index 000000000..4fae07ad7 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: org.collectionspace.nuxeo.listener.relation +Bundle-SymbolicName: org.collectionspace.nuxeo.listener.relation;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +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 +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/default-life-cycle-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-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 new file mode 100644 index 000000000..8cedf8009 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +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 new file mode 100644 index 000000000..08d595182 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -0,0 +1,4 @@ + + + + diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/deployment-fragment.xml b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..270abbd5f --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,10 @@ + + + + + + ${bundle.fileName} + + + + 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 new file mode 100644 index 000000000..d25de03a7 --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,11 @@ + + + + + + lifecycle_transition_event + + + + 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 new file mode 100644 index 000000000..91f74f30b --- /dev/null +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,4 @@ + + + + -- 2.47.3