Skip to content

Commit

Permalink
fix(core): ensure no type change in partial attribute update operation (
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal authored Nov 27, 2023
1 parent 17c1c56 commit 793a5ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import arrow.core.Either
import arrow.core.flatMap
import arrow.core.left
import arrow.core.raise.either
import arrow.core.raise.ensure
import arrow.core.right
import arrow.fx.coroutines.parMap
import com.egm.stellio.search.model.*
import com.egm.stellio.search.util.*
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.AttributeType
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_TYPE
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_OBSERVED_AT_PROPERTY
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_PREFIX
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_PROPERTY_VALUE
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_RELATIONSHIP_HAS_OBJECT
import com.egm.stellio.shared.util.JsonLdUtils.buildNonReifiedDateTime
Expand Down Expand Up @@ -655,6 +659,11 @@ class TemporalEntityAttributeService(
if (exists) {
// first update payload in temporal entity attribute
val tea = getForEntityAndAttribute(entityId, attributeName, datasetId).bind()
attributeValues[JSONLD_TYPE]?.let {
ensure(isAttributeOfType(attributeValues, AttributeType(NGSILD_PREFIX + tea.attributeType))) {
BadRequestDataException("The type of the attribute has to be the same as the existing one")
}
}
val (jsonTargetObject, updatedAttributeInstance) = mergeAttributePayload(tea, attributeValues)
val value = getValueFromPartialAttributePayload(tea, updatedAttributeInstance)
val attributeValueType = guessAttributeValueType(tea.attributeType, attributeValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object JsonLdUtils {
"https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/master"
const val NGSILD_EGM_CONTEXT = "$EGM_BASE_CONTEXT_URL/shared-jsonld-contexts/egm.jsonld"

const val NGSILD_PREFIX = "https://uri.etsi.org/ngsi-ld/"
const val NGSILD_DEFAULT_VOCAB = "https://uri.etsi.org/ngsi-ld/default-context/"

val NGSILD_PROPERTY_TYPE = AttributeType("https://uri.etsi.org/ngsi-ld/Property")
Expand Down

0 comments on commit 793a5ff

Please sign in to comment.