Skip to content

Commit

Permalink
Merge pull request #1721 from FIWARE/issue/1707-type-discovery-and-local
Browse files Browse the repository at this point in the history
Issue/1707 type discovery and local
  • Loading branch information
kzangeli authored Dec 13, 2024
2 parents 51f2004 + 987a637 commit fd6283e
Show file tree
Hide file tree
Showing 15 changed files with 603 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Fixed Issues:
#XXXX: Complex @contexts of subscriptions weren't persisted in mongodb
#1707: Support for local=true in the type discovery endpoints (GET /ngsi-ld/v1/types[/{typeName}]
#1708: Reloaded hosted contexts were not persisted in mongo, only the context cache

## New Features:
Expand Down
19 changes: 10 additions & 9 deletions src/lib/orionld/db/dbEntityTypesGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ KjNode* typeObjectLookup(KjNode* arrayP, const char* type)
//
// dbEntityTypesGet -
//
KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details)
KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details, bool localOnly)
{
KjNode* local;
KjNode* remote;
KjNode* arrayP = NULL;
KjNode* local = NULL;
KjNode* remote = NULL;
KjNode* arrayP = NULL;

//
// This is a bit ugly ...
Expand Down Expand Up @@ -372,11 +372,13 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details)
//
// GET remote types - i.e. from the "registrations" collection
//
remote = entityTypesFromRegistrationsGet(details);

if ((remote != NULL) && (details == true))
remote = typesAndAttributesExtractFromRegistrations(remote);
if (localOnly == false)
{
remote = entityTypesFromRegistrationsGet(details);

if ((remote != NULL) && (details == true))
remote = typesAndAttributesExtractFromRegistrations(remote);
}

//
// Fix duplicates in 'local'
Expand Down Expand Up @@ -491,7 +493,6 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details)
}
}


if ((remote == NULL) && (local == NULL))
{
char entityTypesId[64];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/db/dbEntityTypesGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ extern "C"
//
// dbEntityTypesGet -
//
extern KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details);
extern KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details, bool localOnly);

#endif // SRC_LIB_ORIONLD_DB_DBENTITYTYPESGET_H_
6 changes: 6 additions & 0 deletions src/lib/orionld/service/orionldServiceInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,22 @@ static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceS
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS;
serviceP->uriParams |= ORIONLD_URIPARAM_LOCAL;
}
else if (serviceP->serviceRoutine == orionldGetEntityType)
{
serviceP->uriParams |= ORIONLD_URIPARAM_LOCAL;
}
else if (serviceP->serviceRoutine == orionldGetEntityAttributes)
{
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS;
serviceP->uriParams |= ORIONLD_URIPARAM_LOCAL;
}
else if (serviceP->serviceRoutine == orionldGetEntityAttribute)
{
serviceP->uriParams |= ORIONLD_URIPARAM_LOCAL;
}
else if (serviceP->serviceRoutine == orionldPostTemporalEntities)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/serviceRoutines/orionldGetEntityTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool orionldGetEntityTypes(void)
{
OrionldProblemDetails pd;

orionldState.responseTree = dbEntityTypesGet(&pd, orionldState.uriParams.details);
orionldState.responseTree = dbEntityTypesGet(&pd, orionldState.uriParams.details, orionldState.uriParams.local);
if (orionldState.responseTree == NULL)
{
orionldError(OrionldResourceNotFound, pd.title, pd.detail, pd.status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ echo

echo "08. GET Entity Type T1 - see T1, count 3, and attrs P1, P2, R1, and R2"
echo "======================================================================"
orionCurl --url /ngsi-ld/v1/types/T1
orionCurl --url /ngsi-ld/v1/types/T1?local=true
echo
echo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ orionldStart CB
# 04. Create registration R2, entity type T1, with attributes P4 and R4
# 05. GET Types - see T1
# 06. GET Types with details - see T1 with P1-P4 and R1-R4
# 07. GET Types with local=true - see T1
# 08. GET Types with details and local=true - see T1 but attributes only from entities E1+E2
#

echo "01. Create entity E1, type T1, with attributes P1 and R1"
Expand Down Expand Up @@ -137,6 +139,20 @@ echo
echo


echo "07. GET Types with local=true - see T1"
echo "======================================"
orionCurl --url /ngsi-ld/v1/types?local=true
echo
echo


echo "08. GET Types with details and local=true - see T1 but attributes only from entities E1+E2"
echo "=========================================================================================="
orionCurl --url '/ngsi-ld/v1/types?details=true&local=true'
echo
echo


--REGEXPECT--
01. Create entity E1, type T1, with attributes P1 and R1
========================================================
Expand Down Expand Up @@ -218,6 +234,46 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


07. GET Types with local=true - see T1
======================================
HTTP/1.1 200 OK
Content-Length: 114
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"id": "urn:ngsi-ld:EntityTypeList:REGEX(.*)",
"type": "EntityTypeList",
"typeList": [
"T1"
]
}


08. GET Types with details and local=true - see T1 but attributes only from entities E1+E2
==========================================================================================
HTTP/1.1 200 OK
Content-Length: 133
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"attributeNames": [
"P2",
"R2",
"P1",
"R1"
],
"id": "https://uri.etsi.org/ngsi-ld/default-context/T1",
"type": "EntityType",
"typeName": "T1"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ orionldStart CB
# 02. Create entity E2, type T1, with attributes P2 and R2
# 03. GET Types - see T1
# 04. GET Types with details - see T1 with P1, P2, R1, R2
# 05. Create entity E3, type T2, with attributes P1 and R1
# 06. Create entity E4, type T2, with attributes P2 and R2
# 07. GET Types - see T1 and T2
# 08. GET Types with details - see T1 and T2 with P1, P2, R1, R2
# 05. GET Types with local=true - see T1
# 06. GET Types with details and local=true - see T1 with P1, P2, R1, R2
# 07. Create entity E3, type T2, with attributes P1 and R1
# 08. Create entity E4, type T2, with attributes P2 and R2
# 09. GET Types - see T1 and T2
# 10. GET Types with details - see T1 and T2 with P1, P2, R1, R2
# 11. GET Types with local=true - see T1 and T2
# 12. GET Types with details and local=true - see T1 and T2 with P1, P2, R1, R2
#

echo "01. Create entity E1, type T1, with attributes P1 and R1"
Expand Down Expand Up @@ -92,7 +96,21 @@ echo
echo


echo "05. Create entity E3, type T2, with attributes P1 and R1"
echo "05. GET Types with local=true - see T1"
echo "======================================"
orionCurl --url /ngsi-ld/v1/types?local=true
echo
echo


echo "06. GET Types with details and local=true - see T1 with P1, P2, R1, R2"
echo "======================================================================"
orionCurl --url '/ngsi-ld/v1/types?details=true&local=true'
echo
echo


echo "07. Create entity E3, type T2, with attributes P1 and R1"
echo "========================================================"
payload='{
"id": "urn:ngsi-ld:entities:E3",
Expand All @@ -111,7 +129,7 @@ echo
echo


echo "06. Create entity E4, type T2, with attributes P2 and R2"
echo "08. Create entity E4, type T2, with attributes P2 and R2"
echo "========================================================"
payload='{
"id": "urn:ngsi-ld:entities:E4",
Expand All @@ -130,20 +148,34 @@ echo
echo


echo "07. GET Types - see T1 and T2"
echo "09. GET Types - see T1 and T2"
echo "============================="
orionCurl --url /ngsi-ld/v1/types
echo
echo


echo "08. GET Types with details - see T1 and T2 with P1, P2, R1, R2"
echo "10. GET Types with details - see T1 and T2 with P1, P2, R1, R2"
echo "=============================================================="
orionCurl --url /ngsi-ld/v1/types?details=true
echo
echo


echo "11. GET Types with local=true - see T1 and T2"
echo "============================================="
orionCurl --url /ngsi-ld/v1/types?local=true
echo
echo


echo "12. GET Types with details and local=true - see T1 and T2 with P1, P2, R1, R2"
echo "============================================================================="
orionCurl --url '/ngsi-ld/v1/types?details=true&local=true'
echo
echo


--REGEXPECT--
01. Create entity E1, type T1, with attributes P1 and R1
========================================================
Expand Down Expand Up @@ -203,7 +235,47 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


05. Create entity E3, type T2, with attributes P1 and R1
05. GET Types with local=true - see T1
======================================
HTTP/1.1 200 OK
Content-Length: 114
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"id": "urn:ngsi-ld:EntityTypeList:REGEX(.*)",
"type": "EntityTypeList",
"typeList": [
"T1"
]
}


06. GET Types with details and local=true - see T1 with P1, P2, R1, R2
======================================================================
HTTP/1.1 200 OK
Content-Length: 133
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"attributeNames": [
"P2",
"R2",
"P1",
"R1"
],
"id": "https://uri.etsi.org/ngsi-ld/default-context/T1",
"type": "EntityType",
"typeName": "T1"
}
]


07. Create entity E3, type T2, with attributes P1 and R1
========================================================
HTTP/1.1 201 Created
Content-Length: 0
Expand All @@ -212,7 +284,7 @@ Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:E3



06. Create entity E4, type T2, with attributes P2 and R2
08. Create entity E4, type T2, with attributes P2 and R2
========================================================
HTTP/1.1 201 Created
Content-Length: 0
Expand All @@ -221,7 +293,7 @@ Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:E4



07. GET Types - see T1 and T2
09. GET Types - see T1 and T2
=============================
HTTP/1.1 200 OK
Content-Length: 119
Expand All @@ -239,7 +311,7 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
}


08. GET Types with details - see T1 and T2 with P1, P2, R1, R2
10. GET Types with details - see T1 and T2 with P1, P2, R1, R2
==============================================================
HTTP/1.1 200 OK
Content-Length: 265
Expand Down Expand Up @@ -273,6 +345,58 @@ Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
]


11. GET Types with local=true - see T1 and T2
=============================================
HTTP/1.1 200 OK
Content-Length: 119
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

{
"id": "urn:ngsi-ld:EntityTypeList:REGEX(.*)",
"type": "EntityTypeList",
"typeList": [
"T1",
"T2"
]
}


12. GET Types with details and local=true - see T1 and T2 with P1, P2, R1, R2
=============================================================================
HTTP/1.1 200 OK
Content-Length: 265
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"attributeNames": [
"P2",
"R2",
"P1",
"R1"
],
"id": "https://uri.etsi.org/ngsi-ld/default-context/T1",
"type": "EntityType",
"typeName": "T1"
},
{
"attributeNames": [
"P2",
"R2",
"P1",
"R1"
],
"id": "https://uri.etsi.org/ngsi-ld/default-context/T2",
"type": "EntityType",
"typeName": "T2"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB
Loading

0 comments on commit fd6283e

Please sign in to comment.