diff --git a/src/lib/apiTypesV2/CMakeLists.txt b/src/lib/apiTypesV2/CMakeLists.txt index da8090aca6..d9f70c96cd 100644 --- a/src/lib/apiTypesV2/CMakeLists.txt +++ b/src/lib/apiTypesV2/CMakeLists.txt @@ -26,7 +26,6 @@ SET (SOURCES Entities.cpp Subscription.cpp Registration.cpp - EntID.cpp BatchQuery.cpp BatchUpdate.cpp HttpInfo.cpp @@ -39,7 +38,6 @@ SET (HEADERS Entities.h Subscription.h Registration.h - EntID.h BatchQuery.h BatchUpdate.h CustomPayloadType.h diff --git a/src/lib/apiTypesV2/EntID.cpp b/src/lib/apiTypesV2/EntID.cpp deleted file mode 100644 index 9968585ab0..0000000000 --- a/src/lib/apiTypesV2/EntID.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2017 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: Fermín Galán Márquez -*/ - -#include - -#include "apiTypesV2/EntID.h" - -#include "common/JsonHelper.h" - -namespace ngsiv2 -{ -/* **************************************************************************** -* -* EntID::toJson - -*/ -std::string EntID::toJson() -{ - JsonObjectHelper jh; - - if (!this->id.empty()) - { - jh.addString("id", this->id); - } - - if (!this->idPattern.empty()) - { - jh.addString("idPattern", this->idPattern); - } - - if (!this->type.empty()) - { - jh.addString("type", this->type); - } - - if (!this->typePattern.empty()) - { - jh.addString("typePattern", this->typePattern); - } - - return jh.str(); -} -} diff --git a/src/lib/apiTypesV2/EntID.h b/src/lib/apiTypesV2/EntID.h deleted file mode 100644 index d47444f5b1..0000000000 --- a/src/lib/apiTypesV2/EntID.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef SRC_LIB_APITYPESV2_ENTID_H_ -#define SRC_LIB_APITYPESV2_ENTID_H_ - -/* -* -* Copyright 2017 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: Fermín Galán Márquez -*/ -#include - - -namespace ngsiv2 -{ -/* **************************************************************************** -* -* EntID - -*/ -struct EntID -{ - std::string id; - std::string idPattern; - std::string type; - std::string typePattern; - std::string toJson(); - - EntID(const std::string& idA, const std::string& idPatternA, - const std::string& typeA, const std::string& typePatternA): - id(idA), - idPattern(idPatternA), - type(typeA), - typePattern(typePatternA) - {} - - EntID() {} - - bool operator==(const EntID& e) - { - return (id == e.id) && - (idPattern == e.idPattern) && - (type == e.type) && - (typePattern == e.typePattern); - } - - bool operator!=(const EntID& e) - { - return (id != e.id) || - (idPattern != e.idPattern) || - (type != e.type) || - (typePattern != e.typePattern); - } -}; - -} // end namespace - -#endif // SRC_LIB_APITYPESV2_ENTID_H_ diff --git a/src/lib/apiTypesV2/Registration.cpp b/src/lib/apiTypesV2/Registration.cpp index e58e7ede7a..8ab6769c81 100644 --- a/src/lib/apiTypesV2/Registration.cpp +++ b/src/lib/apiTypesV2/Registration.cpp @@ -133,7 +133,7 @@ void Registration::setEntities(const orion::BSONObj& cr0) for (unsigned int ix = 0; ix < dbEntityV.size(); ++ix) { - ngsiv2::EntID entity; + EntityId entity; orion::BSONObj ce = dbEntityV[ix].embeddedObject(); if (ce.hasField(REG_ENTITY_ISPATTERN)) diff --git a/src/lib/apiTypesV2/Registration.h b/src/lib/apiTypesV2/Registration.h index ad478f0817..63d79e5428 100644 --- a/src/lib/apiTypesV2/Registration.h +++ b/src/lib/apiTypesV2/Registration.h @@ -28,7 +28,7 @@ #include #include -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" #include "mongoDriver/BSONObj.h" @@ -124,7 +124,7 @@ struct Provider */ struct DataProvided { - std::vector entities; + std::vector entities; std::vector attributes; std::string toJson(); diff --git a/src/lib/apiTypesV2/Subscription.h b/src/lib/apiTypesV2/Subscription.h index 8bd25dfee0..1a97fd57fe 100644 --- a/src/lib/apiTypesV2/Subscription.h +++ b/src/lib/apiTypesV2/Subscription.h @@ -28,10 +28,10 @@ #include #include -#include "apiTypesV2/EntID.h" #include "apiTypesV2/HttpInfo.h" #include "apiTypesV2/MqttInfo.h" #include "apiTypesV2/SubscriptionExpression.h" +#include "ngsi/EntityId.h" #include "ngsi/ScopeVector.h" #include "common/RenderFormat.h" @@ -136,9 +136,9 @@ struct Condition */ struct Subject { - std::vector entities; - Condition condition; - std::string toJson(); + std::vector entities; + Condition condition; + std::string toJson(); }; diff --git a/src/lib/cache/subCache.cpp b/src/lib/cache/subCache.cpp index 79bdbef228..2074fbc4fa 100644 --- a/src/lib/cache/subCache.cpp +++ b/src/lib/cache/subCache.cpp @@ -810,7 +810,7 @@ void subCacheItemInsert const char* servicePath, const ngsiv2::HttpInfo& httpInfo, const ngsiv2::MqttInfo& mqttInfo, - const std::vector& entIdVector, + const std::vector& entIdVector, const std::vector& attributes, const std::vector& metadata, const std::vector& conditionAttrs, @@ -918,7 +918,7 @@ void subCacheItemInsert // for (unsigned int ix = 0; ix < entIdVector.size(); ++ix) { - const ngsiv2::EntID* eIdP = &entIdVector[ix]; + const EntityId* eIdP = &entIdVector[ix]; std::string isPattern = (eIdP->id.empty())? "true" : "false"; bool isTypePattern = (eIdP->type.empty()); std::string id = (eIdP->id.empty())? eIdP->idPattern : eIdP->id; diff --git a/src/lib/cache/subCache.h b/src/lib/cache/subCache.h index 2fbff68fff..42ed21e314 100644 --- a/src/lib/cache/subCache.h +++ b/src/lib/cache/subCache.h @@ -196,7 +196,7 @@ extern void subCacheItemInsert const char* servicePath, const ngsiv2::HttpInfo& httpInfo, const ngsiv2::MqttInfo& mqttInfo, - const std::vector& entities, + const std::vector& entities, const std::vector& attributes, const std::vector& metadata, const std::vector& conditionAttrs, diff --git a/src/lib/jsonParseV2/parseEntitiesVector.cpp b/src/lib/jsonParseV2/parseEntitiesVector.cpp index 041b6cf0f4..48ba071322 100644 --- a/src/lib/jsonParseV2/parseEntitiesVector.cpp +++ b/src/lib/jsonParseV2/parseEntitiesVector.cpp @@ -35,7 +35,7 @@ #include "rest/ConnectionInfo.h" #include "rest/OrionError.h" #include "parse/forbiddenChars.h" -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" #include "common/string.h" #include "common/errorMessages.h" #include "jsonParseV2/utilsParse.h" @@ -49,10 +49,10 @@ */ bool parseEntitiesVector ( - ConnectionInfo* ciP, - std::vector* eivP, - const rapidjson::Value& entities, - std::string* errorStringP + ConnectionInfo* ciP, + std::vector* eivP, + const rapidjson::Value& entities, + std::string* errorStringP ) { if (!entities.IsArray()) @@ -209,7 +209,7 @@ bool parseEntitiesVector } } - ngsiv2::EntID eid(id, idPattern, type, typePattern); + EntityId eid(id, idPattern, type, typePattern); if (std::find(eivP->begin(), eivP->end(), eid) == eivP->end()) // if not already included { diff --git a/src/lib/jsonParseV2/parseEntitiesVector.h b/src/lib/jsonParseV2/parseEntitiesVector.h index 92c1bdea39..bf34906ef3 100644 --- a/src/lib/jsonParseV2/parseEntitiesVector.h +++ b/src/lib/jsonParseV2/parseEntitiesVector.h @@ -31,7 +31,7 @@ #include "rapidjson/document.h" #include "rest/ConnectionInfo.h" -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" @@ -41,10 +41,10 @@ */ extern bool parseEntitiesVector ( - ConnectionInfo* ciP, - std::vector* eivP, - const rapidjson::Value& entities, - std::string* errorStringP + ConnectionInfo* ciP, + std::vector* eivP, + const rapidjson::Value& entities, + std::string* errorStringP ); #endif // SRC_LIB_JSONPARSEV2_PARSEENTITIESVECTOR_H_ diff --git a/src/lib/jsonParseV2/parseRegistration.cpp b/src/lib/jsonParseV2/parseRegistration.cpp index c72d9df72a..8aa76f527a 100644 --- a/src/lib/jsonParseV2/parseRegistration.cpp +++ b/src/lib/jsonParseV2/parseRegistration.cpp @@ -93,7 +93,7 @@ static bool dataProvidedParse // for (unsigned int eIx = 0; eIx < dataProvidedP->entities.size(); ++eIx) { - ngsiv2::EntID* eP = &dataProvidedP->entities[eIx]; + EntityId* eP = &dataProvidedP->entities[eIx]; if ((!eP->idPattern.empty()) && (eP->idPattern != ".*")) { diff --git a/src/lib/jsonParseV2/parseSubscription.cpp b/src/lib/jsonParseV2/parseSubscription.cpp index ca8126ff42..cf518c63e3 100644 --- a/src/lib/jsonParseV2/parseSubscription.cpp +++ b/src/lib/jsonParseV2/parseSubscription.cpp @@ -59,7 +59,6 @@ * USING */ using ngsiv2::SubscriptionUpdate; -using ngsiv2::EntID; using rapidjson::Value; diff --git a/src/lib/mongoBackend/MongoCommonSubscription.cpp b/src/lib/mongoBackend/MongoCommonSubscription.cpp index 2ea5f0d053..f7456d3f7f 100644 --- a/src/lib/mongoBackend/MongoCommonSubscription.cpp +++ b/src/lib/mongoBackend/MongoCommonSubscription.cpp @@ -45,7 +45,6 @@ */ using ngsiv2::Subscription; using ngsiv2::HttpInfo; -using ngsiv2::EntID; @@ -398,7 +397,7 @@ void setEntities(const Subscription& sub, orion::BSONObjBuilder* b) for (unsigned int ix = 0; ix < sub.subject.entities.size(); ++ix) { - EntID en = sub.subject.entities[ix]; + EntityId en = sub.subject.entities[ix]; std::string finalId; std::string finalType; std::string isIdPattern; diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 11f00cb648..0edd4b53b7 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -71,7 +71,6 @@ * USING */ using ngsiv2::HttpInfo; -using ngsiv2::EntID; @@ -401,7 +400,7 @@ void ensureDateExpirationIndex(const std::string& tenant) * commutative: en1 is interpreted as the entity to match *in* en2 (i.e. * it is assumed that the pattern is in en2) */ -bool matchEntity(const EntityId* en1, const ngsiv2::EntID& en2) +bool matchEntity(const EntityId* en1, const EntityId& en2) { bool idMatch; @@ -422,7 +421,7 @@ bool matchEntity(const EntityId* en1, const ngsiv2::EntID& en2) regfree(®ex); // If regcomp fails it frees up itself (see glibc sources for details) } } - else /* isPattern == false */ + else /* is not a pattern */ { idMatch = (en2.id == en1->id); } @@ -2234,7 +2233,7 @@ void cprLookupByAttribute /* Is there a matching entity in the Registration? */ for (unsigned enIx = 0; enIx < reg.dataProvided.entities.size(); ++enIx) { - EntID regEn = reg.dataProvided.entities[enIx]; + EntityId regEn = reg.dataProvided.entities[enIx]; if (regEn.idPattern == ".*") { diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index 4d37316e33..0c51f52770 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -175,7 +175,7 @@ extern void ensureDateExpirationIndex(const std::string& tenant); * * matchEntity - */ -extern bool matchEntity(const EntityId* en1, const ngsiv2::EntID& en2); +extern bool matchEntity(const EntityId* en1, const EntityId& en2); diff --git a/src/lib/mongoBackend/mongoGetSubscriptions.cpp b/src/lib/mongoBackend/mongoGetSubscriptions.cpp index c14866017c..b1a51be48a 100644 --- a/src/lib/mongoBackend/mongoGetSubscriptions.cpp +++ b/src/lib/mongoBackend/mongoGetSubscriptions.cpp @@ -51,7 +51,6 @@ * USING - */ using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -94,7 +93,7 @@ static void setSubject(Subscription* s, const orion::BSONObj& r) bool isTypePattern = ent.hasField(CSUB_ENTITY_ISTYPEPATTERN)? getBoolFieldF(ent, CSUB_ENTITY_ISTYPEPATTERN) : false; - EntID en; + EntityId en; if (isFalse(isPattern)) { en.id = id; diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index 44daae307e..348eb5ad49 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -105,16 +105,14 @@ static bool lookupProvider(const std::vector& providerV, const static void addContextProviderEntity ( ContextElementResponseVector& cerV, - const ngsiv2::EntID& regEn, + const EntityId& regEn, const ngsiv2::Provider& provider, const std::string& regId ) { for (unsigned int ix = 0; ix < cerV.size(); ++ix) { - // FIXME PR ngsiv2::EntID should be changed to EntityId - EntityId temp(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); - if (cerV[ix]->entity.entityId == temp) + if (cerV[ix]->entity.entityId == regEn) { // Avoid duplicate Provider in the vector if (!lookupProvider(cerV[ix]->entity.providerList, provider)) @@ -150,7 +148,7 @@ static void addContextProviderEntity static void addContextProviderAttribute ( ContextElementResponseVector& cerV, - ngsiv2::EntID regEn, + EntityId regEn, const std::string& regAttr, const ngsiv2::Provider& provider, const std::string& regId, @@ -214,7 +212,7 @@ static bool matchEntityInRegistration(const ngsiv2::Registration& reg, const Ent { for (unsigned int ix = 0; ix < reg.dataProvided.entities.size(); ++ix) { - ngsiv2::EntID entId = reg.dataProvided.entities[ix]; + EntityId entId = reg.dataProvided.entities[ix]; if (matchEntity(enP, entId)) { diff --git a/src/lib/mongoBackend/mongoRegistrationCreate.cpp b/src/lib/mongoBackend/mongoRegistrationCreate.cpp index fa17c450ea..d83017688d 100644 --- a/src/lib/mongoBackend/mongoRegistrationCreate.cpp +++ b/src/lib/mongoBackend/mongoRegistrationCreate.cpp @@ -115,7 +115,7 @@ static void setContextRegistrationVector(ngsiv2::Registration* regP, orion::BSON for (unsigned int eIx = 0; eIx < regP->dataProvided.entities.size(); ++eIx) { - ngsiv2::EntID* eP = ®P->dataProvided.entities[eIx]; + EntityId* eP = ®P->dataProvided.entities[eIx]; orion::BSONObjBuilder bob; if (eP->idPattern.empty()) diff --git a/src/lib/mongoBackend/mongoUpdateSubscription.cpp b/src/lib/mongoBackend/mongoUpdateSubscription.cpp index 6a6ed36cf1..2fbf89a989 100644 --- a/src/lib/mongoBackend/mongoUpdateSubscription.cpp +++ b/src/lib/mongoBackend/mongoUpdateSubscription.cpp @@ -54,7 +54,6 @@ using ngsiv2::HttpInfo; using ngsiv2::Subscription; using ngsiv2::SubscriptionUpdate; -using ngsiv2::EntID; /* **************************************************************************** diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index 0a2f54f596..9cf63a0393 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -777,23 +777,7 @@ void postQueryContext EntityId tempEn(responseV[ix]->contextElementResponseVector[jx]->entity.entityId); for (unsigned int kx = 0; kx < qcrP->entityIdVector.size(); ++kx) { - ngsiv2::EntID entityId; - /*if (isTrue(qcrP->entityIdVector[kx]->isPattern)) - { - entityId.idPattern = qcrP->entityIdVector[kx]->id; - } - else - { - entityId.id = qcrP->entityIdVector[kx]->id; - } - entityId.type = qcrP->entityIdVector[kx]->type;*/ - // FIXME PR: next line will be simpler when EntID+EntityId unification comes - entityId.id = qcrP->entityIdVector[kx]->id; - entityId.idPattern = qcrP->entityIdVector[kx]->idPattern; - entityId.type = qcrP->entityIdVector[kx]->type; - entityId.typePattern = qcrP->entityIdVector[kx]->typePattern; - - if (matchEntity(&tempEn, entityId)) + if (matchEntity(&tempEn, qcrP->entityIdVector[kx])) { found = true; break; // kx diff --git a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp index b3d40712b8..9508d8e5c1 100644 --- a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp +++ b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp @@ -52,7 +52,6 @@ using mongo::BSONObj; using mongo::BSONArray; using mongo::OID; using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -74,8 +73,8 @@ TEST(mongoCreateSubscriptions, createSubscriptionNotCustomOK) sub.throttling = 5; sub.attrsFormat = NGSI_V2_NORMALIZED; - EntID en1("E1", "", "T1", ""); - EntID en2("", "E.*", "T2", ""); + EntityId en1("E1", "", "T1", ""); + EntityId en2("", "E.*", "T2", ""); sub.subject.entities.push_back(en1); sub.subject.entities.push_back(en2); sub.subject.condition.attributes.push_back("A"); @@ -165,8 +164,8 @@ TEST(mongoCreateSubscriptions, createSubscriptionCustomOK) sub.throttling = 5; sub.attrsFormat = NGSI_V2_NORMALIZED; - EntID en1("E1", "", "T1", ""); - EntID en2("", "E.*", "T2", ""); + EntityId en1("E1", "", "T1", ""); + EntityId en2("", "E.*", "T2", ""); sub.subject.entities.push_back(en1); sub.subject.entities.push_back(en2); sub.subject.condition.attributes.push_back("A"); diff --git a/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp b/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp index 07c0a6cbc0..26e3b79a14 100644 --- a/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp +++ b/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp @@ -53,7 +53,6 @@ using ::testing::_; using ::testing::Throw; using ::testing::Return; using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -145,7 +144,7 @@ TEST(mongoListSubscriptions, getAllSubscriptionsV1Info) ASSERT_EQ(3, subs.size()); Subscription s; - std::vector ents; + std::vector ents; std::vector attrs; /* Subscription #1 */ @@ -247,7 +246,7 @@ TEST(mongoGetSubscription, getSubscription) EXPECT_EQ("OK", oe.error); EXPECT_EQ("", oe.description); - std::vector ents; + std::vector ents; std::vector attrs; /* Subscription #1 */