Skip to content

Commit

Permalink
Merge branch 'feature/1259_new_json_for_v2' into task/part3_creation_…
Browse files Browse the repository at this point in the history
…update_of_attributes
  • Loading branch information
Ken Zangelin committed Sep 25, 2015
2 parents e5cc9ba + d9d0f5b commit 9477c86
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/lib/apiTypesV2/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
*/
Entity::Entity()
{
typeGiven = false;
}


Expand Down
1 change: 1 addition & 0 deletions src/lib/apiTypesV2/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Entity
ErrorCode errorCode; // Optional - mandatory if not 200-OK

std::string servicePath; // Not part of payload, just an internal field
bool typeGiven; // Was 'type' part of the incoming payload?

Entity();
~Entity();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/jsonParseV2/parseContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static std::string parseContextAttributeObject(const Value& start, ContextAttrib
return "invalid JSON type for attribute type";
}

caP->type = iter->value.GetString();
caP->type = iter->value.GetString();
caP->typeGiven = true;
}
else if (name == "value")
{
Expand Down Expand Up @@ -232,7 +233,7 @@ std::string parseContextAttribute(ConnectionInfo* ciP, ContextAttribute* caP)
OrionError oe(SccBadRequest, "Errors found in incoming JSON buffer");

LM_W(("Bad Input (JSON parse error)"));
ciP->httpStatusCode = SccBadRequest;;
ciP->httpStatusCode = SccBadRequest;
return oe.render(ciP, "");
}

Expand Down
19 changes: 10 additions & 9 deletions src/lib/jsonParseV2/parseEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (!document.HasMember("id"))
{
LM_W(("Bad Input (No entity id specified"));
eP->errorCode.fill("ParseError", "no entity id specified");
eP->errorCode.fill("BadRequest", "no entity id specified");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
Expand All @@ -90,15 +90,15 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (document.HasMember("id"))
{
LM_W(("Bad Input (entity id specified in payload"));
eP->errorCode.fill("ParseError", "entity id specified in payload");
eP->errorCode.fill("BadRequest", "entity id specified in payload");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}

if (document.HasMember("type"))
{
LM_W(("Bad Input (entity type specified in payload"));
eP->errorCode.fill("ParseError", "entity type specified in payload");
eP->errorCode.fill("BadRequest", "entity type specified in payload");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
Expand All @@ -117,7 +117,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (type != "String")
{
LM_W(("Bad Input (invalid JSON type for entity id"));
eP->errorCode.fill("ParseError", "invalid JSON type for entity id");
eP->errorCode.fill("BadRequest", "invalid JSON type for entity id");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
Expand All @@ -127,7 +127,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
else // "id" present in payload for /v2/entities/<eid> - not a valid payload
{
LM_W(("Bad Input ('id' is not a valid attribute"));
eP->errorCode.fill("ParseError", "invalid input, 'id' as attribute");
eP->errorCode.fill("BadRequest", "invalid input, 'id' as attribute");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
Expand All @@ -137,12 +137,13 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (type != "String")
{
LM_W(("Bad Input (invalid JSON type for entity type"));
eP->errorCode.fill("ParseError", "invalid JSON type for entity type");
eP->errorCode.fill("BadRequest", "invalid JSON type for entity type");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}

eP->type = iter->value.GetString();
eP->type = iter->value.GetString();
eP->typeGiven = true;
}
else
{
Expand All @@ -153,7 +154,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (r != "OK")
{
LM_W(("Bad Input (parse error in context attribute)"));
eP->errorCode.fill("ParseError", r);
eP->errorCode.fill("BadRequest", r);
ciP->httpStatusCode = SccBadRequest;
return eP->render(ciP, EntitiesRequest);
}
Expand All @@ -165,7 +166,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
if (eP->id == "")
{
LM_W(("Bad Input (empty entity id"));
eP->errorCode.fill("ParseError", "empty entity id");
eP->errorCode.fill("BadRequest", "empty entity id");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/jsonParseV2/parseMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static std::string parseMetadataObject(const Value& start, Metadata* mP)
return "invalid JSON type for attribute metadata type";
}

mP->type = iter->value.GetString();
mP->type = iter->value.GetString();
mP->typeGiven = true;
}
else if (name == "value")
{
Expand Down
7 changes: 7 additions & 0 deletions src/lib/ngsi/ContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ContextAttribute::ContextAttribute()
typeFromXmlAttribute = "";
found = false;
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand All @@ -90,6 +91,7 @@ ContextAttribute::ContextAttribute(ContextAttribute* caP)
found = caP->found;
typeFromXmlAttribute = "";
skip = false;
typeGiven = caP->typeGiven;

providingApplication.set(caP->providingApplication.get());
providingApplication.setFormat(caP->providingApplication.getFormat());
Expand Down Expand Up @@ -134,6 +136,7 @@ ContextAttribute::ContextAttribute
compoundValueP = NULL;
found = _found;
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand Down Expand Up @@ -165,6 +168,7 @@ ContextAttribute::ContextAttribute
compoundValueP = NULL;
found = _found;
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand Down Expand Up @@ -196,6 +200,7 @@ ContextAttribute::ContextAttribute
compoundValueP = NULL;
found = _found;
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand Down Expand Up @@ -227,6 +232,7 @@ ContextAttribute::ContextAttribute
compoundValueP = NULL;
found = _found;
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand Down Expand Up @@ -255,6 +261,7 @@ ContextAttribute::ContextAttribute
found = false;
valueType = orion::ValueTypeObject; // FIXME P6: Could be ValueTypeVector ...
skip = false;
typeGiven = false;

providingApplication.set("");
providingApplication.setFormat(NOFORMAT);
Expand Down
1 change: 1 addition & 0 deletions src/lib/ngsi/ContextAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef struct ContextAttribute
bool skip; // For internal use in mongoBackend - in case of 'op=append' and the attribute already exists
std::string typeFromXmlAttribute;
orion::CompoundValueNode* compoundValueP;
bool typeGiven; // Was 'type' part of the incoming payload?

~ContextAttribute();
ContextAttribute();
Expand Down
14 changes: 10 additions & 4 deletions src/lib/ngsi/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Metadata::Metadata()
type = "";
stringValue = "";
valueType = orion::ValueTypeString;
typeGiven = false;
}


Expand All @@ -65,6 +66,7 @@ Metadata::Metadata(Metadata* mP)
stringValue = mP->stringValue;
numberValue = mP->numberValue;
boolValue = mP->boolValue;
typeGiven = false;
}


Expand All @@ -79,6 +81,7 @@ Metadata::Metadata(const std::string& _name, const std::string& _type, const cha
type = _type;
valueType = orion::ValueTypeString;
stringValue = std::string(_value);
typeGiven = false;
}


Expand All @@ -93,6 +96,7 @@ Metadata::Metadata(const std::string& _name, const std::string& _type, const std
type = _type;
valueType = orion::ValueTypeString;
stringValue = _value;
typeGiven = false;
}


Expand All @@ -107,6 +111,7 @@ Metadata::Metadata(const std::string& _name, const std::string& _type, double _v
type = _type;
valueType = orion::ValueTypeNumber;
numberValue = _value;
typeGiven = false;
}


Expand All @@ -117,10 +122,11 @@ Metadata::Metadata(const std::string& _name, const std::string& _type, double _v
*/
Metadata::Metadata(const std::string& _name, const std::string& _type, bool _value)
{
name = _name;
type = _type;
valueType = orion::ValueTypeBoolean;
boolValue = _value;
name = _name;
type = _type;
valueType = orion::ValueTypeBoolean;
boolValue = _value;
typeGiven = false;
}


Expand Down
1 change: 1 addition & 0 deletions src/lib/ngsi/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct Metadata
std::string stringValue; // "value" as a String
double numberValue; // "value" as a Number
bool boolValue; // "value" as a Boolean
bool typeGiven; // Was 'type' part of the incoming payload?

Metadata();
Metadata(Metadata* mP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Date: REGEX(.*)

{
"description": "no entity id specified",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -170,7 +170,7 @@ Date: REGEX(.*)

{
"description": "empty entity id",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -183,7 +183,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity id",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -196,7 +196,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity id",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -209,7 +209,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity type",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -222,7 +222,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity type",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -235,7 +235,7 @@ Date: REGEX(.*)

{
"description": "no 'name' for ContextAttribute",
"error": "ParseError"
"error": "BadRequest"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity id",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -135,7 +135,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for entity type",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -148,7 +148,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for attribute type",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -161,7 +161,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for attribute metadata type",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -174,7 +174,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for attribute metadata value",
"error": "ParseError"
"error": "BadRequest"
}


Expand All @@ -187,7 +187,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON field for attribute metadata",
"error": "ParseError"
"error": "BadRequest"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Date: REGEX(.*)

{
"description": "invalid JSON type for attribute metadata value",
"error": "ParseError"
"error": "BadRequest"
}


Expand Down
Loading

0 comments on commit 9477c86

Please sign in to comment.