8 from pprint import pprint
10 CAMUNDA="http://localhost:8085/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))
58 res = requests.get(CAMUNDA + "filter")
61 def cleanup_filters(keep = ["All Tasks"]):
62 for filter in get_filters():
63 # keep filter "All Tasks"
64 if filter['name'] in keep:
67 res = requests.delete(CAMUNDA + "filter/" + filter['id'])
68 if (res.status_code == 204):
69 print ("Cleaned up filter {}".format(filter['name']))
71 print ("Error cleaning filter {} ({}): Code: {}".format(filter['name'], filter['id'], res.status_code))
77 def create_deployment(cleanup=False):
79 ("deployment-name", "sentiment-analysis"),
80 #("enable-duplicate-filtering", "true"),
81 #("deploy-changed-only", "true"),
82 ("file1", open("sentiment-analysis.bpmn")),
83 ("file2", open("forms/input-terms.html")),
84 ("file3", open("forms/download-pdf.html")),
87 cleanup_old_deployments()
88 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
89 if (res.status_code == 200):
90 print ("Successfully deployed Sentiment Analysis")
92 pprint ("Status Code: {}".format(res.status_code))
98 def submit_terms(terms):
99 termlist = [{'term': term} for term in terms]
104 'value': json.dumps(termlist),
107 'serializationDataFormat': "application/json",
112 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
113 if (res.status_code == 200):
114 print ("Successfully started Sentiment Analysis")
116 pprint ("Status Code: {}".format(res.status_code))
121 import xml.dom.minidom
122 content = res.content.decode('utf-8').replace('<!doctype html>', '')
123 print(xml.dom.minidom.parseString(content).toprettyxml())
128 instances = get_current_process_instances()
129 if len(instances) == 0:
130 print ("Error: no running instance found.")
132 instance = instances[0]['id']
133 res = requests.get(CAMUNDA + 'process-instance/' + instance + '/variables')
139 if __name__ == "__main__":
140 parser = argparse.ArgumentParser()
141 parser.add_argument('--no-deploy', dest='deploy', default=True, action='store_false', help="Do not run the deployment step")
142 parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup")
143 parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick")
144 parser.add_argument('--terms', dest='terms', type=str, nargs='*', default=["aic", "TU Wien"], help="How many steps to autoclick")
145 args = parser.parse_args()
148 # initialize camunda process
149 create_deployment(cleanup=args.cleanup)
154 if args.autoclick >= 1:
156 submit_terms(args.terms)
158 if args.autoclick >= 2: