From 8a6b86c45c4f63d2db3f8da2a45ce33cafdac320 Mon Sep 17 00:00:00 2001
From: David Kaufmann <david.kaufmann@student.tuwien.ac.at>
Date: Sat, 24 Nov 2018 06:03:36 +0100
Subject: [PATCH] fix autoclick

---
 camunda-overlay/camunda.py | 41 +++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/camunda-overlay/camunda.py b/camunda-overlay/camunda.py
index 7329f21..e975e22 100755
--- a/camunda-overlay/camunda.py
+++ b/camunda-overlay/camunda.py
@@ -10,7 +10,8 @@ CAMUNDA="http://localhost:8080/engine-rest/"
 
 def get_current_deployments(key = 'sentiment-analysis'):
     res = requests.get(CAMUNDA + "deployment")
-    return [proc for proc in res.json() if proc['name'] == key]
+    #return [proc for proc in res.json() if proc['name'] == key]
+    return res.json()
 
 def cleanup_old_deployments(key='sentiment-analysis'):
     print ("Cleaning up old deployments")
@@ -21,16 +22,18 @@ def cleanup_old_deployments(key='sentiment-analysis'):
         else:
             print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
 
-def create_deployment(initial=False):
-    files = [
+def create_deployment(cleanup=False):
+    parameters = [
             ("deployment-name", "sentiment-analysis"),
+            #("enable-duplicate-filtering", "true"),
+            #("deploy-changed-only", "true"),
             ("file1", open("sentiment-analysis.bpmn")),
             ("file2", open("forms/input-terms.html")),
             ("file3", open("forms/download-pdf.html")),
             ]
-    if not initial:
+    if cleanup:
         cleanup_old_deployments()
-    res = requests.post(CAMUNDA + "deployment/create", files=files)
+    res = requests.post(CAMUNDA + "deployment/create", files=parameters)
     if (res.status_code == 200):
         print ("Successfully deployed Sentiment Analysis")
     else:
@@ -44,19 +47,39 @@ def create_deployment(initial=False):
 def submit_terms(terms=[]):
     termlist = [{'term': term} for term in terms]
     # submit to camunda
-    pass
+    params = {
+            'variables': {
+                'terms': {
+                    'value': json.dumps(termlist),
+                    'type': "json",
+                    'valueInfo': {
+                        'serializationDataFormat': "application/json",
+                        }
+                    }
+                }
+            }
+    res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
+    if (res.status_code == 200):
+        print ("Successfully started Sentiment Analysis")
+    else:
+        from pprint import pprint
+        pprint ("Status Code: {}".format(res.status_code))
+        try:
+            pprint(res.json())
+        except:
+            pprint(res.content)
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
     parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step")
-    parser.add_argument('--initial', dest='initial', default=False, action='store_true', help="Initial deploy does not need cleanup")
+    parser.add_argument('--cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy needs cleanup")
     parser.add_argument('--autoclick', dest='autoclick', type=int, nargs=1, default=0, help="How many steps to autoclick")
     args = parser.parse_args()
 
     if args.deploy:
         # initialize camunda process
-        create_deployment(initial=args.initial)
+        create_deployment(cleanup=args.cleanup)
 
-    if args.autoclick >= 1:
+    if args.autoclick[0] >= 1:
         # start clicking
         submit_terms(["voting", "phonegate", "35c3"])
-- 
2.43.0