]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
45436ad9b21d626d0d3232f569dabfa94939192a
[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     @Override
22         public void handleEvent(Event event) {
23         EventContext ec = event.getContext();
24
25         if (isRegistered(event) && ec instanceof DocumentEventContext) {
26             DocumentEventContext context = (DocumentEventContext) ec;
27             DocumentModel doc = context.getSourceDocument();
28
29             if (doc.getType().startsWith(MovementConstants.NUXEO_DOCTYPE) &&
30                         !doc.isVersion() && 
31                         !doc.isProxy() && 
32                         !doc.getCurrentLifeCycleState().equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
33                 String actionCode = (String) doc.getProperty(MovementBotGardenConstants.ACTION_CODE_SCHEMA_NAME, 
34                                 MovementBotGardenConstants.ACTION_CODE_FIELD_NAME);
35                 
36                 logger.debug("actionCode=" + actionCode);
37                 
38                 if (actionCode != null && actionCode.equals(MovementBotGardenConstants.DEAD_ACTION_CODE)) {
39                         CoreSession session = context.getCoreSession();
40                         
41                         if (session.getAllowedStateTransitions(doc.getRef()).contains(WorkflowClient.WORKFLOWTRANSITION_DELETE)) {
42                                 session.followTransition(doc.getRef(), WorkflowClient.WORKFLOWTRANSITION_DELETE);
43                         }
44                 }
45             }
46         }
47     }
48 }