]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e8d14949b2561cc9d4fa1c7f9055d2fc84a874ae
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.listener.botgarden;
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.MovementBotGardenConstants;
7 import org.collectionspace.services.movement.nuxeo.MovementConstants;
8 import org.collectionspace.services.nuxeo.listener.AbstractCSEventListenerImpl;
9 import org.nuxeo.ecm.core.api.CoreSession;
10 import org.nuxeo.ecm.core.api.DocumentModel;
11 import org.nuxeo.ecm.core.event.Event;
12 import org.nuxeo.ecm.core.event.EventContext;
13 import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
14
15 public class DeleteDeadLocationListener extends AbstractCSEventListenerImpl {
16         final Log logger = LogFactory.getLog(DeleteDeadLocationListener.class);
17
18     /* 
19      * Delete dead locations. 
20      */
21     public void handleEvent(Event event) {
22         EventContext ec = event.getContext();
23
24         if (ec instanceof DocumentEventContext) {
25             DocumentEventContext context = (DocumentEventContext) ec;
26             DocumentModel doc = context.getSourceDocument();
27
28             if (doc.getType().startsWith(MovementConstants.NUXEO_DOCTYPE) &&
29                         !doc.isVersion() && 
30                         !doc.isProxy() && 
31                         !doc.getCurrentLifeCycleState().equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
32                 String actionCode = (String) doc.getProperty(MovementBotGardenConstants.ACTION_CODE_SCHEMA_NAME, 
33                                 MovementBotGardenConstants.ACTION_CODE_FIELD_NAME);
34                 
35                 logger.debug("actionCode=" + actionCode);
36                 
37                 if (actionCode != null && actionCode.equals(MovementBotGardenConstants.DEAD_ACTION_CODE)) {
38                         CoreSession session = context.getCoreSession();
39                         
40                         if (session.getAllowedStateTransitions(doc.getRef()).contains(WorkflowClient.WORKFLOWTRANSITION_DELETE)) {
41                                 session.followTransition(doc.getRef(), WorkflowClient.WORKFLOWTRANSITION_DELETE);
42                         }
43                 }
44             }
45         }
46     }
47 }