diff --git a/shared/config/detekt/baseline.xml b/shared/config/detekt/baseline.xml index 111b01c87..c359f0fb8 100644 --- a/shared/config/detekt/baseline.xml +++ b/shared/config/detekt/baseline.xml @@ -7,7 +7,6 @@ LongMethod:QueryUtils.kt$private fun transformQQueryToSqlJsonPath( mainAttributePath: List<ExpandedTerm>, trailingAttributePath: List<ExpandedTerm>, operator: String, value: String ) LongParameterList:ApiResponses.kt$( body: String, count: Int, resourceUrl: String, paginationQuery: PaginationQuery, requestParams: MultiValueMap<String, String>, mediaType: MediaType, contexts: List<String> ) LongParameterList:ApiResponses.kt$( entities: Any, count: Int, resourceUrl: String, paginationQuery: PaginationQuery, requestParams: MultiValueMap<String, String>, mediaType: MediaType, contexts: List<String> ) - NestedBlockDepth:CompactedEntity.kt$private fun filterLanguageProperty(value: Map<String, Any>, transformationParameters: Map<String, String>?): Any SpreadOperator:EntityEvent.kt$EntityEvent$( *[ JsonSubTypes.Type(value = EntityCreateEvent::class), JsonSubTypes.Type(value = EntityReplaceEvent::class), JsonSubTypes.Type(value = EntityDeleteEvent::class), JsonSubTypes.Type(value = AttributeAppendEvent::class), JsonSubTypes.Type(value = AttributeReplaceEvent::class), JsonSubTypes.Type(value = AttributeUpdateEvent::class), JsonSubTypes.Type(value = AttributeDeleteEvent::class), JsonSubTypes.Type(value = AttributeDeleteAllInstancesEvent::class) ] ) TooManyFunctions:JsonLdUtils.kt$JsonLdUtils diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/model/CompactedEntity.kt b/shared/src/main/kotlin/com/egm/stellio/shared/model/CompactedEntity.kt index 517b353b1..e6665d52b 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/model/CompactedEntity.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/model/CompactedEntity.kt @@ -53,12 +53,12 @@ val JSONLD_COMPACTED_ATTRIBUTE_CORE_MEMBERS = JSONLD_OBJECT, JSONLD_JSON_TERM, JSONLD_VOCAB_TERM, + JSONLD_LANGUAGEMAP_TERM, NGSILD_UNIT_CODE_TERM, NGSILD_DATASET_ID_TERM, NGSILD_CREATED_AT_TERM, NGSILD_MODIFIED_AT_TERM, - NGSILD_OBSERVED_AT_TERM, - JSONLD_LANGUAGEMAP_TERM + NGSILD_OBSERVED_AT_TERM ) fun CompactedEntity.getRelationshipsObjects(): Set = @@ -160,7 +160,7 @@ private fun filterLanguageProperty(value: Map, transformationParame AttributeCompactedType.forKey(value[JSONLD_TYPE_TERM] as String) } - if (attributeCompactedType == LANGUAGEPROPERTY) { + return if (attributeCompactedType == LANGUAGEPROPERTY) { val localeRanges = Locale.LanguageRange.parse(languageFilter) val propertyLocales = (value[JSONLD_LANGUAGEMAP_TERM] as Map).keys.sorted() val bestLocaleMatch = Locale.filterTags(localeRanges, propertyLocales) @@ -168,34 +168,29 @@ private fun filterLanguageProperty(value: Map, transformationParame // as the list is sorted, @none is the first in the list if it exists propertyLocales.first() } - val filteredMainAttribute = mutableMapOf( - JSONLD_TYPE_TERM to NGSILD_PROPERTY_TERM, - JSONLD_VALUE_TERM to (value[JSONLD_LANGUAGEMAP_TERM] as Map)[bestLocaleMatch], - NGSILD_LANG_TERM to bestLocaleMatch - ) - value.forEach { (key, value) -> - if (JSONLD_COMPACTED_ATTRIBUTE_CORE_MEMBERS.contains(key)) { - if (key != JSONLD_LANGUAGEMAP_TERM && key != JSONLD_TYPE_TERM) filteredMainAttribute[key] = value - } else { - filteredMainAttribute[key] = filterLanguageProperty( - value as Map, - transformationParameters - ) - } - } - return filteredMainAttribute - } else { - return value.map { entry -> + value.map { entry -> when { - entry.key == NGSILD_ENTITY_TERM -> - entry.key to (entry.value as CompactedEntity).toFilteredLanguageProperties(languageFilter) - !JSONLD_COMPACTED_ATTRIBUTE_CORE_MEMBERS.contains(entry.key) -> + entry.key == JSONLD_TYPE_TERM -> + JSONLD_TYPE_TERM to NGSILD_PROPERTY_TERM + entry.key == JSONLD_LANGUAGEMAP_TERM -> + JSONLD_VALUE_TERM to (value[JSONLD_LANGUAGEMAP_TERM] as Map)[bestLocaleMatch] + JSONLD_COMPACTED_ATTRIBUTE_CORE_MEMBERS.contains(entry.key) -> + entry.key to entry.value + else -> entry.key to filterLanguageProperty(entry.value as Map, transformationParameters) - else -> entry.key to entry.value } }.toMap() - } + .plus(NGSILD_LANG_TERM to bestLocaleMatch) + } else value.map { entry -> + when { + entry.key == NGSILD_ENTITY_TERM -> + entry.key to (entry.value as CompactedEntity).toFilteredLanguageProperties(languageFilter) + !JSONLD_COMPACTED_ATTRIBUTE_CORE_MEMBERS.contains(entry.key) -> + entry.key to filterLanguageProperty(entry.value as Map, transformationParameters) + else -> entry.key to entry.value + } + }.toMap() } fun CompactedEntity.toGeoJson(geometryProperty: String): Map {