1
- function isValidLabel (abstractNode:: N ):: Bool where N <: AbstractCGNode
1
+ # return ::Bool
2
+ function isValidLabel (abstractNode:: N ) where N <: AbstractCGNode
2
3
id = String (abstractNode. id)
3
4
return all (t -> t != uppercase (id), _invalidIds) && match (_validLabelRegex, id) != = nothing
4
5
end
5
6
6
7
# Fastest way I can think to convert the data into a dict
7
8
# TODO : Probably should be made more efficient...definitely should be made more efficient
8
- function _convertNodeToDict (abstractNode:: N ):: Dict{String, Any} where N <: AbstractCGNode
9
+ # return ::Dict{String, Any}
10
+ function _convertNodeToDict (abstractNode:: N ) where N <: AbstractCGNode
9
11
cp = deepcopy (abstractNode)
10
12
data = length (cp. data) != 0 ? JSON2. write (cp. data) : " {}"
11
13
ser = JSON2. read (JSON2. write (abstractNode), Dict{String, Any})
@@ -15,7 +17,8 @@ function _convertNodeToDict(abstractNode::N)::Dict{String, Any} where N <: Abstr
15
17
end
16
18
17
19
# TODO : Refactor, #HACK :D (but it works!)
18
- function _convertDictToSession (dict:: Dict{String, Any} ):: Session
20
+ # return ::Session
21
+ function _convertDictToSession (dict:: Dict{String, Any} )
19
22
data = JSON2. read (String (base64decode (dict[" data" ])), Dict{Symbol, String})
20
23
session = Session (
21
24
Symbol (dict[" id" ]),
@@ -29,7 +32,8 @@ function _convertDictToSession(dict::Dict{String, Any})::Session
29
32
return session
30
33
end
31
34
# TODO : Refactor, #HACK :D (but it works!)
32
- function _convertDictToRobot (dict:: Dict{String, Any} ):: Robot
35
+ # returns ::Robot
36
+ function _convertDictToRobot (dict:: Dict{String, Any} )
33
37
data = JSON2. read (String (base64decode (dict[" data" ])), Dict{Symbol, String})
34
38
robot = Robot (
35
39
Symbol (dict[" id" ]),
@@ -42,7 +46,8 @@ function _convertDictToRobot(dict::Dict{String, Any})::Robot
42
46
return robot
43
47
end
44
48
# TODO : Refactor, #HACK :D (but it works!)
45
- function _convertDictToUser (dict:: Dict{String, Any} ):: User
49
+ # returns ::User
50
+ function _convertDictToUser (dict:: Dict{String, Any} )
46
51
data = JSON2. read (String (base64decode (dict[" data" ])), Dict{Symbol, String})
47
52
user = User (
48
53
Symbol (dict[" id" ]),
@@ -54,7 +59,8 @@ function _convertDictToUser(dict::Dict{String, Any})::User
54
59
return user
55
60
end
56
61
57
- function createUser (dfg:: Neo4jDFG , user:: User ):: User
62
+ # returns ::User
63
+ function createUser (dfg:: Neo4jDFG , user:: User )
58
64
Symbol (dfg. userId) != user. id && error (" DFG user ID must match user's ID" )
59
65
! isValidLabel (user) && error (" Node cannot have an ID '$(user. id) '." )
60
66
@@ -64,7 +70,8 @@ function createUser(dfg::Neo4jDFG, user::User)::User
64
70
return user
65
71
end
66
72
67
- function createRobot (dfg:: Neo4jDFG , robot:: Robot ):: Robot
73
+ # returns ::Robot
74
+ function createRobot (dfg:: Neo4jDFG , robot:: Robot )
68
75
Symbol (dfg. robotId) != robot. id && error (" DFG robot ID must match robot's ID" )
69
76
Symbol (dfg. userId) != robot. userId && error (" DFG user ID must match robot's user ID" )
70
77
! isValidLabel (robot) && error (" Node cannot have an ID '$(robot. id) '." )
@@ -84,7 +91,8 @@ function createRobot(dfg::Neo4jDFG, robot::Robot)::Robot
84
91
return robot
85
92
end
86
93
87
- function createSession (dfg:: Neo4jDFG , session:: Session ):: Session
94
+ # returns ::Session
95
+ function createSession (dfg:: Neo4jDFG , session:: Session )
88
96
Symbol (dfg. robotId) != session. robotId && error (" DFG robot ID must match session's robot ID" )
89
97
Symbol (dfg. userId) != session. userId && error (" DFG user ID must match session's->robot's->user ID" )
90
98
! isValidLabel (session) && error (" Node cannot have an ID '$(session. id) '." )
107
115
"""
108
116
$(SIGNATURES)
109
117
Shortcut method to create the user, robot, and session if it doesn't already exist.
118
+
119
+ Notes
120
+ - return `::Session`
110
121
"""
111
- function createDfgSessionIfNotExist (dfg:: Neo4jDFG ):: Session
122
+ function createDfgSessionIfNotExist (dfg:: Neo4jDFG )
112
123
strip (dfg. userId) == " " && error (" User ID is not populated in DFG." )
113
124
strip (dfg. robotId) == " " && error (" Robot ID is not populated in DFG." )
114
125
strip (dfg. sessionId) == " " && error (" Session ID is not populated in DFG." )
129
140
$(SIGNATURES)
130
141
List all sessions for the specified DFG's robot and user.
131
142
Returns nothing if it isn't found.
143
+
144
+ Notes
145
+ - Returns `Vector{Session}`
132
146
"""
133
- function lsSessions (dfg:: Neo4jDFG ):: Vector{Session}
147
+ function lsSessions (dfg:: Neo4jDFG )
134
148
sessionNodes = _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:SESSION:$(dfg. robotId) :$(dfg. userId) )" )
135
149
return map (s -> _convertDictToSession (Neo4j. getnodeproperties (s)), sessionNodes)
136
150
end
139
153
$(SIGNATURES)
140
154
List all robots for the specified DFG's user.
141
155
Returns nothing if it isn't found.
156
+
157
+ Notes
158
+ - Returns `::Vector{Robot}`
142
159
"""
143
- function lsRobots (dfg:: Neo4jDFG ):: Vector{Robot}
160
+ function lsRobots (dfg:: Neo4jDFG )
144
161
robotNodes = _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:ROBOT:$(dfg. userId) )" )
145
162
return map (s -> _convertDictToRobot (Neo4j. getnodeproperties (s)), robotNodes)
146
163
end
149
166
$(SIGNATURES)
150
167
List all users.
151
168
Returns nothing if it isn't found.
169
+
170
+ Notes
171
+ - Returns `::Vector{User}`
152
172
"""
153
- function lsUsers (dfg:: Neo4jDFG ):: Vector{User}
173
+ function lsUsers (dfg:: Neo4jDFG )
154
174
userNodes = _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:USER)" )
155
175
return map (s -> _convertDictToUser (Neo4j. getnodeproperties (s)), userNodes)
156
176
end
159
179
$(SIGNATURES)
160
180
Get a session specified by userId:robotId:sessionId.
161
181
Returns nothing if it isn't found.
182
+
183
+ Notes
184
+ - Returns either `::Union{Session, Nothing}`
162
185
"""
163
- function getSession (dfg:: Neo4jDFG , userId:: Symbol , robotId:: Symbol , sessionId:: Symbol ):: Union{Session, Nothing}
186
+ function getSession (dfg:: Neo4jDFG , userId:: Symbol , robotId:: Symbol , sessionId:: Symbol )
164
187
! isValidLabel (userId) && error (" Can't retrieve session with user ID '$(userId) '." )
165
188
! isValidLabel (robotId) && error (" Can't retrieve session with robot ID '$(robotId) '." )
166
189
! isValidLabel (sessionId) && error (" Can't retrieve session with session ID '$(sessionId) '." )
@@ -174,17 +197,23 @@ end
174
197
$(SIGNATURES)
175
198
Get the session specified by the DFG object.
176
199
Returns nothing if it isn't found.
200
+
201
+ Notes
202
+ - Returns either `::Union{Nothing, Session}`
177
203
"""
178
- function getSession (dfg:: Neo4jDFG ):: Union{Nothing, Session}
204
+ function getSession (dfg:: Neo4jDFG )
179
205
return getSession (dfg, Symbol (dfg. userId), Symbol (dfg. robotId), Symbol (dfg. sessionId))
180
206
end
181
207
182
208
"""
183
209
$(SIGNATURES)
184
210
Get a robot specified by userId:robotId.
185
211
Returns nothing if it isn't found.
212
+
213
+ Notes
214
+ - Returns either `::Union{Robot, Nothing}`
186
215
"""
187
- function getRobot (dfg:: Neo4jDFG , userId:: Symbol , robotId:: Symbol ):: Union{Robot, Nothing}
216
+ function getRobot (dfg:: Neo4jDFG , userId:: Symbol , robotId:: Symbol )
188
217
! isValidLabel (userId) && error (" Can't retrieve robot with user ID '$(userId) '." )
189
218
! isValidLabel (robotId) && error (" Can't retrieve robot with robot ID '$(robotId) '." )
190
219
robotNode = _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:ROBOT:$(robotId) :$(userId) )" )
@@ -197,17 +226,23 @@ end
197
226
$(SIGNATURES)
198
227
Get the robot specified by the DFG object.
199
228
Returns nothing if it isn't found.
229
+
230
+ Notes
231
+ - Returns either `::Union{Nothing, Robot}`
200
232
"""
201
- function getRobot (dfg:: Neo4jDFG ):: Union{Nothing, Robot}
233
+ function getRobot (dfg:: Neo4jDFG )
202
234
return getRobot (dfg, Symbol (dfg. userId), Symbol (dfg. robotId))
203
235
end
204
236
205
237
"""
206
238
$(SIGNATURES)
207
239
Get a user specified by userId.
208
240
Returns nothing if it isn't found.
241
+
242
+ Notes
243
+ - Returns either `::Union{User, Nothing}`
209
244
"""
210
- function getUser (dfg:: Neo4jDFG , userId:: Symbol ):: Union{User, Nothing}
245
+ function getUser (dfg:: Neo4jDFG , userId:: Symbol )
211
246
! isValidLabel (userId) && error (" Can't retrieve user with user ID '$(userId) '." )
212
247
userNode = _getNeoNodesFromCyphonQuery (dfg. neo4jInstance, " (node:USER:$(userId) )" )
213
248
length (userNode) == 0 && return nothing
@@ -219,17 +254,23 @@ end
219
254
$(SIGNATURES)
220
255
Get the user specified by the DFG object.
221
256
Returns nothing if it isn't found.
257
+
258
+ Notes
259
+ - Returns either `::Union{Nothing, User}`
222
260
"""
223
- function getUser (dfg:: Neo4jDFG ):: Union{Nothing, User}
261
+ function getUser (dfg:: Neo4jDFG )
224
262
return getUser (dfg, Symbol (dfg. userId))
225
263
end
226
264
227
265
228
266
"""
229
267
$(SIGNATURES)
230
268
DANGER: Clears the whole session from the database.
269
+
270
+ Notes
271
+ - Returns `::Nothing`
231
272
"""
232
- function clearSession!! (dfg:: Neo4jDFG ):: Nothing
273
+ function clearSession!! (dfg:: Neo4jDFG )
233
274
# Perform detach+deletion
234
275
_queryNeo4j (dfg. neo4jInstance, " match (node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) ) detach delete node " )
235
276
241
282
"""
242
283
$(SIGNATURES)
243
284
DANGER: Clears the whole robot + sessions from the database.
285
+
286
+ Notes
287
+ - Returns `::Nothing`
244
288
"""
245
- function clearRobot!! (dfg:: Neo4jDFG ):: Nothing
289
+ function clearRobot!! (dfg:: Neo4jDFG )
246
290
# Perform detach+deletion
247
291
_queryNeo4j (dfg. neo4jInstance, " match (node:$(dfg. userId) :$(dfg. robotId) ) detach delete node " )
248
292
254
298
"""
255
299
$(SIGNATURES)
256
300
DANGER: Clears the whole user + robot + sessions from the database.
301
+
302
+ Notes
303
+ - Returns `::Nothing`
257
304
"""
258
- function clearUser!! (dfg:: Neo4jDFG ):: Nothing
305
+ function clearUser!! (dfg:: Neo4jDFG )
259
306
# Perform detach+deletion
260
307
_queryNeo4j (dfg. neo4jInstance, " match (node:$(dfg. userId) ) detach delete node " )
261
308
268
315
$(SIGNATURES)
269
316
DANGER: Copies and overwrites the destination session.
270
317
If no destination specified then it creates a unique one.
318
+
319
+ Notes
320
+ - Returns `::Neo4jDFG `
271
321
"""
272
- function copySession! (sourceDFG:: Neo4jDFG , destDFG:: Union{Nothing, Neo4jDFG} ):: Neo4jDFG
322
+ function copySession! (sourceDFG:: Neo4jDFG , destDFG:: Union{Nothing, <: Neo4jDFG} )
273
323
if destDFG == nothing
274
324
destDFG = _getDuplicatedEmptyDFG (sourceDFG)
275
325
end
279
329
"""
280
330
$(SIGNATURES)
281
331
DANGER: Copies the source to a new unique destination.
332
+
333
+ Notes
334
+ - Returns `::Neo4jDFG`
282
335
"""
283
- copySession! (sourceDFG:: Neo4jDFG ):: Neo4jDFG = copySession! (sourceDFG, nothing )
336
+ copySession! (sourceDFG:: Neo4jDFG ) = copySession! (sourceDFG, nothing )
0 commit comments