1 <?xml version="1.0" encoding="UTF-8"?>
2 <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_0co5an7" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.0.3">
3 <bpmn:collaboration id="Collaboration">
4 <bpmn:participant id="Sentiment_Analysis" name="Sentiment Analysis" processRef="sentiment-analysis" />
6 <bpmn:process id="sentiment-analysis" name="Sentiment Analysis" isExecutable="true" camunda:versionTag="0.0.1">
7 <bpmn:laneSet id="LaneSet_1u08y0e" />
8 <bpmn:sequenceFlow id="SequenceFlow_14nqu0e" sourceRef="service-report" targetRef="IntermediateThrowEvent_0sns4tf" />
9 <bpmn:sequenceFlow id="SequenceFlow_0jebdb9" sourceRef="Task_1e7059p" targetRef="EndEvent_0bmuv13" />
10 <bpmn:sequenceFlow id="SequenceFlow_15dip2q" sourceRef="StartEvent_1t6nxib" targetRef="IntermediateThrowEvent_193oik9" />
11 <bpmn:sequenceFlow id="SequenceFlow_1j2y6tv" sourceRef="terms_loop" targetRef="service-report" />
12 <bpmn:startEvent id="StartEvent_1t6nxib" camunda:formKey="embedded:deployment:input-terms.html">
13 <bpmn:extensionElements>
14 <camunda:executionListener event="start">
15 <camunda:script scriptFormat="javascript">// make variable global
16 execution.setVariable("results", S('[]'))</camunda:script>
17 </camunda:executionListener>
18 </bpmn:extensionElements>
19 <bpmn:outgoing>SequenceFlow_15dip2q</bpmn:outgoing>
21 <bpmn:endEvent id="EndEvent_0bmuv13">
22 <bpmn:incoming>SequenceFlow_0jebdb9</bpmn:incoming>
24 <bpmn:sequenceFlow id="SequenceFlow_0o77usd" sourceRef="IntermediateThrowEvent_193oik9" targetRef="terms_loop" />
25 <bpmn:userTask id="Task_1e7059p" name="download pdf" camunda:formKey="embedded:deployment:download-pdf.html">
26 <bpmn:incoming>SequenceFlow_1mnqqvo</bpmn:incoming>
27 <bpmn:outgoing>SequenceFlow_0jebdb9</bpmn:outgoing>
29 <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_193oik9">
30 <bpmn:incoming>SequenceFlow_15dip2q</bpmn:incoming>
31 <bpmn:outgoing>SequenceFlow_0o77usd</bpmn:outgoing>
32 <bpmn:timerEventDefinition>
33 <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT0S</bpmn:timeDuration>
34 </bpmn:timerEventDefinition>
35 </bpmn:intermediateCatchEvent>
36 <bpmn:subProcess id="terms_loop">
37 <bpmn:extensionElements>
38 <camunda:executionListener event="start">
39 <camunda:script scriptFormat="javascript">// make variables local to loop
40 execution.setVariable("analysis", 0, "terms_loop");
41 execution.setVariable('tweets', S('[]'), "terms_loop");</camunda:script>
42 </camunda:executionListener>
43 <camunda:executionListener event="end">
44 <camunda:script scriptFormat="javascript">var results = execution.getVariable("results");
45 var term = execution.getVariable("term");
46 var analysis = execution.getVariable("analysis");
47 var termStr = term.prop('term').value();
49 // this is for dictionary
50 //results.prop(termStr, analysis);
53 item["name"] = termStr;
54 item["sentiment"] = S(analysis).prop("sentiment").value();
57 execution.setVariable("results", S(results))</camunda:script>
58 </camunda:executionListener>
59 </bpmn:extensionElements>
60 <bpmn:incoming>SequenceFlow_0o77usd</bpmn:incoming>
61 <bpmn:outgoing>SequenceFlow_1j2y6tv</bpmn:outgoing>
62 <bpmn:multiInstanceLoopCharacteristics camunda:collection="${terms.elements()}" camunda:elementVariable="term" />
63 <bpmn:serviceTask id="service-analysis" name="Analysis Service">
64 <bpmn:extensionElements>
67 <camunda:inputParameter name="url">http://analysis:8081/</camunda:inputParameter>
68 <camunda:inputParameter name="method">POST</camunda:inputParameter>
69 <camunda:inputParameter name="headers">
71 <camunda:entry key="Accept">application/json</camunda:entry>
72 <camunda:entry key="Content-Type">application/json</camunda:entry>
74 </camunda:inputParameter>
75 <camunda:inputParameter name="payload">${tweets.toString()}</camunda:inputParameter>
76 <camunda:outputParameter name="analysis">${response.trim()}</camunda:outputParameter>
77 </camunda:inputOutput>
78 <camunda:connectorId>http-connector</camunda:connectorId>
80 </bpmn:extensionElements>
81 <bpmn:incoming>SequenceFlow_0g6bfz6</bpmn:incoming>
82 <bpmn:outgoing>SequenceFlow_1bz7zx2</bpmn:outgoing>
84 <bpmn:serviceTask id="service-twitter" name="Twitter Service">
85 <bpmn:extensionElements>
88 <camunda:inputParameter name="url">
89 <camunda:script scriptFormat="Javascript">var term = execution.getVariable("term");
90 'http://twitter:8084/search/tweets.json?q='+encodeURI(term.prop('term').value())</camunda:script>
91 </camunda:inputParameter>
92 <camunda:inputParameter name="method">GET</camunda:inputParameter>
93 <camunda:inputParameter name="headers">
95 <camunda:entry key="Accept">application/json</camunda:entry>
97 </camunda:inputParameter>
98 <camunda:outputParameter name="tweets">
99 <camunda:script scriptFormat="Javascript">var response = connector.getVariable("response");
100 S(response);</camunda:script>
101 </camunda:outputParameter>
102 </camunda:inputOutput>
103 <camunda:connectorId>http-connector</camunda:connectorId>
105 </bpmn:extensionElements>
106 <bpmn:incoming>SequenceFlow_0f6v4j4</bpmn:incoming>
107 <bpmn:outgoing>SequenceFlow_0g6bfz6</bpmn:outgoing>
109 <bpmn:startEvent id="StartEvent_parsing_term">
110 <bpmn:outgoing>SequenceFlow_0f6v4j4</bpmn:outgoing>
112 <bpmn:sequenceFlow id="SequenceFlow_0f6v4j4" sourceRef="StartEvent_parsing_term" targetRef="service-twitter" />
113 <bpmn:sequenceFlow id="SequenceFlow_0g6bfz6" sourceRef="service-twitter" targetRef="service-analysis" />
114 <bpmn:sequenceFlow id="SequenceFlow_1bz7zx2" sourceRef="service-analysis" targetRef="EndEvent_parsing_term" />
115 <bpmn:endEvent id="EndEvent_parsing_term">
116 <bpmn:incoming>SequenceFlow_1bz7zx2</bpmn:incoming>
119 <bpmn:serviceTask id="service-report" name="Report Service">
120 <bpmn:extensionElements>
122 <camunda:inputOutput>
123 <camunda:inputParameter name="url">http://reporting:8083/generatePDF/</camunda:inputParameter>
124 <camunda:inputParameter name="method">POST</camunda:inputParameter>
125 <camunda:inputParameter name="headers">
127 <camunda:entry key="Accept">application/base64</camunda:entry>
128 <camunda:entry key="Content-Type">application/json</camunda:entry>
130 </camunda:inputParameter>
131 <camunda:inputParameter name="payload">${results.toString()}</camunda:inputParameter>
132 <camunda:outputParameter name="reportPDF">
133 <camunda:script scriptFormat="javascript">var response = connector.getVariable("response");
134 // from nodejs base64 package
137 var javaByteArray = Java.type('byte[]')
139 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
140 for (var i = 0, len = code.length; i < len; ++i) {
142 revLookup[code.charCodeAt(i)] = i
145 // Support decoding URL-safe base64 strings, as Node.js does.
146 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
147 revLookup['-'.charCodeAt(0)] = 62
148 revLookup['_'.charCodeAt(0)] = 63
150 function getLens (b64) {
153 if (len % 4 > 0) {
154 throw new Error('Invalid string. Length must be a multiple of 4: '+b64)
157 // Trim off extra bytes after placeholder bytes are found
158 // See: https://github.com/beatgammit/base64-js/issues/42
159 var validLen = b64.indexOf('=')
160 if (validLen === -1) validLen = len
162 var placeHoldersLen = validLen === len
166 return [validLen, placeHoldersLen]
169 function _byteLength (b64, validLen, placeHoldersLen) {
170 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
173 function toByteArray (b64) {
175 var lens = getLens(b64)
176 var validLen = lens[0]
177 var placeHoldersLen = lens[1]
179 var arr = new javaByteArray(_byteLength(b64, validLen, placeHoldersLen))
183 // if there are placeholders, only get up to the last complete 4 chars
184 var len = placeHoldersLen > 0
188 for (var i = 0; i < len; i += 4) {
190 (revLookup[b64.charCodeAt(i)] << 18) |
191 (revLookup[b64.charCodeAt(i + 1)] << 12) |
192 (revLookup[b64.charCodeAt(i + 2)] << 6) |
193 revLookup[b64.charCodeAt(i + 3)]
194 arr[curByte++] = (tmp >> 16) & 0xFF
195 arr[curByte++] = (tmp >> 8) & 0xFF
196 arr[curByte++] = tmp & 0xFF
199 if (placeHoldersLen === 2) {
201 (revLookup[b64.charCodeAt(i)] << 2) |
202 (revLookup[b64.charCodeAt(i + 1)] >> 4)
203 arr[curByte++] = tmp & 0xFF
206 if (placeHoldersLen === 1) {
208 (revLookup[b64.charCodeAt(i)] << 10) |
209 (revLookup[b64.charCodeAt(i + 1)] << 4) |
210 (revLookup[b64.charCodeAt(i + 2)] >> 2)
211 arr[curByte++] = (tmp >> 8) & 0xFF
212 arr[curByte++] = tmp & 0xFF
218 var source = "kP/+kA==";
219 var decoded = toByteArray(source);
221 var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("report.pdf").file(toByteArray(response)).mimeType('application/pdf').create()
222 file</camunda:script>
223 </camunda:outputParameter>
224 </camunda:inputOutput>
225 <camunda:connectorId>http-connector</camunda:connectorId>
227 </bpmn:extensionElements>
228 <bpmn:incoming>SequenceFlow_1j2y6tv</bpmn:incoming>
229 <bpmn:outgoing>SequenceFlow_14nqu0e</bpmn:outgoing>
231 <bpmn:sequenceFlow id="SequenceFlow_1mnqqvo" sourceRef="IntermediateThrowEvent_0sns4tf" targetRef="Task_1e7059p" />
232 <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_0sns4tf">
233 <bpmn:incoming>SequenceFlow_14nqu0e</bpmn:incoming>
234 <bpmn:outgoing>SequenceFlow_1mnqqvo</bpmn:outgoing>
235 <bpmn:timerEventDefinition>
236 <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT0S</bpmn:timeDuration>
237 </bpmn:timerEventDefinition>
238 </bpmn:intermediateCatchEvent>
240 <bpmndi:BPMNDiagram id="BPMNDiagram_1">
241 <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration">
242 <bpmndi:BPMNShape id="Participant_0gzc3m9_di" bpmnElement="Sentiment_Analysis">
243 <dc:Bounds x="0" y="0" width="1084" height="202" />
245 <bpmndi:BPMNShape id="SubProcess_1skl2rb_di" bpmnElement="terms_loop" isExpanded="true">
246 <dc:Bounds x="188" y="19" width="443" height="163" />
248 <bpmndi:BPMNShape id="ServiceTask_01bq7a6_di" bpmnElement="service-analysis">
249 <dc:Bounds x="434" y="60" width="100" height="80" />
251 <bpmndi:BPMNShape id="ServiceTask_1o2usc9_di" bpmnElement="service-twitter">
252 <dc:Bounds x="283" y="60" width="100" height="80" />
254 <bpmndi:BPMNShape id="StartEvent_1nx6b6f_di" bpmnElement="StartEvent_parsing_term">
255 <dc:Bounds x="209" y="82" width="36" height="36" />
257 <bpmndi:BPMNEdge id="SequenceFlow_0f6v4j4_di" bpmnElement="SequenceFlow_0f6v4j4">
258 <di:waypoint x="245" y="100" />
259 <di:waypoint x="283" y="100" />
261 <bpmndi:BPMNEdge id="SequenceFlow_0g6bfz6_di" bpmnElement="SequenceFlow_0g6bfz6">
262 <di:waypoint x="383" y="100" />
263 <di:waypoint x="434" y="100" />
265 <bpmndi:BPMNEdge id="SequenceFlow_1bz7zx2_di" bpmnElement="SequenceFlow_1bz7zx2">
266 <di:waypoint x="534" y="100" />
267 <di:waypoint x="569" y="100" />
269 <bpmndi:BPMNShape id="StartEvent_1t6nxib_di" bpmnElement="StartEvent_1t6nxib">
270 <dc:Bounds x="56" y="83" width="36" height="36" />
272 <bpmndi:BPMNShape id="ServiceTask_1gaqtzh_di" bpmnElement="service-report">
273 <dc:Bounds x="664" y="61" width="100" height="80" />
275 <bpmndi:BPMNShape id="UserTask_0iooc2g_di" bpmnElement="Task_1e7059p">
276 <dc:Bounds x="889" y="61" width="100" height="80" />
278 <bpmndi:BPMNShape id="EndEvent_0bmuv13_di" bpmnElement="EndEvent_0bmuv13">
279 <dc:Bounds x="1024" y="83" width="36" height="36" />
281 <bpmndi:BPMNEdge id="SequenceFlow_14nqu0e_di" bpmnElement="SequenceFlow_14nqu0e">
282 <di:waypoint x="764" y="101" />
283 <di:waypoint x="803" y="101" />
285 <bpmndi:BPMNEdge id="SequenceFlow_0jebdb9_di" bpmnElement="SequenceFlow_0jebdb9">
286 <di:waypoint x="989" y="101" />
287 <di:waypoint x="1024" y="101" />
289 <bpmndi:BPMNEdge id="SequenceFlow_15dip2q_di" bpmnElement="SequenceFlow_15dip2q">
290 <di:waypoint x="92" y="101" />
291 <di:waypoint x="122" y="101" />
293 <bpmndi:BPMNEdge id="SequenceFlow_1j2y6tv_di" bpmnElement="SequenceFlow_1j2y6tv">
294 <di:waypoint x="631" y="101" />
295 <di:waypoint x="664" y="101" />
297 <bpmndi:BPMNShape id="EndEvent_07g109m_di" bpmnElement="EndEvent_parsing_term">
298 <dc:Bounds x="569" y="82" width="36" height="36" />
300 <bpmndi:BPMNEdge id="SequenceFlow_0o77usd_di" bpmnElement="SequenceFlow_0o77usd">
301 <di:waypoint x="158" y="101" />
302 <di:waypoint x="188" y="101" />
304 <bpmndi:BPMNShape id="IntermediateCatchEvent_1248i6u_di" bpmnElement="IntermediateThrowEvent_193oik9">
305 <dc:Bounds x="122" y="83" width="36" height="36" />
307 <bpmndi:BPMNEdge id="SequenceFlow_1mnqqvo_di" bpmnElement="SequenceFlow_1mnqqvo">
308 <di:waypoint x="839" y="101" />
309 <di:waypoint x="889" y="101" />
311 <bpmndi:BPMNShape id="IntermediateCatchEvent_065fcij_di" bpmnElement="IntermediateThrowEvent_0sns4tf">
312 <dc:Bounds x="803" y="83" width="36" height="36" />
315 </bpmndi:BPMNDiagram>