Skip to content

Commit

Permalink
Merge pull request #1703 from FIWARE/dds/betterAttributes
Browse files Browse the repository at this point in the history
Removed some 'garbage' from DDS samples before storing attr in NGSI-LD current state
  • Loading branch information
kzangeli authored Oct 31, 2024
2 parents 25fcdcd + e5a9d1c commit 5141932
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 58 deletions.
27 changes: 21 additions & 6 deletions src/lib/orionld/dds/ddsNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,32 @@ void ddsNotification(const char* typeName, const char* topicName, const char* js
char* expandedType = orionldContextItemExpand(orionldState.contextP, entityType, true, NULL);
typeNodeP = kjString(orionldState.kjsonP, "type", expandedType);

KjNode* attrValueNodeP = kjLookup(kTree, topicName);
if (attrValueNodeP == NULL)
KjNode* topicNameNodeP = kjLookup(kTree, topicName);
if (topicNameNodeP == NULL)
KT_RVE("No attribute field ('%s') in DDS payload", topicName);
KjNode* dataNodeP = kjLookup(topicNameNodeP, "data");
if (dataNodeP == NULL)
KT_RVE("No 'data' field in DDS attribute payload", topicName);

KjNode* tNodeP = kjLookup(topicNameNodeP, "type");
if (tNodeP != NULL)
kjChildRemove(topicNameNodeP, tNodeP);

KjNode* valueNodeP = dataNodeP->value.firstChildP;
char* xId = valueNodeP->name;
KjNode* subAttrP = kjString(orionldState.kjsonP, "xId", xId);
KjNode* attrNodeP = kjObject(orionldState.kjsonP, NULL);

valueNodeP->name = (char*) "value";

kjChildAdd(attrNodeP, valueNodeP);

// Add the xId node as "hidden" sub-property - not to be included in GETs, only for DDS publish reconstruction
kjChildAdd(attrNodeP, subAttrP);

orionldState.payloadIdNode = idNodeP;
orionldState.payloadTypeNode = typeNodeP;

KjNode* attrNodeP = kjObject(orionldState.kjsonP, NULL);
kjChildAdd(attrNodeP, attrValueNodeP);
attrValueNodeP->name = (char*) "value";

orionldState.requestTree = attrNodeP;
orionldState.uriParams.format = (char*) "simplified";
orionldState.uriParams.type = typeNodeP->value.s;
Expand Down
100 changes: 48 additions & 52 deletions test/functionalTest/cases/0000_dds/dds_notifications.test
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,18 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
},
"type": "Property",
"value": {
"data": {
"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0": {
"b": false,
"f": 0,
"i": 0,
"ia": [
0,
0
],
"s": "abc"
}
},
"type": "NgsildSample"
"b": false,
"f": 0,
"i": 0,
"ia": [
0,
0
],
"s": "abc"
},
"xId": {
"type": "Property",
"value": "REGEX(.*)"
}
},
"type": "Camera"
Expand All @@ -194,19 +193,18 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
},
"type": "Property",
"value": {
"data": {
"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0": {
"b": false,
"f": 0,
"i": 2,
"ia": [
0,
0
],
"s": ""
}
},
"type": "NgsildSample"
"b": false,
"f": 0,
"i": 2,
"ia": [
0,
0
],
"s": ""
},
"xId": {
"type": "Property",
"value": "REGEX(.*)"
}
},
"ddsType": {
Expand All @@ -228,19 +226,18 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
},
"type": "Property",
"value": {
"data": {
"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0": {
"b": false,
"f": 3.14,
"i": 0,
"ia": [
0,
0
],
"s": ""
}
},
"type": "NgsildSample"
"b": false,
"f": 3.14,
"i": 0,
"ia": [
0,
0
],
"s": ""
},
"xId": {
"type": "Property",
"value": "REGEX(.*)"
}
},
"P4": {
Expand All @@ -254,19 +251,18 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
},
"type": "Property",
"value": {
"data": {
"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0": {
"b": false,
"f": 4.14,
"i": 4,
"ia": [
0,
0
],
"s": "p4"
}
},
"type": "NgsildSample"
"b": false,
"f": 4.14,
"i": 4,
"ia": [
0,
0
],
"s": "p4"
},
"xId": {
"type": "Property",
"value": "REGEX(.*)"
}
},
"ddsType": {
Expand Down

0 comments on commit 5141932

Please sign in to comment.