Skip to content

Commit

Permalink
Merge pull request #1726 from FIWARE/bug/array-reduction-for-vocab
Browse files Browse the repository at this point in the history
Array reduction for vocab properties for normalized mode
  • Loading branch information
kzangeli authored Jan 9, 2025
2 parents 8215d0e + d177f76 commit 1cc913f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#1708: Reloaded hosted contexts were not persisted in mongo, only the context cache
#XXXX: Using "VocabProperty" and not "VocabularyProperty" (old name still accepted as input)
#XXXX: Array reduction for LanguageProperty languageMap values
#XXXX: Array reduction for VocabProperty vocab values, for normalized mode

## New Features:
#1707: Support for local=true in the type discovery endpoints (GET /ngsi-ld/v1/types[/{typeName}]
Expand Down
9 changes: 7 additions & 2 deletions src/lib/orionld/payloadCheck/pCheckAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,13 @@ static bool pCheckAttributeObject
else
LM_W(("No languageMap field found!"));
}

if (attributeType == NoAttributeType)
else if (attributeType == VocabularyProperty)
{
KjNode* vocabP = kjLookup(attrP, "vocab");
if (vocabP != NULL)
arrayReduce(vocabP);
}
else if (attributeType == NoAttributeType)
{
if (isGeoJsonValue(attrP))
{
Expand Down
49 changes: 49 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_vocab-property.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ accumulatorStart --pretty-print
# 11. Query entities with q=V1==abc&expandValues=V1,V2 => see urn:E1
# 12. Query entities with q=V2==id&expandValues=V1,V2 => see urn:E2
#
# 13. Create an entity urn:E4, type T, with a VocabProperty V4 whose vocab is an array with a single element - for array reduction
# 14. GET urn:E4 in normalized format, see V4 with an array-recuced 'vocab'
#

echo '01. Create a subscription on entity type T'
echo '=========================================='
Expand Down Expand Up @@ -194,6 +197,25 @@ echo
echo


echo "13. Create an entity urn:E4, type T, with a VocabProperty V4 whose vocab is an array with a single element - for array reduction"
echo "================================================================================================================================"
payload='{
"id": "urn:E4",
"type": "T",
"V4": { "type": "VocabProperty", "vocab": [ "test" ] }
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload"
echo
echo


echo "14. GET urn:E4 in normalized format, see V4 with an array-recuced 'vocab'"
echo "========================================================================="
orionCurl --url /ngsi-ld/v1/entities/urn:E4
echo
echo


--REGEXPECT--
01. Create a subscription on entity type T
==========================================
Expand Down Expand Up @@ -539,6 +561,33 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


13. Create an entity urn:E4, type T, with a VocabProperty V4 whose vocab is an array with a single element - for array reduction
================================================================================================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:E4



14. GET urn:E4 in normalized format, see V4 with an array-recuced 'vocab'
=========================================================================
HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"V4": {
"type": "VocabProperty",
"vocab": "test"
},
"id": "urn:E4",
"type": "T"
}


--TEARDOWN--
brokerStop CB
accumulatorStop
Expand Down

0 comments on commit 1cc913f

Please sign in to comment.