8 from pprint import pprint
10 CAMUNDA="http://localhost:8080/engine-rest/"
12 def get_current_deployments(key = 'sentiment-analysis'):
13 res = requests.get(CAMUNDA + "deployment")
14 #return [proc for proc in res.json() if proc['name'] == key]
17 def get_current_process_instances(key = 'sentiment-analysis'):
18 res = requests.get(CAMUNDA + 'process-instance')
22 return [instance for instance in res.json() if instance['definitionId'].startswith(key + ":")]
24 def cleanup_old_deployments(key='sentiment-analysis'):
25 print ("Cleaning up old deployments")
26 for deployment in get_current_deployments(key):
27 res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true&skipCustomListeners=true")
28 if (res.status_code == 204):
29 print ("Cleaned up deployment {}".format(deployment['id']))
31 print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
38 res = requests.get(CAMUNDA + "user")
41 def cleanup_users(keep = ["demo"]):
42 for user in get_users():
44 if user['id'] in keep:
47 res = requests.delete(CAMUNDA + "user/" + user['id'])
48 if (res.status_code == 204):
49 print ("Cleaned up user {}".format(user['id']))
51 print ("Error cleaning user {}: Code: {}".format(user['id'], res.status_code))
57 def create_deployment(cleanup=False):
59 ("deployment-name", "sentiment-analysis"),
60 #("enable-duplicate-filtering", "true"),
61 #("deploy-changed-only", "true"),
62 ("file1", open("sentiment-analysis.bpmn")),
63 ("file2", open("forms/input-terms.html")),
64 ("file3", open("forms/download-pdf.html")),
67 cleanup_old_deployments()
68 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
69 if (res.status_code == 200):
70 print ("Successfully deployed Sentiment Analysis")
72 pprint ("Status Code: {}".format(res.status_code))
78 def submit_terms(terms):
79 termlist = [{'term': term} for term in terms]
84 'value': json.dumps(termlist),
87 'serializationDataFormat': "application/json",
92 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
93 if (res.status_code == 200):
94 print ("Successfully started Sentiment Analysis")
96 pprint ("Status Code: {}".format(res.status_code))
101 import xml.dom.minidom
102 content = res.content.decode('utf-8').replace('<!doctype html>', '')
103 print(xml.dom.minidom.parseString(content).toprettyxml())
108 instances = get_current_process_instances()
109 if len(instances) == 0:
110 print ("Error: no running instance found.")
112 instance = instances[0]['id']
113 res = requests.get(CAMUNDA + 'process-instance/' + instance + '/variables')
119 if __name__ == "__main__":
120 parser = argparse.ArgumentParser()
121 parser.add_argument('--no-deploy', dest='deploy', default=True, action='store_false', help="Do not run the deployment step")
122 parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup")
123 parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick")
124 parser.add_argument('--term', dest='terms', type=str, nargs='*', default=["aic", "TU Wien"], help="How many steps to autoclick")
125 args = parser.parse_args()
128 # initialize camunda process
129 create_deployment(cleanup=args.cleanup)
133 if args.autoclick >= 1:
135 submit_terms(args.terms)
137 if args.autoclick >= 2: