]> git.somenet.org - pub/jan/aic18.git/blob - camunda-overlay/sentiment-analysis.bpmn
Merge branch 'master' into '48-create-failover-service'
[pub/jan/aic18.git] / camunda-overlay / sentiment-analysis.bpmn
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" />
5   </bpmn:collaboration>
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:sequenceFlow id="SequenceFlow_0o77usd" sourceRef="IntermediateThrowEvent_193oik9" targetRef="terms_loop" />
13     <bpmn:subProcess id="terms_loop">
14       <bpmn:extensionElements>
15         <camunda:executionListener event="start">
16           <camunda:script scriptFormat="javascript">// make variables local to loop
17 execution.setVariable("analysis", 0, "terms_loop");
18 execution.setVariable('tweets', S('[]'), "terms_loop");</camunda:script>
19         </camunda:executionListener>
20         <camunda:executionListener event="end">
21           <camunda:script scriptFormat="javascript">var results = execution.getVariable("results");
22 var term = execution.getVariable("term");
23 var analysis = execution.getVariable("analysis");
24 var termStr = term.prop('term').value();
25
26 // this is for dictionary
27 //results.prop(termStr, analysis);
28 // this is for list
29 var item = {};
30 item["name"] = termStr;
31 item["sentiment"] = S(analysis).prop("sentiment").value();
32 results.append(item);
33
34 execution.setVariable("results", S(results))</camunda:script>
35         </camunda:executionListener>
36       </bpmn:extensionElements>
37       <bpmn:incoming>SequenceFlow_0o77usd</bpmn:incoming>
38       <bpmn:outgoing>SequenceFlow_1j2y6tv</bpmn:outgoing>
39       <bpmn:multiInstanceLoopCharacteristics camunda:collection="${terms.elements()}" camunda:elementVariable="term" />
40       <bpmn:serviceTask id="service-analysis" name="Analysis Service">
41         <bpmn:extensionElements>
42           <camunda:connector>
43             <camunda:inputOutput>
44               <camunda:inputParameter name="url">http://analysis:8081/</camunda:inputParameter>
45               <camunda:inputParameter name="method">POST</camunda:inputParameter>
46               <camunda:inputParameter name="headers">
47                 <camunda:map>
48                   <camunda:entry key="Accept">application/json</camunda:entry>
49                   <camunda:entry key="Content-Type">application/json</camunda:entry>
50                 </camunda:map>
51               </camunda:inputParameter>
52               <camunda:inputParameter name="payload">${tweets.toString()}</camunda:inputParameter>
53               <camunda:outputParameter name="analysis">${response.trim()}</camunda:outputParameter>
54             </camunda:inputOutput>
55             <camunda:connectorId>http-connector</camunda:connectorId>
56           </camunda:connector>
57         </bpmn:extensionElements>
58         <bpmn:incoming>SequenceFlow_0g6bfz6</bpmn:incoming>
59         <bpmn:outgoing>SequenceFlow_1bz7zx2</bpmn:outgoing>
60       </bpmn:serviceTask>
61       <bpmn:serviceTask id="service-twitter" name="Twitter Service">
62         <bpmn:extensionElements>
63           <camunda:connector>
64             <camunda:inputOutput>
65               <camunda:inputParameter name="url">
66                 <camunda:script scriptFormat="Javascript">var term = execution.getVariable("term");
67 'http://twitter:8084/search/tweets.json?q='+encodeURI(term.prop('term').value())</camunda:script>
68               </camunda:inputParameter>
69               <camunda:inputParameter name="method">GET</camunda:inputParameter>
70               <camunda:inputParameter name="headers">
71                 <camunda:map>
72                   <camunda:entry key="Accept">application/json</camunda:entry>
73                 </camunda:map>
74               </camunda:inputParameter>
75               <camunda:outputParameter name="tweets">
76                 <camunda:script scriptFormat="Javascript">var response = connector.getVariable("response");
77 S(response);</camunda:script>
78               </camunda:outputParameter>
79             </camunda:inputOutput>
80             <camunda:connectorId>http-connector</camunda:connectorId>
81           </camunda:connector>
82         </bpmn:extensionElements>
83         <bpmn:incoming>SequenceFlow_0f6v4j4</bpmn:incoming>
84         <bpmn:outgoing>SequenceFlow_0g6bfz6</bpmn:outgoing>
85       </bpmn:serviceTask>
86       <bpmn:startEvent id="StartEvent_parsing_term">
87         <bpmn:outgoing>SequenceFlow_0f6v4j4</bpmn:outgoing>
88       </bpmn:startEvent>
89       <bpmn:sequenceFlow id="SequenceFlow_0f6v4j4" sourceRef="StartEvent_parsing_term" targetRef="service-twitter" />
90       <bpmn:sequenceFlow id="SequenceFlow_0g6bfz6" sourceRef="service-twitter" targetRef="service-analysis" />
91       <bpmn:sequenceFlow id="SequenceFlow_1bz7zx2" sourceRef="service-analysis" targetRef="EndEvent_parsing_term" />
92       <bpmn:endEvent id="EndEvent_parsing_term">
93         <bpmn:incoming>SequenceFlow_1bz7zx2</bpmn:incoming>
94         <bpmn:incoming>SequenceFlow_0d4q1qg</bpmn:incoming>
95       </bpmn:endEvent>
96       <bpmn:boundaryEvent id="BoundaryEvent_0qgiers" attachedToRef="service-analysis">
97         <bpmn:outgoing>SequenceFlow_0a608kq</bpmn:outgoing>
98         <bpmn:errorEventDefinition />
99       </bpmn:boundaryEvent>
100       <bpmn:serviceTask id="ServiceTask_0y5nlkj" name="Analysis Service">
101         <bpmn:extensionElements>
102           <camunda:connector>
103             <camunda:inputOutput>
104               <camunda:inputParameter name="url">http://analysis:8081/offline_analysis/</camunda:inputParameter>
105               <camunda:inputParameter name="method">POST</camunda:inputParameter>
106               <camunda:inputParameter name="headers">
107                 <camunda:map>
108                   <camunda:entry key="Accept">application/json</camunda:entry>
109                   <camunda:entry key="Content-Type">application/json</camunda:entry>
110                 </camunda:map>
111               </camunda:inputParameter>
112               <camunda:inputParameter name="payload">${tweets.toString()}</camunda:inputParameter>
113               <camunda:outputParameter name="analysis">${response.trim()}</camunda:outputParameter>
114             </camunda:inputOutput>
115             <camunda:connectorId>http-connector</camunda:connectorId>
116           </camunda:connector>
117         </bpmn:extensionElements>
118         <bpmn:incoming>SequenceFlow_0a608kq</bpmn:incoming>
119         <bpmn:outgoing>SequenceFlow_0d4q1qg</bpmn:outgoing>
120       </bpmn:serviceTask>
121       <bpmn:sequenceFlow id="SequenceFlow_0a608kq" sourceRef="BoundaryEvent_0qgiers" targetRef="ServiceTask_0y5nlkj" />
122       <bpmn:sequenceFlow id="SequenceFlow_0d4q1qg" sourceRef="ServiceTask_0y5nlkj" targetRef="EndEvent_parsing_term" />
123     </bpmn:subProcess>
124     <bpmn:sequenceFlow id="SequenceFlow_1mnqqvo" sourceRef="IntermediateThrowEvent_0sns4tf" targetRef="Task_1e7059p" />
125     <bpmn:sequenceFlow id="SequenceFlow_0pjn3f9" sourceRef="BoundaryEvent_0vcqy0m" targetRef="IntermediateThrowEvent_193oik9" />
126     <bpmn:boundaryEvent id="BoundaryEvent_0vcqy0m" attachedToRef="terms_loop">
127       <bpmn:outgoing>SequenceFlow_0pjn3f9</bpmn:outgoing>
128       <bpmn:errorEventDefinition />
129     </bpmn:boundaryEvent>
130     <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_193oik9">
131       <bpmn:incoming>SequenceFlow_15dip2q</bpmn:incoming>
132       <bpmn:incoming>SequenceFlow_0pjn3f9</bpmn:incoming>
133       <bpmn:outgoing>SequenceFlow_0o77usd</bpmn:outgoing>
134       <bpmn:timerEventDefinition>
135         <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT0S</bpmn:timeDuration>
136       </bpmn:timerEventDefinition>
137     </bpmn:intermediateCatchEvent>
138     <bpmn:startEvent id="StartEvent_1t6nxib" camunda:formKey="embedded:deployment:input-terms.html">
139       <bpmn:extensionElements>
140         <camunda:executionListener event="start">
141           <camunda:script scriptFormat="javascript">// make variable global
142 execution.setVariable("results", S('[]'))</camunda:script>
143         </camunda:executionListener>
144       </bpmn:extensionElements>
145       <bpmn:outgoing>SequenceFlow_15dip2q</bpmn:outgoing>
146     </bpmn:startEvent>
147     <bpmn:serviceTask id="service-report" name="Report Service">
148       <bpmn:extensionElements>
149         <camunda:connector>
150           <camunda:inputOutput>
151             <camunda:inputParameter name="url">http://reporting:8083/generatePDF/</camunda:inputParameter>
152             <camunda:inputParameter name="method">POST</camunda:inputParameter>
153             <camunda:inputParameter name="headers">
154               <camunda:map>
155                 <camunda:entry key="Accept">application/base64</camunda:entry>
156                 <camunda:entry key="Content-Type">application/json</camunda:entry>
157               </camunda:map>
158             </camunda:inputParameter>
159             <camunda:inputParameter name="payload">${results.toString()}</camunda:inputParameter>
160             <camunda:outputParameter name="reportPDF">
161               <camunda:script scriptFormat="javascript">var response = connector.getVariable("response");
162 // from nodejs base64 package                             
163 var lookup = []
164 var revLookup = []
165 var javaByteArray = Java.type('byte[]')
166
167 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
168 for (var i = 0, len = code.length; i &lt; len; ++i) {
169   lookup[i] = code[i]
170   revLookup[code.charCodeAt(i)] = i
171 }
172
173 // Support decoding URL-safe base64 strings, as Node.js does.
174 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
175 revLookup['-'.charCodeAt(0)] = 62
176 revLookup['_'.charCodeAt(0)] = 63
177
178 function getLens (b64) {
179   var len = b64.length
180
181   if (len % 4 &gt; 0) {
182     throw new Error('Invalid string. Length must be a multiple of 4: '+b64)
183   }
184
185   // Trim off extra bytes after placeholder bytes are found
186   // See: https://github.com/beatgammit/base64-js/issues/42
187   var validLen = b64.indexOf('=')
188   if (validLen === -1) validLen = len
189
190   var placeHoldersLen = validLen === len
191     ? 0
192     : 4 - (validLen % 4)
193
194   return [validLen, placeHoldersLen]
195 }
196
197 function _byteLength (b64, validLen, placeHoldersLen) {
198   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
199 }
200
201 function toByteArray (b64) {
202   var tmp
203   var lens = getLens(b64)
204   var validLen = lens[0]
205   var placeHoldersLen = lens[1]
206
207   var arr = new javaByteArray(_byteLength(b64, validLen, placeHoldersLen))
208
209   var curByte = 0
210
211   // if there are placeholders, only get up to the last complete 4 chars
212   var len = placeHoldersLen &gt; 0
213     ? validLen - 4
214     : validLen
215
216   for (var i = 0; i &lt; len; i += 4) {
217     tmp =
218       (revLookup[b64.charCodeAt(i)] &lt;&lt; 18) |
219       (revLookup[b64.charCodeAt(i + 1)] &lt;&lt; 12) |
220       (revLookup[b64.charCodeAt(i + 2)] &lt;&lt; 6) |
221       revLookup[b64.charCodeAt(i + 3)]
222     arr[curByte++] = (tmp &gt;&gt; 16) &amp; 0xFF
223     arr[curByte++] = (tmp &gt;&gt; 8) &amp; 0xFF
224     arr[curByte++] = tmp &amp; 0xFF
225   }
226
227   if (placeHoldersLen === 2) {
228     tmp =
229       (revLookup[b64.charCodeAt(i)] &lt;&lt; 2) |
230       (revLookup[b64.charCodeAt(i + 1)] &gt;&gt; 4)
231     arr[curByte++] = tmp &amp; 0xFF
232   }
233
234   if (placeHoldersLen === 1) {
235     tmp =
236       (revLookup[b64.charCodeAt(i)] &lt;&lt; 10) |
237       (revLookup[b64.charCodeAt(i + 1)] &lt;&lt; 4) |
238       (revLookup[b64.charCodeAt(i + 2)] &gt;&gt; 2)
239     arr[curByte++] = (tmp &gt;&gt; 8) &amp; 0xFF
240     arr[curByte++] = tmp &amp; 0xFF
241   }
242
243   return arr
244 }
245
246 var source = "kP/+kA==";
247 var decoded = toByteArray(source);
248 //decoded
249 var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("pdfTest").file(toByteArray(response)).mimeType('application/pdf').create()
250 file</camunda:script>
251             </camunda:outputParameter>
252           </camunda:inputOutput>
253           <camunda:connectorId>http-connector</camunda:connectorId>
254         </camunda:connector>
255       </bpmn:extensionElements>
256       <bpmn:incoming>SequenceFlow_1j2y6tv</bpmn:incoming>
257       <bpmn:outgoing>SequenceFlow_14nqu0e</bpmn:outgoing>
258     </bpmn:serviceTask>
259     <bpmn:intermediateCatchEvent id="IntermediateThrowEvent_0sns4tf">
260       <bpmn:incoming>SequenceFlow_14nqu0e</bpmn:incoming>
261       <bpmn:outgoing>SequenceFlow_1mnqqvo</bpmn:outgoing>
262       <bpmn:timerEventDefinition>
263         <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT0S</bpmn:timeDuration>
264       </bpmn:timerEventDefinition>
265     </bpmn:intermediateCatchEvent>
266     <bpmn:userTask id="Task_1e7059p" name="download pdf" camunda:formKey="embedded:deployment:download-pdf.html">
267       <bpmn:incoming>SequenceFlow_1mnqqvo</bpmn:incoming>
268       <bpmn:outgoing>SequenceFlow_0jebdb9</bpmn:outgoing>
269     </bpmn:userTask>
270     <bpmn:endEvent id="EndEvent_0bmuv13">
271       <bpmn:incoming>SequenceFlow_0jebdb9</bpmn:incoming>
272     </bpmn:endEvent>
273   </bpmn:process>
274   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
275     <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration">
276       <bpmndi:BPMNShape id="Participant_0gzc3m9_di" bpmnElement="Sentiment_Analysis">
277         <dc:Bounds x="0" y="0" width="1087" height="369" />
278       </bpmndi:BPMNShape>
279       <bpmndi:BPMNShape id="SubProcess_1skl2rb_di" bpmnElement="terms_loop" isExpanded="true">
280         <dc:Bounds x="188" y="19" width="440" height="297" />
281       </bpmndi:BPMNShape>
282       <bpmndi:BPMNShape id="ServiceTask_01bq7a6_di" bpmnElement="service-analysis">
283         <dc:Bounds x="434" y="60" width="100" height="80" />
284       </bpmndi:BPMNShape>
285       <bpmndi:BPMNShape id="ServiceTask_1o2usc9_di" bpmnElement="service-twitter">
286         <dc:Bounds x="283" y="60" width="100" height="80" />
287       </bpmndi:BPMNShape>
288       <bpmndi:BPMNShape id="StartEvent_1nx6b6f_di" bpmnElement="StartEvent_parsing_term">
289         <dc:Bounds x="209" y="82" width="36" height="36" />
290       </bpmndi:BPMNShape>
291       <bpmndi:BPMNEdge id="SequenceFlow_0f6v4j4_di" bpmnElement="SequenceFlow_0f6v4j4">
292         <di:waypoint x="245" y="100" />
293         <di:waypoint x="283" y="100" />
294       </bpmndi:BPMNEdge>
295       <bpmndi:BPMNEdge id="SequenceFlow_0g6bfz6_di" bpmnElement="SequenceFlow_0g6bfz6">
296         <di:waypoint x="383" y="100" />
297         <di:waypoint x="434" y="100" />
298       </bpmndi:BPMNEdge>
299       <bpmndi:BPMNEdge id="SequenceFlow_1bz7zx2_di" bpmnElement="SequenceFlow_1bz7zx2">
300         <di:waypoint x="534" y="100" />
301         <di:waypoint x="569" y="100" />
302       </bpmndi:BPMNEdge>
303       <bpmndi:BPMNShape id="StartEvent_1t6nxib_di" bpmnElement="StartEvent_1t6nxib">
304         <dc:Bounds x="54" y="151" width="36" height="36" />
305       </bpmndi:BPMNShape>
306       <bpmndi:BPMNShape id="ServiceTask_1gaqtzh_di" bpmnElement="service-report">
307         <dc:Bounds x="664" y="129" width="100" height="80" />
308       </bpmndi:BPMNShape>
309       <bpmndi:BPMNShape id="UserTask_0iooc2g_di" bpmnElement="Task_1e7059p">
310         <dc:Bounds x="882" y="129" width="100" height="80" />
311       </bpmndi:BPMNShape>
312       <bpmndi:BPMNShape id="EndEvent_0bmuv13_di" bpmnElement="EndEvent_0bmuv13">
313         <dc:Bounds x="1021" y="151" width="36" height="36" />
314       </bpmndi:BPMNShape>
315       <bpmndi:BPMNEdge id="SequenceFlow_14nqu0e_di" bpmnElement="SequenceFlow_14nqu0e">
316         <di:waypoint x="764" y="169" />
317         <di:waypoint x="804" y="169" />
318       </bpmndi:BPMNEdge>
319       <bpmndi:BPMNEdge id="SequenceFlow_0jebdb9_di" bpmnElement="SequenceFlow_0jebdb9">
320         <di:waypoint x="982" y="169" />
321         <di:waypoint x="1021" y="169" />
322       </bpmndi:BPMNEdge>
323       <bpmndi:BPMNEdge id="SequenceFlow_15dip2q_di" bpmnElement="SequenceFlow_15dip2q">
324         <di:waypoint x="90" y="169" />
325         <di:waypoint x="122" y="169" />
326       </bpmndi:BPMNEdge>
327       <bpmndi:BPMNEdge id="SequenceFlow_1j2y6tv_di" bpmnElement="SequenceFlow_1j2y6tv">
328         <di:waypoint x="628" y="169" />
329         <di:waypoint x="664" y="169" />
330       </bpmndi:BPMNEdge>
331       <bpmndi:BPMNShape id="EndEvent_07g109m_di" bpmnElement="EndEvent_parsing_term">
332         <dc:Bounds x="569" y="82" width="36" height="36" />
333       </bpmndi:BPMNShape>
334       <bpmndi:BPMNEdge id="SequenceFlow_0o77usd_di" bpmnElement="SequenceFlow_0o77usd">
335         <di:waypoint x="158" y="169" />
336         <di:waypoint x="188" y="169" />
337       </bpmndi:BPMNEdge>
338       <bpmndi:BPMNShape id="IntermediateCatchEvent_1248i6u_di" bpmnElement="IntermediateThrowEvent_193oik9">
339         <dc:Bounds x="122" y="151" width="36" height="36" />
340       </bpmndi:BPMNShape>
341       <bpmndi:BPMNEdge id="SequenceFlow_1mnqqvo_di" bpmnElement="SequenceFlow_1mnqqvo">
342         <di:waypoint x="840" y="169" />
343         <di:waypoint x="882" y="169" />
344       </bpmndi:BPMNEdge>
345       <bpmndi:BPMNShape id="IntermediateCatchEvent_065fcij_di" bpmnElement="IntermediateThrowEvent_0sns4tf">
346         <dc:Bounds x="804" y="151" width="36" height="36" />
347       </bpmndi:BPMNShape>
348       <bpmndi:BPMNShape id="BoundaryEvent_1yw4jbm_di" bpmnElement="BoundaryEvent_0vcqy0m">
349         <dc:Bounds x="566" y="298" width="36" height="36" />
350       </bpmndi:BPMNShape>
351       <bpmndi:BPMNEdge id="SequenceFlow_0pjn3f9_di" bpmnElement="SequenceFlow_0pjn3f9">
352         <di:waypoint x="584" y="334" />
353         <di:waypoint x="584" y="354" />
354         <di:waypoint x="140" y="354" />
355         <di:waypoint x="140" y="187" />
356       </bpmndi:BPMNEdge>
357       <bpmndi:BPMNShape id="BoundaryEvent_1gxbbqe_di" bpmnElement="BoundaryEvent_0qgiers">
358         <dc:Bounds x="466" y="122" width="36" height="36" />
359       </bpmndi:BPMNShape>
360       <bpmndi:BPMNShape id="ServiceTask_0y5nlkj_di" bpmnElement="ServiceTask_0y5nlkj">
361         <dc:Bounds x="434" y="202" width="100" height="80" />
362       </bpmndi:BPMNShape>
363       <bpmndi:BPMNEdge id="SequenceFlow_0a608kq_di" bpmnElement="SequenceFlow_0a608kq">
364         <di:waypoint x="484" y="158" />
365         <di:waypoint x="484" y="202" />
366       </bpmndi:BPMNEdge>
367       <bpmndi:BPMNEdge id="SequenceFlow_0d4q1qg_di" bpmnElement="SequenceFlow_0d4q1qg">
368         <di:waypoint x="534" y="242" />
369         <di:waypoint x="552" y="242" />
370         <di:waypoint x="552" y="100" />
371         <di:waypoint x="569" y="100" />
372       </bpmndi:BPMNEdge>
373     </bpmndi:BPMNPlane>
374   </bpmndi:BPMNDiagram>
375 </bpmn:definitions>