]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b380ae4e209a11e67b2ad701f8b5bfef5171ba0b
[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.MovementConstants;
7 import org.collectionspace.services.nuxeo.listener.AbstractCSEventListenerImpl;
8 import org.nuxeo.ecm.core.api.DocumentModel;
9 import org.nuxeo.ecm.core.api.DocumentRef;
10 import org.nuxeo.ecm.core.api.VersioningOption;
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 CreateVersionListener extends AbstractCSEventListenerImpl {
16         public static final String SKIP_PROPERTY = "CreateVersionListener.SKIP";
17
18         final Log logger = LogFactory.getLog(CreateVersionListener.class);
19
20         public void handleEvent(Event event) {
21                 EventContext ec = event.getContext();
22
23                 if (ec instanceof DocumentEventContext) {
24                         DocumentEventContext context = (DocumentEventContext) ec;
25
26                         if (ec.hasProperty(SKIP_PROPERTY) && ((Boolean) ec.getProperty(SKIP_PROPERTY))) {
27                                 logger.debug("Skipping create version");
28                         }
29                         else {
30                                 DocumentModel doc = context.getSourceDocument();
31
32                                 logger.debug("docType=" + doc.getType());
33
34                                 if (doc.getType().startsWith(MovementConstants.NUXEO_DOCTYPE) && 
35                                                 !doc.isVersion() && 
36                                                 !doc.isProxy() &&
37                                                 !doc.getCurrentLifeCycleState().equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
38                                         // Version the document
39                                         DocumentRef versionRef = doc.checkIn(VersioningOption.MINOR, null);             
40                                         DocumentModel versionDoc = context.getCoreSession().getDocument(versionRef);
41
42                                         logger.debug("created version: id=" + versionDoc.getId() + " csid=" + versionDoc.getName());
43
44                                         // Check out the document, so it can be modified
45                                         doc.checkOut();
46                                 }
47                         }
48                 }
49         }
50 }