1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.document;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21 import org.kuali.rice.kew.api.WorkflowRuntimeException;
22 import org.kuali.rice.kew.api.document.DocumentProcessingOptions;
23 import org.kuali.rice.kew.api.document.DocumentProcessingQueue;
24 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
25 import org.kuali.rice.kew.engine.OrchestrationConfig;
26 import org.kuali.rice.kew.engine.WorkflowEngine;
27 import org.kuali.rice.kew.engine.WorkflowEngineFactory;
28
29 import javax.jws.WebParam;
30 import java.util.Collections;
31
32
33
34
35
36
37 public class DocumentProcessingQueueImpl implements DocumentProcessingQueue {
38
39 private static final Logger LOG = Logger.getLogger(DocumentProcessingQueueImpl.class);
40
41 private WorkflowEngineFactory workflowEngineFactory;
42 private DocumentAttributeIndexingQueue documentAttributeIndexingQueue;
43
44 @Override
45 public void process(@WebParam(name = "documentId") String documentId) {
46 processWithOptions(documentId, null);
47 }
48
49 @Override
50 public void processWithOptions(@WebParam(name = "documentId") String documentId,
51 @WebParam(name = "options") DocumentProcessingOptions options) {
52 if (StringUtils.isBlank(documentId)) {
53 throw new RiceIllegalArgumentException("documentId was a null or blank value");
54 }
55 if (options == null) {
56 options = DocumentProcessingOptions.createDefault();
57 }
58 OrchestrationConfig config = new OrchestrationConfig(OrchestrationConfig.EngineCapability.STANDARD,
59 Collections.<String>emptySet(), null, options.isSendNotifications(), options.isRunPostProcessor());
60 WorkflowEngine engine = getWorkflowEngineFactory().newEngine(config);
61 try {
62 engine.process(documentId, null);
63 } catch (Exception e) {
64 LOG.error("Failed to process document through the workflow engine", e);
65 if (e instanceof RuntimeException) {
66 throw (RuntimeException)e;
67 }
68 throw new WorkflowRuntimeException(e);
69 }
70 if (options.isIndexSearchAttributes()) {
71 getDocumentAttributeIndexingQueue().indexDocument(documentId);
72 }
73 }
74
75 public WorkflowEngineFactory getWorkflowEngineFactory() {
76 return workflowEngineFactory;
77 }
78
79 public void setWorkflowEngineFactory(WorkflowEngineFactory workflowEngineFactory) {
80 this.workflowEngineFactory = workflowEngineFactory;
81 }
82
83 public DocumentAttributeIndexingQueue getDocumentAttributeIndexingQueue() {
84 return documentAttributeIndexingQueue;
85 }
86
87 public void setDocumentAttributeIndexingQueue(DocumentAttributeIndexingQueue documentAttributeIndexingQueue) {
88 this.documentAttributeIndexingQueue = documentAttributeIndexingQueue;
89 }
90
91 }