From b50c413398dcef6b2b0349d1be7a4df1321e965d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 5 Sep 2024 19:34:36 +0200 Subject: [PATCH] REMOVE redundant Entities class (in favour of EntityVector) --- src/lib/apiTypesV2/BatchQuery.h | 5 +- src/lib/apiTypesV2/BatchUpdate.h | 5 +- src/lib/apiTypesV2/CMakeLists.txt | 2 - src/lib/apiTypesV2/Entities.cpp | 146 ------------------ src/lib/apiTypesV2/Entities.h | 67 -------- src/lib/jsonParseV2/parseEntitiesResponse.cpp | 3 +- src/lib/jsonParseV2/parseEntitiesResponse.h | 3 +- .../jsonParseV2/parseEntitiesResponseV1.cpp | 3 +- src/lib/jsonParseV2/parseEntitiesResponseV1.h | 5 +- src/lib/jsonParseV2/parseEntityVector.cpp | 4 +- src/lib/jsonParseV2/parseEntityVector.h | 3 +- src/lib/ngsi10/QueryContextRequest.cpp | 2 +- src/lib/ngsi10/QueryContextResponse.cpp | 6 +- src/lib/ngsi10/QueryContextResponse.h | 3 +- src/lib/ngsi10/UpdateContextRequest.cpp | 4 +- src/lib/ngsi10/UpdateContextRequest.h | 3 +- src/lib/serviceRoutines/postQueryContext.cpp | 2 +- src/lib/serviceRoutines/postUpdateContext.cpp | 4 +- src/lib/serviceRoutinesV2/deleteEntity.cpp | 1 - src/lib/serviceRoutinesV2/getEntities.cpp | 72 ++++++++- src/lib/serviceRoutinesV2/getEntity.cpp | 1 - src/lib/serviceRoutinesV2/patchEntity.cpp | 1 - src/lib/serviceRoutinesV2/postBatchQuery.cpp | 71 ++++++++- src/lib/serviceRoutinesV2/postBatchUpdate.cpp | 3 +- src/lib/serviceRoutinesV2/postEntities.cpp | 1 - src/lib/serviceRoutinesV2/postEntity.cpp | 1 - src/lib/serviceRoutinesV2/putEntity.cpp | 1 - 27 files changed, 163 insertions(+), 259 deletions(-) delete mode 100644 src/lib/apiTypesV2/Entities.cpp delete mode 100644 src/lib/apiTypesV2/Entities.h diff --git a/src/lib/apiTypesV2/BatchQuery.h b/src/lib/apiTypesV2/BatchQuery.h index 48a3b5df64..74ca63a318 100644 --- a/src/lib/apiTypesV2/BatchQuery.h +++ b/src/lib/apiTypesV2/BatchQuery.h @@ -31,7 +31,8 @@ #include "ngsi/StringList.h" #include "ngsi/Request.h" #include "ngsi/ScopeVector.h" -#include "apiTypesV2/Entities.h" + +#include "apiTypesV2/EntityVector.h" @@ -42,7 +43,7 @@ class BatchQuery { public: - Entities entities; + EntityVector entities; StringList attributeV; // Deprecated StringList attrsV; ScopeVector scopeV; diff --git a/src/lib/apiTypesV2/BatchUpdate.h b/src/lib/apiTypesV2/BatchUpdate.h index 2d2282d6d0..26215d23a4 100644 --- a/src/lib/apiTypesV2/BatchUpdate.h +++ b/src/lib/apiTypesV2/BatchUpdate.h @@ -30,7 +30,8 @@ #include "orionTypes/UpdateActionType.h" #include "ngsi/Request.h" -#include "apiTypesV2/Entities.h" + +#include "apiTypesV2/EntityVector.h" @@ -42,7 +43,7 @@ class BatchUpdate { public: ActionType updateActionType; // Mandatory - Entities entities; // Mandatory + EntityVector entities; // Mandatory BatchUpdate(); ~BatchUpdate(); diff --git a/src/lib/apiTypesV2/CMakeLists.txt b/src/lib/apiTypesV2/CMakeLists.txt index d9f70c96cd..33f68bc7d5 100644 --- a/src/lib/apiTypesV2/CMakeLists.txt +++ b/src/lib/apiTypesV2/CMakeLists.txt @@ -23,7 +23,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES Entity.cpp EntityVector.cpp - Entities.cpp Subscription.cpp Registration.cpp BatchQuery.cpp @@ -35,7 +34,6 @@ SET (SOURCES SET (HEADERS Entity.h EntityVector.h - Entities.h Subscription.h Registration.h BatchQuery.h diff --git a/src/lib/apiTypesV2/Entities.cpp b/src/lib/apiTypesV2/Entities.cpp deleted file mode 100644 index 12a83c7a51..0000000000 --- a/src/lib/apiTypesV2/Entities.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "ngsi10/QueryContextResponse.h" -#include "apiTypesV2/Entities.h" - - - -/* **************************************************************************** -* -* Entities::Entities - -*/ -Entities::Entities() -{ -} - - - -/* **************************************************************************** -* -* Entities::~Entities - -*/ -Entities::~Entities() -{ - release(); -} - - - -/* **************************************************************************** -* -* Entities::toJson - -* -*/ -std::string Entities::toJson -( - RenderFormat renderFormat, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter -) -{ - return vec.toJson(renderFormat, attrsFilter, blacklist, metadataFilter); -} - - - - -/* **************************************************************************** -* -* Entities::release - -*/ -void Entities::release(void) -{ - vec.release(); -} - - - -/* **************************************************************************** -* -* Entities::fill - -* -* NOTE -* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. -* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be -* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). -* Other values for "details" are lost as well, if errorCode::code equals SccOk. -*/ -void Entities::fill(const QueryContextResponse& qcrs, OrionError* oeP) -{ - if (qcrs.errorCode.code == SccContextElementNotFound) - { - // - // If no entities are found, we respond with a 200 OK - // and an empty vector of entities ( [] ) - // - - oeP->fill(SccOk, "", "OK"); - return; - } - else if (qcrs.errorCode.code != SccOk) - { - // - // If any other error - use the error for the response - // - - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); - return; - } - - for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) - { - Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; - StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; - - if (scP->code == SccReceiverInternalError) - { - // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't - // think so, as the releasing logic in the upper layer will deal with that but - // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite - // cannot help here and it is better to ensure) - oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); - vec.release(); - return; - } - else - { - Entity* newP = new Entity(); - - 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/Entities.h b/src/lib/apiTypesV2/Entities.h deleted file mode 100644 index bfa6600b90..0000000000 --- a/src/lib/apiTypesV2/Entities.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SRC_LIB_APITYPESV2_ENTITIES_H_ -#define SRC_LIB_APITYPESV2_ENTITIES_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "apiTypesV2/EntityVector.h" -#include "rest/OrionError.h" - - - -/* **************************************************************************** -* -* To avoid a problematic and not necessary include -*/ -struct QueryContextResponse; - - - -/* **************************************************************************** -* -* Entities - -*/ -class Entities -{ - public: - EntityVector vec; // Mandatory - - Entities(); - ~Entities(); - - std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter); - - void release(void); - void fill(const QueryContextResponse& qcrs, OrionError* oeP); - int size(void) const { return vec.vec.size(); } -}; - -#endif // SRC_LIB_APITYPESV2_ENTITIES_H_ diff --git a/src/lib/jsonParseV2/parseEntitiesResponse.cpp b/src/lib/jsonParseV2/parseEntitiesResponse.cpp index 14878152d4..3c714efd3c 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponse.cpp +++ b/src/lib/jsonParseV2/parseEntitiesResponse.cpp @@ -33,7 +33,6 @@ #include "common/errorMessages.h" #include "alarmMgr/AlarmManager.h" #include "alarmMgr/alarmMgr.h" -#include "apiTypesV2/Entities.h" #include "rest/ConnectionInfo.h" #include "rest/OrionError.h" #include "jsonParseV2/parseEntityObject.h" @@ -55,7 +54,7 @@ * of forwarded request so maybe it can be simplified) * */ -bool parseEntitiesResponse(ConnectionInfo* ciP, const char* payload, Entities* evP, OrionError* oeP) +bool parseEntitiesResponse(ConnectionInfo* ciP, const char* payload, EntityVector* evP, OrionError* oeP) { rapidjson::Document document; diff --git a/src/lib/jsonParseV2/parseEntitiesResponse.h b/src/lib/jsonParseV2/parseEntitiesResponse.h index d36e124753..6714128437 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponse.h +++ b/src/lib/jsonParseV2/parseEntitiesResponse.h @@ -31,7 +31,6 @@ #include "rapidjson/document.h" #include "rest/ConnectionInfo.h" -#include "apiTypesV2/Entities.h" @@ -43,7 +42,7 @@ extern bool parseEntitiesResponse ( ConnectionInfo* ciP, const char* payload, - Entities* evP, + EntityVector* evP, OrionError* oeP ); diff --git a/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp index 0ce8f5e026..0e0157df43 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp +++ b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp @@ -33,7 +33,6 @@ #include "common/errorMessages.h" #include "alarmMgr/AlarmManager.h" #include "alarmMgr/alarmMgr.h" -#include "apiTypesV2/Entities.h" #include "rest/ConnectionInfo.h" #include "rest/OrionError.h" #include "jsonParseV2/jsonParseTypeNames.h" @@ -413,7 +412,7 @@ static std::string parseEntity(ConnectionInfo* ciP, rapidjson::Value::ConstMembe * } * */ -bool parseEntitiesResponseV1(ConnectionInfo* ciP, const char* payload, Entities* evP, OrionError* oeP) +bool parseEntitiesResponseV1(ConnectionInfo* ciP, const char* payload, EntityVector* evP, OrionError* oeP) { rapidjson::Document document; diff --git a/src/lib/jsonParseV2/parseEntitiesResponseV1.h b/src/lib/jsonParseV2/parseEntitiesResponseV1.h index 49e7644dcc..5eca35ba68 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponseV1.h +++ b/src/lib/jsonParseV2/parseEntitiesResponseV1.h @@ -31,7 +31,8 @@ #include "rapidjson/document.h" #include "rest/ConnectionInfo.h" -#include "apiTypesV2/Entities.h" + +#include "apiTypesV2/EntityVector.h" @@ -43,7 +44,7 @@ extern bool parseEntitiesResponseV1 ( ConnectionInfo* ciP, const char* payload, - Entities* evP, + EntityVector* evP, OrionError* oeP ); diff --git a/src/lib/jsonParseV2/parseEntityVector.cpp b/src/lib/jsonParseV2/parseEntityVector.cpp index 14dd8f1854..cab50317dc 100644 --- a/src/lib/jsonParseV2/parseEntityVector.cpp +++ b/src/lib/jsonParseV2/parseEntityVector.cpp @@ -30,7 +30,7 @@ #include "ngsi/ContextAttribute.h" -#include "apiTypesV2/Entities.h" +#include "apiTypesV2/EntityVector.h" #include "rest/ConnectionInfo.h" #include "jsonParseV2/jsonParseTypeNames.h" #include "jsonParseV2/parseEntityObject.h" @@ -46,7 +46,7 @@ std::string parseEntityVector ( ConnectionInfo* ciP, const rapidjson::Value::ConstMemberIterator& iter, - Entities* evP, + EntityVector* evP, bool idPatternAllowed, bool attributesAllowed ) diff --git a/src/lib/jsonParseV2/parseEntityVector.h b/src/lib/jsonParseV2/parseEntityVector.h index 92f09de906..9a51a3c96f 100644 --- a/src/lib/jsonParseV2/parseEntityVector.h +++ b/src/lib/jsonParseV2/parseEntityVector.h @@ -29,7 +29,6 @@ #include "rapidjson/document.h" -#include "apiTypesV2/Entities.h" #include "rest/ConnectionInfo.h" @@ -42,7 +41,7 @@ extern std::string parseEntityVector ( ConnectionInfo* ciP, const rapidjson::Value::ConstMemberIterator& iter, - Entities* evP, + EntityVector* evP, bool idPatternAllowed, bool attributesAllowed ); diff --git a/src/lib/ngsi10/QueryContextRequest.cpp b/src/lib/ngsi10/QueryContextRequest.cpp index e2f7e165cf..196349d857 100644 --- a/src/lib/ngsi10/QueryContextRequest.cpp +++ b/src/lib/ngsi10/QueryContextRequest.cpp @@ -222,7 +222,7 @@ void QueryContextRequest::fill(BatchQuery* bqP) { if (bqP->entities.vec.size() != 0) { - entityIdVector.fill(bqP->entities.vec); + entityIdVector.fill(bqP->entities); } else { diff --git a/src/lib/ngsi10/QueryContextResponse.cpp b/src/lib/ngsi10/QueryContextResponse.cpp index 5cac915f90..c3b87ff0e7 100644 --- a/src/lib/ngsi10/QueryContextResponse.cpp +++ b/src/lib/ngsi10/QueryContextResponse.cpp @@ -74,11 +74,11 @@ void QueryContextResponse::release(void) * * QueryContextResponse::fill - */ -void QueryContextResponse::fill(const Entities& entities) +void QueryContextResponse::fill(const EntityVector& entities) { - for (int eIx = 0; eIx < entities.size(); eIx++) + for (unsigned int eIx = 0; eIx < entities.vec.size(); eIx++) { - ContextElementResponse* cerP = new ContextElementResponse(entities.vec.vec[eIx]); + ContextElementResponse* cerP = new ContextElementResponse(entities.vec[eIx]); contextElementResponseVector.push_back(cerP); } } diff --git a/src/lib/ngsi10/QueryContextResponse.h b/src/lib/ngsi10/QueryContextResponse.h index 1123f12016..3e36be0d39 100644 --- a/src/lib/ngsi10/QueryContextResponse.h +++ b/src/lib/ngsi10/QueryContextResponse.h @@ -30,7 +30,6 @@ #include #include "ngsi/ContextElementResponseVector.h" -#include "apiTypesV2/Entities.h" #include "ngsi/StatusCode.h" @@ -52,7 +51,7 @@ typedef struct QueryContextResponse ~QueryContextResponse(); void release(void); - void fill(const Entities& entities); + void fill(const EntityVector& entities); ContextAttribute* getAttr(const std::string& attrName, OrionError* oeP); } QueryContextResponse; diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index 8d0c74e5af..435a61781b 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -287,8 +287,8 @@ void UpdateContextRequest::fill */ void UpdateContextRequest::fill ( - Entities* entities, - ActionType _updateActionType + EntityVector* entities, + ActionType _updateActionType ) { updateActionType = _updateActionType; diff --git a/src/lib/ngsi10/UpdateContextRequest.h b/src/lib/ngsi10/UpdateContextRequest.h index b51f4039ad..14d70483c4 100644 --- a/src/lib/ngsi10/UpdateContextRequest.h +++ b/src/lib/ngsi10/UpdateContextRequest.h @@ -31,7 +31,6 @@ #include "apiTypesV2/EntityVector.h" #include "orionTypes/UpdateActionType.h" #include "apiTypesV2/Entity.h" -#include "apiTypesV2/Entities.h" @@ -67,7 +66,7 @@ typedef struct UpdateContextRequest ActionType _updateActionType, const std::string& type = ""); - void fill(Entities* entities, ActionType _updateActionType); + void fill(EntityVector* entities, ActionType _updateActionType); } UpdateContextRequest; #endif // SRC_LIB_NGSI10_UPDATECONTEXTREQUEST_H_ diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index 9cf63a0393..fe2771434c 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -371,7 +371,7 @@ static bool queryForward } bool result; - Entities entities; + EntityVector entities; OrionError oe; // Depending NGSIv1 or NGSIv2 in the CPr we use parseEntitiesResponseV1() or parseEntitiesResponseV2() diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index 98da55a087..80a07a8f26 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -259,8 +259,8 @@ static bool updateForward // 4. Parse the response and fill in a binary UpdateContextResponse // bool result; - Entities entities; - OrionError oe; + EntityVector entities; + OrionError oe; cleanPayload = jsonPayloadClean(out.c_str()); diff --git a/src/lib/serviceRoutinesV2/deleteEntity.cpp b/src/lib/serviceRoutinesV2/deleteEntity.cpp index a9d4d933d0..b0065a3b4d 100644 --- a/src/lib/serviceRoutinesV2/deleteEntity.cpp +++ b/src/lib/serviceRoutinesV2/deleteEntity.cpp @@ -31,7 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/OrionError.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/deleteEntity.h" diff --git a/src/lib/serviceRoutinesV2/getEntities.cpp b/src/lib/serviceRoutinesV2/getEntities.cpp index dc5618bcb0..aa41db5f54 100644 --- a/src/lib/serviceRoutinesV2/getEntities.cpp +++ b/src/lib/serviceRoutinesV2/getEntities.cpp @@ -35,7 +35,6 @@ #include "rest/uriParamNames.h" #include "rest/EntityTypeInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "serviceRoutinesV2/getEntities.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" #include "serviceRoutines/postQueryContext.h" @@ -43,6 +42,71 @@ +/* **************************************************************************** +* +* fillEntityVector - +* +* NOTE +* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. +* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be +* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). +* Other values for "details" are lost as well, if errorCode::code equals SccOk. +* +* FIXME PR: v1 is mentioned above... review this closely +*/ +static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) +{ + if (qcrs.errorCode.code == SccContextElementNotFound) + { + // + // If no entities are found, we respond with a 200 OK + // and an empty vector of entities ( [] ) + // + + oeP->fill(SccOk, "", "OK"); + return; + } + else if (qcrs.errorCode.code != SccOk) + { + // + // If any other error - use the error for the response + // + + oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + return; + } + + for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) + { + Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; + StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; + + if (scP->code == SccReceiverInternalError) + { + // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't + // think so, as the releasing logic in the upper layer will deal with that but + // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite + // cannot help here and it is better to ensure) + oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); + enVP->release(); + return; + } + else + { + Entity* newP = new Entity(); + + newP->entityId = eP->entityId; + newP->creDate = eP->creDate; + newP->modDate = eP->modDate; + + newP->attributeVector.fill(eP->attributeVector); + enVP->push_back(newP); + } + } +} + + + /* **************************************************************************** * * getEntities - @@ -82,7 +146,7 @@ std::string getEntities ParseData* parseDataP ) { - Entities entities; + EntityVector entities; std::string answer; std::string pattern = ".*"; // all entities, default value std::string id = ciP->uriParam["id"]; @@ -308,7 +372,7 @@ std::string getEntities if (parseDataP->qcrs.res.errorCode.code == SccReceiverInternalError) { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); TIMED_RENDER(answer = oe.toJson()); ciP->httpStatusCode = oe.code; } @@ -321,7 +385,7 @@ std::string getEntities else { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); if (oe.code != SccNone) { diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index e396612311..f2117d12f3 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -33,7 +33,6 @@ #include "rest/ConnectionInfo.h" #include "rest/uriParamNames.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/getEntities.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" diff --git a/src/lib/serviceRoutinesV2/patchEntity.cpp b/src/lib/serviceRoutinesV2/patchEntity.cpp index 6cfc8ac7e1..d0a57b4e98 100644 --- a/src/lib/serviceRoutinesV2/patchEntity.cpp +++ b/src/lib/serviceRoutinesV2/patchEntity.cpp @@ -31,7 +31,6 @@ #include "parse/forbiddenChars.h" #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/patchEntity.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" diff --git a/src/lib/serviceRoutinesV2/postBatchQuery.cpp b/src/lib/serviceRoutinesV2/postBatchQuery.cpp index f35efc8964..5ff115c25d 100644 --- a/src/lib/serviceRoutinesV2/postBatchQuery.cpp +++ b/src/lib/serviceRoutinesV2/postBatchQuery.cpp @@ -32,7 +32,6 @@ #include "ngsi/ParseData.h" #include "rest/OrionError.h" #include "rest/uriParamNames.h" -#include "apiTypesV2/Entities.h" #include "ngsi10/QueryContextRequest.h" #include "alarmMgr/alarmMgr.h" #include "serviceRoutines/postQueryContext.h" @@ -41,6 +40,72 @@ +/* **************************************************************************** +* +* fillEntityVector - +* +* NOTE +* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. +* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be +* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). +* Other values for "details" are lost as well, if errorCode::code equals SccOk. +* +* FIXME PR: v1 is mentioned above... review this closely +* FIXME PR: copied from getEntities.cpp. Move to common place +*/ +static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) +{ + if (qcrs.errorCode.code == SccContextElementNotFound) + { + // + // If no entities are found, we respond with a 200 OK + // and an empty vector of entities ( [] ) + // + + oeP->fill(SccOk, "", "OK"); + return; + } + else if (qcrs.errorCode.code != SccOk) + { + // + // If any other error - use the error for the response + // + + oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + return; + } + + for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) + { + Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; + StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; + + if (scP->code == SccReceiverInternalError) + { + // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't + // think so, as the releasing logic in the upper layer will deal with that but + // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite + // cannot help here and it is better to ensure) + oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); + enVP->release(); + return; + } + else + { + Entity* newP = new Entity(); + + newP->entityId = eP->entityId; + newP->creDate = eP->creDate; + newP->modDate = eP->modDate; + + newP->attributeVector.fill(eP->attributeVector); + enVP->push_back(newP); + } + } +} + + + /* **************************************************************************** * * postBatchQuery - @@ -65,7 +130,7 @@ std::string postBatchQuery { BatchQuery* bqP = &parseDataP->bq.res; QueryContextRequest* qcrP = &parseDataP->qcr.res; - Entities entities; + EntityVector entities; std::string answer; // To be used later in the render stage @@ -89,7 +154,7 @@ std::string postBatchQuery else { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); TIMED_RENDER(answer = entities.toJson(getRenderFormat(ciP->uriParamOptions), filterAttrs.stringV, false, qcrP->metadataList.stringV)); diff --git a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp index 0c93164753..04e261181f 100644 --- a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp +++ b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp @@ -34,7 +34,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "rest/OrionError.h" -#include "apiTypesV2/Entities.h" #include "serviceRoutinesV2/postBatchUpdate.h" #include "ngsi10/UpdateContextRequest.h" #include "serviceRoutines/postUpdateContext.h" @@ -67,7 +66,7 @@ std::string postBatchUpdate { BatchUpdate* buP = &parseDataP->bu.res; UpdateContextRequest* upcrP = &parseDataP->upcr.res; - Entities entities; + EntityVector entities; upcrP->fill(&buP->entities, buP->updateActionType); buP->release(); // upcrP just 'took over' the data from buP, buP is no longer needed diff --git a/src/lib/serviceRoutinesV2/postEntities.cpp b/src/lib/serviceRoutinesV2/postEntities.cpp index eb9ead16ce..68312cd544 100644 --- a/src/lib/serviceRoutinesV2/postEntities.cpp +++ b/src/lib/serviceRoutinesV2/postEntities.cpp @@ -29,7 +29,6 @@ #include "common/clockFunctions.h" #include "common/errorMessages.h" -#include "apiTypesV2/Entities.h" #include "ngsi/ParseData.h" #include "rest/ConnectionInfo.h" #include "rest/EntityTypeInfo.h" diff --git a/src/lib/serviceRoutinesV2/postEntity.cpp b/src/lib/serviceRoutinesV2/postEntity.cpp index 88b4ed94dd..56375810b1 100644 --- a/src/lib/serviceRoutinesV2/postEntity.cpp +++ b/src/lib/serviceRoutinesV2/postEntity.cpp @@ -32,7 +32,6 @@ #include "common/clockFunctions.h" #include "common/errorMessages.h" -#include "apiTypesV2/Entities.h" #include "ngsi/ParseData.h" #include "rest/ConnectionInfo.h" #include "rest/EntityTypeInfo.h" diff --git a/src/lib/serviceRoutinesV2/putEntity.cpp b/src/lib/serviceRoutinesV2/putEntity.cpp index 7ac9c38889..8ee0f5dd00 100644 --- a/src/lib/serviceRoutinesV2/putEntity.cpp +++ b/src/lib/serviceRoutinesV2/putEntity.cpp @@ -31,7 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/putEntity.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h"