#return [proc for proc in res.json() if proc['name'] == key]
return res.json()
+def get_current_process_instances(key = 'sentiment-analysis'):
+ res = requests.get(CAMUNDA + 'process-instance')
+ if (key is None):
+ return res.json()
+ else:
+ return [instance for instance in res.json() if instance['definitionId'].startswith(key + ":")]
+
def cleanup_old_deployments(key='sentiment-analysis'):
print ("Cleaning up old deployments")
for deployment in get_current_deployments(key):
except:
pprint(res.content)
+def get_users():
+ res = requests.get(CAMUNDA + "user")
+ return res.json()
+
+def cleanup_users(keep = ["demo"]):
+ for user in get_users():
+ # keep user "demo"
+ if user['id'] in keep:
+ continue
+
+ res = requests.delete(CAMUNDA + "user/" + user['id'])
+ if (res.status_code == 204):
+ print ("Cleaned up user {}".format(user['id']))
+ else:
+ print ("Error cleaning user {}: Code: {}".format(user['id'], res.status_code))
+ try:
+ pprint(res.json())
+ except:
+ pprint(res.content)
+
def create_deployment(cleanup=False):
parameters = [
("deployment-name", "sentiment-analysis"),
except:
pprint(res.content)
+def download_pdf():
+ instances = get_current_process_instances()
+ if len(instances) == 0:
+ print ("Error: no running instance found.")
+ return
+ instance = instances[0]['id']
+ res = requests.get(CAMUNDA + 'process-instance/' + instance + '/variables')
+ try:
+ pprint(res.json())
+ except:
+ pprint(res.content)
+
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--no-deploy', dest='deploy', default=True, action='store_false', help="Do not run the deployment step")
if args.deploy:
# initialize camunda process
create_deployment(cleanup=args.cleanup)
+ if args.cleanup:
+ cleanup_users()
if args.autoclick >= 1:
# start clicking
submit_terms(["voting", "phonegate", "35c3"])
+
+ if args.autoclick >= 2:
+ download_pdf()
//results.prop(termStr, analysis);
// this is for list
var item = {};
-item[termStr] = analysis;
-results.append(item)
+item["name"] = termStr;
+item["sentiment"] = S(analysis).prop("sentiment").value();
+results.append(item);
execution.setVariable("results", S(results))</camunda:script>
</camunda:executionListener>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="payload">${tweets.toString()}</camunda:inputParameter>
- <camunda:outputParameter name="analysis">
- <camunda:script scriptFormat="Javascript">var response = connector.getVariable("response");
-response.trim()</camunda:script>
- </camunda:outputParameter>
+ <camunda:outputParameter name="analysis">${response.trim()}</camunda:outputParameter>
</camunda:inputOutput>
<camunda:connectorId>http-connector</camunda:connectorId>
</camunda:connector>
<camunda:inputParameter name="method">POST</camunda:inputParameter>
<camunda:inputParameter name="headers">
<camunda:map>
- <camunda:entry key="Accept">application/pdf</camunda:entry>
+ <camunda:entry key="Accept">application/base64</camunda:entry>
<camunda:entry key="Content-Type">application/json</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="payload">${results.toString()}</camunda:inputParameter>
<camunda:outputParameter name="reportPDF">
<camunda:script scriptFormat="javascript">var response = connector.getVariable("response");
-print ("response: ")
-print (response)
-var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("pdfTest").file(response.getBytes("utf-8")).mimeType('application/pdf').create()
-//response.getBytes("utf-8")
+// from nodejs base64 package
+var lookup = []
+var revLookup = []
+var javaByteArray = Java.type('byte[]')
+
+var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
+for (var i = 0, len = code.length; i < len; ++i) {
+ lookup[i] = code[i]
+ revLookup[code.charCodeAt(i)] = i
+}
+
+// Support decoding URL-safe base64 strings, as Node.js does.
+// See: https://en.wikipedia.org/wiki/Base64#URL_applications
+revLookup['-'.charCodeAt(0)] = 62
+revLookup['_'.charCodeAt(0)] = 63
+
+function getLens (b64) {
+ var len = b64.length
+
+ if (len % 4 > 0) {
+ throw new Error('Invalid string. Length must be a multiple of 4: '+b64)
+ }
+
+ // Trim off extra bytes after placeholder bytes are found
+ // See: https://github.com/beatgammit/base64-js/issues/42
+ var validLen = b64.indexOf('=')
+ if (validLen === -1) validLen = len
+
+ var placeHoldersLen = validLen === len
+ ? 0
+ : 4 - (validLen % 4)
+
+ return [validLen, placeHoldersLen]
+}
+
+function _byteLength (b64, validLen, placeHoldersLen) {
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
+}
+
+function toByteArray (b64) {
+ var tmp
+ var lens = getLens(b64)
+ var validLen = lens[0]
+ var placeHoldersLen = lens[1]
+
+ var arr = new javaByteArray(_byteLength(b64, validLen, placeHoldersLen))
+
+ var curByte = 0
+
+ // if there are placeholders, only get up to the last complete 4 chars
+ var len = placeHoldersLen > 0
+ ? validLen - 4
+ : validLen
+
+ for (var i = 0; i < len; i += 4) {
+ tmp =
+ (revLookup[b64.charCodeAt(i)] << 18) |
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
+ revLookup[b64.charCodeAt(i + 3)]
+ arr[curByte++] = (tmp >> 16) & 0xFF
+ arr[curByte++] = (tmp >> 8) & 0xFF
+ arr[curByte++] = tmp & 0xFF
+ }
+
+ if (placeHoldersLen === 2) {
+ tmp =
+ (revLookup[b64.charCodeAt(i)] << 2) |
+ (revLookup[b64.charCodeAt(i + 1)] >> 4)
+ arr[curByte++] = tmp & 0xFF
+ }
+
+ if (placeHoldersLen === 1) {
+ tmp =
+ (revLookup[b64.charCodeAt(i)] << 10) |
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
+ (revLookup[b64.charCodeAt(i + 2)] >> 2)
+ arr[curByte++] = (tmp >> 8) & 0xFF
+ arr[curByte++] = tmp & 0xFF
+ }
+
+ return arr
+}
+
+var source = "kP/+kA==";
+var decoded = toByteArray(source);
+//decoded
+var file = Java.type('org.camunda.bpm.engine.variable.Variables').fileValue("pdfTest").file(toByteArray(response)).mimeType('application/pdf').create()
file</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>