Skip to content

Commit a7ff1b6

Browse files
authored
Merge pull request #417 from JuliaRobotics/2Q20/cg_structure_updates
CG Structure updates and creating sentinel nodes in the constructor
2 parents 8b66b77 + 3bee453 commit a7ff1b6

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

src/CloudGraphsDFG/entities/CGStructure.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,34 @@ mutable struct User <: AbstractCGNode
1010
id::Symbol
1111
name::String
1212
description::String
13-
# labels::Vector{Symbol}
1413
data::Dict{Symbol, String}
14+
createdTimestamp::String
15+
lastUpdatedTimestamp::String
16+
User(id::Symbol,
17+
name::String,
18+
description::String,
19+
data::Dict{Symbol, String},
20+
createdTimestamp::String=string(now(UTC)),
21+
lastUpdatedTimestamp::String=string(now(UTC))) =
22+
new(id, name, description, data, createdTimestamp, lastUpdatedTimestamp)
1523
end
1624

1725
mutable struct Robot <: AbstractCGNode
1826
id::Symbol
1927
userId::Symbol
2028
name::String
2129
description::String
22-
# labels::Vector{Symbol}
2330
data::Dict{Symbol, String}
31+
createdTimestamp::String
32+
lastUpdatedTimestamp::String
33+
Robot(id::Symbol,
34+
userId::Symbol,
35+
name::String,
36+
description::String,
37+
data::Dict{Symbol, String},
38+
createdTimestamp::String=string(now(UTC)),
39+
lastUpdatedTimestamp::String=string(now(UTC))) =
40+
new(id, userId, name, description, data, createdTimestamp, lastUpdatedTimestamp)
2441
end
2542

2643
mutable struct Session <: AbstractCGNode
@@ -29,6 +46,17 @@ mutable struct Session <: AbstractCGNode
2946
userId::Symbol
3047
name::String
3148
description::String
32-
# labels::Vector{Symbol}
3349
data::Dict{Symbol, String}
50+
createdTimestamp::String
51+
lastUpdatedTimestamp::String
52+
Session(id::Symbol,
53+
robotId::Symbol,
54+
userId::Symbol,
55+
name::String,
56+
description::String,
57+
data::Dict{Symbol, String},
58+
createdTimestamp::String=string(now(UTC)),
59+
lastUpdatedTimestamp::String=string(now(UTC))) =
60+
new(id, robotId,userId, name, description, data, createdTimestamp, lastUpdatedTimestamp)
61+
3462
end

src/CloudGraphsDFG/entities/CloudGraphsDFG.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ function CloudGraphsDFG{T}(neo4jConnection::Neo4j.Connection,
3232
getPackedTypeFunc,
3333
decodePackedTypeFunc,
3434
rebuildFactorMetadata!;
35-
solverParams::T=NoSolverParams()) where T <: AbstractParams
35+
solverParams::T=NoSolverParams(),
36+
createSessionNodes::Bool=true) where T <: AbstractParams
3637
graph = Neo4j.getgraph(neo4jConnection)
3738
neo4jInstance = Neo4jInstance(neo4jConnection, graph)
38-
return CloudGraphsDFG{T}(neo4jInstance, userId, robotId, sessionId, description, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, Symbol[], solverParams)
39+
dfg = CloudGraphsDFG{T}(neo4jInstance, userId, robotId, sessionId, description, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, Symbol[], solverParams)
40+
# Create the session if it doesn't already exist
41+
createSessionNodes && createDfgSessionIfNotExist(dfg)
42+
return dfg
3943
end
4044
"""
4145
$(SIGNATURES)
@@ -53,9 +57,10 @@ function CloudGraphsDFG{T}(host::String,
5357
getPackedTypeFunc,
5458
decodePackedTypeFunc,
5559
rebuildFactorMetadata!;
56-
solverParams::T=NoSolverParams()) where T <: AbstractParams
60+
solverParams::T=NoSolverParams(),
61+
createSessionNodes::Bool=true) where T <: AbstractParams
5762
neo4jConnection = Neo4j.Connection(host, port=port, user=dbUser, password=dbPassword);
58-
return CloudGraphsDFG{T}(neo4jConnection, userId, robotId, sessionId, description, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, solverParams=solverParams)
63+
return CloudGraphsDFG{T}(neo4jConnection, userId, robotId, sessionId, description, encodePackedTypeFunc, getPackedTypeFunc, decodePackedTypeFunc, rebuildFactorMetadata!, solverParams=solverParams, createSessionNodes=createSessionNodes)
5964
end
6065

6166

src/CloudGraphsDFG/services/CGStructure.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ function _convertDictToSession(dict::Dict{String, Any})::Session
3232
Symbol(dict["userId"]),
3333
dict["name"],
3434
dict["description"],
35-
data)
35+
data,
36+
dict["createdTimestamp"],
37+
dict["lastUpdatedTimestamp"])
3638
return session
3739
end
3840
#TODO: Refactor, #HACK :D (but it works!)
@@ -43,7 +45,9 @@ function _convertDictToRobot(dict::Dict{String, Any})::Robot
4345
Symbol(dict["userId"]),
4446
dict["name"],
4547
dict["description"],
46-
data)
48+
data,
49+
dict["createdTimestamp"],
50+
dict["lastUpdatedTimestamp"])
4751
return robot
4852
end
4953
#TODO: Refactor, #HACK :D (but it works!)
@@ -53,7 +57,9 @@ function _convertDictToUser(dict::Dict{String, Any})::User
5357
Symbol(dict["id"]),
5458
dict["name"],
5559
dict["description"],
56-
data)
60+
data,
61+
dict["createdTimestamp"],
62+
dict["lastUpdatedTimestamp"])
5763
return user
5864
end
5965

@@ -114,7 +120,7 @@ function createDfgSessionIfNotExist(dfg::CloudGraphsDFG)::Session
114120
strip(dfg.sessionId) == "" && error("Session ID is not populated in DFG.")
115121
user = User(Symbol(dfg.userId), dfg.userId, "Description for $(dfg.userId)", Dict{Symbol, String}())
116122
robot = Robot(Symbol(dfg.robotId), Symbol(dfg.userId), dfg.robotId, "Description for $(dfg.userId):$(dfg.robotId)", Dict{Symbol, String}())
117-
session = Session(Symbol(dfg.sessionId), Symbol(dfg.robotId), Symbol(dfg.userId), dfg.sessionId, "Description for $(dfg.userId):$(dfg.robotId):$(dfg.sessionId)", Dict{Symbol, String}())
123+
session = Session(Symbol(dfg.sessionId), Symbol(dfg.robotId), Symbol(dfg.userId), dfg.sessionId, dfg.description, Dict{Symbol, String}())
118124

119125
_getNodeCount(dfg.neo4jInstance, [dfg.userId, "USER"]) == 0 && createUser(dfg, user)
120126
_getNodeCount(dfg.neo4jInstance, [dfg.userId, dfg.robotId, "ROBOT"]) == 0 && createRobot(dfg, robot)

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function _getDuplicatedEmptyDFG(dfg::CloudGraphsDFG)::CloudGraphsDFG
99
while true #do..while loop
1010
count += 1
1111
sessionId = dfg.sessionId*"_$count"
12-
length(_getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(dfg.userId):$(dfg.robotId):$(sessionId))")) == 0 && break
12+
_getNodeCount(dfg.neo4jInstance, [dfg.userId, dfg.robotId, sessionId]) == 0 && break
1313
end
1414
@debug "Unique+empty copy session name: $sessionId"
1515
return CloudGraphsDFG{typeof(dfg.solverParams)}(

0 commit comments

Comments
 (0)