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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20 import org.kuali.rice.kew.actions.BlanketApproveAction;
21 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
22 import org.kuali.rice.kew.api.KewApiServiceLocator;
23 import org.kuali.rice.kew.api.WorkflowRuntimeException;
24 import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue;
25 import org.kuali.rice.kew.api.document.DocumentProcessingOptions;
26 import org.kuali.rice.kew.api.document.OrchestrationConfig;
27 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
28 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29 import org.kuali.rice.kew.service.KEWServiceLocator;
30 import org.kuali.rice.kim.api.identity.principal.Principal;
31
32
33
34
35
36
37 public class DocumentOrchestrationQueueImpl implements DocumentOrchestrationQueue {
38
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentOrchestrationQueueImpl.class);
40
41 @Override
42 public void orchestrateDocument(String documentId, String principalId, OrchestrationConfig orchestrationConfig,
43 DocumentProcessingOptions documentProcessingOptions) {
44 if (StringUtils.isBlank(principalId)) {
45 throw new RiceIllegalArgumentException("principalId is null or blank");
46 }
47
48 if (StringUtils.isBlank(documentId)) {
49 throw new RiceIllegalArgumentException("documentId is null");
50 }
51
52 if (orchestrationConfig == null) {
53 throw new RiceIllegalArgumentException("orchestrationConfig is null");
54 }
55 if (documentProcessingOptions == null) {
56 documentProcessingOptions = DocumentProcessingOptions.createDefault();
57 }
58
59 LOG.info("Performing document orchestration on documentId=" + documentId);
60 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId);
61 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId);
62 ActionTakenValue actionTaken = KEWServiceLocator.getActionTakenService().findByActionTakenId(orchestrationConfig.getActionTakenId());
63 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId);
64 BlanketApproveAction blanketApprove = new BlanketApproveAction(document, principal, "", orchestrationConfig.getNodeNames());
65 try {
66 blanketApprove.performDeferredBlanketApproveWork(actionTaken, documentProcessingOptions);
67 } catch (Exception e) {
68 if (e instanceof RuntimeException) {
69 throw (RuntimeException)e;
70 }
71 throw new WorkflowRuntimeException(e);
72 }
73 if (documentProcessingOptions.isIndexSearchAttributes()) {
74 DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(document.getDocumentType().getApplicationId());
75 queue.indexDocument(documentId);
76 }
77 LOG.info("Document orchestration complete against documentId=" + documentId);
78 }
79
80 }