-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassActivityHandler.py
181 lines (150 loc) · 6.29 KB
/
classActivityHandler.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# The activity handler fetches fine details of different activities
class ActivityHandler:
def __init__(self):
defaultHandler = DefaultHandler()
renameHandler = RenameHandler(defaultHandler)
deleteHandler = DeleteHandler(renameHandler)
createHandler = CreateHandler(deleteHandler)
moveHandler = MoveHandler(createHandler)
editHandler = EditHandler(moveHandler)
permissionChangeHandler = PermissionChangeHandler(editHandler)
self.activityHandler = permissionChangeHandler
def handleActivity(self, ActivityObject):
return self.activityHandler.handle(ActivityObject)
# Acitivity handler interface base class
class ActivityHandlerInterface:
def handle(self, ActivityObject):
pass
# Activity Handler to deal with PERMISSION CHANGE ACTIVITY
class PermissionChangeHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
try:
if ActivityObject.action[0:3] == "Per":
activityAction = ActivityObject.action
activityAction = activityAction.split("-")
action = activityAction[0]
addedPermission = activityAction[1]
addedPermission = addedPermission.split(':')
newPermission = addedPermission[1]
removedPermission = activityAction[2]
removedPermission = removedPermission.split(':')
previousPermission = removedPermission[1]
if newPermission == "none":
self.actiontype = "Remove Permission"
elif previousPermission == "none":
self.actiontype = "Add Permission"
else:
self.actiontype = "Update Permission"
self.action = action
self.target = ActivityObject.actorName
self.value = "TRUE"
self.trueValue = activityAction[3].split(':')[1]
return self
else:
return self.next.handle(ActivityObject)
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)
# Activity Handler to deal with EDIT ACTIVITY
class EditHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
try:
if ActivityObject.action[0:3] == "Edi":
self.action = "Edit"
self.actiontype = "Time Limit Edit"
self.target = ActivityObject.actorName
self.value = "TRUE"
self.trueValue = ActivityObject.activityTime
return self
else:
return self.next.handle(ActivityObject)
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)
# Activity Handler to deal with MOVE ACTIVITY
class MoveHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
try:
if ActivityObject.action[0:3] == "Mov":
self.action = "Move"
self.actiontype = "Can Move"
self.target = ActivityObject.actorName
self.value = "TRUE"
self.trueValue = ActivityObject.action.split(':')[2]
return self
else:
return self.next.handle(ActivityObject)
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)
# Activity Handler to deal with CREATE ACTIVITY
class CreateHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
try:
if ActivityObject.action[0:3] == "Cre":
self.action = "Create"
self.actiontype = "Can Create"
self.target = ActivityObject.actorName
self.value = "TRUE"
self.trueValue = ""
return self
else:
return self.next.handle(ActivityObject)
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)
# Activity Handler to deal with DELETE ACTIVITY
class DeleteHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
try:
if ActivityObject.action[0:3] == "Del":
self.action = "Delete"
self.actiontype = "Can Delete"
self.target = ActivityObject.actorName
self.value = "TRUE"
self.trueValue = ""
return self
else:
return self.next.handle(ActivityObject)
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)
# Activity Handler to deal with RENAME ACTIVITY
class RenameHandler(ActivityHandlerInterface):
def __init__(self,next):
self.next = next
def handle(self, ActivityObject):
if ActivityObject.action[0:3] == "Ren":
self.action = "Rename"
return self
else:
return self.next.handle(ActivityObject)
# Default Activity Handler to deal
class DefaultHandler(ActivityHandlerInterface):
def handle(self, ActivityObject):
return "Activity cannot be handled to detect the conflicts"