From 97fc17ca2b908e353e847dbac6da42b67a471318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Mon, 2 Sep 2024 09:26:50 +0200 Subject: [PATCH] FIX Merge EntID logic into EntityId class (to remove EntID in a soon next commit) --- src/lib/apiTypesV2/Entities.cpp | 8 +- src/lib/apiTypesV2/Entity.cpp | 280 ++++++++++++------ src/lib/apiTypesV2/Entity.h | 26 +- src/lib/apiTypesV2/EntityVector.cpp | 2 +- src/lib/apiTypesV2/HttpInfo.cpp | 4 +- src/lib/apiTypesV2/MqttInfo.cpp | 4 +- .../jsonParseV2/parseEntitiesResponseV1.cpp | 6 +- src/lib/jsonParseV2/parseEntity.cpp | 21 +- src/lib/jsonParseV2/parseEntityObject.cpp | 18 +- src/lib/jsonParseV2/parseNotification.cpp | 3 +- src/lib/jsonParseV2/parseSubscription.cpp | 4 +- .../mongoBackend/MongoCommonSubscription.cpp | 16 +- src/lib/mongoBackend/MongoCommonUpdate.cpp | 49 +-- src/lib/mongoBackend/MongoGlobal.cpp | 50 ++-- src/lib/mongoBackend/mongoQueryContext.cpp | 14 +- src/lib/ngsi/ContextElementResponse.cpp | 7 +- src/lib/ngsi/ContextElementResponseVector.cpp | 2 +- src/lib/ngsi/EntityId.cpp | 65 ++-- src/lib/ngsi/EntityId.h | 45 ++- src/lib/ngsi/EntityIdVector.cpp | 25 +- src/lib/ngsi/EntityIdVector.h | 2 +- src/lib/ngsi10/QueryContextRequest.cpp | 18 +- src/lib/ngsi10/QueryContextRequest.h | 2 +- src/lib/ngsi10/UpdateContextRequest.cpp | 30 +- src/lib/ngsi10/UpdateContextRequest.h | 2 +- src/lib/ngsi10/UpdateContextResponse.cpp | 8 +- src/lib/ngsiNotify/Notifier.cpp | 23 +- src/lib/rest/EntityTypeInfo.h | 2 + src/lib/serviceRoutines/postQueryContext.cpp | 12 +- src/lib/serviceRoutines/postUpdateContext.cpp | 20 +- src/lib/serviceRoutinesV2/deleteEntity.cpp | 6 +- src/lib/serviceRoutinesV2/getEntities.cpp | 14 +- src/lib/serviceRoutinesV2/getEntity.cpp | 2 +- .../serviceRoutinesV2/getEntityAttribute.cpp | 2 +- .../getEntityAttributeValue.cpp | 2 +- src/lib/serviceRoutinesV2/patchEntity.cpp | 6 +- src/lib/serviceRoutinesV2/postEntities.cpp | 8 +- src/lib/serviceRoutinesV2/postEntity.cpp | 4 +- src/lib/serviceRoutinesV2/putEntity.cpp | 4 +- .../bugfix_op_update_id_min_max_length.test | 4 +- .../fwd_v1_ngsiv2_query_forward.test | 6 +- .../fwd_v1_ngsiv2_update_forward.test | 2 +- ...wd_v1_ngsiv2_update_forward_with_fail.test | 2 +- .../apiTypesV2/EntityVector_test.cpp | 4 +- test/unittests/apiTypesV2/Entity_test.cpp | 47 +-- .../common/commonMacroSubstitute_test.cpp | 24 +- .../ContextElementResponseVector_test.cpp | 5 +- .../ngsi/ContextElementResponse_test.cpp | 5 +- .../ngsi10/NotifyContextRequest_test.cpp | 6 +- .../testData/ngsi.entityId.render.middle.json | 2 +- test/unittests/testInit.cpp | 23 +- 51 files changed, 528 insertions(+), 418 deletions(-) diff --git a/src/lib/apiTypesV2/Entities.cpp b/src/lib/apiTypesV2/Entities.cpp index d13ab1a887..12a83c7a51 100644 --- a/src/lib/apiTypesV2/Entities.cpp +++ b/src/lib/apiTypesV2/Entities.cpp @@ -135,11 +135,9 @@ void Entities::fill(const QueryContextResponse& qcrs, OrionError* oeP) { Entity* newP = new Entity(); - newP->id = eP->id; - newP->type = eP->type; - newP->isPattern = eP->isPattern; - newP->creDate = eP->creDate; - newP->modDate = eP->modDate; + newP->entityId = eP->entityId; + newP->creDate = eP->creDate; + newP->modDate = eP->modDate; newP->attributeVector.fill(eP->attributeVector); vec.push_back(newP); diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index d096e8959b..8ffde8bcfa 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -48,10 +48,8 @@ * * Entity::Entity - */ -Entity::Entity(): isTypePattern(false), typeGiven(false), renderId(true), creDate(0), modDate(0) +Entity::Entity(): typeGiven(false), renderId(true), creDate(0), modDate(0) { - creDate = 0; - modDate = 0; } @@ -62,14 +60,16 @@ Entity::Entity(): isTypePattern(false), typeGiven(false), renderId(true), creDat * * This constructor was ported from old ContextElement class */ -Entity::Entity(const std::string& _id, const std::string& _type, const std::string& _isPattern, bool _isTypePattern) +Entity::Entity(const std::string& _id, const std::string& _idPattern, const std::string& _type, const std::string& _typePattern) { - id = _id; - type = _type; - isPattern = _isPattern; - isTypePattern = _isTypePattern; - creDate = 0; - modDate = 0; + entityId.id = _id; + entityId.idPattern = _idPattern; + entityId.type = _type; + entityId.typePattern = _typePattern; + typeGiven = false; + renderId = true; + creDate = 0; + modDate = 0; } @@ -321,10 +321,10 @@ std::string Entity::toJsonKeyvalues(const std::vector& ordere if (renderId) { - jh.addString("id", id); + jh.addString("id", entityId.id); /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ - jh.addString("type", (!type.empty())? type : DEFAULT_ENTITY_TYPE); + jh.addString("type", (!entityId.type.empty())? entityId.type : DEFAULT_ENTITY_TYPE); } for (unsigned int ix = 0; ix < orderedAttrs.size(); ix++) @@ -361,21 +361,21 @@ std::string Entity::toJsonNormalized { /* In ngsi field in notifications "" is allowed for id and type, in which case we don't * print the field */ - if (!id.empty()) + if (!entityId.id.empty()) { - jh.addString("id", id); + jh.addString("id", entityId.id); } - if (!type.empty()) + if (!entityId.type.empty()) { - jh.addString("type", type); + jh.addString("type", entityId.type); } } else { - jh.addString("id", id); + jh.addString("id", entityId.id); /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ - jh.addString("type", (!type.empty())? type : DEFAULT_ENTITY_TYPE); + jh.addString("type", (!entityId.type.empty())? entityId.type : DEFAULT_ENTITY_TYPE); } } @@ -394,19 +394,34 @@ std::string Entity::toJsonNormalized * * toString - * -* FIXME P3: Copied from EntityId class */ -std::string Entity::toString(bool useIsPattern, const std::string& delimiter) +std::string Entity::toString(void) { std::string s; - s = id + delimiter + type; + std::string effectiveId; + std::string effectiveType; - if (useIsPattern) + if (entityId.idPattern.empty()) { - s += delimiter + isPattern; + effectiveId = entityId.id; + } + else + { + effectiveId = entityId.idPattern; } + if (entityId.typePattern.empty()) + { + effectiveType = entityId.type; + } + else + { + effectiveType = entityId.typePattern; + } + + return effectiveId + ", " + effectiveType; + return s; } @@ -414,79 +429,199 @@ std::string Entity::toString(bool useIsPattern, const std::string& delimiter) /* **************************************************************************** * -* ContextElement::check +* ContextElement::checkId * */ -std::string Entity::check(RequestType requestType) +std::string Entity::checkId(RequestType requestType) { ssize_t len; char errorMsg[128]; - if (((len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) + if (((len = strlen(entityId.id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) { snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } - if ((requestType == EntitiesRequest) && (id.empty())) + if ((len = strlen(entityId.id.c_str())) > MAX_ID_LEN) { - return "No Entity ID"; + snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } - if ((len = strlen(id.c_str())) > MAX_ID_LEN) + // Check for forbidden chars for "id", but not for "idPattern" is a pattern + if (forbiddenIdCharsV2(entityId.id.c_str())) { - snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, entityId.id); + return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::checkIdPattern +* +*/ +std::string Entity::checkIdPattern(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; + + if (((len = strlen(entityId.idPattern.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) + { + snprintf(errorMsg, sizeof errorMsg, "entity idPattern length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } - if (isPattern.empty()) + if ((len = strlen(entityId.idPattern.c_str())) > MAX_ID_LEN) { - isPattern = "false"; + snprintf(errorMsg, sizeof errorMsg, "entity idPattern length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } - // isPattern MUST be either "true" or "false" (or empty => "false") - if ((isPattern != "true") && (isPattern != "false")) + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::checkType +* +*/ +std::string Entity::checkType(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; + + if ((len = strlen(entityId.type.c_str())) > MAX_ID_LEN) { - alarmMgr.badInput(clientIp, "invalid value for isPattern", isPattern); - return "Invalid value for isPattern"; + snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } - // Check for forbidden chars for "id", but not if "id" is a pattern - if (isPattern == "false") + if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven))) { - if (forbiddenIdCharsV2(id.c_str())) + if ((len = strlen(entityId.type.c_str())) < MIN_ID_LEN) { - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, id); - return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; + snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } } - if ((len = strlen(type.c_str())) > MAX_ID_LEN) + // Check for forbidden chars for "type", but not for "typePattern" + if (forbiddenIdCharsV2(entityId.type.c_str())) { - snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, entityId.type); + return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::checkTypePattern +* +*/ +std::string Entity::checkTypePattern(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; + + if ((len = strlen(entityId.typePattern.c_str())) > MAX_ID_LEN) + { + snprintf(errorMsg, sizeof errorMsg, "entity typePattern length: %zd, max length supported: %d", len, MAX_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven))) { - if ((len = strlen(type.c_str())) < MIN_ID_LEN) + if ((len = strlen(entityId.typePattern.c_str())) < MIN_ID_LEN) { - snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN); + snprintf(errorMsg, sizeof errorMsg, "entity typePattern length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } } - // Check for forbidden chars for "type", but not if "type" is a pattern - if (isTypePattern == false) + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::check +* +*/ +std::string Entity::check(RequestType requestType) +{ + std::string err; + char errorMsg[128]; + + // In EntityRequest the entity id comes in the URL so Entity is allowed to have empty id and idPattern + if ((requestType != EntityRequest) && (entityId.id.empty()) && (entityId.idPattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "id and idPattern cannot be both empty at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.id.empty()) && (!entityId.idPattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "id and idPattern cannot be both filled at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.id.empty()) && ((err = checkId(requestType)) != "OK")) { - if (forbiddenIdCharsV2(type.c_str())) + return err; + } + if ((!entityId.idPattern.empty()) && ((err = checkIdPattern(requestType)) != "OK")) + { + return err; + } + + // typeGiven enables some additional checkings for type and typePattern + if (typeGiven) + { + if ((entityId.type.empty()) && (entityId.typePattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "type and typePattern cannot be both empty at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.type.empty()) && (!entityId.typePattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "type and typePattern cannot be both filled at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.type.empty()) && ((err = checkType(requestType)) != "OK")) + { + return err; + } + + if ((!entityId.typePattern.empty()) && ((err = checkTypePattern(requestType)) != "OK")) { - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, type); - return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; + return err; } } @@ -500,17 +635,13 @@ std::string Entity::check(RequestType requestType) */ void Entity::fill ( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern, + const EntityId& _entityId, const ContextAttributeVector& caV, double _creDate, double _modDate ) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; creDate = _creDate; modDate = _modDate; @@ -526,17 +657,13 @@ void Entity::fill */ void Entity::fill ( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern, + const EntityId& _entityId, const std::string& _servicePath, double _creDate, double _modDate ) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; servicePath = _servicePath; @@ -550,16 +677,9 @@ void Entity::fill * * Entity::fill - */ -void Entity::fill -( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern -) +void Entity::fill(const EntityId& _entityId) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; } @@ -572,17 +692,14 @@ void Entity::fill */ void Entity::fill(const Entity& en, bool useDefaultType, bool cloneCompounds) { - id = en.id; - type = en.type; - isPattern = en.isPattern; - isTypePattern = en.isTypePattern; + entityId = en.entityId; servicePath = en.servicePath; creDate = en.creDate; modDate = en.modDate; - if (useDefaultType && (type.empty())) + if (useDefaultType && (entityId.type.empty())) { - type = DEFAULT_ENTITY_TYPE; + entityId.type = DEFAULT_ENTITY_TYPE; } attributeVector.fill(en.attributeVector, useDefaultType, cloneCompounds); @@ -634,9 +751,7 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) } } - fill(eP->id, - eP->type, - eP->isPattern, + fill(eP->entityId, eP->attributeVector, eP->creDate, eP->modDate); @@ -711,8 +826,5 @@ ContextAttribute* Entity::getAttribute(const std::string& attrName) */ bool Entity::equal(Entity* eP) { - return ((eP->id == id) && - (eP->type == type) && - (isTrue(eP->isPattern) == isTrue(isPattern)) && - (eP->isTypePattern == isTypePattern)); + return entityId == eP->entityId; } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index 8b8f33e377..838676fab8 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -51,10 +51,7 @@ struct QueryContextResponse; class Entity { public: - std::string id; // Mandatory - std::string type; // Optional - std::string isPattern; // Optional - bool isTypePattern; + EntityId entityId; // Mandatory ContextAttributeVector attributeVector; // Optional std::string servicePath; // Not part of payload, just an internal field @@ -68,7 +65,7 @@ class Entity 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); + Entity(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern); ~Entity(); @@ -82,7 +79,7 @@ class Entity std::string toJson(RenderFormat renderFormat, bool renderNgsiField = false); - std::string toString(bool useIsPattern = false, const std::string& delimiter = ", "); + std::string toString(void); std::string check(RequestType requestType); @@ -90,23 +87,17 @@ class Entity void release(void); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern, + void fill(const EntityId& entId, const ContextAttributeVector& caV, double creDate, double modDate); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern, + void fill(const EntityId& entId, const std::string& servicePath, double creDate = 0, double modDate = 0); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern); + void fill(const EntityId& entId); void fill(const Entity& en, bool useDefaultType = false, bool cloneCompounds = false); @@ -132,6 +123,11 @@ class Entity const std::vector& metadataFilter, bool renderNgsiField = false, ExprContextObject* exprContextObject = NULL); + + std::string checkId(RequestType requestType); + std::string checkIdPattern(RequestType requestType); + std::string checkType(RequestType requestType); + std::string checkTypePattern(RequestType requestType); }; #endif // SRC_LIB_APITYPESV2_ENTITY_H_ diff --git a/src/lib/apiTypesV2/EntityVector.cpp b/src/lib/apiTypesV2/EntityVector.cpp index d9c87ff513..eb3e8a1504 100644 --- a/src/lib/apiTypesV2/EntityVector.cpp +++ b/src/lib/apiTypesV2/EntityVector.cpp @@ -141,7 +141,7 @@ Entity* EntityVector::lookup(const std::string& name, const std::string& type) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { - if ((vec[ix]->id == name) && (vec[ix]->type == type)) + if ((vec[ix]->entityId.id == name) && (vec[ix]->entityId.type == type)) { return vec[ix]; } diff --git a/src/lib/apiTypesV2/HttpInfo.cpp b/src/lib/apiTypesV2/HttpInfo.cpp index d4eb24114c..c5b473991c 100644 --- a/src/lib/apiTypesV2/HttpInfo.cpp +++ b/src/lib/apiTypesV2/HttpInfo.cpp @@ -193,11 +193,11 @@ void HttpInfo::fill(const orion::BSONObj& bo) orion::BSONObj ngsiObj = getObjectFieldF(bo, CSUB_NGSI); if (ngsiObj.hasField(ENT_ENTITY_ID)) { - this->ngsi.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); + this->ngsi.entityId.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); } if (ngsiObj.hasField(ENT_ENTITY_TYPE)) { - this->ngsi.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); + this->ngsi.entityId.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); } if (ngsiObj.hasField(ENT_ATTRS)) { diff --git a/src/lib/apiTypesV2/MqttInfo.cpp b/src/lib/apiTypesV2/MqttInfo.cpp index 1ee9e874ce..895e363779 100644 --- a/src/lib/apiTypesV2/MqttInfo.cpp +++ b/src/lib/apiTypesV2/MqttInfo.cpp @@ -195,11 +195,11 @@ void MqttInfo::fill(const orion::BSONObj& bo) orion::BSONObj ngsiObj = getObjectFieldF(bo, CSUB_NGSI); if (ngsiObj.hasField(ENT_ENTITY_ID)) { - this->ngsi.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); + this->ngsi.entityId.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); } if (ngsiObj.hasField(ENT_ENTITY_TYPE)) { - this->ngsi.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); + this->ngsi.entityId.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); } if (ngsiObj.hasField(ENT_ATTRS)) { diff --git a/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp index 4b45f9027b..0ce8f5e026 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp +++ b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp @@ -322,7 +322,7 @@ static std::string parseEntity(ConnectionInfo* ciP, rapidjson::Value::ConstMembe { return "entity id must be a string"; } - eP->id = iter->value.GetString(); + eP->entityId.id = iter->value.GetString(); } if (name == "type") { @@ -330,11 +330,11 @@ static std::string parseEntity(ConnectionInfo* ciP, rapidjson::Value::ConstMembe { return "entity type must be a string"; } - eP->type = iter->value.GetString(); + eP->entityId.type = iter->value.GetString(); } } - if ((eP->id.empty()) || (eP->type.empty())) + if ((eP->entityId.id.empty()) || (eP->entityId.type.empty())) { return "entity must have id and type"; } diff --git a/src/lib/jsonParseV2/parseEntity.cpp b/src/lib/jsonParseV2/parseEntity.cpp index 032b9d16d1..0382d98722 100644 --- a/src/lib/jsonParseV2/parseEntity.cpp +++ b/src/lib/jsonParseV2/parseEntity.cpp @@ -161,9 +161,9 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - eP->id = iter->value.GetString(); + eP->entityId.id = iter->value.GetString(); - if (eP->id.empty()) + if (eP->entityId.id.empty()) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITY_ID, ERROR_BAD_REQUEST); @@ -173,11 +173,11 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdCharsV2(eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.id.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, ERROR_BAD_REQUEST); - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, eP->id); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, eP->entityId.id); ciP->httpStatusCode = SccBadRequest; return oe.toJson(); @@ -205,10 +205,10 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - eP->type = iter->value.GetString(); - eP->typeGiven = true; + eP->entityId.type = iter->value.GetString(); + eP->typeGiven = true; - if (eP->type.empty()) + if (eP->entityId.type.empty()) { const char* errorText = ERROR_DESC_BAD_REQUEST_EMPTY_ENTTYPE; OrionError oe(SccBadRequest, errorText, ERROR_BAD_REQUEST); @@ -219,14 +219,13 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdCharsV2(eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.type.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, ERROR_BAD_REQUEST); - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, eP->type); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, eP->entityId.type); ciP->httpStatusCode = SccBadRequest; - return oe.toJson(); } } else // attribute @@ -269,7 +268,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) if (!eP->typeGiven) { - eP->type = DEFAULT_ENTITY_TYPE; + eP->entityId.type = DEFAULT_ENTITY_TYPE; } return "OK"; diff --git a/src/lib/jsonParseV2/parseEntityObject.cpp b/src/lib/jsonParseV2/parseEntityObject.cpp index 3e9753f69e..0e241d5bb2 100644 --- a/src/lib/jsonParseV2/parseEntityObject.cpp +++ b/src/lib/jsonParseV2/parseEntityObject.cpp @@ -81,9 +81,9 @@ std::string parseEntityObject return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID; } - eP->id = iter->value.GetString(); + eP->entityId.id = iter->value.GetString(); - if (forbiddenIdCharsV2(eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.id.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; } @@ -106,8 +106,7 @@ std::string parseEntityObject } regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - eP->id = iter->value.GetString(); - eP->isPattern = "true"; + eP->entityId.idPattern = iter->value.GetString(); } else if (name == "type") { @@ -116,15 +115,15 @@ std::string parseEntityObject return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE; } - eP->type = iter->value.GetString(); - eP->typeGiven = true; + eP->entityId.type = iter->value.GetString(); + eP->typeGiven = true; - if (eP->type.empty()) + if (eP->entityId.type.empty()) { return ERROR_DESC_BAD_REQUEST_EMPTY_ENTTYPE; } - if (forbiddenIdCharsV2(eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.type.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; } @@ -143,8 +142,7 @@ std::string parseEntityObject } regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - eP->type = iter->value.GetString(); - eP->isTypePattern = true; + eP->entityId.typePattern = iter->value.GetString(); } else { diff --git a/src/lib/jsonParseV2/parseNotification.cpp b/src/lib/jsonParseV2/parseNotification.cpp index ff15d20e46..6b4ff6f660 100644 --- a/src/lib/jsonParseV2/parseNotification.cpp +++ b/src/lib/jsonParseV2/parseNotification.cpp @@ -79,7 +79,8 @@ static bool parseContextElementResponse return false; } - cerP->entity.fill(entity.id, entity.type, entity.isPattern); + EntityId enId(entity.entityId.id, entity.entityId.idPattern, entity.entityId.type, entity.entityId.typePattern); + cerP->entity.fill(enId); cerP->entity.attributeVector.push_back(entity.attributeVector); entity.release(); diff --git a/src/lib/jsonParseV2/parseSubscription.cpp b/src/lib/jsonParseV2/parseSubscription.cpp index 4d5f807000..ca8126ff42 100644 --- a/src/lib/jsonParseV2/parseSubscription.cpp +++ b/src/lib/jsonParseV2/parseSubscription.cpp @@ -524,7 +524,7 @@ static std::string parseCustomPayload return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID); } - ngsi->id = iter->value.GetString(); + ngsi->entityId.id = iter->value.GetString(); } else if (name == "type") { @@ -533,7 +533,7 @@ static std::string parseCustomPayload return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE); } - ngsi->type = iter->value.GetString(); + ngsi->entityId.type = iter->value.GetString(); } else // attribute { diff --git a/src/lib/mongoBackend/MongoCommonSubscription.cpp b/src/lib/mongoBackend/MongoCommonSubscription.cpp index 1374f4d046..2ea5f0d053 100644 --- a/src/lib/mongoBackend/MongoCommonSubscription.cpp +++ b/src/lib/mongoBackend/MongoCommonSubscription.cpp @@ -162,13 +162,13 @@ static void setCustomHttpInfo(const HttpInfo& httpInfo, orion::BSONObjBuilder* b { // id and type (both optional in this case) orion::BSONObjBuilder bob; - if (!httpInfo.ngsi.id.empty()) + if (!httpInfo.ngsi.entityId.id.empty()) { - bob.append(ENT_ENTITY_ID, httpInfo.ngsi.id); + bob.append(ENT_ENTITY_ID, httpInfo.ngsi.entityId.id); } - if (!httpInfo.ngsi.type.empty()) + if (!httpInfo.ngsi.entityId.type.empty()) { - bob.append(ENT_ENTITY_TYPE, httpInfo.ngsi.type); + bob.append(ENT_ENTITY_TYPE, httpInfo.ngsi.entityId.type); } // attributes @@ -234,13 +234,13 @@ static void setCustomMqttInfo(const ngsiv2::MqttInfo& mqttInfo, orion::BSONObjBu { // id and type (both optional in this case) orion::BSONObjBuilder bob; - if (!mqttInfo.ngsi.id.empty()) + if (!mqttInfo.ngsi.entityId.id.empty()) { - bob.append(ENT_ENTITY_ID, mqttInfo.ngsi.id); + bob.append(ENT_ENTITY_ID, mqttInfo.ngsi.entityId.id); } - if (!mqttInfo.ngsi.type.empty()) + if (!mqttInfo.ngsi.entityId.type.empty()) { - bob.append(ENT_ENTITY_TYPE, mqttInfo.ngsi.type); + bob.append(ENT_ENTITY_TYPE, mqttInfo.ngsi.entityId.type); } // attributes diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 63488176fa..c1f4988720 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -1999,8 +1999,8 @@ static unsigned int processSubscriptions std::string keyType = "_id." ENT_ENTITY_TYPE; std::string keySp = "_id." ENT_SERVICE_PATH; - std::string id = notifyCerP->entity.id; - std::string type = notifyCerP->entity.type; + std::string id = notifyCerP->entity.entityId.id; + std::string type = notifyCerP->entity.entityId.type; std::string sp = notifyCerP->entity.servicePath; bobCountQuery.append(keyId, id); @@ -2170,7 +2170,8 @@ static void buildGeneralErrorResponse { ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(ceP->id, ceP->type, ceP->isPattern); + EntityId enId(ceP->entityId.id, ceP->entityId.idPattern, ceP->entityId.type, ceP->entityId.typePattern); + cerP->entity.fill(enId); if (caP != NULL) { @@ -2644,8 +2645,8 @@ static bool processContextAttributeVector OrionError* oe ) { - std::string entityId = cerP->entity.id; - std::string entityType = cerP->entity.type; + std::string entityId = cerP->entity.entityId.id; + std::string entityType = cerP->entity.entityId.type; std::string entityDetail = cerP->entity.toString(); bool entityModified = false; std::vector attrsWithModifiedValue; @@ -2916,15 +2917,15 @@ static bool createEntity orion::BSONObjBuilder bsonIdBuilder; - bsonIdBuilder.append(ENT_ENTITY_ID, eP->id); + bsonIdBuilder.append(ENT_ENTITY_ID, eP->entityId.id); - if (eP->type.empty()) + if (eP->entityId.type.empty()) { bsonIdBuilder.append(ENT_ENTITY_TYPE, DEFAULT_ENTITY_TYPE); } else { - bsonIdBuilder.append(ENT_ENTITY_TYPE, eP->type); + bsonIdBuilder.append(ENT_ENTITY_TYPE, eP->entityId.type); } bsonIdBuilder.append(ENT_SERVICE_PATH, servicePathV[0].empty()? SERVICE_PATH_ROOT : servicePathV[0]); @@ -3477,12 +3478,13 @@ static unsigned int updateEntity std::string entityType = idField.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(idField, ENT_ENTITY_TYPE) : ""; std::string entitySPath = getStringFieldF(idField, ENT_SERVICE_PATH); - EntityId en(entityId, entityType); + EntityId en(entityId, "", entityType, ""); LM_T(LmtServicePath, ("Found entity '%s' in ServicePath '%s'", entityId.c_str(), entitySPath.c_str())); ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(entityId, entityType, "false"); + EntityId enId(entityId, "", entityType, ""); + cerP->entity.fill(enId); /* Build CER used for notifying (if needed) */ StringList emptyAttrL; @@ -3515,8 +3517,8 @@ static unsigned int updateEntity // Note we cannot use eP->type for the type, as it may be blank in the request // (that would break the cases/1494_subscription_alteration_types/sub_alteration_type_entity_delete2.test case) - if (!addTriggeredSubscriptions(notifyCerP->entity.id, - notifyCerP->entity.type, + if (!addTriggeredSubscriptions(notifyCerP->entity.entityId.id, + notifyCerP->entity.entityId.type, attrNames, attrNames, attrNames, @@ -3997,8 +3999,8 @@ static bool contextElementPreconditionsCheck } } - /* Not supporting isPattern = true currently */ - if (isTrue(eP->isPattern)) + /* Not supporting idPattern currently */ + if (!eP->entityId.idPattern.empty()) { buildGeneralErrorResponse(eP, NULL, responseP, SccNotImplemented); // No need of filling responseP->oe, this cannot happen in NGSIv2 @@ -4070,15 +4072,15 @@ unsigned int processContextElement const std::string typeString = "_id." ENT_ENTITY_TYPE; orion::BSONObjBuilder bob; - EntityId en(eP->id, eP->type); - std::string enStr = eP->id; + EntityId en(eP->entityId.id, "", eP->entityId.type, ""); + std::string enStr = eP->entityId.id; - bob.append(idString, eP->id); + bob.append(idString, eP->entityId.id); - if (!eP->type.empty()) + if (!eP->entityId.type.empty()) { - bob.append(typeString, eP->type); - enStr += '/' + eP->type; + bob.append(typeString, eP->entityId.type); + enStr += '/' + eP->entityId.type; } // Service path @@ -4243,7 +4245,8 @@ unsigned int processContextElement /* Creating the common part of the response that doesn't depend on the case */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, "false"); + EntityId enId(eP->entityId.id, "", eP->entityId.type, ""); + cerP->entity.fill(enId); /* All the attributes existing in the request are added to the response with 'found' set to false * in the of UPDATE/DELETE and true in the case of APPEND @@ -4326,8 +4329,8 @@ unsigned int processContextElement attrNames.push_back(eP->attributeVector[ix]->name); } - if (!addTriggeredSubscriptions(eP->id, - eP->type, + if (!addTriggeredSubscriptions(eP->entityId.id, + eP->entityId.type, attrNames, attrNames, attrNames, diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 041dfe0c80..11f00cb648 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -470,12 +470,12 @@ static void fillQueryEntity(orion::BSONObjBuilder* bobP, const EntityId* enP) const std::string idString = "_id." ENT_ENTITY_ID; const std::string typeString = "_id." ENT_ENTITY_TYPE; - if (enP->isPattern == "true") + if (!enP->idPattern.empty()) { // In the case of "universal pattern" we can avoid adding anything (simpler query) - if (enP->id != ".*") + if (enP->idPattern != ".*") { - bobP->appendRegex(idString, enP->id); + bobP->appendRegex(idString, enP->idPattern); } } else @@ -483,17 +483,18 @@ static void fillQueryEntity(orion::BSONObjBuilder* bobP, const EntityId* enP) bobP->append(idString, enP->id); } - if (!enP->type.empty()) + + if (!enP->typePattern.empty()) { - if (enP->isTypePattern) + // In the case of "universal pattern" we can avoid adding anything (simpler query) + if (enP->typePattern != ".*") { - // In the case of "universal pattern" we can avoid adding anything (simpler query) - if (enP->type != ".*") - { - bobP->appendRegex(typeString, enP->type); - } + bobP->appendRegex(typeString, enP->typePattern); } - else + } + else + { + if (!enP->type.empty()) { bobP->append(typeString, enP->type); } @@ -1511,11 +1512,12 @@ bool entitiesQuery // if (enV.size() == 1) { - cer->entity.fill(enV[0]->id, enV[0]->type, enV[0]->isPattern); + cer->entity.fill(enV[0]); } else { - cer->entity.fill("", "", ""); + EntityId enId("", "", "", ""); + cer->entity.fill(enId); } cer->statusCode.fill(SccReceiverInternalError, nextErr); @@ -1547,13 +1549,13 @@ bool entitiesQuery * used before pruning in the CPr calculation logic */ for (unsigned int ix = 0; ix < enV.size(); ++ix) { - if (enV[ix]->isPattern != "true") + if (enV[ix]->idPattern.empty()) { bool needToAdd = true; for (unsigned int jx = 0; jx < cerV->size(); ++jx) { - if (((*cerV)[jx]->entity.id == enV[ix]->id) && ((*cerV)[jx]->entity.type == enV[ix]->type)) + if (((*cerV)[jx]->entity.entityId.id == enV[ix]->id) && ((*cerV)[jx]->entity.entityId.type == enV[ix]->type)) { needToAdd = false; break; /* jx */ @@ -1564,9 +1566,7 @@ bool entitiesQuery { ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.id = enV[ix]->id; - cerP->entity.type = enV[ix]->type; - cerP->entity.isPattern = "false"; + cerP->entity.entityId = enV[ix]; // // This entity has to be pruned if after CPr searching no attribute is "added" to it. @@ -1622,9 +1622,7 @@ void pruneContextElements ContextElementResponse* cerP = oldCerV[ix]; ContextElementResponse* newCerP = new ContextElementResponse(); - newCerP->entity.fill(cerP->entity.id, - cerP->entity.type, - cerP->entity.isPattern, + newCerP->entity.fill(cerP->entity.entityId, cerP->entity.servicePath, cerP->entity.creDate, cerP->entity.modDate); @@ -1722,11 +1720,11 @@ bool registrationsQuery const EntityId* en = enV[ix]; orion::BSONObjBuilder b; - if (isTrue(en->isPattern)) + if (!en->idPattern.empty()) { - b.appendRegex(crEntitiesId, en->id); + b.appendRegex(crEntitiesId, en->idPattern); } - else /* isPattern = false */ + else /* not a pattern */ { b.append(crEntitiesId, en->id); } @@ -2242,13 +2240,13 @@ void cprLookupByAttribute { // By the moment the only supported pattern is .*. In this case matching is // based exclusively in type - if (regEn.type != en.type && !regEn.type.empty()) + if (regEn.type != en.entityId.type && !regEn.type.empty()) { /* No match (keep searching the Registration) */ continue; } } - else if (regEn.id != en.id || (regEn.type != en.type && !regEn.type.empty())) + else if (regEn.id != en.entityId.id || (regEn.type != en.entityId.type && !regEn.type.empty())) { /* No match (keep searching the Registration) */ continue; diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index bfc1cb9726..44daae307e 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -112,7 +112,9 @@ static void addContextProviderEntity { 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)) + // 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) { // Avoid duplicate Provider in the vector if (!lookupProvider(cerV[ix]->entity.providerList, provider)) @@ -127,7 +129,8 @@ static void addContextProviderEntity /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(regEn.idPattern.empty() ? regEn.id : regEn.idPattern, regEn.type, regEn.idPattern.empty()? "false": "true"); + EntityId enId(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); + cerP->entity.fill(enId); cerP->entity.providerList.push_back(provider); cerP->entity.providerRegIdList.push_back(regId); @@ -156,7 +159,7 @@ static void addContextProviderAttribute { for (unsigned int ix = 0; ix < cerV.size(); ++ix) { - if ((cerV[ix]->entity.id != regEn.id) || (cerV[ix]->entity.type != regEn.type)) + if ((cerV[ix]->entity.entityId.id != regEn.id) || (cerV[ix]->entity.entityId.type != regEn.type)) { continue; } @@ -188,7 +191,8 @@ static void addContextProviderAttribute /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(regEn.idPattern.empty() ? regEn.id : regEn.idPattern, regEn.type, regEn.idPattern.empty() ? "false" : "true"); + EntityId enId(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); + cerP->entity.fill(enId); cerP->statusCode.fill(SccOk); ContextAttribute* caP = new ContextAttribute(regAttr, "", ""); @@ -309,7 +313,7 @@ static void processGenericEntities for (unsigned int ix = 0; ix < enV.size(); ++ix) { const EntityId* enP = enV[ix]; - if (enP->type.empty() || isTrue(enP->isPattern)) + if (enP->type.empty() || !enP->idPattern.empty()) { addContextProviders(cerV, regV, limitReached, enP); } diff --git a/src/lib/ngsi/ContextElementResponse.cpp b/src/lib/ngsi/ContextElementResponse.cpp index 8903ff5250..8144c00f1d 100644 --- a/src/lib/ngsi/ContextElementResponse.cpp +++ b/src/lib/ngsi/ContextElementResponse.cpp @@ -61,7 +61,7 @@ ContextElementResponse::ContextElementResponse(EntityId* eP, ContextAttribute* a { prune = false; - entity.fill(eP->id, eP->type, eP->isPattern); + entity.fill(eP); if (aP != NULL) { @@ -105,10 +105,9 @@ ContextElementResponse::ContextElementResponse // Entity orion::BSONObj id = getFieldF(entityDoc, "_id").embeddedObject(); - std::string entityId = getStringFieldF(id, ENT_ENTITY_ID); - std::string entityType = id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : ""; + EntityId entId(getStringFieldF(id, ENT_ENTITY_ID), "", id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : "", ""); - entity.fill(entityId, entityType, "false"); + entity.fill(entId); entity.servicePath = id.hasField(ENT_SERVICE_PATH) ? getStringFieldF(id, ENT_SERVICE_PATH) : ""; /* Get the location attribute (if it exists) */ diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index 53a2ed0c73..50c170034b 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -161,7 +161,7 @@ void ContextElementResponseVector::fill(EntityVector& erV, HttpStatusCode sc) { ContextElementResponse* cerP = new ContextElementResponse(erV[ix]); - cerP->statusCode.fill(sc, erV[ix]->id); + cerP->statusCode.fill(sc, erV[ix]->entityId.id); push_back(cerP); } diff --git a/src/lib/ngsi/EntityId.cpp b/src/lib/ngsi/EntityId.cpp index fce3d3bc94..8cb25ab740 100644 --- a/src/lib/ngsi/EntityId.cpp +++ b/src/lib/ngsi/EntityId.cpp @@ -40,13 +40,11 @@ * * EntityId::EntityId - */ -EntityId::EntityId(): creDate(0), modDate(0) +EntityId::EntityId(): id(""), idPattern(""), type(""), typePattern("") { - isTypePattern = false; } - /* **************************************************************************** * * EntityId::EntityId - @@ -57,6 +55,7 @@ EntityId::EntityId(EntityId* eP) } + /* **************************************************************************** * * EntityId::EntityId - @@ -64,15 +63,13 @@ EntityId::EntityId(EntityId* eP) EntityId::EntityId ( const std::string& _id, + const std::string& _idPattern, const std::string& _type, - const std::string& _isPattern, - bool _isTypePattern + const std::string& _typePattern ) : id(_id), + idPattern(_idPattern), type(_type), - isPattern(_isPattern), - isTypePattern(_isTypePattern), - creDate(0), - modDate(0) + typePattern(_typePattern) { } @@ -87,18 +84,24 @@ std::string EntityId::toJson(void) { JsonObjectHelper jh; - if (isTrue(isPattern)) + if (!this->id.empty()) + { + jh.addString("id", this->id); + } + + if (!this->idPattern.empty()) { - jh.addString("idPattern", id); + jh.addString("idPattern", this->idPattern); } - else + + if (!this->type.empty()) { - jh.addString("id", id); + jh.addString("type", this->type); } - if (!type.empty()) + if (!this->typePattern.empty()) { - jh.addString("type", type); + jh.addString("typePattern", this->typePattern); } return jh.str(); @@ -113,12 +116,9 @@ std::string EntityId::toJson(void) void EntityId::fill(const struct EntityId* eidP, bool useDefaultType) { id = eidP->id; + idPattern = eidP->idPattern; type = eidP->type; - isPattern = eidP->isPattern; - isTypePattern = eidP->isTypePattern; - servicePath = eidP->servicePath; - creDate = eidP->creDate; - modDate = eidP->modDate; + typePattern = eidP->typePattern; if (useDefaultType && (type.empty())) { @@ -130,20 +130,19 @@ void EntityId::fill(const struct EntityId* eidP, bool useDefaultType) /* **************************************************************************** * -* release - +* EntityId::fill - */ -void EntityId::release(void) -{ - /* This method is included for the sake of homogeneity */ -} - - -/* **************************************************************************** -* -* isPatternIsTrue - -*/ -bool EntityId::isPatternIsTrue(void) +void EntityId::fill +( + const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern +) { - return isTrue(isPattern); + id = _id; + idPattern = _idPattern; + type = _type; + typePattern = _typePattern; } diff --git a/src/lib/ngsi/EntityId.h b/src/lib/ngsi/EntityId.h index 8aabcaff5f..ab66bc8655 100644 --- a/src/lib/ngsi/EntityId.h +++ b/src/lib/ngsi/EntityId.h @@ -39,27 +39,40 @@ class EntityId { public: - std::string id; // Mandatory - std::string type; // Optional - std::string isPattern; // Optional - bool isTypePattern; // Used by NGSIv2 API - - std::string servicePath; // Not part of payload, just an internal field - - double creDate; // used by dateCreated functionality in NGSIv2 - double modDate; // used by dateModified functionality in NGSIv2 + std::string id; + std::string idPattern; + std::string type; + std::string typePattern; EntityId(); + EntityId(EntityId* eP); - EntityId(const std::string& _id, - const std::string& _type, - const std::string& _isPattern = "", - bool _isTypePattern = false); + EntityId(const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern); - void fill(const struct EntityId* eidP, bool useDefaultType = false); + bool operator==(const EntityId& e) + { + return (id == e.id) && + (idPattern == e.idPattern) && + (type == e.type) && + (typePattern == e.typePattern); + } + + bool operator!=(const EntityId& e) + { + return (id != e.id) || + (idPattern != e.idPattern) || + (type != e.type) || + (typePattern != e.typePattern); + } - void release(void); - bool isPatternIsTrue(void); + void fill(const struct EntityId* eidP, bool useDefaultType = false); + void fill(const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern); std::string toJson(void); }; diff --git a/src/lib/ngsi/EntityIdVector.cpp b/src/lib/ngsi/EntityIdVector.cpp index 06ce14cd88..9b57ef98bf 100644 --- a/src/lib/ngsi/EntityIdVector.cpp +++ b/src/lib/ngsi/EntityIdVector.cpp @@ -61,27 +61,11 @@ std::string EntityIdVector::toJson(void) * * EntityIdVector::lookup - find a matching entity in the entity-vector */ -EntityId* EntityIdVector::lookup(const std::string& id, const std::string& type, const std::string& isPattern) +EntityId* EntityIdVector::lookup(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern) { - // - // isPattern: "false" or "" is the same - // - std::string isPatternFromParam = isPattern; - if (isPatternFromParam.empty()) - { - isPatternFromParam = "false"; - } - for (unsigned int ix = 0; ix < vec.size(); ++ix) { - std::string isPatternFromVec = vec[ix]->isPattern; - - if (isPatternFromVec.empty()) - { - isPatternFromVec = "false"; - } - - if ((vec[ix]->id == id) && (vec[ix]->type == type) && (isPatternFromVec == isPatternFromParam)) + if ((vec[ix]->id == id) && (vec[ix]->type == type) && (vec[ix]->idPattern == idPattern) && (vec[ix]->typePattern == typePattern)) { return vec[ix]; } @@ -113,7 +97,7 @@ void EntityIdVector::push_back(EntityId* item) */ bool EntityIdVector::push_back_if_absent(EntityId* item) { - if (lookup(item->id, item->type, item->isPattern) == NULL) + if (lookup(item->id, item->idPattern, item->type, item->typePattern) == NULL) { vec.push_back(item); return true; @@ -157,7 +141,6 @@ void EntityIdVector::release(void) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { - vec[ix]->release(); delete(vec[ix]); } @@ -176,7 +159,7 @@ void EntityIdVector::fill(EntityVector& _vec) for (unsigned int ix = 0; ix < _vec.size(); ++ix) { Entity* entityP = _vec[ix]; - EntityId* entityIdP = new EntityId(entityP->id, entityP->type, entityP->isPattern, entityP->isTypePattern); + EntityId* entityIdP = new EntityId(entityP->entityId.id, entityP->entityId.idPattern, entityP->entityId.type, entityP->entityId.typePattern); vec.push_back(entityIdP); } diff --git a/src/lib/ngsi/EntityIdVector.h b/src/lib/ngsi/EntityIdVector.h index 9ca7d88c77..07ae40e1f1 100644 --- a/src/lib/ngsi/EntityIdVector.h +++ b/src/lib/ngsi/EntityIdVector.h @@ -53,7 +53,7 @@ typedef struct EntityIdVector void push_back(EntityId* item); bool push_back_if_absent(EntityId* item); unsigned int size(void) const; - EntityId* lookup(const std::string& name, const std::string& type, const std::string& isPattern); + EntityId* lookup(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern); void release(); void fill(EntityVector& _vec); diff --git a/src/lib/ngsi10/QueryContextRequest.cpp b/src/lib/ngsi10/QueryContextRequest.cpp index 0b89722e30..e2f7e165cf 100644 --- a/src/lib/ngsi10/QueryContextRequest.cpp +++ b/src/lib/ngsi10/QueryContextRequest.cpp @@ -134,9 +134,17 @@ std::string QueryContextRequest::toJsonV1(void) for (unsigned int ix = 0; ix < entityIdVector.size(); ++ix) { JsonObjectHelper jhEntity; - jhEntity.addString("id", entityIdVector[ix]->id); + if (entityIdVector[ix]->idPattern.empty()) + { + jhEntity.addString("id", entityIdVector[ix]->id); + jhEntity.addString("isPattern", "false"); + } + else + { + jhEntity.addString("id", entityIdVector[ix]->idPattern); + jhEntity.addString("isPattern", "true"); + } jhEntity.addString("type", entityIdVector[ix]->type); - jhEntity.addString("isPattern", entityIdVector[ix]->isPattern); jhEntities.addRaw(jhEntity.str()); } @@ -173,13 +181,13 @@ void QueryContextRequest::release(void) void QueryContextRequest::fill ( const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, EntityTypeInfo typeInfo, const std::string& attributeName ) { - EntityId* eidP = new EntityId(entityId, entityType, isPattern); + EntityId* eidP = new EntityId(entityId, entityIdPattern, entityType, ""); entityIdVector.push_back(eidP); @@ -218,7 +226,7 @@ void QueryContextRequest::fill(BatchQuery* bqP) } else { - EntityId* eP = new EntityId(".*", "", "true"); + EntityId* eP = new EntityId("", ".*", "", ""); entityIdVector.push_back(eP); } diff --git a/src/lib/ngsi10/QueryContextRequest.h b/src/lib/ngsi10/QueryContextRequest.h index b64ff809d1..4bfa80785a 100644 --- a/src/lib/ngsi10/QueryContextRequest.h +++ b/src/lib/ngsi10/QueryContextRequest.h @@ -68,8 +68,8 @@ typedef struct QueryContextRequest std::string toJson(void); void release(void); void fill(const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, EntityTypeInfo typeInfo, const std::string& attributeName); void fill(BatchQuery* bqP); diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index 7fea610c4c..8d0c74e5af 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -56,7 +56,7 @@ UpdateContextRequest::UpdateContextRequest(const std::string& _contextProvider, contextProvider = _contextProvider; legacyProviderFormat = _legacyProviderFormat; - Entity* neweP = new Entity(eP->id, eP->type, eP->isPattern); + Entity* neweP = new Entity(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); neweP->renderId = eP->renderId; entityVector.push_back(neweP); } @@ -124,9 +124,17 @@ std::string UpdateContextRequest::toJsonV1(void) JsonObjectHelper jhEntity; Entity* eP = entityVector[ix]; - jhEntity.addString("id", eP->id); - jhEntity.addString("type", eP->type); - jhEntity.addString("isPattern", eP->isPattern); + if (eP->entityId.idPattern.empty()) + { + jhEntity.addString("id", eP->entityId.id); + jhEntity.addString("isPattern", "false"); + } + else + { + jhEntity.addString("id", eP->entityId.idPattern); + jhEntity.addString("isPattern", "true"); + } + jhEntity.addString("type", eP->entityId.type); JsonVectorHelper jhAttributes; for (unsigned int jx = 0; jx < eP->attributeVector.size(); ++jx) @@ -207,15 +215,17 @@ void UpdateContextRequest::release(void) void UpdateContextRequest::fill ( const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, const std::string& attributeName, ActionType _updateActionType ) { Entity* eP = new Entity(); - eP->fill(entityId, entityType, isPattern); + EntityId enId(entityId, entityIdPattern, entityType, ""); + + eP->fill(enId); entityVector.push_back(eP); updateActionType = _updateActionType; @@ -235,7 +245,7 @@ void UpdateContextRequest::fill */ void UpdateContextRequest::fill(const Entity* entP, ActionType _updateActionType) { - Entity* eP = new Entity(entP->id, entP->type, "false"); + Entity* eP = new Entity(entP->entityId.id, "", entP->entityId.type, ""); eP->attributeVector.fill(entP->attributeVector); @@ -257,7 +267,7 @@ void UpdateContextRequest::fill const std::string& type ) { - Entity* eP = new Entity(entityId, type, "false"); + Entity* eP = new Entity(entityId, "", type, ""); ContextAttribute* aP = new ContextAttribute(attributeP); eP->attributeVector.push_back(aP); @@ -286,7 +296,7 @@ void UpdateContextRequest::fill for (unsigned int eIx = 0; eIx < entities->vec.size(); ++eIx) { Entity* eP = entities->vec[eIx]; - Entity* neweP = new Entity(eP->id, eP->type, eP->isPattern); + Entity* neweP = new Entity(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) { @@ -312,7 +322,7 @@ ContextAttribute* UpdateContextRequest::attributeLookup(Entity* eP, const std::s Entity* enP = entityVector[ceIx]; // empty type in request (enP) is always a match - if ((enP->id != eP->id) || ((enP->type != "") && (enP->type != eP->type))) + if ((enP->entityId.id != eP->entityId.id) || ((enP->entityId.type != "") && (enP->entityId.type != eP->entityId.type))) { continue; } diff --git a/src/lib/ngsi10/UpdateContextRequest.h b/src/lib/ngsi10/UpdateContextRequest.h index fb6d7c131a..b51f4039ad 100644 --- a/src/lib/ngsi10/UpdateContextRequest.h +++ b/src/lib/ngsi10/UpdateContextRequest.h @@ -56,8 +56,8 @@ typedef struct UpdateContextRequest ContextAttribute* attributeLookup(Entity* eP, const std::string& attributeName); void fill(const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, const std::string& attributeName, ActionType _updateActionType); diff --git a/src/lib/ngsi10/UpdateContextResponse.cpp b/src/lib/ngsi10/UpdateContextResponse.cpp index 1ede1ddf73..8704d6a23c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.cpp +++ b/src/lib/ngsi10/UpdateContextResponse.cpp @@ -90,7 +90,8 @@ void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, Statu { // Build ContextElementResponse cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, eP->isPattern); + EntityId enId(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); + cerP->entity.fill(enId); if (aP != NULL) { // We copy ContextAttribute given Entity destructor does release() on the vector @@ -103,7 +104,7 @@ void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, Statu } else { - cerP->statusCode.fill(SccContextElementNotFound, eP->id); + cerP->statusCode.fill(SccContextElementNotFound, eP->entityId.id); } contextElementResponseVector.push_back(cerP); @@ -133,7 +134,8 @@ void UpdateContextResponse::foundPush(Entity* eP, ContextAttribute* aP) { // Build ContextElementResponse cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, eP->isPattern); + EntityId enId(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); + cerP->entity.fill(enId); if (aP != NULL) { // We copy ContextAttribute given Entity destructor does release() on the vector diff --git a/src/lib/ngsiNotify/Notifier.cpp b/src/lib/ngsiNotify/Notifier.cpp index b84fd0c70b..795d3c738a 100644 --- a/src/lib/ngsiNotify/Notifier.cpp +++ b/src/lib/ngsiNotify/Notifier.cpp @@ -140,7 +140,9 @@ static bool setPayload NotifyContextRequest ncr; ContextElementResponse cer; - cer.entity.fill(en.id, en.type, en.isPattern, en.servicePath); + EntityId enId(en.entityId.id, en.entityId.idPattern, en.entityId.type, en.entityId.typePattern); + + cer.entity.fill(enId, en.servicePath); // cloneCompount set to true. Otherwise nasty things as the one // described in issue #4263 will happend @@ -262,28 +264,29 @@ static bool setNgsiPayload ContextElementResponse cer; std::string effectiveId; - if (ngsi.id.empty()) + if (ngsi.entityId.id.empty()) { - effectiveId = en.id; + effectiveId = en.entityId.id; } else { // If id is not found in the replacements macro, we use en.id. - effectiveId = removeQuotes(smartStringValue(ngsi.id, exprContextObjectP, '"' + en.id + '"')); + effectiveId = removeQuotes(smartStringValue(ngsi.entityId.id, exprContextObjectP, '"' + en.entityId.id + '"')); } std::string effectiveType; - if (ngsi.type.empty()) + if (ngsi.entityId.type.empty()) { - effectiveType = en.type; + effectiveType = en.entityId.type; } else { // If type is not found in the replacements macro, we use en.type. - effectiveType = removeQuotes(smartStringValue(ngsi.type, exprContextObjectP, '"' + en.type + '"')); + effectiveType = removeQuotes(smartStringValue(ngsi.entityId.type, exprContextObjectP, '"' + en.entityId.type + '"')); } - cer.entity.fill(effectiveId, effectiveType, en.isPattern, en.servicePath); + EntityId entId(effectiveId, "", effectiveType, ""); + cer.entity.fill(entId, en.servicePath); // First we add attributes in the ngsi field, adding calculated expressions to context in order of priority std::vector orderedNgsiAttrs; @@ -375,8 +378,8 @@ static SenderThreadParams* buildSenderParamsCustom // into account that in the case of an attribute with name "service", "servicePath" or "authToken", it must have precedence // over the ones comming from headers of the same name, we conditionally add them depending the case TIME_EXPR_CTXBLD_START(); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); if (!basic) { diff --git a/src/lib/rest/EntityTypeInfo.h b/src/lib/rest/EntityTypeInfo.h index adcdac7047..fc7e09e1f6 100644 --- a/src/lib/rest/EntityTypeInfo.h +++ b/src/lib/rest/EntityTypeInfo.h @@ -31,6 +31,8 @@ /* **************************************************************************** * * EntityTypeInfo - entity::type empty, not empty OR either +* +* FIXME PR: review usage of this class */ typedef enum EntityTypeInfo { diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index f37755d90e..0a2f54f596 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -562,7 +562,7 @@ void postQueryContext for (unsigned int ix = 0 ; ix < qcrsP->contextElementResponseVector.size(); ++ix) { ContextElementResponse* cerP = qcrsP->contextElementResponseVector[ix]; - EntityId en(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + EntityId en(cerP->entity.entityId); // // If a Context Provider has been registered with an empty attribute list for @@ -649,7 +649,6 @@ void postQueryContext pushed = requestP->entityIdVector.push_back_if_absent(entityP); if (pushed == false) { - entityP->release(); delete entityP; } } @@ -775,11 +774,11 @@ void postQueryContext for (unsigned int jx = 0; jx < responseV[ix]->contextElementResponseVector.size(); ++jx) { bool found = false; - EntityId tempEn(responseV[ix]->contextElementResponseVector[jx]->entity.id, responseV[ix]->contextElementResponseVector[jx]->entity.type, "false"); + 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)) + /*if (isTrue(qcrP->entityIdVector[kx]->isPattern)) { entityId.idPattern = qcrP->entityIdVector[kx]->id; } @@ -787,7 +786,12 @@ void postQueryContext { 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)) { diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index a87595e6e5..98da55a087 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -400,7 +400,7 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U { if ((cerP->statusCode.code == SccOk) || (cerP->statusCode.code == SccNone)) { - cerP->statusCode.fill(SccContextElementNotFound, cerP->entity.id); + cerP->statusCode.fill(SccContextElementNotFound, cerP->entity.entityId.id); } } else if ((noOfFounds > 0) && (noOfNotFounds > 0)) @@ -408,12 +408,12 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // Adding a ContextElementResponse for the 'Not-Founds' ContextElementResponse* notFoundCerP = new ContextElementResponse(); - notFoundCerP->entity.fill(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + notFoundCerP->entity.fill(cerP->entity.entityId); // // Filling in StatusCode (SccContextElementNotFound) for NotFound // - notFoundCerP->statusCode.fill(SccContextElementNotFound, cerP->entity.id); + notFoundCerP->statusCode.fill(SccContextElementNotFound, cerP->entity.entityId.id); // // Setting StatusCode to OK for Found @@ -450,7 +450,7 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // if ((cerP->statusCode.code == SccContextElementNotFound) && (cerP->statusCode.details.empty())) { - cerP->statusCode.details = cerP->entity.id; + cerP->statusCode.details = cerP->entity.entityId.id; } } @@ -475,7 +475,7 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U { if (upcrsP->errorCode.code == SccOk) { - upcrsP->errorCode.fill(SccContextElementNotFound, upcrP->entityVector[0]->id); + upcrsP->errorCode.fill(SccContextElementNotFound, upcrP->entityVector[0]->entityId.id); } } } @@ -489,11 +489,11 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U { if (upcrsP->contextElementResponseVector.size() == 1) { - upcrsP->errorCode.details = upcrsP->contextElementResponseVector[0]->entity.id; + upcrsP->errorCode.details = upcrsP->contextElementResponseVector[0]->entity.entityId.id; } else if (upcrsP->contextElementResponseVector.size() == 0) { - upcrsP->errorCode.details = upcrP->entityVector[0]->id; + upcrsP->errorCode.details = upcrP->entityVector[0]->entityId.id; } } } @@ -710,11 +710,11 @@ void postUpdateContext // 3. Lookup ContextElement in UpdateContextRequest according to EntityId. // If not found, add one (to the EntityVector of the UpdateContextRequest). // - Entity* eP = reqP->entityVector.lookup(cerP->entity.id, cerP->entity.type); + Entity* eP = reqP->entityVector.lookup(cerP->entity.entityId.id, cerP->entity.entityId.type); if (eP == NULL) { eP = new Entity(); - eP->fill(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + eP->fill(cerP->entity.entityId); reqP->entityVector.push_back(eP); } @@ -804,7 +804,7 @@ void postUpdateContext } } - failing += cerP->entity.id + "-" + cerP->entity.type + " : [" + failingPerCer + "], "; + failing += cerP->entity.entityId.id + "-" + cerP->entity.entityId.type + " : [" + failingPerCer + "], "; } } diff --git a/src/lib/serviceRoutinesV2/deleteEntity.cpp b/src/lib/serviceRoutinesV2/deleteEntity.cpp index 67a1001560..a9d4d933d0 100644 --- a/src/lib/serviceRoutinesV2/deleteEntity.cpp +++ b/src/lib/serviceRoutinesV2/deleteEntity.cpp @@ -74,9 +74,9 @@ std::string deleteEntity return oe.toJson(); } - eP = new Entity(); - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP = new Entity(); + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; if (compV.size() == 5) // Deleting an attribute { diff --git a/src/lib/serviceRoutinesV2/getEntities.cpp b/src/lib/serviceRoutinesV2/getEntities.cpp index 11e0149052..dc5618bcb0 100644 --- a/src/lib/serviceRoutinesV2/getEntities.cpp +++ b/src/lib/serviceRoutinesV2/getEntities.cpp @@ -272,22 +272,16 @@ std::string getEntities if (!typePattern.empty()) { - bool isIdPattern = (!idPattern.empty() || pattern == ".*"); - EntityId* entityId = new EntityId(pattern, typePattern, isIdPattern ? "true" : "false", true); - + EntityId* entityId = new EntityId("", pattern, "", typePattern); parseDataP->qcr.res.entityIdVector.push_back(entityId); } else if (ciP->uriParamTypes.size() == 0) { - parseDataP->qcr.res.fill(pattern, "", "true", EntityTypeEmptyOrNotEmpty, ""); - } - else if (ciP->uriParamTypes.size() == 1) - { - parseDataP->qcr.res.fill(pattern, type, "true", EntityTypeNotEmpty, ""); + parseDataP->qcr.res.fill("", pattern, "", EntityTypeEmptyOrNotEmpty, ""); } else if (ciP->uriParamTypes.size() == 1) { - parseDataP->qcr.res.fill(pattern, type, "true", EntityTypeNotEmpty, ""); + parseDataP->qcr.res.fill("", pattern, type, EntityTypeNotEmpty, ""); } else { @@ -297,7 +291,7 @@ std::string getEntities // for (unsigned int ix = 0; ix < ciP->uriParamTypes.size(); ++ix) { - EntityId* entityId = new EntityId(pattern, ciP->uriParamTypes[ix], "true"); + EntityId* entityId = new EntityId("", pattern, ciP->uriParamTypes[ix], ""); parseDataP->qcr.res.entityIdVector.push_back(entityId); } diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index a6dd4b25ef..e396612311 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -84,7 +84,7 @@ std::string getEntity } // Fill in QueryContextRequest - parseDataP->qcr.res.fill(entityId, type, "false", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill(entityId, "", type, EntityTypeEmptyOrNotEmpty, ""); // Get attrs and metadata filters from URL params setAttrsFilter(ciP->uriParam, ciP->uriParamOptions, &parseDataP->qcr.res.attrsList); diff --git a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp index 097a4dad4f..545125171e 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp @@ -74,7 +74,7 @@ std::string getEntityAttribute } // 01. Fill in QueryContextRequest - parseDataP->qcr.res.fill(compV[2], type, "false", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill(compV[2], "", type, EntityTypeEmptyOrNotEmpty, ""); // 02. Call standard op postQueryContext OrionError oe; diff --git a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp index 60232b2264..c41899896f 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp @@ -76,7 +76,7 @@ std::string getEntityAttributeValue } // Fill in QueryContextRequest - parseDataP->qcr.res.fill(compV[2], type, "false", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill("", compV[2], type, EntityTypeEmptyOrNotEmpty, ""); // Call standard op postQueryContext OrionError oe; diff --git a/src/lib/serviceRoutinesV2/patchEntity.cpp b/src/lib/serviceRoutinesV2/patchEntity.cpp index 15f059a01c..6cfc8ac7e1 100644 --- a/src/lib/serviceRoutinesV2/patchEntity.cpp +++ b/src/lib/serviceRoutinesV2/patchEntity.cpp @@ -69,10 +69,10 @@ std::string patchEntity std::string answer = ""; Entity* eP = &parseDataP->ent.res; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; - if (forbiddenIdCharsV2(eP->id.c_str() , NULL)) + if (forbiddenIdCharsV2(eP->entityId.id.c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/postEntities.cpp b/src/lib/serviceRoutinesV2/postEntities.cpp index 00ce0ad4ed..eb9ead16ce 100644 --- a/src/lib/serviceRoutinesV2/postEntities.cpp +++ b/src/lib/serviceRoutinesV2/postEntities.cpp @@ -51,7 +51,7 @@ static const int STRUCTURAL_OVERHEAD_BSON_ID = 10; static bool legalEntityLength(Entity* eP, const std::string& servicePath) { - return (servicePath.size() + eP->id.size() + eP->type.size() + STRUCTURAL_OVERHEAD_BSON_ID) < 1024; + return (servicePath.size() + eP->entityId.id.size() + eP->entityId.type.size() + STRUCTURAL_OVERHEAD_BSON_ID) < 1024; } @@ -139,10 +139,10 @@ std::string postEntities else { // Prepare HTTP headers - std::string location = "/v2/entities/" + eP->id; - if (!eP->type.empty()) + std::string location = "/v2/entities/" + eP->entityId.id; + if (!eP->entityId.type.empty()) { - location += "?type=" + eP->type; + location += "?type=" + eP->entityId.type; } else { diff --git a/src/lib/serviceRoutinesV2/postEntity.cpp b/src/lib/serviceRoutinesV2/postEntity.cpp index 2de3d59941..88b4ed94dd 100644 --- a/src/lib/serviceRoutinesV2/postEntity.cpp +++ b/src/lib/serviceRoutinesV2/postEntity.cpp @@ -65,8 +65,8 @@ std::string postEntity Entity* eP = &parseDataP->ent.res; ActionType op; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { diff --git a/src/lib/serviceRoutinesV2/putEntity.cpp b/src/lib/serviceRoutinesV2/putEntity.cpp index e42af8a1f0..7ac9c38889 100644 --- a/src/lib/serviceRoutinesV2/putEntity.cpp +++ b/src/lib/serviceRoutinesV2/putEntity.cpp @@ -68,8 +68,8 @@ std::string putEntity { Entity* eP = &parseDataP->ent.res; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { diff --git a/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test b/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test index 3c4d38535f..235d61b132 100644 --- a/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test +++ b/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test @@ -100,10 +100,10 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 83 +Content-Length: 93 { - "description": "entity id length: 0, min length supported: 1", + "description": "id and idPattern cannot be both empty at the same time", "error": "BadRequest" } diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test index c2f2098446..8a36c3d8ba 100644 --- a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test @@ -272,9 +272,9 @@ Content-Length: 44 07. Check three forwarded requests in logs ========================================== -Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/queryContext, request payload (88 bytes): {"entities":[{"id":"ConferenceRoom","type":"Room","isPattern":"false"}],"attributes":[]}, response payload (3912 bytes): -Request forwarded (regId: REG2_ID): POST http://localhost:9997/cpr/queryContext, request payload (89 bytes): {"entities":[{"id":"ConferenceRoom2","type":"Room","isPattern":"false"}],"attributes":[]}, response payload (3912 bytes): -Request forwarded (regId: REG3_ID): POST http://localhost:9997/cpr/queryContext, request payload (99 bytes): {"entities":[{"id":"ConferenceRoom3","type":"Room","isPattern":"false"}],"attributes":["pressure"]}, response payload (3912 bytes): +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/queryContext, request payload (88 bytes): {"entities":[{"id":"ConferenceRoom","isPattern":"false","type":"Room"}],"attributes":[]}, response payload (3912 bytes): +Request forwarded (regId: REG2_ID): POST http://localhost:9997/cpr/queryContext, request payload (89 bytes): {"entities":[{"id":"ConferenceRoom2","isPattern":"false","type":"Room"}],"attributes":[]}, response payload (3912 bytes): +Request forwarded (regId: REG3_ID): POST http://localhost:9997/cpr/queryContext, request payload (99 bytes): {"entities":[{"id":"ConferenceRoom3","isPattern":"false","type":"Room"}],"attributes":["pressure"]}, response payload (3912 bytes): --TEARDOWN-- diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test index eb25ee3ec2..83fbb38ce1 100644 --- a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test @@ -133,7 +133,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) 03. Check one forwarded requests in logs ======================================== -Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","type":"Room","isPattern":"false","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3899 bytes): { +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","isPattern":"false","type":"Room","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3899 bytes): { --TEARDOWN-- diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test index 858cfc0f25..af02a8aad8 100644 --- a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test @@ -154,7 +154,7 @@ Raising alarm ForwardingError localhost:9997/cprfail/updateContext: error parsin 04. Check one forwarded requests in logs ======================================== -Request forwarded (regId: REG1_ID): POST http://localhost:9997/cprfail/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","type":"Room","isPattern":"false","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3188 bytes): { +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cprfail/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","isPattern":"false","type":"Room","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3188 bytes): { --TEARDOWN-- diff --git a/test/unittests/apiTypesV2/EntityVector_test.cpp b/test/unittests/apiTypesV2/EntityVector_test.cpp index 6c3fd8660f..99351710cb 100644 --- a/test/unittests/apiTypesV2/EntityVector_test.cpp +++ b/test/unittests/apiTypesV2/EntityVector_test.cpp @@ -45,8 +45,8 @@ TEST(EntityVector, render) rendered = eV.toJson(NGSI_V2_NORMALIZED); EXPECT_STREQ("[]", rendered.c_str()); - eP->id = "E_ID"; - eP->type = "E_TYPE"; + eP->entityId.id = "E_ID"; + eP->entityId.type = "E_TYPE"; eV.push_back(eP); rendered = eV.toJson(NGSI_V2_NORMALIZED); diff --git a/test/unittests/apiTypesV2/Entity_test.cpp b/test/unittests/apiTypesV2/Entity_test.cpp index 01960cb6eb..8fbdcc94db 100644 --- a/test/unittests/apiTypesV2/Entity_test.cpp +++ b/test/unittests/apiTypesV2/Entity_test.cpp @@ -43,34 +43,34 @@ TEST(Entity, check) utInit(); Entity* enP = new Entity(); - enP->id = "E"; - enP->type = "T"; - enP->isPattern = "false"; - enP->isTypePattern = false; + enP->entityId.id = "E"; + enP->entityId.type = "T"; ContextAttribute* caP = new ContextAttribute("A", "T", "val"); enP->attributeVector.push_back(caP); EXPECT_EQ("OK", enP->check(EntitiesRequest)); - enP->id = ""; - EXPECT_EQ("entity id length: 0, min length supported: 1", enP->check(EntitiesRequest)); + enP->entityId.id = ""; + EXPECT_EQ("id and idPattern cannot be both empty at the same time", enP->check(EntitiesRequest)); - enP->id = "E<1>"; + enP->entityId.id = "E<1>"; EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, enP->check(EntitiesRequest)); - enP->isPattern = "true"; + + enP->entityId.idPattern = "E<1>"; + enP->entityId.id = ""; EXPECT_EQ("OK", enP->check(EntitiesRequest)); - enP->id = "E"; - enP->isPattern = "false"; - enP->type = "T<1>"; + enP->entityId.id = "E"; + enP->entityId.idPattern = ""; + + enP->entityId.type = "T<1>"; + enP->typeGiven = true; EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, enP->check(EntitiesRequest)); - enP->isTypePattern = true; - EXPECT_EQ("OK", enP->check(EntitiesRequest)); - enP->type = "T"; - enP->isPattern = ""; - EXPECT_EQ("Invalid value for isPattern", enP->check(EntitiesRequest)); + enP->entityId.typePattern = "T<1>"; + enP->entityId.type = ""; + EXPECT_EQ("OK", enP->check(EntitiesRequest)); delete enP; @@ -88,23 +88,24 @@ TEST(Entity, checkV1) { utInit(); - Entity* enP = new Entity(); + Entity* enP = new Entity(); - enP->id = ""; - EXPECT_EQ(enP->check(BatchUpdateRequest), "entity id length: 0, min length supported: 1"); + enP->entityId.id = ""; + EXPECT_EQ(enP->check(BatchUpdateRequest), "id and idPattern cannot be both empty at the same time"); - enP->id = "id"; + enP->entityId.id = "id"; enP->typeGiven = true; - EXPECT_EQ(enP->check(BatchUpdateRequest), "entity type length: 0, min length supported: 1"); + EXPECT_EQ(enP->check(BatchUpdateRequest), "type and typePattern cannot be both empty at the same time"); ContextAttribute* aP = new ContextAttribute(); aP->name = ""; aP->stringValue = "V"; enP->attributeVector.push_back(aP); - EXPECT_EQ(enP->check(BatchUpdateRequest), "entity type length: 0, min length supported: 1"); + EXPECT_EQ(enP->check(BatchUpdateRequest), "type and typePattern cannot be both empty at the same time"); aP->name = "name"; - Entity* en2P = new Entity("id", "", "false"); + Entity* en2P = new Entity("id", "", "", ""); + en2P->renderId = true; EntityVector* ceVectorP = new EntityVector(); diff --git a/test/unittests/common/commonMacroSubstitute_test.cpp b/test/unittests/common/commonMacroSubstitute_test.cpp index 90011a3708..2b079770c1 100644 --- a/test/unittests/common/commonMacroSubstitute_test.cpp +++ b/test/unittests/common/commonMacroSubstitute_test.cpp @@ -39,7 +39,7 @@ */ TEST(commonMacroSubstitute, simple) { - Entity en("E1", "T1", "false"); + Entity en("E1", "", "T1", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); bool b; @@ -50,8 +50,8 @@ TEST(commonMacroSubstitute, simple) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -67,7 +67,7 @@ TEST(commonMacroSubstitute, simple) */ TEST(commonMacroSubstitute, withRealloc) { - Entity en("E1", "T1", "false"); + Entity en("E1", "", "T1", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); bool b; @@ -92,8 +92,8 @@ TEST(commonMacroSubstitute, withRealloc) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -112,7 +112,7 @@ TEST(commonMacroSubstitute, withRealloc) TEST(commonMacroSubstitute, bufferTooBigInitially) { bool b; - Entity en("EntityId000001", "EntityType000001", "false"); + Entity en("EntityId000001", "", "EntityType000001", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); en.attributeVector.push_back(caP); @@ -127,8 +127,8 @@ TEST(commonMacroSubstitute, bufferTooBigInitially) std::string result; ExprContextObject exprContext; - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -152,7 +152,7 @@ TEST(commonMacroSubstitute, bufferTooBigInitially) TEST(commonMacroSubstitute, bufferTooBigAfterSubstitution) { bool b; - Entity en("EntityId000001", "EntityType000001", "false"); + Entity en("EntityId000001", "", "EntityType000001", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); en.attributeVector.push_back(caP); @@ -168,8 +168,8 @@ TEST(commonMacroSubstitute, bufferTooBigAfterSubstitution) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); diff --git a/test/unittests/ngsi/ContextElementResponseVector_test.cpp b/test/unittests/ngsi/ContextElementResponseVector_test.cpp index c892f347a9..5f4ccd78e9 100644 --- a/test/unittests/ngsi/ContextElementResponseVector_test.cpp +++ b/test/unittests/ngsi/ContextElementResponseVector_test.cpp @@ -49,9 +49,8 @@ TEST(ContextElementResponseVector, render) out = cerv.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); EXPECT_STREQ("[]", out.c_str()); - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; + cer.entity.entityId.id = "ID"; + cer.entity.entityId.type = "Type"; cer.statusCode.fill(SccOk, "details"); utExit(); diff --git a/test/unittests/ngsi/ContextElementResponse_test.cpp b/test/unittests/ngsi/ContextElementResponse_test.cpp index 2a5f21cc32..940ed68d38 100644 --- a/test/unittests/ngsi/ContextElementResponse_test.cpp +++ b/test/unittests/ngsi/ContextElementResponse_test.cpp @@ -45,9 +45,8 @@ TEST(ContextElementResponse, render) std::vector emptyV; - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; + cer.entity.entityId.id = "ID"; + cer.entity.entityId.type = "Type"; cer.statusCode.fill(SccOk, "details"); diff --git a/test/unittests/ngsi10/NotifyContextRequest_test.cpp b/test/unittests/ngsi10/NotifyContextRequest_test.cpp index 0241489575..b11800d705 100644 --- a/test/unittests/ngsi10/NotifyContextRequest_test.cpp +++ b/test/unittests/ngsi10/NotifyContextRequest_test.cpp @@ -63,7 +63,8 @@ TEST(NotifyContextRequest, json_render) // 2. With ContextResponseList cerP = new ContextElementResponse(); - cerP->entity.fill("E01", "EType", "false"); + EntityId enId1("E01", "", "EType", ""); + cerP->entity.fill(enId1); ncrP->contextElementResponseVector.push_back(cerP); cerP->statusCode.fill(SccOk); @@ -74,7 +75,8 @@ TEST(NotifyContextRequest, json_render) // 3. ContextResponseList with two instances cerP = new ContextElementResponse(); - cerP->entity.fill("E02", "EType", "false"); + EntityId enId2("E02", "", "EType", ""); + cerP->entity.fill(enId2); ncrP->contextElementResponseVector.push_back(cerP); cerP->statusCode.fill(SccOk); diff --git a/test/unittests/testData/ngsi.entityId.render.middle.json b/test/unittests/testData/ngsi.entityId.render.middle.json index d99cfc28a1..9e26dfeeb6 100644 --- a/test/unittests/testData/ngsi.entityId.render.middle.json +++ b/test/unittests/testData/ngsi.entityId.render.middle.json @@ -1 +1 @@ -{"id":""} \ No newline at end of file +{} \ No newline at end of file diff --git a/test/unittests/testInit.cpp b/test/unittests/testInit.cpp index dc2acbfc75..1b3c6cfb02 100644 --- a/test/unittests/testInit.cpp +++ b/test/unittests/testInit.cpp @@ -85,24 +85,7 @@ void setupDatabase(void) */ static bool equalEntity(EntityId enExpected, EntityId enArg) { - LM_M(("enArg '%s', '%s', '%s'", - enArg.id.c_str(), - enArg.type.c_str(), - enArg.isPattern.c_str())); - - LM_M(("enExpected '%s', '%s', '%s'", - enExpected.id.c_str(), - enExpected.type.c_str(), - enExpected.isPattern.c_str())); - - if (enExpected.id == enArg.id && enExpected.type == enArg.type && enExpected.isPattern == enArg.isPattern) - { - return true; - } - else - { - return false; - } + return (enExpected == enArg); } @@ -226,8 +209,8 @@ static bool equalContextElementResponseVector ContextElementResponse* cerArg = cerArgV[ix]; ContextElementResponse* cerExpected = cerExpectedV[jx]; - EntityId enExpected(cerExpected->entity.id, cerExpected->entity.type); - EntityId enArg(cerArg->entity.id, cerArg->entity.type); + EntityId enExpected(cerExpected->entity.entityId.id, cerExpected->entity.entityId.idPattern, cerExpected->entity.entityId.type, cerExpected->entity.entityId.typePattern); + EntityId enArg(cerArg->entity.entityId.id, cerArg->entity.entityId.idPattern, cerArg->entity.entityId.type, cerArg->entity.entityId.typePattern); if (!equalEntity(enExpected, enArg)) {