Skip to content

Commit

Permalink
feat(common): use provided context to compact returned entities
Browse files Browse the repository at this point in the history
- upgrade jsonld-java to allow using a local cache of @context
  - cf jsonld-java/jsonld-java#294
  - TODO more tests and configurations
- use the provided context in API call for compaction in every concerned service
- ensure core context comes last when compacting
- do not re-add core context if already referenced by a context provided in the query
  • Loading branch information
bobeal committed Dec 29, 2020
1 parent 5d15580 commit 05c3a10
Show file tree
Hide file tree
Showing 17 changed files with 2,249 additions and 143 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ subprojects {
implementation("org.springframework.cloud:spring-cloud-starter-stream-kafka")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.github.jsonld-java:jsonld-java:0.13.0")
implementation("com.github.jsonld-java:jsonld-java:0.13.2")

implementation("io.arrow-kt:arrow-fx:0.10.4")
implementation("io.arrow-kt:arrow-syntax:0.10.4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class EntityEventService(
jsonLdAttributes[updatedDetails.attributeName]!!,
contexts
),
JsonLdUtils.compactAndSerialize(updatedEntity, MediaType.APPLICATION_JSON),
JsonLdUtils.compactAndSerialize(updatedEntity, contexts, MediaType.APPLICATION_JSON),
contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand All @@ -79,7 +79,7 @@ class EntityEventService(
jsonLdAttributes[updatedDetails.attributeName]!!,
contexts
),
JsonLdUtils.compactAndSerialize(updatedEntity, MediaType.APPLICATION_JSON),
JsonLdUtils.compactAndSerialize(updatedEntity, contexts, MediaType.APPLICATION_JSON),
contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.egm.stellio.shared.util.JsonLdUtils.EGM_OBSERVED_BY
import com.egm.stellio.shared.util.JsonLdUtils.EGM_VENDOR_ID
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.NGSILD_EGM_CONTEXT
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_RELATIONSHIP_HAS_OBJECT
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_RELATIONSHIP_TYPE
import com.egm.stellio.shared.util.JsonLdUtils.compactAndStringifyFragment
Expand Down Expand Up @@ -784,7 +785,7 @@ class EntityService(
observedProperty.name.extractShortTypeFromExpanded(),
observedProperty.datasetId,
propertyPayload,
JsonLdUtils.compactAndSerialize(it, MediaType.APPLICATION_JSON),
JsonLdUtils.compactAndSerialize(it, listOf(NGSILD_EGM_CONTEXT), MediaType.APPLICATION_JSON),
entity.contexts
),
entity.type[0].extractShortTypeFromExpanded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class EntityHandler(
)
}

val compactedEntities = compactEntities(filteredEntities, useSimplifiedRepresentation)
val compactedEntities = compactEntities(filteredEntities, useSimplifiedRepresentation, contextLink)

return ResponseEntity.status(HttpStatus.OK).body(serializeObject(compactedEntities))
}
Expand Down Expand Up @@ -163,7 +163,7 @@ class EntityHandler(
JsonLdUtils.filterJsonLdEntityOnAttributes(jsonLdEntity, expandedAttrs),
jsonLdEntity.contexts
)
val compactedEntity = filteredJsonLdEntity.compact()
val compactedEntity = JsonLdUtils.compact(filteredJsonLdEntity, contextLink)

return if (useSimplifiedRepresentation)
ResponseEntity.status(HttpStatus.OK).body(serializeObject(compactedEntity.toKeyValues()))
Expand Down Expand Up @@ -282,7 +282,7 @@ class EntityHandler(
jsonLdAttributes[updatedDetails.attributeName]!!,
contexts
),
compactAndSerialize(updatedEntity!!, MediaType.APPLICATION_JSON),
compactAndSerialize(updatedEntity!!, contexts, MediaType.APPLICATION_JSON),
contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand Down Expand Up @@ -332,7 +332,7 @@ class EntityHandler(
attributeName = attrId,
datasetId = getPropertyValueFromMapAsString(expandedBody, NGSILD_DATASET_ID_PROPERTY)?.toUri(),
operationPayload = removeContextFromInput(body),
updatedEntity = compactAndSerialize(updatedEntity!!, MediaType.APPLICATION_JSON),
updatedEntity = compactAndSerialize(updatedEntity!!, contexts, MediaType.APPLICATION_JSON),
contexts = contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand Down Expand Up @@ -374,7 +374,7 @@ class EntityHandler(
AttributeDeleteAllInstancesEvent(
entityId = entityId.toUri(),
attributeName = attrId,
updatedEntity = compactAndSerialize(updatedEntity!!, MediaType.APPLICATION_JSON),
updatedEntity = compactAndSerialize(updatedEntity!!, contexts, MediaType.APPLICATION_JSON),
contexts = contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand All @@ -385,7 +385,7 @@ class EntityHandler(
entityId = entityId.toUri(),
attributeName = attrId,
datasetId = datasetId,
updatedEntity = compactAndSerialize(updatedEntity!!, MediaType.APPLICATION_JSON),
updatedEntity = compactAndSerialize(updatedEntity!!, contexts, MediaType.APPLICATION_JSON),
contexts = contexts
),
updatedEntity.type.extractShortTypeFromExpanded()
Expand Down

0 comments on commit 05c3a10

Please sign in to comment.