]> git.somenet.org - pub/jan/aic18.git/blob - camunda-overlay/sentiment-analysis.bpmn
Add empty website 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: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>
20     </bpmn:startEvent>
21     <bpmn:endEvent id="EndEvent_0bmuv13">
22       <bpmn:incoming>SequenceFlow_0jebdb9</bpmn:incoming>
23     </bpmn:endEvent>
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>
28     </bpmn:userTask>
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();
48
49 // this is for dictionary
50 //results.prop(termStr, analysis);
51 // this is for list
52 var item = {};
53 item["name"] = termStr;
54 item["sentiment"] = S(analysis).prop("sentiment").value();
55 results.append(item);
56
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>
65           <camunda:connector>
66             <camunda:inputOutput>
67               <camunda:inputParameter name="url">http://analysis:8081/</camunda:inputParameter>
68               <camunda:inputParameter name="method">POST</camunda:inputParameter>
69               <camunda:inputParameter name="headers">
70                 <camunda:map>
71                   <camunda:entry key="Accept">application/json</camunda:entry>
72                   <camunda:entry key="Content-Type">application/json</camunda:entry>
73                 </camunda:map>
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>
79           </camunda:connector>
80         </bpmn:extensionElements>
81         <bpmn:incoming>SequenceFlow_0g6bfz6</bpmn:incoming>
82         <bpmn:outgoing>SequenceFlow_1bz7zx2</bpmn:outgoing>
83       </bpmn:serviceTask>
84       <bpmn:serviceTask id="service-twitter" name="Twitter Service">
85         <bpmn:extensionElements>
86           <camunda:connector>
87             <camunda:inputOutput>
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">
94                 <camunda:map>
95                   <camunda:entry key="Accept">application/json</camunda:entry>
96                 </camunda:map>
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>
104           </camunda:connector>
105         </bpmn:extensionElements>
106         <bpmn:incoming>SequenceFlow_0f6v4j4</bpmn:incoming>
107         <bpmn:outgoing>SequenceFlow_0g6bfz6</bpmn:outgoing>
108       </bpmn:serviceTask>
109       <bpmn:startEvent id="StartEvent_parsing_term">
110         <bpmn:outgoing>SequenceFlow_0f6v4j4</bpmn:outgoing>
111       </bpmn:startEvent>
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>
117       </bpmn:endEvent>
118     </bpmn:subProcess>
119     <bpmn:serviceTask id="service-report" name="Report Service">
120       <bpmn:extensionElements>
121         <camunda:connector>
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">
126               <camunda:map>
127                 <camunda:entry key="Accept">application/base64</camunda:entry>
128                 <camunda:entry key="Content-Type">application/json</camunda:entry>
129               </camunda:map>
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                             
135 var lookup = []
136 var revLookup = []
137 var javaByteArray = Java.type('byte[]')
138
139 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
140 for (var i = 0, len = code.length; i &lt; len; ++i) {
141   lookup[i] = code[i]
142   revLookup[code.charCodeAt(i)] = i
143 }
144
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
149
150 function getLens (b64) {
151   var len = b64.length
152
153   if (len % 4 &gt; 0) {
154     throw new Error('Invalid string. Length must be a multiple of 4: '+b64)
155   }
156
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
161
162   var placeHoldersLen = validLen === len
163     ? 0
164     : 4 - (validLen % 4)
165
166   return [validLen, placeHoldersLen]
167 }
168
169 function _byteLength (b64, validLen, placeHoldersLen) {
170   return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
171 }
172
173 function toByteArray (b64) {
174   var tmp
175   var lens = getLens(b64)
176   var validLen = lens[0]
177   var placeHoldersLen = lens[1]
178
179   var arr = new javaByteArray(_byteLength(b64, validLen, placeHoldersLen))
180
181   var curByte = 0
182
183   // if there are placeholders, only get up to the last complete 4 chars
184   var len = placeHoldersLen &gt; 0
185     ? validLen - 4
186     : validLen
187
188   for (var i = 0; i &lt; len; i += 4) {
189     tmp =
190       (revLookup[b64.charCodeAt(i)] &lt;&lt; 18) |
191       (revLookup[b64.charCodeAt(i + 1)] &lt;&lt; 12) |
192       (revLookup[b64.charCodeAt(i + 2)] &lt;&lt; 6) |
193       revLookup[b64.charCodeAt(i + 3)]
194     arr[curByte++] = (tmp &gt;&gt; 16) &amp; 0xFF
195     arr[curByte++] = (tmp &gt;&gt; 8) &amp; 0xFF
196     arr[curByte++] = tmp &amp; 0xFF
197   }
198
199   if (placeHoldersLen === 2) {
200     tmp =
201       (revLookup[b64.charCodeAt(i)] &lt;&lt; 2) |
202       (revLookup[b64.charCodeAt(i + 1)] &gt;&gt; 4)
203     arr[curByte++] = tmp &amp; 0xFF
204   }
205
206   if (placeHoldersLen === 1) {
207     tmp =
208       (revLookup[b64.charCodeAt(i)] &lt;&lt; 10) |
209       (revLookup[b64.charCodeAt(i + 1)] &lt;&lt; 4) |
210       (revLookup[b64.charCodeAt(i + 2)] &gt;&gt; 2)
211     arr[curByte++] = (tmp &gt;&gt; 8) &amp; 0xFF
212     arr[curByte++] = tmp &amp; 0xFF
213   }
214
215   return arr
216 }
217
218 var source = "kP/+kA==";
219 var decoded = toByteArray(source);
220 //decoded
221 var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("pdfTest").file(toByteArray(response)).mimeType('application/pdf').create()
222 file</camunda:script>
223             </camunda:outputParameter>
224           </camunda:inputOutput>
225           <camunda:connectorId>http-connector</camunda:connectorId>
226         </camunda:connector>
227       </bpmn:extensionElements>
228       <bpmn:incoming>SequenceFlow_1j2y6tv</bpmn:incoming>
229       <bpmn:outgoing>SequenceFlow_14nqu0e</bpmn:outgoing>
230     </bpmn:serviceTask>
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>
239   </bpmn:process>
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" />
244       </bpmndi:BPMNShape>
245       <bpmndi:BPMNShape id="SubProcess_1skl2rb_di" bpmnElement="terms_loop" isExpanded="true">
246         <dc:Bounds x="188" y="19" width="443" height="163" />
247       </bpmndi:BPMNShape>
248       <bpmndi:BPMNShape id="ServiceTask_01bq7a6_di" bpmnElement="service-analysis">
249         <dc:Bounds x="434" y="60" width="100" height="80" />
250       </bpmndi:BPMNShape>
251       <bpmndi:BPMNShape id="ServiceTask_1o2usc9_di" bpmnElement="service-twitter">
252         <dc:Bounds x="283" y="60" width="100" height="80" />
253       </bpmndi:BPMNShape>
254       <bpmndi:BPMNShape id="StartEvent_1nx6b6f_di" bpmnElement="StartEvent_parsing_term">
255         <dc:Bounds x="209" y="82" width="36" height="36" />
256       </bpmndi:BPMNShape>
257       <bpmndi:BPMNEdge id="SequenceFlow_0f6v4j4_di" bpmnElement="SequenceFlow_0f6v4j4">
258         <di:waypoint x="245" y="100" />
259         <di:waypoint x="283" y="100" />
260       </bpmndi:BPMNEdge>
261       <bpmndi:BPMNEdge id="SequenceFlow_0g6bfz6_di" bpmnElement="SequenceFlow_0g6bfz6">
262         <di:waypoint x="383" y="100" />
263         <di:waypoint x="434" y="100" />
264       </bpmndi:BPMNEdge>
265       <bpmndi:BPMNEdge id="SequenceFlow_1bz7zx2_di" bpmnElement="SequenceFlow_1bz7zx2">
266         <di:waypoint x="534" y="100" />
267         <di:waypoint x="569" y="100" />
268       </bpmndi:BPMNEdge>
269       <bpmndi:BPMNShape id="StartEvent_1t6nxib_di" bpmnElement="StartEvent_1t6nxib">
270         <dc:Bounds x="56" y="83" width="36" height="36" />
271       </bpmndi:BPMNShape>
272       <bpmndi:BPMNShape id="ServiceTask_1gaqtzh_di" bpmnElement="service-report">
273         <dc:Bounds x="664" y="61" width="100" height="80" />
274       </bpmndi:BPMNShape>
275       <bpmndi:BPMNShape id="UserTask_0iooc2g_di" bpmnElement="Task_1e7059p">
276         <dc:Bounds x="889" y="61" width="100" height="80" />
277       </bpmndi:BPMNShape>
278       <bpmndi:BPMNShape id="EndEvent_0bmuv13_di" bpmnElement="EndEvent_0bmuv13">
279         <dc:Bounds x="1024" y="83" width="36" height="36" />
280       </bpmndi:BPMNShape>
281       <bpmndi:BPMNEdge id="SequenceFlow_14nqu0e_di" bpmnElement="SequenceFlow_14nqu0e">
282         <di:waypoint x="764" y="101" />
283         <di:waypoint x="803" y="101" />
284       </bpmndi:BPMNEdge>
285       <bpmndi:BPMNEdge id="SequenceFlow_0jebdb9_di" bpmnElement="SequenceFlow_0jebdb9">
286         <di:waypoint x="989" y="101" />
287         <di:waypoint x="1024" y="101" />
288       </bpmndi:BPMNEdge>
289       <bpmndi:BPMNEdge id="SequenceFlow_15dip2q_di" bpmnElement="SequenceFlow_15dip2q">
290         <di:waypoint x="92" y="101" />
291         <di:waypoint x="122" y="101" />
292       </bpmndi:BPMNEdge>
293       <bpmndi:BPMNEdge id="SequenceFlow_1j2y6tv_di" bpmnElement="SequenceFlow_1j2y6tv">
294         <di:waypoint x="631" y="101" />
295         <di:waypoint x="664" y="101" />
296       </bpmndi:BPMNEdge>
297       <bpmndi:BPMNShape id="EndEvent_07g109m_di" bpmnElement="EndEvent_parsing_term">
298         <dc:Bounds x="569" y="82" width="36" height="36" />
299       </bpmndi:BPMNShape>
300       <bpmndi:BPMNEdge id="SequenceFlow_0o77usd_di" bpmnElement="SequenceFlow_0o77usd">
301         <di:waypoint x="158" y="101" />
302         <di:waypoint x="188" y="101" />
303       </bpmndi:BPMNEdge>
304       <bpmndi:BPMNShape id="IntermediateCatchEvent_1248i6u_di" bpmnElement="IntermediateThrowEvent_193oik9">
305         <dc:Bounds x="122" y="83" width="36" height="36" />
306       </bpmndi:BPMNShape>
307       <bpmndi:BPMNEdge id="SequenceFlow_1mnqqvo_di" bpmnElement="SequenceFlow_1mnqqvo">
308         <di:waypoint x="839" y="101" />
309         <di:waypoint x="889" y="101" />
310       </bpmndi:BPMNEdge>
311       <bpmndi:BPMNShape id="IntermediateCatchEvent_065fcij_di" bpmnElement="IntermediateThrowEvent_0sns4tf">
312         <dc:Bounds x="803" y="83" width="36" height="36" />
313       </bpmndi:BPMNShape>
314     </bpmndi:BPMNPlane>
315   </bpmndi:BPMNDiagram>
316 </bpmn:definitions>