Skip to content

Commit

Permalink
Merge pull request #151 from Open-MBEE/hotfix/0.1.2
Browse files Browse the repository at this point in the history
fix: resolve source graph in separate query
  • Loading branch information
dlamoris authored Jan 31, 2024
2 parents c8ca3e9 + 16979c2 commit 712dbf7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
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/
68 changes: 49 additions & 19 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,29 +217,53 @@ fun Route.loadModel() {

// compute the delta
run {
val updateString = genDiffUpdate("", localConditions, """
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 .
val selectQueryString = """
select distinct ?srcGraph ?srcCommit {
graph mor-graph:Metadata {
# select the latest commit from the current named ref
?srcRef mms:commit ?srcCommit .
# ...if model is not available
filter not exists {
?srcCommit ^mms:commit/mms:snapshot/a mms:Model .
# 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 sourceCommitri = bindings[0].jsonObject["srcCommit"]!!.jsonObject["value"]!!.jsonPrimitive.content

val updateString = genDiffUpdate("", localConditions, "")

executeSparqlUpdate(updateString) {
prefixes(prefixes)
Expand All @@ -253,6 +277,12 @@ fun Route.loadModel() {

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

// use explicit srcGraph
"srcGraph" to sourceGraphIri,

// use explicit srcCommit
"srcCommit" to sourceCommitri,
)
}
}
Expand Down

0 comments on commit 712dbf7

Please sign in to comment.