Skip to content

Commit

Permalink
feat: temporalValues representation of a LanguageProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Apr 6, 2024
1 parent 1880944 commit 66535ea
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_VALUE_TERM
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_DATASET_ID_PROPERTY
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_GEOPROPERTY_TYPE
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_JSONPROPERTY_VALUE
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_LANGUAGEPROPERTY_VALUE
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_PREFIX
import com.egm.stellio.shared.util.JsonLdUtils.buildExpandedPropertyValue
import com.egm.stellio.shared.util.JsonLdUtils.buildExpandedTemporalValue
Expand Down Expand Up @@ -113,8 +114,8 @@ object TemporalEntityBuilder {
*/
private fun buildAttributesSimplifiedRepresentation(
attributeAndResultsMap: TemporalEntityAttributeInstancesResult
): Map<TemporalEntityAttribute, SimplifiedTemporalAttribute> {
return attributeAndResultsMap.mapValues {
): Map<TemporalEntityAttribute, SimplifiedTemporalAttribute> =
attributeAndResultsMap.mapValues {
val attributeInstance = mutableMapOf<String, Any>(
JSONLD_TYPE to listOf(it.key.attributeType.toExpandedName())
)
Expand Down Expand Up @@ -142,6 +143,14 @@ object TemporalEntityBuilder {
),
mapOf(JSONLD_VALUE to attributeInstanceResult.time)
)
} else if (it.key.attributeType == TemporalEntityAttribute.AttributeType.LanguageProperty) {
listOf(
mapOf(
NGSILD_LANGUAGEPROPERTY_VALUE to
deserializeListOfObjects(attributeInstanceResult.value as String)
),
mapOf(JSONLD_VALUE to attributeInstanceResult.time)
)
} else {
listOf(
mapOf(JSONLD_VALUE to attributeInstanceResult.value),
Expand All @@ -151,7 +160,6 @@ object TemporalEntityBuilder {
}
attributeInstance.toMap()
}
}

/**
* Creates the aggregated representation for each temporal entity attribute in the input map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.egm.stellio.search.scope.ScopeInstanceResult
import com.egm.stellio.search.scope.SimplifiedScopeInstanceResult
import com.egm.stellio.search.support.EMPTY_JSON_PAYLOAD
import com.egm.stellio.search.support.SAMPLE_JSON_PROPERTY_PAYLOAD
import com.egm.stellio.search.support.SAMPLE_LANGUAGE_PROPERTY_PAYLOAD
import com.egm.stellio.search.support.buildAttributeInstancePayload
import com.egm.stellio.shared.util.JsonLdUtils
import com.egm.stellio.shared.util.loadSampleData
Expand Down Expand Up @@ -575,6 +576,55 @@ class TemporalEntityParameterizedSource {
loadSampleData("expectations/beehive_json_property_temporal_values.jsonld")
)

private val beehiveLanguagePropertyTemporalValues =
Arguments.arguments(
emptyList<ScopeInstanceResult>(),
mapOf(
TemporalEntityAttribute(
entityId = entityId,
attributeName = "https://ontology.eglobalmark.com/apic#friendlyName",
attributeType = TemporalEntityAttribute.AttributeType.LanguageProperty,
attributeValueType = TemporalEntityAttribute.AttributeValueType.OBJECT,
datasetId = null,
createdAt = now,
payload = SAMPLE_LANGUAGE_PROPERTY_PAYLOAD
) to
listOf(
SimplifiedAttributeInstanceResult(
temporalEntityAttribute = UUID.randomUUID(),
value = """
[{
"@value": "One beautiful beehive",
"@language": "en"
},
{
"@value": "Une belle ruche",
"@language": "fr"
}]
""",
time = ZonedDateTime.parse("2020-03-25T08:29:17.965206Z")
),
SimplifiedAttributeInstanceResult(
temporalEntityAttribute = UUID.randomUUID(),
value = """
[{
"@value": "My beautiful beehive",
"@language": "en"
},
{
"@value": "Ma belle ruche",
"@language": "fr"
}]
""",
time = ZonedDateTime.parse("2020-03-25T08:33:17.965206Z")
)
)
),
true,
false,
loadSampleData("expectations/beehive_language_property_temporal_values.jsonld")
)

@JvmStatic
fun rawResultsProvider(): Stream<Arguments> {
return Stream.of(
Expand All @@ -591,7 +641,8 @@ class TemporalEntityParameterizedSource {
beehiveRelationshipMultiInstancesTemporalValues,
beehiveScopeMultiInstancesTemporalValues,
beehiveScopeMultiInstances,
beehiveJsonPropertyTemporalValues
beehiveJsonPropertyTemporalValues,
beehiveLanguagePropertyTemporalValues
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"@id": "urn:ngsi-ld:BeeHive:TESTC",
"@type": [
"https://ontology.eglobalmark.com/apic#BeeHive"
],
"https://ontology.eglobalmark.com/apic#friendlyName": [
{
"@type": [
"https://uri.etsi.org/ngsi-ld/LanguageProperty"
],
"https://uri.etsi.org/ngsi-ld/hasLanguageMaps": [
{
"@list": [
{
"@list": [
{
"https://uri.etsi.org/ngsi-ld/hasLanguageMap": [
{
"@value": "One beautiful beehive",
"@language": "en"
},
{
"@value": "Une belle ruche",
"@language": "fr"
}
]
},
{
"@value": "2020-03-25T08:29:17.965206Z"
}
]
},
{
"@list": [
{
"https://uri.etsi.org/ngsi-ld/hasLanguageMap": [
{
"@value": "My beautiful beehive",
"@language": "en"
},
{
"@value": "Ma belle ruche",
"@language": "fr"
}
]
},
{
"@value": "2020-03-25T08:33:17.965206Z"
}
]
}
]
}
]
}
]
}

0 comments on commit 66535ea

Please sign in to comment.