1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.messaging;
18
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.kew.api.KewApiServiceLocator;
21 import org.kuali.rice.kew.api.WorkflowRuntimeException;
22 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue;
23 import org.kuali.rice.kew.engine.OrchestrationConfig;
24 import org.kuali.rice.kew.engine.OrchestrationConfig.EngineCapability;
25 import org.kuali.rice.kew.engine.WorkflowEngine;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
28
29
30
31
32
33
34
35 public class RouteDocumentMessageService implements KSBXMLService {
36
37 private static final Logger LOG = Logger.getLogger(RouteDocumentMessageService.class);
38
39 public void invoke(String xml) {
40 try {
41 RouteMessageXmlElement newElement = RouteMessageXmlElement.construct(xml);
42 OrchestrationConfig config = new OrchestrationConfig(EngineCapability.STANDARD, newElement.runPostProcessor);
43 WorkflowEngine engine = KEWServiceLocator.getWorkflowEngineFactory().newEngine(config);
44 engine.process(newElement.documentId, null);
45 if (newElement.shouldSearchAttributeIndex) {
46 DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(KEWServiceLocator.getRouteHeaderService().getRouteHeader(newElement.documentId).getDocumentType().getApplicationId());
47 queue.indexDocument(newElement.documentId);
48 }
49 } catch (Exception e) {
50 LOG.error(e);
51 throw new WorkflowRuntimeException(e);
52 }
53 }
54
55 public static class RouteMessageXmlElement {
56 public String documentId;
57 public boolean runPostProcessor = true;
58 public boolean shouldSearchAttributeIndex = false;
59 public RouteMessageXmlElement(String documentId) {
60 this.documentId = documentId;
61 }
62 public RouteMessageXmlElement(String documentId, boolean runPostProcessor) {
63 this(documentId);
64 this.runPostProcessor = runPostProcessor;
65 }
66 public RouteMessageXmlElement(String documentId, boolean runPostProcessor, boolean shouldIndex) {
67 this(documentId, runPostProcessor);
68 this.shouldSearchAttributeIndex = shouldIndex;
69 }
70 private static final String SPLIT = "::~~::";
71 public static RouteMessageXmlElement construct(String content) {
72 if (content.contains(SPLIT)) {
73 String[] values = content.split(SPLIT);
74 if (values.length == 3) {
75 return new RouteMessageXmlElement(values[0], Boolean.valueOf(values[1]), Boolean.valueOf(values[2]));
76 } else {
77 return new RouteMessageXmlElement(values[0],Boolean.valueOf(values[1]));
78 }
79 } else {
80 return new RouteMessageXmlElement(content);
81 }
82 }
83 public String translate() {
84 return documentId + SPLIT + String.valueOf(runPostProcessor) + SPLIT + String.valueOf(shouldSearchAttributeIndex);
85 }
86 }
87
88 }