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