From b8d51a9496f11676c90709da6499aac48bc6c2a6 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Fri, 13 Dec 2024 10:36:57 +0100 Subject: [PATCH 1/2] Support for local=true in the type discovery endpoints (GET /ngsi-ld/v1/types[/{typeName}] --- CHANGES_NEXT_RELEASE | 1 + src/lib/orionld/db/dbEntityTypesGet.cpp | 13 +- src/lib/orionld/db/dbEntityTypesGet.h | 2 +- .../orionld/service/orionldServiceInit.cpp | 6 + .../serviceRoutines/orionldGetEntityTypes.cpp | 2 +- .../cases/0000_ngsild/ngsild_entity_type.test | 2 +- ...s-merge-of-entities-and-registrations.test | 56 +++++++ ...ngsild_entity_types-merge-of-entities.test | 148 ++++++++++++++++-- ...d_entity_types-merge-of-registrations.test | 46 ++++++ .../0000_ngsild/ngsild_entity_types.test | 53 +++++++ .../0000_ngsild/ngsild_new_entity_type.test | 2 +- ...s-merge-of-entities-and-registrations.test | 56 +++++++ ...ld_new_entity_types-merge-of-entities.test | 148 ++++++++++++++++-- ...w_entity_types-merge-of-registrations.test | 46 ++++++ .../0000_ngsild/ngsild_new_entity_types.test | 53 +++++++ 15 files changed, 600 insertions(+), 34 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 4ba32f2d9c..5f562009f7 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -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}] ## New Features: * Support for ... diff --git a/src/lib/orionld/db/dbEntityTypesGet.cpp b/src/lib/orionld/db/dbEntityTypesGet.cpp index 303879613a..161cb85d23 100644 --- a/src/lib/orionld/db/dbEntityTypesGet.cpp +++ b/src/lib/orionld/db/dbEntityTypesGet.cpp @@ -311,7 +311,7 @@ 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; @@ -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' @@ -491,7 +493,6 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details) } } - if ((remote == NULL) && (local == NULL)) { char entityTypesId[64]; diff --git a/src/lib/orionld/db/dbEntityTypesGet.h b/src/lib/orionld/db/dbEntityTypesGet.h index df61ea6909..54e9c0254b 100644 --- a/src/lib/orionld/db/dbEntityTypesGet.h +++ b/src/lib/orionld/db/dbEntityTypesGet.h @@ -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_ diff --git a/src/lib/orionld/service/orionldServiceInit.cpp b/src/lib/orionld/service/orionldServiceInit.cpp index 5c899979c6..d1894efbac 100644 --- a/src/lib/orionld/service/orionldServiceInit.cpp +++ b/src/lib/orionld/service/orionldServiceInit.cpp @@ -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) { diff --git a/src/lib/orionld/serviceRoutines/orionldGetEntityTypes.cpp b/src/lib/orionld/serviceRoutines/orionldGetEntityTypes.cpp index 9cb4716381..aa43438248 100644 --- a/src/lib/orionld/serviceRoutines/orionldGetEntityTypes.cpp +++ b/src/lib/orionld/serviceRoutines/orionldGetEntityTypes.cpp @@ -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); diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_entity_type.test b/test/functionalTest/cases/0000_ngsild/ngsild_entity_type.test index ab4c612186..b2ef8cbcaa 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_entity_type.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_entity_type.test @@ -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 diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_entity_types-merge-of-entities-and-registrations.test b/test/functionalTest/cases/0000_ngsild/ngsild_entity_types-merge-of-entities-and-registrations.test index 42f9960ed5..25c9d57d72 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_entity_types-merge-of-entities-and-registrations.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_entity_types-merge-of-entities-and-registrations.test @@ -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" @@ -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 ======================================================== @@ -218,6 +234,46 @@ Link: Date: Fri, 13 Dec 2024 11:08:41 +0100 Subject: [PATCH 2/2] Fixed a warning in non-debug compilation --- src/lib/orionld/db/dbEntityTypesGet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/orionld/db/dbEntityTypesGet.cpp b/src/lib/orionld/db/dbEntityTypesGet.cpp index 161cb85d23..ee6356b9da 100644 --- a/src/lib/orionld/db/dbEntityTypesGet.cpp +++ b/src/lib/orionld/db/dbEntityTypesGet.cpp @@ -313,9 +313,9 @@ KjNode* typeObjectLookup(KjNode* arrayP, const char* type) // 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 ...