Skip to content

Commit

Permalink
REMOVE Attribute class
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Aug 30, 2024
1 parent 5ae4133 commit a7e594c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 256 deletions.
142 changes: 0 additions & 142 deletions src/lib/apiTypesV2/Attribute.cpp

This file was deleted.

69 changes: 0 additions & 69 deletions src/lib/apiTypesV2/Attribute.h

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib/apiTypesV2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SET (SOURCES
Entity.cpp
EntityVector.cpp
Entities.cpp
Attribute.cpp
Subscription.cpp
Registration.cpp
EntID.cpp
Expand All @@ -38,7 +37,6 @@ SET (HEADERS
Entity.h
EntityVector.h
Entities.h
Attribute.h
Subscription.h
Registration.h
EntID.h
Expand Down
56 changes: 56 additions & 0 deletions src/lib/ngsi10/QueryContextResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "logMsg/logMsg.h"

#include "common/string.h"
#include "common/errorMessages.h"
#include "alarmMgr/alarmMgr.h"
#include "rest/HttpStatusCode.h"
#include "ngsi/StatusCode.h"
Expand Down Expand Up @@ -81,3 +82,58 @@ void QueryContextResponse::fill(const Entities& entities)
contextElementResponseVector.push_back(cerP);
}
}


/* ****************************************************************************
*
* QueryContextResponse::getAttr -
*
* If attribute is found:
* - It is returned by the function
* - The OrionError is set to SccNone
*
* If attribute is not found
* - Function returns NULL
* - The OrionError is not touched
*
*/
ContextAttribute* QueryContextResponse::getAttr(const std::string& attrName, OrionError* oeP)
{
if (errorCode.code == SccContextElementNotFound)
{
oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND);
return NULL;
}

if (errorCode.code != SccOk)
{
//
// any other error distinct from Not Found
//
oeP->fill(errorCode.code, errorCode.details, errorCode.reasonPhrase);
return NULL;
}

if (contextElementResponseVector.size() > 1) // errorCode.code == SccOk
{
//
// If there are more than one entity, we return an error
//
oeP->fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY);
return NULL;
}

// Look for the attribute by name
ContextElementResponse* cerP = contextElementResponseVector[0];

for (std::size_t i = 0; i < cerP->entity.attributeVector.size(); ++i)
{
if (cerP->entity.attributeVector[i]->name == attrName)
{
return cerP->entity.attributeVector[i];
}
}

oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND);
return NULL;
}
1 change: 1 addition & 0 deletions src/lib/ngsi10/QueryContextResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct QueryContextResponse

void release(void);
void fill(const Entities& entities);
ContextAttribute* getAttr(const std::string& attrName, OrionError* oeP);
} QueryContextResponse;

#endif // SRC_LIB_NGSI10_QUERYCONTEXTRESPONSE_H_
33 changes: 15 additions & 18 deletions src/lib/serviceRoutinesV2/getEntityAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "common/errorMessages.h"
#include "rest/uriParamNames.h"

#include "apiTypesV2/Attribute.h"
#include "rest/ConnectionInfo.h"
#include "ngsi/ParseData.h"
#include "rest/EntityTypeInfo.h"
Expand Down Expand Up @@ -65,7 +64,6 @@ std::string getEntityAttribute
{
std::string type = ciP->uriParam["type"];
std::string answer;
Attribute attribute;

if (forbiddenIdCharsV2(compV[2].c_str(), NULL) ||
forbiddenIdCharsV2(compV[4].c_str(), NULL))
Expand All @@ -78,27 +76,26 @@ std::string getEntityAttribute
// 01. Fill in QueryContextRequest
parseDataP->qcr.res.fill(compV[2], type, "false", EntityTypeEmptyOrNotEmpty, "");


// 02. Call standard op postQueryContext
OrionError oe;
postQueryContext(ciP, components, compV, parseDataP);

ContextAttribute* caP = parseDataP->qcrs.res.getAttr(compV[4], &oe);

// 03. Render entity attribute response
OrionError oe;
attribute.fill(parseDataP->qcrs.res, compV[4], &oe);

if (oe.code == SccNone)
if (caP != NULL)
{
StringList metadataFilter;
setMetadataFilter(ciP->uriParam, &metadataFilter);
TIMED_RENDER(answer = attribute.toJson(ciP->httpHeaders.accepted("text/plain"),
ciP->httpHeaders.accepted("application/json"),
ciP->httpHeaders.outformatSelect(),
&(ciP->outMimeType),
&(ciP->httpStatusCode),
ciP->uriParamOptions[OPT_KEY_VALUES],
metadataFilter.stringV,
false));
if (ciP->uriParamOptions[OPT_KEY_VALUES]) // NGSI_V2_KEYVALUES
{
JsonObjectHelper jh;
jh.addRaw(caP->name, caP->toJsonValue());
TIMED_RENDER(answer = jh.str());
}
else // NGSI_V2_NORMALIZED
{
StringList metadataFilter;
setMetadataFilter(ciP->uriParam, &metadataFilter);
TIMED_RENDER(answer = caP->toJson(metadataFilter.stringV));
}
}
else
{
Expand Down
Loading

0 comments on commit a7e594c

Please sign in to comment.