From 89b4593d0a8a9c1d53f1caa1d2bd3ddbb0e29930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 30 Aug 2024 09:54:16 +0200 Subject: [PATCH] REMOVE ProvidingApplication class (in favour of ngsiv2::Provider class) --- scripts/style_check_in_makefile.sh | 2 - src/lib/apiTypesV2/Entity.cpp | 3 +- src/lib/apiTypesV2/Entity.h | 3 +- src/lib/common/macroSubstitute.cpp | 1 + src/lib/mongoBackend/MongoCommonUpdate.cpp | 2 +- src/lib/mongoBackend/MongoGlobal.cpp | 54 ++++---- src/lib/mongoBackend/MongoGlobal.h | 6 +- src/lib/mongoBackend/mongoQueryContext.cpp | 36 ++---- src/lib/ngsi/CMakeLists.txt | 2 - src/lib/ngsi/ContextAttribute.cpp | 35 +++-- src/lib/ngsi/ContextAttribute.h | 9 +- src/lib/ngsi/ProvidingApplication.cpp | 122 ------------------ src/lib/ngsi/ProvidingApplication.h | 68 ---------- src/lib/ngsi10/QueryContextRequest.cpp | 12 +- src/lib/ngsi10/QueryContextRequest.h | 11 +- src/lib/ngsi10/UpdateContextRequest.cpp | 7 +- src/lib/ngsi10/UpdateContextRequest.h | 4 +- src/lib/orionTypes/EntityTypeVector.cpp | 1 + src/lib/serviceRoutines/postQueryContext.cpp | 28 ++-- src/lib/serviceRoutines/postUpdateContext.cpp | 18 +-- 20 files changed, 125 insertions(+), 299 deletions(-) delete mode 100644 src/lib/ngsi/ProvidingApplication.cpp delete mode 100644 src/lib/ngsi/ProvidingApplication.h diff --git a/scripts/style_check_in_makefile.sh b/scripts/style_check_in_makefile.sh index ba5026b0a2..df8fa8ed39 100755 --- a/scripts/style_check_in_makefile.sh +++ b/scripts/style_check_in_makefile.sh @@ -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) diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index ddd42f3327..d096e8959b 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -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; } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index 41479ec8c8..8b8f33e377 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -64,7 +64,8 @@ class Entity double creDate; // used by dateCreated functionality in NGSIv2 double modDate; // used by dateModified functionality in NGSIv2 - std::vector 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 providerList; // Used internally for CPr forwarding functionality + std::vector 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); diff --git a/src/lib/common/macroSubstitute.cpp b/src/lib/common/macroSubstitute.cpp index 28dd9c156a..91a48fc9e1 100644 --- a/src/lib/common/macroSubstitute.cpp +++ b/src/lib/common/macroSubstitute.cpp @@ -31,6 +31,7 @@ #include "common/globals.h" #include "common/JsonHelper.h" #include "common/macroSubstitute.h" +#include "common/MimeType.h" #include "expressions/exprMgr.h" diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index a24b70043f..63488176fa 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -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; } diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index a5e5a2078d..46b9100d91 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -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; @@ -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; @@ -2152,25 +2153,26 @@ void fillContextProviders(ContextElementResponse* cer, const std::vectorentity, ca->name, regV, - &perEntPa, - &perAttrPa, - &providerFormat, + &perEntProvider, + &perAttrProvider, + &legacyProviderFormat, ®Id); - /* 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()); } } @@ -2213,14 +2215,14 @@ void cprLookupByAttribute const Entity& en, const std::string& attrName, const std::vector& 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) @@ -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 */ } @@ -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; } diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index 31a563a3e0..4d37316e33 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -365,9 +365,9 @@ extern void cprLookupByAttribute const Entity& en, const std::string& attrName, const std::vector& regV, - std::string* perEntPa, - std::string* perAttrPa, - ProviderFormat* providerFormatP, + std::string* perEntProviderP, + std::string* perAttrProviderP, + bool* legacyProviderFormatP, std::string* regId ); diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index 4175347971..bfc1cb9726 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -82,13 +82,13 @@ static void fillContextProviders(ContextElementResponseVector& cerV, const std:: /* **************************************************************************** * -* addContextProviderEntity - +* lookupProvider - */ -static bool lookupProvidingApplication(const std::vector& paV, const ProvidingApplication &pa) +static bool lookupProvider(const std::vector& 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; } @@ -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) */ } @@ -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); @@ -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)) @@ -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; } @@ -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); } diff --git a/src/lib/ngsi/CMakeLists.txt b/src/lib/ngsi/CMakeLists.txt index b618452781..c720add459 100644 --- a/src/lib/ngsi/CMakeLists.txt +++ b/src/lib/ngsi/CMakeLists.txt @@ -29,7 +29,6 @@ SET (SOURCES EntityIdVector.cpp Metadata.cpp MetadataVector.cpp - ProvidingApplication.cpp Request.cpp Scope.cpp ScopeVector.cpp @@ -46,7 +45,6 @@ SET (HEADERS EntityIdVector.h Metadata.h MetadataVector.h - ProvidingApplication.h Scope.h StatusCode.h StringList.h diff --git a/src/lib/ngsi/ContextAttribute.cpp b/src/lib/ngsi/ContextAttribute.cpp index ab1ac66f34..92901c33b4 100644 --- a/src/lib/ngsi/ContextAttribute.cpp +++ b/src/lib/ngsi/ContextAttribute.cpp @@ -339,7 +339,11 @@ ContextAttribute::ContextAttribute() creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -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, @@ -495,7 +498,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -534,7 +541,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -572,7 +583,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -611,7 +626,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } diff --git a/src/lib/ngsi/ContextAttribute.h b/src/lib/ngsi/ContextAttribute.h index c0bb73f274..ef5d578ef1 100644 --- a/src/lib/ngsi/ContextAttribute.h +++ b/src/lib/ngsi/ContextAttribute.h @@ -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" @@ -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 diff --git a/src/lib/ngsi/ProvidingApplication.cpp b/src/lib/ngsi/ProvidingApplication.cpp deleted file mode 100644 index 3857b973aa..0000000000 --- a/src/lib/ngsi/ProvidingApplication.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "ngsi/Request.h" -#include "ngsi/ProvidingApplication.h" - - - -/* **************************************************************************** -* -* ProvidingApplication::ProvidingApplication - -*/ -ProvidingApplication::ProvidingApplication() -{ - /* It is better to have a default constructor than to leave mimeType with a random value */ - string = ""; - providerFormat = PfJson; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::set - -*/ -void ProvidingApplication::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::setProviderFormat - -*/ -void ProvidingApplication::setProviderFormat(const ProviderFormat _providerFormat) -{ - providerFormat = _providerFormat; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::setRegId - -*/ -void ProvidingApplication::setRegId(const std::string& _regId) -{ - regId = _regId; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getProviderFormat - -*/ -ProviderFormat ProvidingApplication::getProviderFormat(void) -{ - return providerFormat; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getRegId - -*/ -std::string ProvidingApplication::getRegId(void) -{ - return regId; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getRegId - -*/ -std::string ProvidingApplication::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* release - -*/ -void ProvidingApplication::release(void) -{ - /* This method is included for the sake of homogeneity */ -} diff --git a/src/lib/ngsi/ProvidingApplication.h b/src/lib/ngsi/ProvidingApplication.h deleted file mode 100644 index fdba64d7f6..0000000000 --- a/src/lib/ngsi/ProvidingApplication.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ -#define SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/MimeType.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ProviderFormat - -*/ -typedef enum ProviderFormat -{ - PfNone, - PfJson, - PfV2 -} ProviderFormat; - - - -/* **************************************************************************** -* -* ProvidingApplication - -*/ -typedef struct ProvidingApplication -{ - std::string string; - ProviderFormat providerFormat; // PfJson ("JSON" in mongo): NGSIv1, PfV2: NGSIv2 - std::string regId; // RegId associated to the provider (for log purposes) - - ProvidingApplication(); - void set(const std::string& value); - void setProviderFormat(const ProviderFormat _providerFormat); - void setRegId(const std::string& _regId); - std::string get(void); - ProviderFormat getProviderFormat(void); - std::string getRegId(void); - void release(void); -} ProvidingApplication; - -#endif // SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ diff --git a/src/lib/ngsi10/QueryContextRequest.cpp b/src/lib/ngsi10/QueryContextRequest.cpp index 5d17ab661e..0b89722e30 100644 --- a/src/lib/ngsi10/QueryContextRequest.cpp +++ b/src/lib/ngsi10/QueryContextRequest.cpp @@ -54,10 +54,10 @@ QueryContextRequest::QueryContextRequest() * * QueryContextRequest::QueryContextRequest */ -QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, ProviderFormat _providerFormat) +QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, bool _legacyProviderFormat) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; entityIdVector.push_back(new EntityId(eP)); @@ -73,10 +73,10 @@ QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, En * * QueryContextRequest::QueryContextRequest */ -QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& _attributeList, ProviderFormat _providerFormat) +QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& _attributeList, bool _legacyProviderFormat) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; entityIdVector.push_back(new EntityId(eP)); diff --git a/src/lib/ngsi10/QueryContextRequest.h b/src/lib/ngsi10/QueryContextRequest.h index 7019f569d8..b64ff809d1 100644 --- a/src/lib/ngsi10/QueryContextRequest.h +++ b/src/lib/ngsi10/QueryContextRequest.h @@ -56,14 +56,13 @@ typedef struct QueryContextRequest StringList attrsList; // Used by the NGSIv2 forwarding logic, to avoid over-querying attributes (see pruneContextElements) ScopeVector scopeVector; // Optional - //int restrictions; - StringList metadataList; // From URI param 'metadata' - std::string contextProvider; // Not part of the payload - used internally only - ProviderFormat providerFormat; // Not part of the payload - used internally only + StringList metadataList; // From URI param 'metadata' + std::string contextProvider; // Not part of the payload - used internally only + bool legacyProviderFormat; // Not part of the payload - used internally only QueryContextRequest(); - QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, ProviderFormat _providerFormat); - QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& attributeList, ProviderFormat _providerFormat); + QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, bool _legacyProviderFormat); + QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& attributeList, bool _legacyProviderFormat); std::string toJsonV1(void); std::string toJson(void); diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index 80cda08d87..48f1464c7c 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -51,10 +51,11 @@ UpdateContextRequest::UpdateContextRequest() * * UpdateContextRequest::UpdateContextRequest - */ -UpdateContextRequest::UpdateContextRequest(const std::string& _contextProvider, ProviderFormat _providerFormat, Entity* eP) +UpdateContextRequest::UpdateContextRequest(const std::string& _contextProvider, bool _legacyProviderFormat, Entity* eP) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; + Entity* neweP = new Entity(eP->id, eP->type, eP->isPattern); neweP->renderId = eP->renderId; entityVector.push_back(neweP); diff --git a/src/lib/ngsi10/UpdateContextRequest.h b/src/lib/ngsi10/UpdateContextRequest.h index 9af9cfc293..3a8bcfca97 100644 --- a/src/lib/ngsi10/UpdateContextRequest.h +++ b/src/lib/ngsi10/UpdateContextRequest.h @@ -45,10 +45,10 @@ typedef struct UpdateContextRequest ActionType updateActionType; // Mandatory std::string contextProvider; // Not part of the payload - used internally only - ProviderFormat providerFormat; // Not part of the payload - used internally only + bool legacyProviderFormat; // Not part of the payload - used internally only UpdateContextRequest(); - UpdateContextRequest(const std::string& _contextProvider, ProviderFormat _providerFormat, Entity* eP); + UpdateContextRequest(const std::string& _contextProvider, bool _providerFormat, Entity* eP); std::string toJsonV1(bool asJsonObject); std::string toJson(void); diff --git a/src/lib/orionTypes/EntityTypeVector.cpp b/src/lib/orionTypes/EntityTypeVector.cpp index 1fbe02b705..b7d90b9ef0 100755 --- a/src/lib/orionTypes/EntityTypeVector.cpp +++ b/src/lib/orionTypes/EntityTypeVector.cpp @@ -31,6 +31,7 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" +#include "common/MimeType.h" #include "ngsi/Request.h" #include "orionTypes/EntityType.h" #include "orionTypes/EntityTypeVector.h" diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index cd3c688221..f37755d90e 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -182,7 +182,7 @@ static bool queryForward std::string mimeType; std::string op; - if (qcrP->providerFormat == PfJson) + if (qcrP->legacyProviderFormat) { op = "/queryContext"; @@ -331,8 +331,8 @@ static bool queryForward noHeaders, mimeType, -1, // default timeout - qcrP->providerFormat == PfJson? -1 : providerLimit, - qcrP->providerFormat == PfJson? -1 : providerOffset); + qcrP->legacyProviderFormat? -1 : providerLimit, + qcrP->legacyProviderFormat? -1 : providerOffset); if (r != 0) { @@ -385,7 +385,7 @@ static bool queryForward // keyValue directly as function parameter. bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; ciP->uriParamOptions[OPT_KEY_VALUES] = false; - result = qcrP->providerFormat == PfJson ? parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe) : parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); + result = qcrP->legacyProviderFormat? parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe) : parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; if (result == false) @@ -438,7 +438,7 @@ static bool forwardsPending(QueryContextResponse* qcrsP) { ContextElementResponse* cerP = qcrsP->contextElementResponseVector[ix]; - if (cerP->entity.providingApplicationList.size() != 0) + if (cerP->entity.providerList.size() != 0) { return true; } @@ -447,7 +447,7 @@ static bool forwardsPending(QueryContextResponse* qcrsP) { ContextAttribute* aP = cerP->entity.attributeVector[aIx]; - if (!aP->providingApplication.get().empty()) + if (!aP->provider.http.url.empty()) { return true; } @@ -572,20 +572,20 @@ void postQueryContext // When there is a Context Provider in ContextElement::providingApplicationList, then the // request must be sent to that Context Provider also // - for (unsigned int ix = 0; ix < cerP->entity.providingApplicationList.size(); ++ix) + for (unsigned int ix = 0; ix < cerP->entity.providerList.size(); ++ix) { QueryContextRequest* requestP; - requestP = new QueryContextRequest(cerP->entity.providingApplicationList[ix].get(), &en, qcrP->attributeList, cerP->entity.providingApplicationList[ix].providerFormat); + requestP = new QueryContextRequest(cerP->entity.providerList[ix].http.url, &en, qcrP->attributeList, cerP->entity.providerList[ix].legacyForwardingMode); requestV.push_back(requestP); - regIdsV.push_back(cerP->entity.providingApplicationList[ix].getRegId()); + regIdsV.push_back(cerP->entity.providerRegIdList[ix]); } // // What if the Attribute Vector of the ContextElementResponse is empty? // For now, just push it into localQcrsP, but only if its local, i.e. its contextElement.providingApplicationList is empty // - if ((cerP->entity.attributeVector.size() == 0) && (cerP->entity.providingApplicationList.size() == 0)) + if ((cerP->entity.attributeVector.size() == 0) && (cerP->entity.providerList.size() == 0)) { localQcrsP->contextElementResponseVector.push_back(new ContextElementResponse(&en, NULL)); } @@ -599,7 +599,7 @@ void postQueryContext // An empty providingApplication means the attribute is local // In such a case, the response is already in our hand, we just need to copy it to responseV // - if (aP->providingApplication.get().empty()) + if (aP->provider.http.url.empty()) { if (aP->found == false) { @@ -631,13 +631,13 @@ void postQueryContext // // Not a local attribute - aP->providingApplication is not empty // - QueryContextRequest* requestP = requestV.lookup(aP->providingApplication.get(), &en); + QueryContextRequest* requestP = requestV.lookup(aP->provider.http.url, &en); if (requestP == NULL) { - requestP = new QueryContextRequest(aP->providingApplication.get(), &en, aP->name, aP->providingApplication.providerFormat); + requestP = new QueryContextRequest(aP->provider.http.url, &en, aP->name, aP->provider.legacyForwardingMode); requestV.push_back(requestP); - regIdsV.push_back(aP->providingApplication.getRegId()); + regIdsV.push_back(aP->providerRegId); } else { diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index bcdc877d50..30f5aaef5b 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -74,7 +74,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; } @@ -153,7 +153,7 @@ static bool updateForward std::string out; int r; - if (upcrP->providerFormat == PfJson) + if (upcrP->legacyProviderFormat) { TIMED_RENDER(payload = upcrP->toJsonV1(asJsonObject)); @@ -246,7 +246,7 @@ static bool updateForward LM_T(LmtCPrForwardResponsePayload, ("forward updateContext response payload: %s", out.c_str())); // - // If NGSIv1 (providerFormat == PfJson): + // If NGSIv1 (legacyProviderFormat): // 4. Parse the response and fill in a binary UpdateContextResponse // 5. Fill in the response from the redirection into the response of this function // 6. 'Fix' StatusCode @@ -256,7 +256,7 @@ static bool updateForward // 4. Look for "204 No Content" in the response of the forwarded request // 5. If found: OK, else, error // - if (upcrP->providerFormat == PfJson) + if (upcrP->legacyProviderFormat) { // // 4. Parse the response and fill in a binary UpdateContextResponse @@ -689,7 +689,7 @@ void postUpdateContext // // 1. If the attribute is found locally - just add the attribute to the outgoing response // - if (aP->providingApplication.get().empty()) + if (aP->provider.http.url.empty()) { ContextAttribute ca(aP); response.foundPush(&cerP->entity, &ca); @@ -698,15 +698,15 @@ void postUpdateContext // - // 2. Lookup UpdateContextRequest in requestV according to providingApplication. + // 2. Lookup UpdateContextRequest in requestV according to provider. // If not found, add one. - UpdateContextRequest* reqP = requestV.lookup(aP->providingApplication.get()); + UpdateContextRequest* reqP = requestV.lookup(aP->provider.http.url); if (reqP == NULL) { - reqP = new UpdateContextRequest(aP->providingApplication.get(), aP->providingApplication.providerFormat, &cerP->entity); + reqP = new UpdateContextRequest(aP->provider.http.url, aP->provider.legacyForwardingMode, &cerP->entity); reqP->updateActionType = ActionTypeUpdate; requestV.push_back(reqP); - regIdsV.push_back(aP->providingApplication.getRegId()); + regIdsV.push_back(aP->providerRegId); } //