Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed part II of #1707 #1722

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/orionld/db/dbConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef bool (*DbSubscriptionMatchCallback)(const char* entityId, KjNode* sub
// Function pointer types for the DB interface
//
typedef KjNode* (*DbEntitiesGet)(char** fieldV, int fields, bool entityIdPresent);
typedef KjNode* (*DbEntityTypesFromRegistrationsGet)(bool details);
typedef KjNode* (*DbEntityTypesFromRegistrationsGet)(bool details, const char* entityType);



Expand Down
6 changes: 3 additions & 3 deletions src/lib/orionld/db/dbEntityAttributesGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static KjNode* dbEntityAttributesGetWithoutDetails(OrionldProblemDetails* pdP, b
//
// GET external attributes - i.e. from the "registrations" collection
//
KjNode* remote = (local == false)? entityTypesFromRegistrationsGet(true) : NULL;
KjNode* remote = (local == false)? entityTypesFromRegistrationsGet(true, NULL) : NULL;

if (remote != NULL)
remoteAttrNamesExtract(outArray, remote);
Expand Down Expand Up @@ -475,11 +475,11 @@ static KjNode* dbEntityAttributesGetWithDetails(OrionldProblemDetails* pdP, char
//
// Need to use local function pointers to not alter the global state of the broker
//
DbEntitiesGet entitiesGet = mongoCppLegacyEntitiesGet;
DbEntitiesGet entitiesGet = mongoCppLegacyEntitiesGet;
if (experimental == true)
{
if (orionldState.in.legacy == NULL)
entitiesGet = mongocEntitiesGet;
entitiesGet = mongocEntitiesGet;
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/db/dbEntityTypesGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP, bool details, bool localOnl
//
if (localOnly == false)
{
remote = entityTypesFromRegistrationsGet(details);
remote = entityTypesFromRegistrationsGet(details, NULL);

if ((remote != NULL) && (details == true))
remote = typesAndAttributesExtractFromRegistrations(remote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool kjAttributesWithTypeExtract(KjNode* kjTree, KjNode* entityP)

if (typeP != NULL)
{
// Set 'attrP' to have the value of 'typeP', ad that's whay we want for 'entityP'
// Set 'attrP' to have the value of 'typeP', as that's what we want for 'entityP'
attrP->value = typeP->value;
attrP->type = typeP->type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void entitiesAndPropertiesExtract(KjNode* regArray, KjNode* typeArray)
// ...
//
//
KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details)
KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details, const char* entityType)
{
mongo::BSONObjBuilder fields;
mongo::BSONObjBuilder filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ extern "C"
//
// mongoCppLegacyEntityTypesFromRegistrationsGet -
//
extern KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details);
extern KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details, const char* entityType);

#endif // SRC_LIB_ORIONLD_MONGOCPPLEGACY_MONGOCPPLEGACYENTITYTYPESFROMREGISTRATIONSGET_H_
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern void entitiesAndPropertiesExtract(KjNode* regArray, KjNode* typeArray);
//
// mongocEntityTypesFromRegistrationsGet -
//
KjNode* mongocEntityTypesFromRegistrationsGet(bool details)
KjNode* mongocEntityTypesFromRegistrationsGet(bool details, const char* entityType)
{
//
// Projection and options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ extern "C"
//
// mongocEntityTypesFromRegistrationsGet -
//
extern KjNode* mongocEntityTypesFromRegistrationsGet(bool details);
extern KjNode* mongocEntityTypesFromRegistrationsGet(bool details, const char* entityType);

#endif // SRC_LIB_ORIONLD_MONGOC_MONGOCENTITYTYPESFROMREGISTRATIONSGET_H_
96 changes: 92 additions & 4 deletions src/lib/orionld/serviceRoutines/orionldGetEntityType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ extern "C"

#include "orionld/types/OrionldProblemDetails.h" // OrionldProblemDetails
#include "orionld/types/OrionLdRestService.h" // OrionLdRestService
#include "orionld/types/RegCache.h" // RegCache
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/orionldError.h" // orionldError
#include "orionld/context/orionldContextItemExpand.h" // orionldContextItemExpand
#include "orionld/context/orionldContextItemAliasLookup.h" // orionldContextItemAliasLookup
#include "orionld/kjTree/kjStringValueLookupInArray.h" // kjStringValueLookupInArray
#include "orionld/mongoc/mongocEntityTypeGet.h" // mongocEntityTypeGet
#include "orionld/mongoCppLegacy/mongoCppLegacyEntityTypeGet.h" // mongoCppLegacyEntityTypeGet
#include "orionld/regMatch/regMatchForEntityGet.h" // regMatchForEntityGet
#include "orionld/serviceRoutines/orionldGetEntityType.h" // Own Interface


Expand Down Expand Up @@ -119,6 +121,41 @@ static void outAttrInfoAdd(KjNode* outAttrP, const char* attrType)



// -----------------------------------------------------------------------------
//
// entityTypeInfoAdd -
//
static void entityTypeInfoAdd(KjNode* entityTypeV, KjNode* propertiesP, KjNode* relationshipsP, const char* typeExpanded)
{
if ((propertiesP == NULL) && (relationshipsP == NULL))
return;

KjNode* attrsP = kjObject(orionldState.kjsonP, NULL);

if (propertiesP != NULL)
{
for (KjNode* propertyP = propertiesP->value.firstChildP; propertyP != NULL; propertyP = propertyP->next)
{
KjNode* itemP = kjString(orionldState.kjsonP, propertyP->value.s, "Property");
kjChildAdd(attrsP, itemP);
}
}

if (relationshipsP != NULL)
{
for (KjNode* relationshipP = relationshipsP->value.firstChildP; relationshipP != NULL; relationshipP = relationshipP->next)
{
KjNode* itemP = kjString(orionldState.kjsonP, relationshipP->value.s, "Relationship");
kjChildAdd(attrsP, itemP);
}
}

if (attrsP->value.firstChildP != NULL)
kjChildAdd(entityTypeV, attrsP);
}



// ----------------------------------------------------------------------------
//
// orionldGetEntityType -
Expand All @@ -142,12 +179,63 @@ bool orionldGetEntityType(void)
else
entityTypeV = mongoCppLegacyEntityTypeGet(&pd, typeExpanded, &entities);

if (entityTypeV == NULL)

if ((orionldState.uriParams.local == false) && (experimental == true))
{
// xxxEntityTypeGet has filled in 'pd'
return false;
// GET entity info from registration cache and add that to entityTypeV
RegCache* rcP = orionldState.tenantP->regCache;

for (RegCacheItem* rciP = rcP->regList; rciP != NULL; rciP = rciP->next)
{
if ((rciP->opMask & (1 << DoRetrieveEntityTypeInfo)) != (1 << DoRetrieveEntityTypeInfo))
continue;

KjNode* infoV = kjLookup(rciP->regTree, "information");
if (infoV == NULL)
continue;

KjNode* propertiesP = NULL;
KjNode* relationshipsP = NULL;
int slotNo = 0;

for (KjNode* infoP = infoV->value.firstChildP; infoP != NULL; infoP = infoP->next)
{
++slotNo;

KjNode* entityV = kjLookup(infoP, "entities");

propertiesP = kjLookup(infoP, "propertyNames");
relationshipsP = kjLookup(infoP, "relationshipNames");

if (entityV == NULL)
{
entityTypeInfoAdd(entityTypeV, propertiesP, relationshipsP, typeExpanded);
break;
}
else
{
for (KjNode* entityP = entityV->value.firstChildP; entityP != NULL; entityP = entityP->next)
{
KjNode* typeNodeP = kjLookup(entityP, "type"); // The entity type field is MANDATORY

if (typeNodeP != NULL)
{
if (strcmp(typeNodeP->value.s, typeExpanded) == 0)
{
entityTypeInfoAdd(entityTypeV, propertiesP, relationshipsP, typeExpanded);
break;
}
}
}
}
}
}
}
else if (entities == 0)

if (entityTypeV == NULL)
return false; // xxxEntityTypeGet has filled in 'pd'

if (entities == 0)
{
LM_E(("xxxEntityTypeGet: no entities found"));
orionldError(OrionldResourceNotFound, "Entity Type Not Found", typeExpanded, 404);
Expand Down
Loading
Loading