Skip to content

Commit e65ab36

Browse files
authored
Merge pull request #17 from Open-MBEE/query
update to latest spec for query
2 parents c2c4d6f + 9e93353 commit e65ab36

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/main/kotlin/org/openmbee/flexo/sysmlv2/apis/QueryApi.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,25 @@ fun PrimitiveConstraint.toSparql(cb: ConstructBuilder): Expr {
4444
"@type" -> { p = RDF.type.asNode(); pvar = "Metatype" }
4545
else -> { p = SYSMLV2.prop(property).asNode() }
4646
}
47-
when(value) {
47+
val firstVal = value.get(0) //TODO what if value is empty list??? or > 1 value
48+
when(firstVal) {
4849
is JsonObject -> {
49-
if (value.containsKey("@id")) {
50-
v = SYSMLV2.element(value.jsonObject["@id"]!!.jsonPrimitive.content).asNode()
50+
if (firstVal.containsKey("@id")) {
51+
v = SYSMLV2.element(firstVal.jsonObject["@id"]!!.jsonPrimitive.content).asNode()
5152
} else {
5253
throw BadRequestException("PrimitiveConstraint value object must contain @id")
5354
}
5455
}
5556
is JsonPrimitive -> {
56-
if (value == JsonNull) {
57+
if (firstVal == JsonNull) {
5758
v = RDF.nil.asNode()
5859
} else {
59-
v = if (property == "@type") SYSMLV2.type(value.content).asNode() else value.toRdfLiteralNode()
60+
v = if (property == "@type") SYSMLV2.type(firstVal.content).asNode() else firstVal.toRdfLiteralNode()
6061
}
6162
}
6263
is JsonArray -> {throw BadRequestException("PrimitiveConstraint value cannot be array")}
6364
}
64-
if (value == JsonNull) {
65+
if (firstVal == JsonNull) {
6566
cb.addOptional("?e", p, "?$pvar")
6667
} else {
6768
cb.addWhere("?e", p, "?$pvar")
@@ -78,9 +79,15 @@ fun PrimitiveConstraint.toSparql(cb: ConstructBuilder): Expr {
7879
PrimitiveConstraint.Operator.Less_Than -> {
7980
ef.lt("?$pvar", v)
8081
}
82+
PrimitiveConstraint.Operator.Less_Than_Equal -> {
83+
ef.le("?$pvar", v)
84+
}
8185
PrimitiveConstraint.Operator.Greater_Than -> {
8286
ef.gt("?$pvar", v)
8387
}
88+
PrimitiveConstraint.Operator.Greater_Than_Equal -> {
89+
ef.ge("?$pvar", v)
90+
}
8491
}
8592
return if (inverse) ef.not(expr) else expr
8693
}

src/main/kotlin/org/openmbee/flexo/sysmlv2/models/PrimitiveConstraint.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data class PrimitiveConstraint @OptIn(ExperimentalSerializationApi::class) const
3232
val inverse: kotlin.Boolean = false,
3333
val operator: PrimitiveConstraint.Operator,
3434
val property: kotlin.String,
35-
val value: JsonElement, //can be Identified, boolean, string, number
35+
val value: kotlin.collections.List<JsonElement>, //can be Identified, boolean, string, number
3636
) : Constraint()
3737
{
3838
/**
@@ -45,7 +45,12 @@ data class PrimitiveConstraint @OptIn(ExperimentalSerializationApi::class) const
4545
@SerialName(">")
4646
Greater_Than(">"),
4747
@SerialName("<")
48-
Less_Than("<");
48+
Less_Than("<"),
49+
@SerialName("<=")
50+
Less_Than_Equal("<="),
51+
@SerialName(">=")
52+
Greater_Than_Equal(">=");
53+
4954
}
5055
}
5156

0 commit comments

Comments
 (0)