Skip to content

Commit

Permalink
Merge pull request #1539 from FIWARE/attributes/vocab-simplified-format
Browse files Browse the repository at this point in the history
Simplified format for VocabularyProperty
  • Loading branch information
kzangeli committed Jan 19, 2024
2 parents 7f0f247 + 4854e37 commit e50921d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/lib/orionld/dbModel/dbModelToApiAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,25 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs,
}
else if (strcmp(attrTypeNodeP->value.s, "VocabularyProperty") == 0)
{
attrP = kjLookup(dbAttrP, "value");
KjNode* valueP = kjLookup(dbAttrP, "value");

if (attrP->type == KjString)
attrP->value.s = orionldContextItemAliasLookup(orionldState.contextP, attrP->value.s, NULL, NULL);
else if (attrP->type == KjArray)
if (valueP->type == KjString)
valueP->value.s = orionldContextItemAliasLookup(orionldState.contextP, valueP->value.s, NULL, NULL);
else if (valueP->type == KjArray)
{
for (KjNode* wordP = attrP->value.firstChildP; wordP != NULL; wordP = wordP->next)
for (KjNode* wordP = valueP->value.firstChildP; wordP != NULL; wordP = wordP->next)
{
if (wordP->type == KjString)
wordP->value.s = orionldContextItemAliasLookup(orionldState.contextP, wordP->value.s, NULL, NULL);
}
}

// Remove everything except the value, and change its name to "vocab"
dbAttrP->value.firstChildP = valueP;
dbAttrP->lastChild = valueP;
valueP->next = NULL;
valueP->name = (char*) "vocab";
attrP = dbAttrP;
}
else
{
Expand Down
18 changes: 10 additions & 8 deletions test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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
# 07. GET urn:E2 in simplified format
#

echo '01. Create a subscription on entity type T'
Expand Down Expand Up @@ -127,7 +127,7 @@ echo
echo


echo "07. GET urn:E1 in simplified format"
echo "07. GET urn:E2 in simplified format"
echo "==================================="
orionCurl --url /ngsi-ld/v1/entities/urn:E2?options=simplified
echo
Expand Down Expand Up @@ -323,19 +323,21 @@ Ngsild-Attribute-Format: Normalized
=======================================


07. GET urn:E1 in simplified format
07. GET urn:E2 in simplified format
===================================
HTTP/1.1 200 OK
Content-Length: 46
Content-Length: 56
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

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

0 comments on commit e50921d

Please sign in to comment.