-
Notifications
You must be signed in to change notification settings - Fork 1
/
classActionConstraints.py
56 lines (49 loc) · 2.49 KB
/
classActionConstraints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# The class extracts all the action constaints related to the activity object
class ActionConstraints:
def __init__(self,ActivityObject, actionConstraints):
self.activityObj = ActivityObject
self.actionConstraints = {}
self.generateConstraints(self.activityObj.documentID, actionConstraints)
# The getConstaints creates an obbject to handle action constraints of a particular document ID
# constraintsObj = {
# action1:
# {
# actionType1:
# {
# target:[val,comp,true_val]
# },
# actionType2 :
# {
# .
# }
# },
# action2:
# .
# .
# }
# Fetch the action constraints from the database
def generateConstraints(self, documentID, actionConstraints):
try:
if documentID in actionConstraints:
constraintsList = actionConstraints[documentID]
for cons in constraintsList:
action = cons[2]
action_type = cons[3]
action_target = cons[4]
action_val = cons[5]
action_comparator = cons[6]
action_trueValues = cons[8].split(',')
valtarget = {action_target:[action_val, action_comparator, action_trueValues]}
if action not in self.actionConstraints:
self.actionConstraints[action] = {action_type: valtarget}
else:
if action_type not in self.actionConstraints[action]:
self.actionConstraints[action][action_type] = valtarget
else:
self.actionConstraints[action][action_type][action_target] = [action_val, action_comparator, action_trueValues]
except LookupError as le:
return "Error in the key or index !!\n" + str(le)
except ValueError as ve:
return "Error in Value Entered !!\n" + str(ve)
except TypeError as te:
return "Error in Type matching !!\n" + str(te)