diff --git a/sonar-project.properties b/sonar-project.properties index d48f9459..6815bc5f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -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 \ No newline at end of file +sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml +sonar.sources=src/main/ +sonar.tests=src/test/ \ No newline at end of file diff --git a/src/main/kotlin/org/openmbee/flexo/mms/routes/gsp/ModelLoad.kt b/src/main/kotlin/org/openmbee/flexo/mms/routes/gsp/ModelLoad.kt index 92607978..a496ea97 100644 --- a/src/main/kotlin/org/openmbee/flexo/mms/routes/gsp/ModelLoad.kt +++ b/src/main/kotlin/org/openmbee/flexo/mms/routes/gsp/ModelLoad.kt @@ -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) @@ -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, ) } }