1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.action;
17
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23 import org.kuali.rice.kew.actions.BlanketApproveAction;
24 import org.kuali.rice.kew.actions.MoveDocumentAction;
25 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
26 import org.kuali.rice.kew.api.KewApiServiceLocator;
27 import org.kuali.rice.kew.api.WorkflowRuntimeException;
28 import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue;
29 import org.kuali.rice.kew.api.document.DocumentProcessingOptions;
30 import org.kuali.rice.kew.api.document.OrchestrationConfig;
31 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
32 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
33 import org.kuali.rice.kew.service.KEWServiceLocator;
34 import org.kuali.rice.kim.api.identity.principal.Principal;
35
36 import javax.jws.WebParam;
37
38
39
40
41
42
43 public class DocumentOrchestrationQueueImpl implements DocumentOrchestrationQueue {
44
45 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentOrchestrationQueueImpl.class);
46
47 @Override
48 public void orchestrateDocument(String documentId, String principalId, OrchestrationConfig orchestrationConfig,
49 DocumentProcessingOptions documentProcessingOptions) {
50 if (StringUtils.isBlank(principalId)) {
51 throw new RiceIllegalArgumentException("principalId is null or blank");
52 }
53
54 if (StringUtils.isBlank(documentId)) {
55 throw new RiceIllegalArgumentException("documentId is null");
56 }
57
58 if (orchestrationConfig == null) {
59 throw new RiceIllegalArgumentException("orchestrationConfig is null");
60 }
61 if (documentProcessingOptions == null) {
62 documentProcessingOptions = DocumentProcessingOptions.createDefault();
63 }
64
65 LOG.info("Performing document orchestration on documentId=" + documentId);
66 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true);
67 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
68 ActionTakenValue actionTaken = KEWServiceLocator.getActionTakenService().findByActionTakenId(orchestrationConfig.getActionTakenId());
69 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
70 BlanketApproveAction blanketApprove = new BlanketApproveAction(document, principal, "", orchestrationConfig.getNodeNames());
71 try {
72 blanketApprove.performDeferredBlanketApproveWork(actionTaken, documentProcessingOptions);
73 } catch (Exception e) {
74 if (e instanceof RuntimeException) {
75 throw (RuntimeException)e;
76 }
77 throw new WorkflowRuntimeException(e);
78 }
79 if (documentProcessingOptions.isIndexSearchAttributes()) {
80 DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(document.getDocumentType().getApplicationId());
81 queue.indexDocument(documentId);
82 }
83 LOG.info("Document orchestration complete against documentId=" + documentId);
84 }
85
86 }