Skip to content

Commit

Permalink
Implemented GET /attributes, but only without details=true
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Apr 13, 2021
1 parent 84ee8b9 commit 372a17d
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* Issue #280 NGSI-LD entity update requests now provoke notifications regardless on whether any actual change has been done on the entity
* Issue #280 Implemented datasetId for PATCH /entities/{EID}/attrs/{attrName}
* Issue #280 Implemented datasetId for DELETE /entities/{EID}/attrs/{attrName} (supporting URI params 'datasetId' and 'deleteAll')
* Issue #280 Implemented GET /attributes, but only without details=true
2 changes: 1 addition & 1 deletion src/lib/orionld/db/dbConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef bool (*DbSubscriptionDelete)(const char* subscriptionId);
typedef KjNode* (*DbRegistrationGet)(const char* registrationId);
typedef bool (*DbRegistrationReplace)(const char* registrationId, KjNode* dbRegistrationP);
typedef KjNode* (*DbEntitiesGet)(char** fieldV, int fields);
typedef KjNode* (*DbEntityTypesFromRegistrationsGet)(void);
typedef KjNode* (*DbEntityTypesFromRegistrationsGet)(bool details);
typedef bool (*DbGeoIndexCreate)(const char* tenant, const char* attrName);
typedef bool (*DbIdIndexCreate)(const char* tenant);
typedef KjNode* (*DbEntitiesQuery)(KjNode* entityInfoArrayP, KjNode* attrsP, QNode* qP, KjNode* geoqP, int limit, int offset, int* countP);
Expand Down
79 changes: 70 additions & 9 deletions src/lib/orionld/db/dbEntityAttributesGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static KjNode* getEntityAttributesResponse(KjNode* sortedArrayP)

// ----------------------------------------------------------------------------
//
// attrNamesExtract -
// localAttrNamesExtract -
//
// PARAMETERS
// - outArray: The result of the operation
Expand All @@ -91,7 +91,7 @@ static KjNode* getEntityAttributesResponse(KjNode* sortedArrayP)
// - lookup the alias
// - sorted insert into a new array - the output array (first lookup to we have no duplicates)
//
static void attrNamesExtract(KjNode* outArray, KjNode* local)
static void localAttrNamesExtract(KjNode* outArray, KjNode* local)
{
for (KjNode* objP = local->value.firstChildP; objP != NULL; objP = objP->next)
{
Expand Down Expand Up @@ -138,27 +138,88 @@ static void attrNamesExtract(KjNode* outArray, KjNode* local)



// ----------------------------------------------------------------------------
//
// remoteAttrNamesExtract -
//
// PARAMETERS
// - outArray: The result of the operation
// - remote: The output from dbEntityTypesFromRegistrationsGet(details=true), which is an array of
// [
// {
// "id": "urn:ngsi-ld:entity:E1",
// "type": "https://uri.etsi.org/ngsi-ld/default-context/T1",
// "attrs": ["https://uri.etsi.org/ngsi-ld/default-context/brandName", "https://uri.etsi.org/ngsi-ld/default-context/speed"]
// },
// {
// "id": "urn:ngsi-ld:entity:E2",
// "type": "https://uri.etsi.org/ngsi-ld/default-context/T2",
// "attrs": ["https://uri.etsi.org/ngsi-ld/default-context/isParked"]
// }
// ]
//
// What we need to do now is to extract all strings in the "attrs" arrays of all the objects in the toplevel array
// - loop over the attribute names
// - lookup the alias
// - sorted insert into a new array - the output array (first lookup to we have no duplicates)
//
static void remoteAttrNamesExtract(KjNode* outArray, KjNode* remote)
{
for (KjNode* objP = remote->value.firstChildP; objP != NULL; objP = objP->next)
{
KjNode* attrsArray = kjLookup(objP, "attrs");

if (attrsArray != NULL)
{
KjNode* attrNameNode = attrsArray->value.firstChildP;
KjNode* next;

while (attrNameNode != NULL)
{
next = attrNameNode->next;

attrNameNode->value.s = orionldContextItemAliasLookup(orionldState.contextP, attrNameNode->value.s, NULL, NULL);

if (kjArrayStringLookup(outArray, attrNameNode->value.s) == NULL)
{
kjChildRemove(objP, attrNameNode);
kjStringArraySortedInsert(outArray, attrNameNode);
}

attrNameNode = next;
}
}
}
}



// -----------------------------------------------------------------------------
//
// dbEntityAttributesGetWithoutDetails -
//
static KjNode* dbEntityAttributesGetWithoutDetails(OrionldProblemDetails* pdP)
{
KjNode* localEntityArray;
char* fields[1] = { (char*) "attrNames" };

//
// GET local attributes - i.e. from the "entities" collection
//
KjNode* localEntityArray;
char* fields[1] = { (char*) "attrNames" };

localEntityArray = dbEntitiesGet(fields, 1);

KjNode* outArray = kjArray(orionldState.kjsonP, "attributeList");

if (localEntityArray != NULL)
attrNamesExtract(outArray, localEntityArray);
else
{
}
localAttrNamesExtract(outArray, localEntityArray);

//
// GET external attributes - i.e. from the "registrations" collection
//
KjNode* remote = dbEntityTypesFromRegistrationsGet(true);

if (remote)
remoteAttrNamesExtract(outArray, remote);

return getEntityAttributesResponse(outArray);
}
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 @@ -396,7 +396,7 @@ KjNode* dbEntityTypesGet(OrionldProblemDetails* pdP)
//
// GET remote types - i.e. from the "registrations" collection
//
remote = dbEntityTypesFromRegistrationsGet();
remote = dbEntityTypesFromRegistrationsGet(orionldState.uriParams.details);

if ((remote != NULL) && (orionldState.uriParams.details == true))
remote = typesAndAttributesExtractFromRegistrations(remote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void entitiesAndProprertiesExtract(KjNode* regArray, KjNode* typeArray)
// ...
//
//
KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(void)
KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details)
{
char collectionPath[256];

Expand All @@ -192,7 +192,7 @@ KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(void)

fields.append("contextRegistration.entities", 1); // Entity Type is inside the 'contextRegistration.entities' field ...

if (orionldState.uriParams.details == true)
if (details == true)
fields.append("contextRegistration.attrs", 1);

fields.append("_id", 0);
Expand Down Expand Up @@ -227,7 +227,7 @@ KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(void)
if (regArray != NULL)
{
typeArray = kjArray(orionldState.kjsonP, NULL);
if (orionldState.uriParams.details == false)
if (details == false)
typeExtract(regArray, typeArray);
else
entitiesAndProprertiesExtract(regArray, typeArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ extern "C"
//
// mongoCppLegacyEntityTypesFromRegistrationsGet -
//
extern KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(void);
extern KjNode* mongoCppLegacyEntityTypesFromRegistrationsGet(bool details);

#endif // SRC_LIB_ORIONLD_MONGOCPPLEGACY_MONGOCPPLEGACYENTITYTYPESFROMREGISTRATIONSGET_H_
Loading

0 comments on commit 372a17d

Please sign in to comment.