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")
42 res = requests.get(CAMUNDA + "group")
45 def cleanup_users(keep = ["demo"]):
46 for user in get_users():
48 if user['id'] in keep:
51 res = requests.delete(CAMUNDA + "user/" + user['id'])
52 if (res.status_code == 204):
53 print ("Cleaned up user {}".format(user['id']))
55 print ("Error cleaning user {}: Code: {}".format(user['id'], res.status_code))
62 for group in get_groups():
63 res = requests.delete(CAMUNDA + "group/" + group['id'])
64 if (res.status_code == 204):
65 print ("Cleaned up group {}".format(group['id']))
67 print ("Error cleaning group {}: Code: {}".format(group['id'], res.status_code))
73 def get_authorizations():
74 res = requests.get(CAMUNDA + "authorization")
77 def create_admin_user():
84 "email": "aic@dsg.tuwien.ac.at"
90 res = requests.post(CAMUNDA + "user/create", json=params)
91 if (res.status_code == 204):
92 print ("Created user admin")
94 print ("Error creating user admin: Code: {}".format(res.status_code))
101 # clean all authorizations
102 for auth in get_authorizations():
103 res = requests.delete(CAMUNDA + "authorization/" + auth['id'])
104 if (res.status_code == 204):
105 print ("Cleaned up authorization {}".format(auth['id']))
107 print ("Error cleaning authorization {}: Code: {}".format(auth['id'], res.status_code))
114 # set all permissions for modifying users
117 "permissions": ["ALL"],
121 "resourceId": "admin"
123 res = requests.post(CAMUNDA + "authorization/create", json=params)
124 if (res.status_code == 200):
125 print ("Set users permissions for admin users")
127 print ("Error setting users permissions for admin user: Code: {}".format(res.status_code))
135 "id": "camunda-admin",
136 "name": "camunda BPM Administrators",
139 res = requests.post(CAMUNDA + "group/create", json=params)
140 if (res.status_code == 204):
141 print ("Created user admin")
143 print ("Error creating group camunda-admin: Code: {}".format(res.status_code))
149 # add admin user to camunda-admin
150 res = requests.put(CAMUNDA + "group/camunda-admin/members/admin")
151 if (res.status_code == 204):
152 print ("Added admin to camunda-admin")
154 print ("Error adding user admin to group camunda-admin: Code: {}".format(res.status_code))
160 # set all permissions for admin group
161 for resourceType in range(0, 16):
164 "permissions": ["ALL"],
166 "groupId": "camunda-admin",
167 "resourceType": resourceType,
170 res = requests.post(CAMUNDA + "authorization/create", json=params)
171 if (res.status_code == 200):
172 print ("Set group permissions for id {}".format(resourceType))
174 print ("Error setting application permissions for admin user: Code: {}".format(res.status_code))
181 res = requests.get(CAMUNDA + "filter")
184 def cleanup_filters(keep = ["All Tasks"]):
185 for filter in get_filters():
186 # keep filter "All Tasks"
187 if filter['name'] in keep:
190 res = requests.delete(CAMUNDA + "filter/" + filter['id'])
191 if (res.status_code == 204):
192 print ("Cleaned up filter {}".format(filter['name']))
194 print ("Error cleaning filter {} ({}): Code: {}".format(filter['name'], filter['id'], res.status_code))
200 def create_deployment(cleanup=False):
202 ("deployment-name", "sentiment-analysis"),
203 #("enable-duplicate-filtering", "true"),
204 #("deploy-changed-only", "true"),
205 ("file1", open("sentiment-analysis.bpmn")),
206 ("file2", open("forms/input-terms.html")),
207 ("file3", open("forms/download-pdf.html")),
210 cleanup_old_deployments()
211 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
212 if (res.status_code == 200):
213 print ("Successfully deployed Sentiment Analysis")
215 pprint ("Status Code: {}".format(res.status_code))
221 def submit_terms(terms):
222 termlist = [{'term': term} for term in terms]
227 'value': json.dumps(termlist),
230 'serializationDataFormat': "application/json",
235 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
236 if (res.status_code == 200):
237 print ("Successfully started Sentiment Analysis")
239 pprint ("Status Code: {}".format(res.status_code))
244 import xml.dom.minidom
245 content = res.content.decode('utf-8').replace('<!doctype html>', '')
246 print(xml.dom.minidom.parseString(content).toprettyxml())
251 instances = get_current_process_instances()
252 if len(instances) == 0:
253 print ("Error: no running instance found.")
255 instance = instances[0]['id']
256 res = requests.get(CAMUNDA + 'process-instance/' + instance + '/variables')
262 if __name__ == "__main__":
263 parser = argparse.ArgumentParser()
264 parser.add_argument('--no-deploy', dest='deploy', default=True, action='store_false', help="Do not run the deployment step")
265 parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup")
266 parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick")
267 parser.add_argument('--terms', dest='terms', type=str, nargs='*', default=["aic", "TU Wien"], help="How many steps to autoclick")
268 args = parser.parse_args()
271 # initialize camunda process
272 create_deployment(cleanup=args.cleanup)
279 if args.autoclick >= 1:
281 submit_terms(args.terms)
283 if args.autoclick >= 2: