Skip to content

Commit

Permalink
REMOVE ProvidingApplication class (in favour of ngsiv2::Provider class)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Aug 30, 2024
1 parent 2545a5f commit 89b4593
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 299 deletions.
2 changes: 0 additions & 2 deletions scripts/style_check_in_makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ style_check test/unittests/serviceRoutines
# o ngsi/NotifyConditionVector.h (haderding/remove_ngsiv1_indent: 2 lines)
# o ngsi/Originator.cpp (haderding/remove_ngsiv1_indent: 9 lines)
# o ngsi/Originator.h (haderding/remove_ngsiv1_indent: 5 lines)
# o ngsi/ProvidingApplication.cpp (haderding/remove_ngsiv1_indent: 9 lines)
# o ngsi/ProvidingApplication.h (haderding/remove_ngsiv1_indent: 5 lines)
# o ngsi/Reference.cpp (haderding/remove_ngsiv1_indent: 9 lines)
# o ngsi/Reference.h (haderding/remove_ngsiv1_indent: 5 lines)
# o ngsi/RegistrationId.cpp (haderding/remove_ngsiv1_indent: 9 lines)
Expand Down
3 changes: 2 additions & 1 deletion src/lib/apiTypesV2/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ void Entity::fill(const Entity& en, bool useDefaultType, bool cloneCompounds)

attributeVector.fill(en.attributeVector, useDefaultType, cloneCompounds);

providingApplicationList = en.providingApplicationList;
providerList = en.providerList;
providerRegIdList = en.providerRegIdList;
}


Expand Down
3 changes: 2 additions & 1 deletion src/lib/apiTypesV2/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Entity
double creDate; // used by dateCreated functionality in NGSIv2
double modDate; // used by dateModified functionality in NGSIv2

std::vector<ProvidingApplication> providingApplicationList; // Not part of NGSI, used internally for CPr forwarding functionality - FIXME PR: this could be a list of Provider (removing ProvidingApplication type)
std::vector<ngsiv2::Provider> providerList; // Used internally for CPr forwarding functionality
std::vector<std::string> providerRegIdList; // Side vector to providerList, to hold the reg ids where they come (used for login purposes)

Entity();
Entity(const std::string& id, const std::string& type, const std::string& isPattern, bool isTypePattern = false);
Expand Down
1 change: 1 addition & 0 deletions src/lib/common/macroSubstitute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "common/globals.h"
#include "common/JsonHelper.h"
#include "common/macroSubstitute.h"
#include "common/MimeType.h"

#include "expressions/exprMgr.h"

Expand Down
2 changes: 1 addition & 1 deletion src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,7 @@ static bool forwardsPending(UpdateContextResponse* upcrsP)
{
ContextAttribute* aP = cerP->entity.attributeVector[aIx];

if (!aP->providingApplication.get().empty())
if (!aP->provider.http.url.empty())
{
return true;
}
Expand Down
54 changes: 28 additions & 26 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,8 @@ void pruneContextElements
cerP->entity.modDate);

// FIXME P10: not sure if this is the right way to do it, maybe we need a fill() method for this
newCerP->entity.providingApplicationList = cerP->entity.providingApplicationList;
newCerP->entity.providerList = cerP->entity.providerList;
newCerP->entity.providerRegIdList = cerP->entity.providerRegIdList;
newCerP->statusCode.fill(&cerP->statusCode);

bool pruneEntity = cerP->prune;
Expand All @@ -1652,8 +1653,8 @@ void pruneContextElements
/* If after pruning the entity has no attribute and no CPr information, then it is not included
* in the output vector, except if "prune" is set to false */
if (pruneEntity &&
(newCerP->entity.attributeVector.size() == 0) &&
(newCerP->entity.providingApplicationList.size() == 0))
(newCerP->entity.attributeVector.size() == 0) &&
(newCerP->entity.providerList.size() == 0))
{
newCerP->release();
delete newCerP;
Expand Down Expand Up @@ -2152,25 +2153,26 @@ void fillContextProviders(ContextElementResponse* cer, const std::vector<ngsiv2:
continue;
}

/* Search for some CPr in crrV */
std::string perEntPa;
std::string perAttrPa;
ProviderFormat providerFormat;
/* Search for some CPr in Registrations vector */
std::string perEntProvider;
std::string perAttrProvider;
bool legacyProviderFormat;
std::string regId;

cprLookupByAttribute(cer->entity,
ca->name,
regV,
&perEntPa,
&perAttrPa,
&providerFormat,
&perEntProvider,
&perAttrProvider,
&legacyProviderFormat,
&regId);

/* Looking results after crrV processing */
ca->providingApplication.set(perAttrPa.empty() ? perEntPa : perAttrPa);
ca->providingApplication.setProviderFormat(providerFormat);
ca->providingApplication.setRegId(regId);
ca->found = (!ca->providingApplication.get().empty());
/* Looking results after Registrations vector processing */
ca->provider.http.url = perAttrProvider.empty() ? perEntProvider : perAttrProvider;
ca->provider.legacyForwardingMode = legacyProviderFormat;
ca->providerRegId = regId;

ca->found = (!ca->provider.http.url.empty());
}
}

Expand Down Expand Up @@ -2213,14 +2215,14 @@ void cprLookupByAttribute
const Entity& en,
const std::string& attrName,
const std::vector<ngsiv2::Registration>& regV,
std::string* perEntPa,
std::string* perAttrPa,
ProviderFormat* providerFormatP, // FIXME PR: ProviderFormat is really needed as type?
std::string* perEntProviderP,
std::string* perAttrProviderP,
bool* legacyPproviderFormatP,
std::string* regId
)
{
*perEntPa = "";
*perAttrPa = "";
*perEntProviderP = "";
*perAttrProviderP = "";
*regId = "";

for (unsigned int regIx = 0; regIx < regV.size(); ++regIx)
Expand Down Expand Up @@ -2251,9 +2253,9 @@ void cprLookupByAttribute
/* Registration without attributes (keep searching in other Registration) */
if (reg.dataProvided.attributes.size() == 0)
{
*perEntPa = reg.provider.http.url;
*providerFormatP = reg.provider.legacyForwardingMode? PfJson : PfV2;
*regId = reg.id;
*perEntProviderP = reg.provider.http.url;
*legacyPproviderFormatP = reg.provider.legacyForwardingMode;
*regId = reg.id;

break; /* enIx */
}
Expand All @@ -2265,9 +2267,9 @@ void cprLookupByAttribute
if (regAttrName == attrName)
{
/* We cannot "improve" this result by keep searching the Registrations vector, so we return */
*perAttrPa = reg.provider.http.url;
*providerFormatP = reg.provider.legacyForwardingMode? PfJson : PfV2;
*regId = reg.id;
*perAttrProviderP = reg.provider.http.url;
*legacyPproviderFormatP = reg.provider.legacyForwardingMode;
*regId = reg.id;

return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/mongoBackend/MongoGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ extern void cprLookupByAttribute
const Entity& en,
const std::string& attrName,
const std::vector<ngsiv2::Registration>& regV,
std::string* perEntPa,
std::string* perAttrPa,
ProviderFormat* providerFormatP,
std::string* perEntProviderP,
std::string* perAttrProviderP,
bool* legacyProviderFormatP,
std::string* regId
);

Expand Down
36 changes: 14 additions & 22 deletions src/lib/mongoBackend/mongoQueryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ static void fillContextProviders(ContextElementResponseVector& cerV, const std::

/* ****************************************************************************
*
* addContextProviderEntity -
* lookupProvider -
*/
static bool lookupProvidingApplication(const std::vector<ProvidingApplication>& paV, const ProvidingApplication &pa)
static bool lookupProvider(const std::vector<ngsiv2::Provider>& providerV, const ngsiv2::Provider &provider)
{
for (unsigned int ix = 0; ix < paV.size(); ++ix)
for (unsigned int ix = 0; ix < providerV.size(); ++ix)
{
if ((paV[ix].string == pa.string) && (paV[ix].regId == pa.regId))
if (providerV[ix].http.url == provider.http.url)
{
return true;
}
Expand All @@ -110,20 +110,15 @@ static void addContextProviderEntity
const std::string& regId
)
{
// FIXME PR: don't like this. Use Provider directly
ProvidingApplication pa;
pa.string = provider.http.url;
pa.providerFormat = provider.legacyForwardingMode ? PfJson : PfV2;
pa.regId = regId;

for (unsigned int ix = 0; ix < cerV.size(); ++ix)
{
if ((cerV[ix]->entity.id == (regEn.idPattern.empty()? regEn.id : regEn.idPattern)) && (cerV[ix]->entity.type == regEn.type))
{
// Avoid duplicate PA in the vector
if (!lookupProvidingApplication(cerV[ix]->entity.providingApplicationList, pa))
// Avoid duplicate Provider in the vector
if (!lookupProvider(cerV[ix]->entity.providerList, provider))
{
cerV[ix]->entity.providingApplicationList.push_back(pa);
cerV[ix]->entity.providerList.push_back(provider);
cerV[ix]->entity.providerRegIdList.push_back(regId);
}
return; /* by construction, no more than one CER with the same entity information should exist in the CERV) */
}
Expand All @@ -133,7 +128,8 @@ static void addContextProviderEntity
ContextElementResponse* cerP = new ContextElementResponse();

cerP->entity.fill(regEn.idPattern.empty() ? regEn.id : regEn.idPattern, regEn.type, regEn.idPattern.empty()? "false": "true");
cerP->entity.providingApplicationList.push_back(pa);
cerP->entity.providerList.push_back(provider);
cerP->entity.providerRegIdList.push_back(regId);

cerP->statusCode.fill(SccOk);
cerV.push_back(cerP);
Expand All @@ -158,12 +154,6 @@ static void addContextProviderAttribute
bool limitReached
)
{
// FIXME PR: don't like this. Use Provider directly
ProvidingApplication pa;
pa.string = provider.http.url;
pa.providerFormat = provider.legacyForwardingMode ? PfJson : PfV2;
pa.regId = regId;

for (unsigned int ix = 0; ix < cerV.size(); ++ix)
{
if ((cerV[ix]->entity.id != regEn.id) || (cerV[ix]->entity.type != regEn.type))
Expand All @@ -187,7 +177,8 @@ static void addContextProviderAttribute
/* Reached this point, no attribute was found, so adding it with corresponding CPr info */
ContextAttribute* caP = new ContextAttribute(regAttr, "", "");

caP->providingApplication = pa;
caP->provider = provider;
caP->providerRegId = regId;
cerV[ix]->entity.attributeVector.push_back(caP);
return;
}
Expand All @@ -202,7 +193,8 @@ static void addContextProviderAttribute

ContextAttribute* caP = new ContextAttribute(regAttr, "", "");

caP->providingApplication = pa;
caP->provider = provider;
caP->providerRegId = regId;
cerP->entity.attributeVector.push_back(caP);
cerV.push_back(cerP);
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/ngsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ SET (SOURCES
EntityIdVector.cpp
Metadata.cpp
MetadataVector.cpp
ProvidingApplication.cpp
Request.cpp
Scope.cpp
ScopeVector.cpp
Expand All @@ -46,7 +45,6 @@ SET (HEADERS
EntityIdVector.h
Metadata.h
MetadataVector.h
ProvidingApplication.h
Scope.h
StatusCode.h
StringList.h
Expand Down
35 changes: 27 additions & 8 deletions src/lib/ngsi/ContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ ContextAttribute::ContextAttribute()
creDate = 0;
modDate = 0;

providingApplication.set("");
provider.http.url = "";
provider.legacyForwardingMode = false;
provider.supportedForwardingMode = ngsiv2::ForwardAll;

providerRegId = "";
}


Expand Down Expand Up @@ -415,9 +419,8 @@ ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType, b
creDate = caP->creDate;
modDate = caP->modDate;

providingApplication.set(caP->providingApplication.get());
providingApplication.setProviderFormat(caP->providingApplication.getProviderFormat());
providingApplication.setRegId(caP->providingApplication.getRegId());
provider = caP->provider;
providerRegId = caP->providerRegId;

LM_T(LmtClone, ("Creating a ContextAttribute: compoundValueP at %p for attribute '%s' at %p",
compoundValueP,
Expand Down Expand Up @@ -495,7 +498,11 @@ ContextAttribute::ContextAttribute
creDate = 0;
modDate = 0;

providingApplication.set("");
provider.http.url = "";
provider.legacyForwardingMode = false;
provider.supportedForwardingMode = ngsiv2::ForwardAll;

providerRegId = "";
}


Expand Down Expand Up @@ -534,7 +541,11 @@ ContextAttribute::ContextAttribute
creDate = 0;
modDate = 0;

providingApplication.set("");
provider.http.url = "";
provider.legacyForwardingMode = false;
provider.supportedForwardingMode = ngsiv2::ForwardAll;

providerRegId = "";
}


Expand Down Expand Up @@ -572,7 +583,11 @@ ContextAttribute::ContextAttribute
creDate = 0;
modDate = 0;

providingApplication.set("");
provider.http.url = "";
provider.legacyForwardingMode = false;
provider.supportedForwardingMode = ngsiv2::ForwardAll;

providerRegId = "";
}


Expand Down Expand Up @@ -611,7 +626,11 @@ ContextAttribute::ContextAttribute
creDate = 0;
modDate = 0;

providingApplication.set("");
provider.http.url = "";
provider.legacyForwardingMode = false;
provider.supportedForwardingMode = ngsiv2::ForwardAll;

providerRegId = "";
}


Expand Down
9 changes: 6 additions & 3 deletions src/lib/ngsi/ContextAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@

#include "common/RenderFormat.h"
#include "common/globals.h"
#include "common/MimeType.h"
#include "orionTypes/OrionValueType.h"
#include "ngsi/MetadataVector.h"
#include "ngsi/Request.h"
#include "ngsi/ProvidingApplication.h"
#include "parse/CompoundValueNode.h"
#include "rest/HttpStatusCode.h"
#include "mongoDriver/BSONObjBuilder.h"
#include "expressions/ExprContext.h"
#include "apiTypesV2/Registration.h"



Expand All @@ -57,8 +58,10 @@ typedef struct ContextAttribute
double numberValue; // "value" as a Number
bool boolValue; // "value" as a Boolean

ProvidingApplication providingApplication; // Not part of NGSI, used internally for CPr forwarding functionality
bool found; // Not part of NGSI, used internally for CPr forwarding functionality (update case)
ngsiv2::Provider provider; // Used internally for CPr forwarding functionality
std::string providerRegId; // Side vector to provider, to hold the reg ids where they come (used for login purposes)

bool found; // Used internally for CPr forwarding functionality (update case)
// It means attribute found either locally or remotely in providing application

bool skip; // For internal use in mongoBackend - in case of 'op=append' and the attribute already exists
Expand Down
Loading

0 comments on commit 89b4593

Please sign in to comment.