Skip to content

Commit

Permalink
Merge pull request #1538 from FIWARE/attributes/vocab-simplified
Browse files Browse the repository at this point in the history
Bug fix: compaction of vocab values for simplified format
  • Loading branch information
kzangeli authored Jan 19, 2024
2 parents 29547ea + dae9535 commit 7f0f247
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/orionld/dbModel/dbModelToApiAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 '=========================================='
Expand Down Expand Up @@ -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
==========================================
Expand Down Expand Up @@ -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: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"V2": [
"vocab",
"id"
],
"id": "urn:E2",
"type": "T"
}


--TEARDOWN--
brokerStop CB
accumulatorStop
Expand Down

0 comments on commit 7f0f247

Please sign in to comment.