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
Show file tree
Hide file tree
Changes from 4 commits
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
4 changes: 3 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
sonar.projectKey=Open-MBEE_flexo-mms-layer1-service
sonar.organization=openmbee
sonar.language=kotlin
sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml
sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml
sonar.sources=src/main/
sonar.tests=src/test/
47 changes: 47 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,50 @@ 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 .
}
}
}
}
""".trimIndent()

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

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

// 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 +297,9 @@ fun Route.loadModel() {

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

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