Skip to content

Commit

Permalink
support for modifiedAt/cretedAt in q of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Nov 3, 2023
1 parent 19ad526 commit dd74cec
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fixed issues:
* #280 - Fixed two erroneous type values in the response payload body (EntityTypeInformation => EntityTypeInfo and EntityAttributeList => AttributeList)
* #280 - Giving errors for expiresAt in the past (for registrations and subscriptions)
* #280 - Highly experimental feature for subscriptions: allowing a wildcard as value for entity type, to not filter on entity type
* #280 - Implemented Periodic Notifications (subscriptions with a 'timeInterval')
* #280 - Support for 'Periodic Notifications' (subscriptions with a 'timeInterval')
* #280 - New CLI (hidden) for extra field in notifications (trigger: "VERB URL PATH"): -triggerOperation
* #1456 - Bug fix - entity id+type duplicated in forwarded request of "Create Entity"
* #1458 - Supporting modifiedAt in q
* #1458 - Supporting system timestamps (createdAt/modifiedAt) in q
39 changes: 32 additions & 7 deletions src/lib/orionld/q/qVariableFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,51 @@ char* qVariableFix(char* varPathIn, bool forDb, bool* isMdP, char** detailsP)

if (forDb)
{
if (strcmp(longName, "createdAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "%s", "creDate");
else if (strcmp(longName, "modifiedAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "%s", "modDate");
else if (caseNo == 1)
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.value", longName);
if (caseNo == 1)
{
LM_T(LmtQ, ("Case 1: attr: '%s'", longName));

if (strcmp(longName, "createdAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "%s", "creDate");
else if (strcmp(longName, "modifiedAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "%s", "modDate");
else
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.value", longName);
}
else if (caseNo == 2)
{
LM_T(LmtQ, ("Case 2: attr: '%s', sub-attr: '%s', rest: '%s'", longName, mdNameP, rest));
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.value.%s", longName, rest);
}
else if (caseNo == 3)
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.md.%s.value", longName, mdNameP);
{
LM_T(LmtQ, ("Case 3: attr: '%s', sub-attr: '%s'", longName, mdNameP));

if (strcmp(mdNameP, "createdAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.%s", longName, "creDate");
else if (strcmp(mdNameP, "modifiedAt") == 0)
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.%s", longName, "modDate");
else
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.md.%s.value", longName, mdNameP);
}
else
{
LM_T(LmtQ, ("Case 3+: attr: '%s', sub-attr: '%s', rest: '%s'", longName, mdNameP, rest));
snprintf(fullPath, sizeof(fullPath) - 1, "attrs.%s.md.%s.value.%s", longName, mdNameP, rest);
}
}
else
{
LM_T(LmtQ, ("Not for DB, case %d: attr: '%s', sub-attr: '%s', rest: '%s'", caseNo, longName, mdNameP, rest));

// If observedAt, createdAt, modifiedAt, unitCode, ... No ".value" must be appended
if (caseNo == 3)
{
if ((strcmp(mdNameP, "observedAt") == 0) || (strcmp(mdNameP, "modifiedAt") == 0) || (strcmp(mdNameP, "createdAt") == 0))
{
LM_T(LmtQ, ("Case 5 - it's a timestamp (%s)", mdNameP));
caseNo = 5;
}
}

if (caseNo == 1)
Expand Down
254 changes: 248 additions & 6 deletions test/functionalTest/cases/0000_ngsild/ngsild_q_with_modifiedAt.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ orionldStart CB -experimental
# 03. Sleep 1 second
# 04. Create E2 with type T and attr A=2 and B=2
# 05. Attempt to filter on existence of 'modifiedAt' - see 400
# 06. GET all entities that have a modifiedAt > the saved modifiedAt of E1 - see E2
# 06. GET all entities that have a modifiedAt > the timestamp between E1 and E2 - see E2
# 07. GET all entities that have a modifiedAt < the timestamp between E1 and E2 - see E1
# 08. GET all entities that have a createdAt > the timestamp between E1 and E2 - see E2
# 09. GET all entities that have a createdAt < the timestamp between E1 and E2 - see E1
# 10. GET all entities that have an attribute A with a modifiedAt > the timestamp between E1 and E2 - see E2
# 11. GET all entities that have an attribute A with a modifiedAt < the timestamp between E1 and E2 - see E1
# 12. GET all entities that have an attribute A with a createdAt > the timestamp between E1 and E2 - see E2
# 13. GET all entities that have an attribute A with a createdAt < the timestamp between E1 and E2 - see E1
#

echo "01. Create E1 with type T and attr A=1 and B=1"
Expand Down Expand Up @@ -100,13 +107,62 @@ echo
echo


echo "06. GET all entities that have a modifiedAt > the saved modifiedAt of E1 - see E2"
echo "================================================================================="
echo "06. GET all entities that have a modifiedAt > the timestamp between E1 and E2 - see E2"
echo "======================================================================================"
orionCurl --url "/ngsi-ld/v1/entities?q=modifiedAt>$e1ModifiedAt&options=sysAttrs"
echo
echo


echo "07. GET all entities that have a modifiedAt < the timestamp between E1 and E2 - see E1"
echo "======================================================================================"
orionCurl --url "/ngsi-ld/v1/entities?q=modifiedAt<$e1ModifiedAt&options=sysAttrs"
echo
echo


echo "08. GET all entities that have a createdAt > the timestamp between E1 and E2 - see E2"
echo "====================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=createdAt>$e1ModifiedAt&options=sysAttrs"
echo
echo


echo "09. GET all entities that have a createdAt < the timestamp between E1 and E2 - see E1"
echo "====================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=createdAt<$e1ModifiedAt&options=sysAttrs"
echo
echo


echo "10. GET all entities that have an attribute A with a modifiedAt > the timestamp between E1 and E2 - see E2"
echo "=========================================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=A.modifiedAt>$e1ModifiedAt"
echo
echo


echo "11. GET all entities that have an attribute A with a modifiedAt < the timestamp between E1 and E2 - see E1"
echo "=========================================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=A.modifiedAt<$e1ModifiedAt"
echo
echo


echo "12. GET all entities that have an attribute A with a createdAt > the timestamp between E1 and E2 - see E2"
echo "========================================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=A.createdAt>$e1ModifiedAt"
echo
echo


echo "13. GET all entities that have an attribute A with a createdAt < the timestamp between E1 and E2 - see E1"
echo "========================================================================================================="
orionCurl --url "/ngsi-ld/v1/entities?q=A.createdAt<$e1ModifiedAt"
echo
echo


--REGEXPECT--
01. Create E1 with type T and attr A=1 and B=1
==============================================
Expand Down Expand Up @@ -173,8 +229,8 @@ Date: REGEX(.*)
}


06. GET all entities that have a modifiedAt > the saved modifiedAt of E1 - see E2
=================================================================================
06. GET all entities that have a modifiedAt > the timestamp between E1 and E2 - see E2
======================================================================================
HTTP/1.1 200 OK
Content-Length: 349
Content-Type: application/json
Expand Down Expand Up @@ -203,6 +259,192 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


07. GET all entities that have a modifiedAt < the timestamp between E1 and E2 - see E1
======================================================================================
HTTP/1.1 200 OK
Content-Length: 349
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 1
},
"B": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 1
},
"createdAt": "202REGEX(.*)Z",
"id": "http://a.b.c/entity/E1",
"modifiedAt": "202REGEX(.*)Z",
"type": "T"
}
]


08. GET all entities that have a createdAt > the timestamp between E1 and E2 - see E2
=====================================================================================
HTTP/1.1 200 OK
Content-Length: 349
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 2
},
"B": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 2
},
"createdAt": "202REGEX(.*)Z",
"id": "http://a.b.c/entity/E2",
"modifiedAt": "202REGEX(.*)Z",
"type": "T"
}
]


09. GET all entities that have a createdAt < the timestamp between E1 and E2 - see E1
=====================================================================================
HTTP/1.1 200 OK
Content-Length: 349
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 1
},
"B": {
"createdAt": "202REGEX(.*)Z",
"modifiedAt": "202REGEX(.*)Z",
"type": "Property",
"value": 1
},
"createdAt": "202REGEX(.*)Z",
"id": "http://a.b.c/entity/E1",
"modifiedAt": "202REGEX(.*)Z",
"type": "T"
}
]


10. GET all entities that have an attribute A with a modifiedAt > the timestamp between E1 and E2 - see E2
==========================================================================================================
HTTP/1.1 200 OK
Content-Length: 112
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"type": "Property",
"value": 2
},
"B": {
"type": "Property",
"value": 2
},
"id": "http://a.b.c/entity/E2",
"type": "T"
}
]


11. GET all entities that have an attribute A with a modifiedAt < the timestamp between E1 and E2 - see E1
==========================================================================================================
HTTP/1.1 200 OK
Content-Length: 112
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"type": "Property",
"value": 1
},
"B": {
"type": "Property",
"value": 1
},
"id": "http://a.b.c/entity/E1",
"type": "T"
}
]


12. GET all entities that have an attribute A with a createdAt > the timestamp between E1 and E2 - see E2
=========================================================================================================
HTTP/1.1 200 OK
Content-Length: 112
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"type": "Property",
"value": 2
},
"B": {
"type": "Property",
"value": 2
},
"id": "http://a.b.c/entity/E2",
"type": "T"
}
]


13. GET all entities that have an attribute A with a createdAt < the timestamp between E1 and E2 - see E1
=========================================================================================================
HTTP/1.1 200 OK
Content-Length: 112
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"A": {
"type": "Property",
"value": 1
},
"B": {
"type": "Property",
"value": 1
},
"id": "http://a.b.c/entity/E1",
"type": "T"
}
]


--TEARDOWN--
brokerStop CB
#dbDrop CB
dbDrop CB

0 comments on commit dd74cec

Please sign in to comment.