Skip to content

Commit

Permalink
fix(core): retrieving of the value type of an attribute in partial at…
Browse files Browse the repository at this point in the history
…tribute updates
  • Loading branch information
bobeal committed Jul 19, 2023
1 parent 012a43d commit 70a4bdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class TemporalEntityAttributeService(
val tea = getForEntityAndAttribute(entityId, attributeName, datasetId).bind()
val (jsonTargetObject, updatedAttributeInstance) = mergeAttributePayload(tea, attributeValues)
val value = getValueFromPartialAttributePayload(tea, updatedAttributeInstance)
val attributeValueType = guessAttributeValueType(tea.attributeType, attributeValues.getValue())
val attributeValueType = guessAttributeValueType(tea.attributeType, attributeValues)
updateOnUpdate(tea.id, attributeValueType, modifiedAt, jsonTargetObject.toString()).bind()

// then update attribute instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.egm.stellio.search.model.AttributeMetadata
import com.egm.stellio.search.model.TemporalEntityAttribute
import com.egm.stellio.search.model.TemporalEntityAttribute.AttributeValueType
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.ExpandedAttributeInstance
import com.egm.stellio.shared.util.JsonLdUtils.logger
import com.egm.stellio.shared.util.JsonUtils.serializeObject
import java.net.URI
Expand Down Expand Up @@ -79,10 +80,11 @@ fun NgsiLdAttributeInstance.toTemporalAttributeMetadata(): Either<APIException,

fun guessAttributeValueType(
attributeType: TemporalEntityAttribute.AttributeType,
value: Any
expandedAttributeInstance: ExpandedAttributeInstance
): AttributeValueType =
when (attributeType) {
TemporalEntityAttribute.AttributeType.Property -> guessPropertyValueType(value).first
TemporalEntityAttribute.AttributeType.Property ->
guessPropertyValueType(expandedAttributeInstance.getPropertyValue()).first
TemporalEntityAttribute.AttributeType.Relationship -> AttributeValueType.URI
TemporalEntityAttribute.AttributeType.GeoProperty -> AttributeValueType.GEOMETRY
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import arrow.fx.coroutines.parMap
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_ID
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_TYPE
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_VALUE
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_VALUE_KW
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_CREATED_AT_PROPERTY
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_DATASET_ID_PROPERTY
Expand Down Expand Up @@ -389,8 +388,8 @@ suspend fun JsonLdEntity.toNgsiLdEntity(): Either<APIException, NgsiLdEntity> =
fun ExpandedAttributeInstance.getDatasetId(): URI? =
(this[NGSILD_DATASET_ID_PROPERTY]?.get(0) as? Map<String, String>)?.get(JSONLD_ID)?.toUri()

fun ExpandedAttributeInstance.getValue(): Any =
(this[NGSILD_PROPERTY_VALUE]!![0] as Map<String, Any>)[JSONLD_VALUE]!!
fun ExpandedAttributeInstance.getPropertyValue(): Any =
(this[NGSILD_PROPERTY_VALUE]!![0] as Map<String, Any>)[JSONLD_VALUE_KW]!!

fun List<NgsiLdAttribute>.flatOnInstances(): List<Pair<NgsiLdAttribute, NgsiLdAttributeInstance>> =
this.flatMap { ngsiLdAttribute ->
Expand Down

0 comments on commit 70a4bdb

Please sign in to comment.