From dae953564d6e70faf219fe8e7e651445c6e19069 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Fri, 19 Jan 2024 12:10:10 +0100 Subject: [PATCH] Bug fix: compaction of vocab values for simplified format --- .../orionld/dbModel/dbModelToApiAttribute.cpp | 15 +++++++++++ .../0000_ngsild/ngsild_vocab-property.test | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp b/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp index 1066a2e7c6..ae748c2302 100644 --- a/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp +++ b/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp @@ -376,6 +376,21 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs, dbModelToApiLangPropertySimplified(dbAttrP, lang); attrP = dbAttrP; } + else if (strcmp(attrTypeNodeP->value.s, "VocabularyProperty") == 0) + { + attrP = kjLookup(dbAttrP, "value"); + + if (attrP->type == KjString) + attrP->value.s = orionldContextItemAliasLookup(orionldState.contextP, attrP->value.s, NULL, NULL); + else if (attrP->type == KjArray) + { + for (KjNode* wordP = attrP->value.firstChildP; wordP != NULL; wordP = wordP->next) + { + if (wordP->type == KjString) + wordP->value.s = orionldContextItemAliasLookup(orionldState.contextP, wordP->value.s, NULL, NULL); + } + } + } else { // "Steal" the value node and rename it to have the attribute's name instead - that's all that's needed for SIMPLIFIED FORMAT diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test b/test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test index 11202aab80..53ec34d274 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test @@ -41,6 +41,8 @@ accumulatorStart --pretty-print # 05b. See urn:E2 in the DB - see [ "vocab", "id" ] expanded # 06. Dump/Reset accumulator, see urn:E1+V1 and urn:E2+V2 # +# 07. GET urn:E1 in simplified format +# echo '01. Create a subscription on entity type T' echo '==========================================' @@ -125,6 +127,13 @@ echo echo +echo "07. GET urn:E1 in simplified format" +echo "===================================" +orionCurl --url /ngsi-ld/v1/entities/urn:E2?options=simplified +echo +echo + + --REGEXPECT-- 01. Create a subscription on entity type T ========================================== @@ -314,6 +323,24 @@ Ngsild-Attribute-Format: Normalized ======================================= +07. GET urn:E1 in simplified format +=================================== +HTTP/1.1 200 OK +Content-Length: 46 +Content-Type: application/json +Date: REGEX(.*) +Link: