Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve source graph in separate query #151

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/main/kotlin/org/openmbee/flexo/mms/routes/gsp/ModelLoad.kt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,80 @@ fun Route.loadModel() {

// compute the delta
run {
val selectQueryString = """
select distinct ?srcGraph {
graph mor-graph:Metadata {
# select the latest commit from the current named ref
?srcRef mms:commit ?srcCommit .

# get the latest snapshot associated with the source commit
?srcCommit ^mms:commit/mms:snapshot ?srcSnapshot .
{
# prefer the model snapshot
?srcSnapshot a mms:Model ;
mms:graph ?srcGraph .
} union {
# settle for staging...
?srcSnapshot a mms:Staging ;
mms:graph ?srcGraph .

# ...if model is not available
filter not exists {
?srcCommit ^mms:commit/mms:snapshot/a mms:Model .
}
}
}

bind(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no need for all the binds here since it's just getting srcgraph

sha256(
concat(str(?dstCommit), "\n", str(?srcCommit))
) as ?diffId
)

bind(
iri(
concat(str(?dstCommit), "/diffs/", ?diffId)
) as ?diff
)

bind(
iri(
concat(str(mor-graph:), "Diff.Ins.", ?diffId)
) as ?insGraph
)

bind(
iri(
concat(str(mor-graph:), "Diff.Del.", ?diffId)
) as ?delGraph
)
}
""".trimIndent()

val selectResponseText = executeSparqlSelectOrAsk(selectQueryString) {
prefixes(prefixes)

iri(
// use current branch as ref source
"srcRef" to prefixes["morb"]!!,

// set dst graph
"dstGraph" to loadGraphUri,

// set dst commit (this commit)
"dstCommit" to prefixes["morc"]!!,
)
}

// parse the JSON response
val bindings = Json.parseToJsonElement(selectResponseText).jsonObject["results"]!!.jsonObject["bindings"]!!.jsonArray

if(bindings.size != 1) {
throw ServerBugException("Failed to resolve source graph")
}

val sourceGraphIri = bindings[0].jsonObject["srcGraph"]!!.jsonObject["value"]!!.jsonPrimitive.content

val updateString = genDiffUpdate("", localConditions, """
graph mor-graph:Metadata {
# select the latest commit from the current named ref
Expand Down Expand Up @@ -253,6 +327,9 @@ fun Route.loadModel() {

// set dst commit (this commit)
"dstCommit" to prefixes["morc"]!!,

// use explicit srcGraph
"srcGraph" to sourceGraphIri,
)
}
}
Expand Down