Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGSIv2 rendering improvements (simplification, unification and performance) #3285

Merged
merged 12 commits into from
Sep 12, 2018
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- Fix: GET /v2/subscriptions and GET /v2/subscriptions/{id} crashes for permanent subscriptions created before version 1.13.0 (#3256)
- Hardening: Mongo driver now compiled using --use-sasl-client --ssl to enable proper DB authentication mechanisms
- Fix: correct error payload using errorCode (previously orionError was used) in POST /v1/queryContext and POST /v1/updateContext in some cases
- Fix: bug in metadata compound value rendering in NGSIv2 (sometimes "toplevel" key was wrongly inserted in the resulting JSON object)
- Hardening: modification of the URL parsing mechanism, making it more efficient, and the source code easier to follow (#3109, step 1)
- Hardening: refactor NGSIv2 rendering code (throughput increase up to 33%/365% in entities/subscriptions rendering intensive scenarios) (#1298)
- Fix: Missing or empty metadata values were not allowed in NGSIv2 create/update operations (#3121)
26 changes: 12 additions & 14 deletions src/lib/apiTypesV2/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "common/errorMessages.h"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CNR entries missing

(Self-node)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a99e4d6

#include "common/RenderFormat.h"
#include "common/string.h"
#include "common/JsonHelper.h"
#include "ngsi10/QueryContextResponse.h"
#include "apiTypesV2/Attribute.h"

Expand All @@ -48,8 +49,7 @@ std::string Attribute::render
HttpStatusCode* scP, // out parameter (pass-through)
bool keyValues, // in parameter
const std::string& metadataList, // in parameter
RequestType requestType, // in parameter
bool comma // in parameter
RequestType requestType // in parameter
)
{
RenderFormat renderFormat = (keyValues == true)? NGSI_V2_KEYVALUES : NGSI_V2_NORMALIZED;
Expand All @@ -76,18 +76,16 @@ std::string Attribute::render
stringSplit(metadataList, ',', metadataFilter);
}

out = "{";

// First parameter (isLastElement) is 'true' as it is the last and only element
out += pcontextAttribute->toJson(true, renderFormat, metadataFilter, requestType);

out += "}";
}


if (comma)
{
out += ",";
if (renderFormat == NGSI_V2_KEYVALUES)
{
JsonHelper jh;
jh.addRaw(pcontextAttribute->name, pcontextAttribute->toJsonValue());
out = jh.str();
}
else // NGSI_V2_NORMALIZED
{
out = pcontextAttribute->toJson(metadataFilter);
}
}

return out;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/apiTypesV2/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class Attribute
HttpStatusCode* scP,
bool keyValues,
const std::string& metadataList,
RequestType requestType,
bool comma = false);
RequestType requestType);
void fill(QueryContextResponse* qcrsP, std::string attrName);
};

Expand Down
Loading