Commit 753d7a15 authored by abitha.s's avatar abitha.s Committed by Uze Choi

Changes for JsonSchema and Raml Parser.

1.Added reading Double from Json Schema
2.Adding prevent and klockwork fixes for Raml and JsonSchema parser.
3.Minor fixes.

Change-Id: I2459bbdee23b8491a290f21fdfa13c7979efda97
Signed-off-by: default avatarabitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3375Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
(cherry picked from commit 0fe7faa0)
Reviewed-on: https://gerrit.iotivity.org/gerrit/3717
parent 9985079f
......@@ -19,6 +19,7 @@
******************************************************************/
#include "RamlParser.h"
#include "Helpers.h"
#include <iostream>
#include <string>
#include <memory>
......@@ -73,20 +74,80 @@ void printRequestResponseBody(const RequestResponseBodyPtr &body)
for ( auto pro : body->getSchema()->getProperties()->getProperties() )
{
std::cout << "-----------------------------" << std::endl;
std::cout << "Name : " << pro.second->getName() << std::endl;
std::cout << "default : " << pro.second->getValue() << std::endl;
std::cout << "update_frequency : " << pro.second->getUpdateFrequencyTime() << std::endl;
int min = 0, max = 0, multipleOf = 0;
pro.second->getRange(min, max, multipleOf);
std::cout << "range_min : " << min << std::endl;
std::cout << "range_max : " << max << std::endl;
std::cout << "allowed values : " << std::endl;
for (auto v : pro.second->getAllowedValues())
std::cout << v << " ";
std::cout << std::endl;
std::cout << "-----------------------------" << std::endl;
try
{
switch (pro.second->getVariantType())
{
case VariantType::INT : // Integer
std::cout << "Defaut: " << pro.second->getValueInt() << std::endl;
for (auto tt : pro.second->getAllowedValuesInt())
{
std::cout << "enum value : " << tt << std::endl;
}
{
int min = 0, max = 0, mul = 0;
pro.second->getRange(min, max, mul);
std::cout << "Minimum: " << min << std::endl;
std::cout << "Maximum: " << max << std::endl;
}
break;
case VariantType::DOUBLE : // Double
std::cout << "Defaut: " << pro.second->getValueDouble() << std::endl;
for (auto tt : pro.second->getAllowedValuesDouble())
{
std::cout << "enum value : " << tt << std::endl;
}
{
double min = 0, max = 0;
int mul = 0;
pro.second->getRangeDouble(min, max, mul);
std::cout << "MinimumDouble: " << min << std::endl;
std::cout << "MaximumDouble: " << max << std::endl;
}
break;
case VariantType::BOOL : // Boolean
std::cout << "Defaut: " << std::boolalpha << pro.second->getValueBool() << std::noboolalpha <<
std::endl;
for (auto tt : pro.second->getAllowedValuesBool())
{
std::cout << "enum value : " << tt << std::endl;
}
break;
case VariantType::STRING : // String
std::cout << "Defaut: " << pro.second->getValueString() << std::endl;
for (auto tt : pro.second->getAllowedValuesString())
{
std::cout << "enum value : " << tt << std::endl;
}
{
int min = 0, max = 0, mul = 0;
pro.second->getRange(min, max, mul);
std::cout << "MinimumLength: " << min << std::endl;
std::cout << "MaximumLength: " << max << std::endl;
}
break;
default:
break;
}
}
catch (const boost::bad_lexical_cast &e)
{
std::cout << e.what() << std::endl;
}
catch ( ... )
{
std::cout << "Unknown exception caught!" << std::endl;
}
}
std::cout << "-----------------------------" << std::endl;
std::cout << "Body : example : " << body->getExample() << std::endl;
#ifdef PRINT_REQUEST_RESPONSE_BODY_PARAMS
......@@ -238,23 +299,74 @@ void printProperties(const PropertiesPtr &prop)
std::cout << "-------------------------------" << std::endl;
std::cout << "Type: " << prop->getType() << std::endl;
std::cout << "Description: " << prop->getDescription() << std::endl;
int type = prop->getValueType();
if (type)
try
{
std::cout << "Defaut: " << prop->getValueString() << std::endl;
for (auto tt : prop->getAllowedValuesString())
switch (prop->getVariantType())
{
std::cout << "enum value : " << tt << std::endl;
case VariantType::INT : // Integer
std::cout << "Defaut: " << prop->getValueInt() << std::endl;
for (auto tt : prop->getAllowedValuesInt())
{
std::cout << "enum value : " << tt << std::endl;
}
{
int min = 0, max = 0, mul = 0;
prop->getRange(min, max, mul);
std::cout << "Minimum: " << min << std::endl;
std::cout << "Maximum: " << max << std::endl;
}
break;
case VariantType::DOUBLE : // Double
std::cout << "Defaut: " << prop->getValueDouble() << std::endl;
for (auto tt : prop->getAllowedValuesDouble())
{
std::cout << "enum value : " << tt << std::endl;
}
{
double min = 0, max = 0;
int mul = 0;
prop->getRangeDouble(min, max, mul);
std::cout << "MinimumDouble: " << min << std::endl;
std::cout << "MaximumDouble: " << max << std::endl;
}
break;
case VariantType::BOOL : // Boolean
std::cout << "Defaut: " << std::boolalpha << prop->getValueBool() << std::noboolalpha << std::endl;
for (auto tt : prop->getAllowedValuesBool())
{
std::cout << std::boolalpha << "enum value : " << tt << std::noboolalpha << std::endl;
}
break;
case VariantType::STRING : // String
std::cout << "Defaut: " << prop->getValueString() << std::endl;
for (auto tt : prop->getAllowedValuesString())
{
std::cout << "enum value : " << tt << std::endl;
}
{
int min = 0, max = 0, mul = 0;
prop->getRange(min, max, mul);
std::cout << "MinimumLength: " << min << std::endl;
std::cout << "MaximumLength: " << max << std::endl;
}
break;
default:
break;
}
}
else
catch (const boost::bad_lexical_cast &e)
{
std::cout << "Defaut: " << prop->getValueInt() << std::endl;
for (auto tt : prop->getAllowedValuesString())
{
std::cout << "enum value : " << tt << std::endl;
}
std::cout << e.what() << std::endl;
}
catch ( ... )
{
std::cout << "Unknown exception caught!" << std::endl;
}
if (prop->getType() == "array")
{
for (auto it : prop->getItems())
......@@ -265,13 +377,17 @@ void printProperties(const PropertiesPtr &prop)
{
std::cout << "enum value : " << tt << std::endl;
}
for (auto tt : it->getProperties())
{
printProperties(tt.second);
}
std::cout << "Item Required Values : " << std::endl;
for (auto tt : it->getRequiredValues())
{
std::cout << tt << std::endl;
}
}
}
int min = 0, max = 0, mul = 0;
prop->getRange(min, max, mul);
std::cout << "Minimum: " << min << std::endl;
std::cout << "Maximum: " << max << std::endl;
std::cout << "MultipleOf: " << mul << std::endl;
#endif
}
......
......@@ -118,7 +118,7 @@ namespace RAML
if (*it == reqValue)
break;
}
if (m_required.end() != it)
if (m_required.end() == it)
{
m_required.push_back(reqValue);
}
......
......@@ -124,7 +124,7 @@ namespace RAML
if (*it == reqValue)
break;
}
if (m_required.end() != it)
if (m_required.end() == it)
{
m_required.push_back(reqValue);
}
......
......@@ -176,11 +176,6 @@ namespace RAML
{
PropertiesPtr property = std::make_shared<Properties>(attName);
cJSON *propertyUpdateFrequency = cJSON_GetObjectItem(childProperties, "update_frequency");
if (propertyUpdateFrequency)
{
property->setUpdateFrequencyTime(propertyUpdateFrequency->valueint);
}
cJSON *propertyDescription = cJSON_GetObjectItem(childProperties, "description");
if (propertyDescription)
{
......@@ -295,7 +290,7 @@ namespace RAML
}
else if (attType == "integer")
{
readNumber(childProperties, property);
readInteger(childProperties, property);
}
else if (attType == "array")
{
......@@ -303,7 +298,7 @@ namespace RAML
}
else if (attType == "number")
{
readNumber(childProperties, property);
readDouble(childProperties, property);
}
}
......@@ -418,7 +413,7 @@ namespace RAML
}
}
void JsonSchema::readNumber(cJSON *childProperties, PropertiesPtr property)
void JsonSchema::readInteger(cJSON *childProperties, PropertiesPtr property)
{
cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");
if (Max)
......@@ -455,6 +450,45 @@ namespace RAML
}
}
void JsonSchema::readDouble(cJSON *childProperties, PropertiesPtr property)
{
cJSON *Max = cJSON_GetObjectItem(childProperties, "maximum");
if (Max)
{
cJSON *exclusiveMax = cJSON_GetObjectItem(childProperties, "exclusiveMaximum");
if (exclusiveMax)
{
if (exclusiveMax->type == cJSON_True)
property->setMaxDouble( --(Max->valuedouble));
else
property->setMaxDouble(Max->valuedouble);
}
else
property->setMaxDouble(Max->valuedouble);
}
cJSON *Min = cJSON_GetObjectItem(childProperties, "minimum");
if (Min)
{
cJSON *exclusiveMin = cJSON_GetObjectItem(childProperties, "exclusiveMinimum");
if (exclusiveMin)
{
if (exclusiveMin->type == cJSON_True)
property->setMinDouble( ++(Min->valuedouble));
else
property->setMinDouble(Min->valuedouble);
}
else
property->setMinDouble(Min->valuedouble);
}
cJSON *multipleOf = cJSON_GetObjectItem(childProperties, "multipleOf");
if (multipleOf)
{
property->setMultipleOf(multipleOf->valueint);
}
}
DefinitionsPtr JsonSchema::readRef(std::string m_ref)
{
std::string delimiter1 = "#";
......
......@@ -280,7 +280,8 @@ namespace RAML
const std::string &attType);
void readString( cJSON *childProperties, PropertiesPtr property);
void readArray( cJSON *childProperties, PropertiesPtr property);
void readNumber( cJSON *childProperties, PropertiesPtr property);
void readInteger( cJSON *childProperties, PropertiesPtr property);
void readDouble( cJSON *childProperties, PropertiesPtr property);
DefinitionsPtr readRef(std::string m_ref);
......
......@@ -50,8 +50,8 @@ namespace RAML
/**
* Constructor of Properties.
*/
Properties(): m_min(INT_MAX), m_max(INT_MAX), m_multipleOf(INT_MAX), m_updateInterval(0),
m_unique(false), m_additionalItems(false) {}
Properties(): m_min(INT_MAX), m_max(INT_MAX), m_doubleMin(INT_MAX), m_doubleMax(INT_MAX),
m_multipleOf(INT_MAX), m_unique(false), m_additionalItems(false) {}
/**
* Constructor of Properties.
......@@ -59,7 +59,8 @@ namespace RAML
* @param name - Properties name as string.
*/
Properties(const std::string &name) : m_name(name), m_min(INT_MAX), m_max(INT_MAX),
m_multipleOf(INT_MAX), m_updateInterval(0), m_unique(false), m_additionalItems(false) {}
m_doubleMin(INT_MAX), m_doubleMax(INT_MAX), m_multipleOf(INT_MAX),
m_unique(false), m_additionalItems(false) {}
/**
* This method is for getting Name from Properties.
......@@ -194,6 +195,19 @@ namespace RAML
multipleOf = m_multipleOf;
}
/**
* This method is for getting Range from Properties.
*
* @param min - reference to hold Minimum value of Properties.
* @param max - reference to hold Maximum value of Properties.
* @param multipleOf - reference to hold multipleOf value of Properties.
*/
inline void getRangeDouble(double &min, double &max, int &multipleOf) const
{
min = m_doubleMin;
max = m_doubleMax;
multipleOf = m_multipleOf;
}
/**
* This method is for setting Minimum to Properties
*
......@@ -214,6 +228,25 @@ namespace RAML
m_max = max;
}
/**
* This method is for setting Minimum to Properties
*
* @param min - Minimum value of Properties.
*/
inline void setMinDouble(const double &min)
{
m_doubleMin = min;
}
/**
* This method is for setting Maximum to Properties
*
* @param max - Maximum value of Properties.
*/
inline void setMaxDouble(const double &max)
{
m_doubleMax = max;
}
/**
* This method is for setting multipleOf to Properties
*
......@@ -322,26 +355,6 @@ namespace RAML
return m_description;
}
/**
* This method is for getting UpdateFrequency from Properties.
*
* @return UpdateFrequency as int
*/
inline int getUpdateFrequencyTime()
{
return m_updateInterval;
}
/**
* This method is for setting UpdateFrequency to Properties
*
* @param interval - UpdateFrequency as int.
*/
inline void setUpdateFrequencyTime(int interval)
{
m_updateInterval = interval;
}
/**
* This method is for setting Type to Properties
*
......@@ -469,9 +482,10 @@ namespace RAML
ValueVariant m_value;
int m_min;
int m_max;
double m_doubleMin;
double m_doubleMax;
int m_multipleOf;
AllowedValues m_allowedValues;
int m_updateInterval;
std::string m_type;
std::string m_pattern;
std::string m_format;
......
......@@ -118,9 +118,6 @@ SimulatorResourceServerImplSP SimulatorResourceCreator::createResource(
break;
}
// Set attriute update frequency interval
attribute.setUpdateFrequencyTime(propertyElement.second->getUpdateFrequencyTime());
// Set range/supported values set
int min = 0, max = 0, multipleof = 0;
propertyElement.second->getRange(min, max, multipleof);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment