]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
39078782e001abe3e4eb3142a75d5f0093857e79
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.listener;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.collectionspace.services.client.workflow.WorkflowClient;
6 import org.collectionspace.services.movement.nuxeo.MovementConstants;
7 import org.nuxeo.ecm.core.api.ClientException;
8 import org.nuxeo.ecm.core.api.DocumentModel;
9 import org.nuxeo.ecm.core.event.Event;
10 import org.nuxeo.ecm.core.event.EventContext;
11 import org.nuxeo.ecm.core.event.EventListener;
12 import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
13
14 public class UpdateObjectLocationOnMove implements EventListener {
15
16     // FIXME: We might experiment here with using log4j instead of Apache Commons Logging;
17     // am using the latter to follow Ray's pattern for now
18     final Log logger = LogFactory.getLog(UpdateObjectLocationOnMove.class);
19
20     @Override
21     public void handleEvent(Event event) throws ClientException {
22
23         logger.info("In handleEvent in UpdateObjectLocationOnMove ...");
24
25         EventContext eventContext = event.getContext();
26         if (eventContext == null) {
27             return;
28         }
29         DocumentEventContext docEventContext = (DocumentEventContext) eventContext;
30         DocumentModel docModel = docEventContext.getSourceDocument();
31         logger.debug("docType=" + docModel.getType());
32         if (docModel.getType().startsWith(MovementConstants.NUXEO_DOCTYPE)
33                 && isActiveDocument(docModel)) {
34             logger.info("A create or update event for an active Movement document was received by UpdateObjectLocationOnMove ...");
35         }
36
37     }
38
39     /**
40      * Identifies whether a document is an active document; that is, if
41      * it is not a versioned record; not a proxy (symbolic link to an
42      * actual record); and not in the 'deleted' workflow state.
43      *
44      * (A note relating the latter: Nuxeo appears to send 'documentModified' events
45      * even on workflow transitions, such when records are 'soft deleted' by being
46      * transitioned to the 'deleted' workflow state.)
47      *
48      * @param docModel
49      * @return true if the document is an active document; false if it
50      * is not.
51      */
52     private boolean isActiveDocument(DocumentModel docModel) {
53         boolean isActiveDocument = false;
54         try {
55             if (!docModel.isVersion()
56                     && !docModel.isProxy()
57                     && !docModel.getCurrentLifeCycleState().equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
58                 isActiveDocument = true;
59             }
60         } catch (ClientException ce) {
61             logger.warn("Error while identifying whether document is an active document: ", ce);
62         }
63         return isActiveDocument;
64     }
65 }