@@ -63,10 +63,19 @@ fun FlexoModelHandler.extractModelElementToJson(elementIri: String): JsonObject
6363 out .forEach { (predicate, values) ->
6464 // extract the suffix name part
6565 var propertyKey = predicate.uri.autoSuffix
66-
66+ val obj = values.elementAt( 0 )
6767 // relations
6868 if (predicate.uri.startsWith(SYSMLV2 .RELATION )) {
69- // prefer the annotation triple for all relations, skip
69+ // multiple values means it's an array, skip and prefer JSON annotation
70+ // if we've already seen a JSON annotation with the same property key then ignore
71+ if (values.size > 1 || seenArrays.contains(propertyKey)) return @forEach
72+ if (obj.isResource()) {
73+ put(propertyKey, buildJsonObject {
74+ put(" @id" , obj.asResource().uri.autoSuffix)
75+ })
76+ } else {
77+ throw InvalidTripleError (" Relation cannot be literal" , elementIri, predicate, obj)
78+ }
7079 }
7180 // properties & annotations
7281 else {
@@ -84,18 +93,16 @@ fun FlexoModelHandler.extractModelElementToJson(elementIri: String): JsonObject
8493 val lit = obj.asLiteral()
8594
8695 // depending on its datatype
87- when (lit.datatype) {
88- XSD .xboolean -> put(propertyKey, lit.boolean)
89- XSD .integer -> put(propertyKey, lit.int)
90- XSD .decimal, XSD .xdouble -> put(propertyKey, lit.float)
96+ when (lit.datatype.uri ) {
97+ XSD .xboolean.uri -> put(propertyKey, lit.boolean)
98+ XSD .integer.uri -> put(propertyKey, lit.int)
99+ XSD .decimal.uri , XSD .xdouble.uri -> put(propertyKey, lit.float)
91100 else -> put(propertyKey, lit.string)
92101 }
93102 }
94103 // object is a Resource
95104 else {
96- put(propertyKey, buildJsonObject {
97- put(" @id" , obj.asResource().uri.autoSuffix)
98- })
105+ throw InvalidTripleError (" Property cannot be resource" , elementIri, predicate, obj)
99106 }
100107 }
101108 // annotations
@@ -131,9 +138,9 @@ fun FlexoModelHandler.extractModelElementToJson(elementIri: String): JsonObject
131138 }
132139 // something else
133140 else {
134- throw InvalidTripleError (" Unrecognized triple purpose" , elementIri, predicate, obj)
141+ // throw InvalidTripleError("Unrecognized triple purpose", elementIri, predicate, obj)
135142 }
136- }
143+ // }
137144 }
138145 }
139146}
0 commit comments