Skip to content

Commit

Permalink
Merge pull request #1718 from FIWARE/bug/persist_created_complex_cont…
Browse files Browse the repository at this point in the history
…exts

Complex @contexts of subscriptions weren't persisted in mongodb
  • Loading branch information
kzangeli authored Dec 11, 2024
2 parents c36be07 + 6ea412a commit fe744a2
Show file tree
Hide file tree
Showing 5 changed files with 751 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Fixed Issues:
#xxxx: yyyy
#XXXX: Complex @contexts of subscriptions weren't persisted in mongodb

## New Features:
* Support for ...
Expand Down
5 changes: 5 additions & 0 deletions src/lib/orionld/contextCache/orionldContextCacheInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,28 @@ void dbContextToCache(KjNode* dbContextP, KjNode* atContextP, bool keyValues, bo
KjNode* urlNodeP = kjLookup(dbContextP, "url");
KjNode* parentNodeP = kjLookup(dbContextP, "parent");
KjNode* originNodeP = kjLookup(dbContextP, "origin");
KjNode* kindNodeP = kjLookup(dbContextP, "kind");
KjNode* createdAtNodeP = kjLookup(dbContextP, "createdAt");

if (idNodeP == NULL) LM_RVE(("Database Error (No 'id' node in cached context in DB)"));
if (urlNodeP == NULL) LM_RVE(("Database Error (No 'url' node in cached context in DB)"));
if (originNodeP == NULL) LM_RVE(("Database Error (No 'origin' node in cached context in DB)"));
if (kindNodeP == NULL) LM_RVE(("Database Error (No 'kind' node in cached context in DB)"));
if (createdAtNodeP == NULL) LM_RVE(("Database Error (No 'createdAt' node in cached context in DB)"));

char* id = idNodeP->value.s;
char* url = urlNodeP->value.s;
double createdAt = createdAtNodeP->value.f;
OrionldContextOrigin origin = orionldOriginFromString(originNodeP->value.s);
OrionldContextKind kind = orionldKindFromString(kindNodeP->value.s);
OrionldContext* contextP = orionldContextFromTree(url, origin, id, atContextP);

if (contextP == NULL)
LM_RVE(("Internal Error (unable to create context '%s' from DB - %s: %s)", url, orionldState.pd.title, orionldState.pd.detail));

contextP->createdAt = createdAt;
contextP->usedAt = 0;
contextP->kind = kind;

if (coreContext == true)
{
Expand Down Expand Up @@ -125,6 +129,7 @@ void orionldContextCacheInit(void)
{
KjNode* contextNodeP = contextArray->value.firstChildP;
KjNode* next;

while (contextNodeP != NULL)
{
next = contextNodeP->next;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/orionld/mhd/mhdConnectionTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern "C"
#include "orionld/context/orionldContextUrlGenerate.h" // orionldContextUrlGenerate
#include "orionld/context/orionldContextItemExpand.h" // orionldContextItemExpand
#include "orionld/context/orionldAttributeExpand.h" // orionldAttributeExpand
#include "orionld/contextCache/orionldContextCachePersist.h" // orionldContextCachePersist
#include "orionld/serviceRoutines/orionldPatchAttribute.h" // orionldPatchAttribute
#include "orionld/serviceRoutines/orionldGetEntity.h" // orionldGetEntity
#include "orionld/serviceRoutines/orionldGetEntities.h" // orionldGetEntities
Expand Down Expand Up @@ -1234,6 +1235,16 @@ MHD_Result mhdConnectionTreat(void)
if (pd.status >= 400)
goto respond;

if (implicitlyCreated == true)
{
if (orionldState.payloadContextNode->type != KjString)
{
orionldState.contextP->origin = OrionldContextFromInline;
orionldState.contextP->kind = OrionldContextHosted;
orionldContextCachePersist(orionldState.contextP);
}
}

if ((orionldState.contextP != orionldCoreContextP) && (implicitlyCreated == true))
orionldState.contextP->kind = OrionldContextImplicit; // Too late - the context is already in mongo
}
Expand Down
Loading

0 comments on commit fe744a2

Please sign in to comment.