Skip to content

Commit

Permalink
Merge pull request #760 from FIWARE/troe/exhaustive_add_attributes_II
Browse files Browse the repository at this point in the history
Troe/exhaustive add attributes ii
  • Loading branch information
kzangeli committed Mar 14, 2021
2 parents dea8507 + a2531d2 commit c52b216
Show file tree
Hide file tree
Showing 6 changed files with 2,317 additions and 9 deletions.
54 changes: 51 additions & 3 deletions src/lib/orionld/kjTree/kjTreeToMetadata.cpp
Expand Up @@ -41,12 +41,61 @@ extern "C"

// -----------------------------------------------------------------------------
//
// metadataAdd - from kjTreeToContextAttribute.cpp - needs its own module under orionld/common
// metadataAdd - from kjTreeToContextAttribute.cpp
//
// FIXME: needs its own module under orionld/common
//
extern bool metadataAdd(ContextAttribute* caP, KjNode* nodeP, char* caName);



// -----------------------------------------------------------------------------
//
// orionldSubAttributeExpand - expand the name of a sub-attribute
//
// FIXME: needs its own module under orionld/context
//
char* orionldSubAttributeExpand
(
OrionldContext* contextP,
char* shortName,
bool useDefaultUrlIfNotFound,
OrionldContextItem** contextItemPP
)
{
if (strcmp(shortName, "location") == 0) return shortName;
else if (strcmp(shortName, "observedAt") == 0) return shortName;
else if (strcmp(shortName, "unitCode") == 0) return shortName;
else if (strcmp(shortName, "datasetId") == 0) return shortName;

return orionldContextItemExpand(contextP, shortName, useDefaultUrlIfNotFound, contextItemPP);
}



// -----------------------------------------------------------------------------
//
// orionldAttributeExpand - expand the name of an attribute
//
// FIXME: needs its own module under orionld/context
//
char* orionldAttributeExpand
(
OrionldContext* contextP,
char* shortName,
bool useDefaultUrlIfNotFound,
OrionldContextItem** contextItemPP
)
{
if (strcmp(shortName, "location") == 0) return shortName;
else if (strcmp(shortName, "observationSpace") == 0) return shortName;
else if (strcmp(shortName, "operationSpace") == 0) return shortName;

return orionldContextItemExpand(contextP, shortName, useDefaultUrlIfNotFound, contextItemPP);
}



// -----------------------------------------------------------------------------
//
// kjTreeToMetadata -
Expand All @@ -64,11 +113,10 @@ bool kjTreeToMetadata(ContextAttribute* caP, KjNode* nodeP, char* caName, char**
return false;
}


//
// Expand sub-attribute name
//
nodeP->name = orionldContextItemExpand(orionldState.contextP, nodeP->name, true, NULL);
nodeP->name = orionldSubAttributeExpand(orionldState.contextP, nodeP->name, true, NULL);

if (caP->metadataVector.lookupByName(nodeP->name) != NULL)
{
Expand Down
22 changes: 18 additions & 4 deletions src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp
Expand Up @@ -163,6 +163,12 @@ bool orionldPatchEntity(ConnectionInfo* ciP)
char* entityId = orionldState.wildcard[0];
char* detail;

// <DEBUG>
char buf[1024 * 4];
kjFastRender(orionldState.kjsonP, orionldState.requestTree, buf, sizeof(buf));
LM_TMP(("PATCH: incoming: %s", buf));
// </DEBUG>

// 1. Is the Entity ID in the URL a valid URI?
if (pcheckUri(entityId, &detail) == false)
{
Expand Down Expand Up @@ -221,6 +227,11 @@ bool orionldPatchEntity(ConnectionInfo* ciP)
return false;
}

// <DEBUG>
kjFastRender(orionldState.kjsonP, inDbAttrsP, buf, sizeof(buf));
LM_TMP(("PATCH: From DB: %s", buf));
// </DEBUG>

//
// 5. Loop over the incoming payload data
// Those attrs that don't exist in the DB (dbEntityP) are discarded and added to the 'notUpdated' array
Expand All @@ -244,19 +255,19 @@ bool orionldPatchEntity(ConnectionInfo* ciP)

if ((strcmp(newAttrP->name, "createdAt") == 0) || (strcmp(newAttrP->name, "modifiedAt") == 0))
{
attributeNotUpdated(notUpdatedP, newAttrP->name, "built-in timestamps are ignored");
attributeNotUpdated(notUpdatedP, shortName, "built-in timestamps are ignored");
newAttrP = next;
continue;
}
else if ((strcmp(newAttrP->name, "id") == 0) || (strcmp(newAttrP->name, "@id") == 0))
{
attributeNotUpdated(notUpdatedP, newAttrP->name, "the ID of an entity cannot be altered");
attributeNotUpdated(notUpdatedP, shortName, "the ID of an entity cannot be altered");
newAttrP = next;
continue;
}
else if ((strcmp(newAttrP->name, "type") == 0) || (strcmp(newAttrP->name, "@type") == 0))
{
attributeNotUpdated(notUpdatedP, newAttrP->name, "the TYPE of an entity cannot be altered");
attributeNotUpdated(notUpdatedP, shortName, "the TYPE of an entity cannot be altered");
newAttrP = next;
continue;
}
Expand Down Expand Up @@ -298,7 +309,10 @@ bool orionldPatchEntity(ConnectionInfo* ciP)
++newAttrs;
newAttrP = next;
}

// <DEBUG>
kjFastRender(orionldState.kjsonP, inDbAttrsP, buf, sizeof(buf));
LM_TMP(("PATCH: inDbAttrsP after processing: %s", buf));
// </DEBUG>

if (newAttrs > 0)
{
Expand Down
14 changes: 13 additions & 1 deletion src/lib/orionld/troe/pgEntityTreat.cpp
Expand Up @@ -103,7 +103,19 @@ bool pgEntityTreat(PGconn* connectionP, KjNode* entityP, char* id, char* type, T
}
}
else
LM_E(("Internal Error (The attribute '%s' is neither an Object nor an Array)", attrP->name));
{
if ((strcmp(attrP->name, "id") == 0) ||
(strcmp(attrP->name, "@id") == 0) ||
(strcmp(attrP->name, "type") == 0) ||
(strcmp(attrP->name, "@type") == 0) ||
(strcmp(attrP->name, "createdAt") == 0) ||
(strcmp(attrP->name, "modifiedAt") == 0))
{
// If present, all these "attributes" are ignmoredd
}
else
LM_E(("Internal Error (The attribute '%s' is neither an Object nor an Array)", attrP->name));
}
}

return true;
Expand Down
Expand Up @@ -215,7 +215,7 @@ Date: REGEX(.*)
05. GET E1 and make sure all 6 createdAt,modifiedAt are as they should (modifiedAt for entity and A1 new - all others as in step 3)
===================================================================================================================================
HTTP/1.1 200 OK
Content-Length: 481
Content-Length: 441
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)
Expand Down

0 comments on commit c52b216

Please sign in to comment.