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.docsearch.service.SearchableAttributeProcessingService;
21 import org.kuali.rice.kew.engine.WorkflowEngine;
22 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
23 import org.kuali.rice.kew.service.KEWServiceLocator;
24 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
25
26
27
28
29
30
31
32 public class RouteDocumentMessageService implements KSBXMLService {
33
34 private static final Logger LOG = Logger.getLogger(RouteDocumentMessageService.class);
35
36 public void invoke(String xml) {
37 try {
38 RouteMessageXmlElement newElement = RouteMessageXmlElement.construct(xml);
39 WorkflowEngine engine = KEWServiceLocator.getWorkflowEngine();
40 engine.setRunPostProcessorLogic(newElement.runPostProcessor);
41 engine.process(newElement.routeHeaderId, null);
42 if (newElement.shouldSearchAttributeIndex) {
43 SearchableAttributeProcessingService searchableAttService = (SearchableAttributeProcessingService) MessageServiceNames.getSearchableAttributeService(KEWServiceLocator.getRouteHeaderService().getRouteHeader(newElement.routeHeaderId));
44 searchableAttService.indexDocument(newElement.routeHeaderId);
45 }
46 } catch (Exception e) {
47 LOG.error(e);
48 throw new WorkflowRuntimeException(e);
49 }
50 }
51
52 public static class RouteMessageXmlElement {
53 public Long routeHeaderId;
54 public boolean runPostProcessor = true;
55 public boolean shouldSearchAttributeIndex = false;
56 public RouteMessageXmlElement(Long routeHeaderId) {
57 this.routeHeaderId = routeHeaderId;
58 }
59 public RouteMessageXmlElement(Long routeHeaderId, boolean runPostProcessor) {
60 this(routeHeaderId);
61 this.runPostProcessor = runPostProcessor;
62 }
63 public RouteMessageXmlElement(Long routeHeaderId, boolean runPostProcessor, boolean shouldIndex) {
64 this(routeHeaderId, runPostProcessor);
65 this.shouldSearchAttributeIndex = shouldIndex;
66 }
67 private static final String SPLIT = "::~~::";
68 public static RouteMessageXmlElement construct(String content) {
69 if (content.contains(SPLIT)) {
70 String[] values = content.split(SPLIT);
71 if (values.length == 3) {
72 return new RouteMessageXmlElement(Long.valueOf(values[0]), Boolean.valueOf(values[1]), Boolean.valueOf(values[2]));
73 } else {
74 return new RouteMessageXmlElement(Long.valueOf(values[0]),Boolean.valueOf(values[1]));
75 }
76 } else {
77 return new RouteMessageXmlElement(Long.valueOf(content));
78 }
79 }
80 public String translate() {
81 return routeHeaderId + SPLIT + String.valueOf(runPostProcessor) + SPLIT + String.valueOf(shouldSearchAttributeIndex);
82 }
83 }
84
85 }