Skip to content

Commit

Permalink
Merge pull request #3324 from telefonicaid/hardening/1298_reg_cleanup…
Browse files Browse the repository at this point in the history
…_and_renders_rename

NGSIv1 regs isDomain/metadta removal and render() to toJsonv1() renaming
  • Loading branch information
AlvaroVega authored Oct 1, 2018
2 parents 4356a4d + 6fb4deb commit f68e35d
Show file tree
Hide file tree
Showing 476 changed files with 1,597 additions and 3,748 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove: isDomain field in NGSIv1 registrations (it was never used)
9 changes: 3 additions & 6 deletions doc/manuals/admin/database_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ Fields:
reasons, **isPattern** may be `"true"` or `"false"` (text) while
**isTypePattern** may be `true` or `false` (boolean).
- **attrs**: an array containing a list of attributes (optional).
The JSON for each attribute contains **name**, **type** and
**isDomain**.
The JSON for each attribute contains **name** and **type**.
- **providingApplication**: the URL of the providing application
for this registration (mandatory)

Expand Down Expand Up @@ -241,13 +240,11 @@ Example document:
"attrs": [
{
"name": "A1",
"type": "TA1",
"isDomain": "false"
"type": "TA1"
},
{
"name": "A2",
"type": "TA2",
"isDomain": "true"
"type": "TA2"
}
],
"providingApplication": "http://foo.bar/notif"
Expand Down
4 changes: 2 additions & 2 deletions doc/manuals/devel/sourceCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ The **ngsi** library contains a collection of classes for the different payloads

These classes (as well as the classes in the libraries `ngsi9`, `ngsi10`, `convenience`) all have a standard set of methods:

* `render()`, to render the object to a JSON string (mainly for NGSIv1)
* `toJson()`, to render the object to a JSON string (for NGSIv2)
* `toJsonV1()`, to render the object to a JSON string (for NGSIv1)
* `present()`, for debugging (the object is dumped as text to the log file)
* `release()`, to release all allocated resources of the object
* `check()`, to make sure the object follows the rules, i.e. about no forbidden characters, or mandatory fields missing, etc.
Expand All @@ -222,7 +222,7 @@ The classes follow a hierarchy, e.g. `UpdateContextRequest` (top hierarchy class
* `ContextAttributeVector`
* `MetadataVector` (this field `MetadataVector domainMetadataVector` is part of NGSIv1 but Orion doesn't make use of it)

The methods `render()`, `check()`, `release()`, etc. are called in a tree-like fashion, starting from the top hierarchy class, e.g. `UpdateContextRequest`:
The methods `toJson()`, `check()`, `release()`, etc. are called in a tree-like fashion, starting from the top hierarchy class, e.g. `UpdateContextRequest`:

* `UpdateContextRequest::check()` calls:
* `ContextElementVector::check()` calls (for each item in the vector):
Expand Down
4 changes: 2 additions & 2 deletions src/lib/apiTypesV2/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

/* ****************************************************************************
*
* Attribute::render -
* Attribute::toJson -
*/
std::string Attribute::render
std::string Attribute::toJson
(
bool acceptedTextPlain, // in parameter (pass-through)
bool acceptedJson, // in parameter (pass-through)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/apiTypesV2/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Attribute

Attribute(): pcontextAttribute(0) {}

std::string render(bool acceptedTextPlain,
std::string toJson(bool acceptedTextPlain,
bool acceptedJson,
MimeType outFormatSelection,
MimeType* outMimeTypeP,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/apiTypesV2/Entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ Entities::~Entities()

/* ****************************************************************************
*
* Entities::render -
* Entities::toJson -
*
*/
std::string Entities::render
std::string Entities::toJson
(
RenderFormat renderFormat,
const std::vector<std::string>& attrsFilter,
bool blacklist,
const std::vector<std::string>& metadataFilter
)
{
return vec.render(renderFormat, attrsFilter, blacklist, metadataFilter);
return vec.toJson(renderFormat, attrsFilter, blacklist, metadataFilter);
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/apiTypesV2/Entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Entities
Entities();
~Entities();

std::string render(RenderFormat renderFormat,
std::string toJson(RenderFormat renderFormat,
const std::vector<std::string>& attrsFilter,
bool blacklist,
const std::vector<std::string>& metadataFilter);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/apiTypesV2/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ std::string Entity::toJsonV1
filterAndOrderAttrs(attrsFilter, blacklist, &orderedAttrs);

EntityId en(id, type, isPattern);
out += en.render(contextAttributeVectorRendered, false);
out += attributeVector.render(asJsonObject, requestType, orderedAttrs, metadataFilter, false, omitAttributeValues);
out += en.toJsonV1(contextAttributeVectorRendered, false);
out += attributeVector.toJsonV1(asJsonObject, requestType, orderedAttrs, metadataFilter, false, omitAttributeValues);

out += endTag(comma, false);

Expand Down
4 changes: 2 additions & 2 deletions src/lib/apiTypesV2/EntityVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@

/* ****************************************************************************
*
* EntityVector::render -
* EntityVector::toJson -
*/
std::string EntityVector::render
std::string EntityVector::toJson
(
RenderFormat renderFormat,
const std::vector<std::string>& attrsFilter,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/apiTypesV2/EntityVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ typedef struct EntityVector
{
std::vector<Entity*> vec;

std::string render(RenderFormat renderFormat,
const std::vector<std::string>& attrsFilter,
bool blacklist,
const std::vector<std::string>& metadataFilter);
std::string toJson(RenderFormat renderFormat,
const std::vector<std::string>& attrsFilter,
bool blacklist,
const std::vector<std::string>& metadataFilter);


std::string check(RequestType requestType);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/convenience/AppendContextElementRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ AppendContextElementRequest::AppendContextElementRequest()

/* ****************************************************************************
*
* render -
* toJsonV1 -
*/
std::string AppendContextElementRequest::render
std::string AppendContextElementRequest::toJsonV1
(
bool asJsonObject,
RequestType requestType
Expand All @@ -60,14 +60,14 @@ std::string AppendContextElementRequest::render

if (entity.id != "")
{
out += entity.render(false);
out += entity.toJsonV1(false);
}

// No metadata filter in this case, an empty vector is used to fulfil method signature.
// For attribute filter, we use the ContextAttributeVector itself
std::vector<std::string> emptyMdV;

out += contextAttributeVector.render(asJsonObject, requestType, contextAttributeVector.vec, emptyMdV);
out += contextAttributeVector.toJsonV1(asJsonObject, requestType, contextAttributeVector.vec, emptyMdV);
out += endTag();

return out;
Expand Down Expand Up @@ -104,7 +104,7 @@ std::string AppendContextElementRequest::check
return "OK";
}

return response.render(asJsonObject, requestType);
return response.toJsonV1(asJsonObject, requestType);
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/convenience/AppendContextElementRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef struct AppendContextElementRequest

AppendContextElementRequest();

std::string render(bool asJsonObject, RequestType requestType);
std::string toJsonV1(bool asJsonObject, RequestType requestType);
void release();
std::string check(ApiVersion apiVersion,
bool asJsonObject,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/convenience/AppendContextElementResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ AppendContextElementResponse::AppendContextElementResponse() : errorCode("errorC

/* ****************************************************************************
*
* AppendContextElementResponse::render -
* AppendContextElementResponse::toJsonV1 -
*/
std::string AppendContextElementResponse::render
std::string AppendContextElementResponse::toJsonV1
(
bool asJsonObject,
RequestType requestType
Expand All @@ -64,16 +64,16 @@ std::string AppendContextElementResponse::render

if ((errorCode.code != SccNone) && (errorCode.code != SccOk))
{
out += errorCode.render(false);
out += errorCode.toJsonV1(false);
}
else
{
if (entity.id != "")
{
out += entity.render(true);
out += entity.toJsonV1(true);
}

out += contextAttributeResponseVector.render(asJsonObject, requestType);
out += contextAttributeResponseVector.toJsonV1(asJsonObject, requestType);
}

out += endTag();
Expand Down Expand Up @@ -110,7 +110,7 @@ std::string AppendContextElementResponse::check
return "OK";
}

return render(asJsonObject, requestType);
return toJsonV1(asJsonObject, requestType);
}


Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/AppendContextElementResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ typedef struct AppendContextElementResponse

AppendContextElementResponse();

std::string render(bool asJsonObject,
RequestType requestType);
std::string toJsonV1(bool asJsonObject, RequestType requestType);
void release(void);
std::string check(ApiVersion apiVersion,
bool asJsonObject,
Expand Down
10 changes: 5 additions & 5 deletions src/lib/convenience/ContextAttributeResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

/* ****************************************************************************
*
* render -
* toJsonV1 -
*/
std::string ContextAttributeResponse::render
std::string ContextAttributeResponse::toJsonV1
(
bool asJsonObject,
RequestType request
Expand All @@ -55,8 +55,8 @@ std::string ContextAttributeResponse::render
std::vector<std::string> emptyMdV;

out += startTag();
out += contextAttributeVector.render(asJsonObject, request, contextAttributeVector.vec, emptyMdV, true);
out += statusCode.render(false);
out += contextAttributeVector.toJsonV1(asJsonObject, request, contextAttributeVector.vec, emptyMdV, true);
out += statusCode.toJsonV1(false);
out += endTag();

return out;
Expand Down Expand Up @@ -102,7 +102,7 @@ std::string ContextAttributeResponse::check
return "OK";
}

return render(asJsonObject, requestType);
return toJsonV1(asJsonObject, requestType);
}


Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ typedef struct ContextAttributeResponse
ContextAttributeVector contextAttributeVector; // Mandatory
StatusCode statusCode; // Mandatory

std::string render(bool asJsonObject,
RequestType request);
std::string toJsonV1(bool asJsonObject, RequestType request);
void release(void);
std::string check(ApiVersion apiVersion,
bool asJsonObject,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/convenience/ContextAttributeResponseVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

/* ****************************************************************************
*
* ContextAttributeResponseVector::render -
* ContextAttributeResponseVector::toJsonV1 -
*/
std::string ContextAttributeResponseVector::render
std::string ContextAttributeResponseVector::toJsonV1
(
bool asJsonObject,
RequestType request
Expand All @@ -55,7 +55,7 @@ std::string ContextAttributeResponseVector::render
out += startTag(key, true);
for (unsigned int ix = 0; ix < vec.size(); ++ix)
{
out += vec[ix]->render(asJsonObject, request);
out += vec[ix]->toJsonV1(asJsonObject, request);
}
out += endTag(false, true);

Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponseVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ typedef struct ContextAttributeResponseVector
{
std::vector<ContextAttributeResponse*> vec;

std::string render(bool asJsonObject,
RequestType request);
std::string toJsonV1(bool asJsonObject, RequestType request);
void push_back(ContextAttributeResponse* item);
unsigned int size(void);
void release(void);
Expand Down
30 changes: 7 additions & 23 deletions src/lib/convenience/RegisterProviderRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,20 @@ RegisterProviderRequest::RegisterProviderRequest()

/* ****************************************************************************
*
* RegisterProviderRequest::render -
* RegisterProviderRequest::toJsonV1 -
*/
std::string RegisterProviderRequest::render(void)
std::string RegisterProviderRequest::toJsonV1(void)
{
std::string out = "";
//bool durationRendered = duration.get() != "";
bool providingApplicationRendered = providingApplication.get() != "";
bool registrationIdRendered = registrationId.get() != "";
bool commaAfterRegistrationId = false; // Last element
bool commaAfterProvidingApplication = registrationIdRendered;
bool commaAfterDuration = commaAfterProvidingApplication || providingApplicationRendered;
//bool commaAfterMetadataVector = commaAfterDuration || durationRendered;

out += startTag();
// out += metadataVector.render(commaAfterMetadataVector); //FIXME #1298 remove context registration metadata
out += duration.render(commaAfterDuration);
out += providingApplication.render(commaAfterProvidingApplication);
out += registrationId.render(RegisterContext, commaAfterRegistrationId);
out += duration.toJsonV1(commaAfterDuration);
out += providingApplication.toJsonV1(commaAfterProvidingApplication);
out += registrationId.toJsonV1(RegisterContext, false);
out += endTag(false);

return out;
Expand All @@ -98,8 +94,7 @@ std::string RegisterProviderRequest::check
{
response.errorCode.fill(SccBadRequest, predetectedError);
}
else if (((res = metadataVector.check(apiVersion)) != "OK") ||
((res = duration.check()) != "OK") ||
else if (((res = duration.check()) != "OK") ||
((res = providingApplication.check()) != "OK") ||
((res = registrationId.check()) != "OK"))
{
Expand All @@ -113,16 +108,5 @@ std::string RegisterProviderRequest::check
std::string details = std::string("RegisterProviderRequest Error: '") + res + "'";
alarmMgr.badInput(clientIp, details);

return response.render();
}



/* ****************************************************************************
*
* RegisterProviderRequest::release -
*/
void RegisterProviderRequest::release(void)
{
metadataVector.release();
return response.toJsonV1();
}
5 changes: 2 additions & 3 deletions src/lib/convenience/RegisterProviderRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@
*/
typedef struct RegisterProviderRequest
{
MetadataVector metadataVector; // Optional
Duration duration; // Optional
ProvidingApplication providingApplication; // Mandatory
RegistrationId registrationId; // Optional

RegisterProviderRequest();

std::string render(void);
std::string toJsonV1(void);
std::string check(ApiVersion apiVersion, RequestType requestType, const std::string& preError);
void release();

} RegisterProviderRequest;

#endif // SRC_LIB_CONVENIENCE_REGISTERPROVIDERREQUEST_H_
Loading

0 comments on commit f68e35d

Please sign in to comment.