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