summaryrefslogtreecommitdiff
path: root/src/components/smart_objects/include/smart_objects
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/smart_objects/include/smart_objects')
-rw-r--r--src/components/smart_objects/include/smart_objects/always_false_schema_item.h9
-rw-r--r--src/components/smart_objects/include/smart_objects/always_true_schema_item.h9
-rw-r--r--src/components/smart_objects/include/smart_objects/array_schema_item.h14
-rw-r--r--src/components/smart_objects/include/smart_objects/default_shema_item.h30
-rw-r--r--src/components/smart_objects/include/smart_objects/enum_schema_item.h30
-rw-r--r--src/components/smart_objects/include/smart_objects/number_schema_item.h35
-rw-r--r--src/components/smart_objects/include/smart_objects/object_schema_item.h9
-rw-r--r--src/components/smart_objects/include/smart_objects/schema_item.h19
-rw-r--r--src/components/smart_objects/include/smart_objects/smart_object.h41
-rw-r--r--src/components/smart_objects/include/smart_objects/smart_schema.h21
-rw-r--r--src/components/smart_objects/include/smart_objects/string_schema_item.h9
11 files changed, 215 insertions, 11 deletions
diff --git a/src/components/smart_objects/include/smart_objects/always_false_schema_item.h b/src/components/smart_objects/include/smart_objects/always_false_schema_item.h
index dfbf4ba43e..cdddcfed55 100644
--- a/src/components/smart_objects/include/smart_objects/always_false_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/always_false_schema_item.h
@@ -49,11 +49,20 @@ class CAlwaysFalseSchemaItem : public ISchemaItem {
**/
static utils::SharedPtr<CAlwaysFalseSchemaItem> create();
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
* @return Errors::ERROR
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ /**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return Errors::ERROR
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
private:
CAlwaysFalseSchemaItem();
diff --git a/src/components/smart_objects/include/smart_objects/always_true_schema_item.h b/src/components/smart_objects/include/smart_objects/always_true_schema_item.h
index 3dd598d7bd..e078ae3240 100644
--- a/src/components/smart_objects/include/smart_objects/always_true_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/always_true_schema_item.h
@@ -49,11 +49,20 @@ class CAlwaysTrueSchemaItem : public ISchemaItem {
**/
static utils::SharedPtr<CAlwaysTrueSchemaItem> create();
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
* @return NsSmartObjects::Errors::eType
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ /**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
private:
CAlwaysTrueSchemaItem();
diff --git a/src/components/smart_objects/include/smart_objects/array_schema_item.h b/src/components/smart_objects/include/smart_objects/array_schema_item.h
index 0d3a651d56..937979f2fa 100644
--- a/src/components/smart_objects/include/smart_objects/array_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/array_schema_item.h
@@ -63,6 +63,8 @@ class CArraySchemaItem : public ISchemaItem {
TSchemaItemParameter<size_t>());
/**
+ * @deprecated
+ *
* @brief Validate smart object.
*
* @param Object Object to validate.
@@ -72,6 +74,18 @@ class CArraySchemaItem : public ISchemaItem {
Errors::eType validate(const SmartObject& Object) OVERRIDE;
/**
+ * @brief Validate smart object.
+ *
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * message if an error occurs
+ *
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
+
+ /**
* @brief Apply schema.
*
* @param Object Object to apply schema.
diff --git a/src/components/smart_objects/include/smart_objects/default_shema_item.h b/src/components/smart_objects/include/smart_objects/default_shema_item.h
index 857354a4e6..56952dbac1 100644
--- a/src/components/smart_objects/include/smart_objects/default_shema_item.h
+++ b/src/components/smart_objects/include/smart_objects/default_shema_item.h
@@ -50,11 +50,20 @@ class CDefaultSchemaItem : public ISchemaItem {
public:
typedef TSchemaItemParameter<Type> ParameterType;
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
- * @return NsSmartObjects::Errors::eType
+ * @return Errors::ERROR
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ /**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return Errors::ERROR
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
/**
* @brief Set default value to an object.
@@ -99,8 +108,23 @@ CDefaultSchemaItem<Type>::CDefaultSchemaItem(const ParameterType& DefaultValue)
template <typename Type>
Errors::eType CDefaultSchemaItem<Type>::validate(const SmartObject& Object) {
- return (getSmartType() == Object.getType()) ? Errors::OK
- : Errors::INVALID_VALUE;
+ rpc::ValidationReport report("RPC");
+ return validate(Object, &report);
+}
+
+template <typename Type>
+Errors::eType CDefaultSchemaItem<Type>::validate(
+ const SmartObject& Object, rpc::ValidationReport* report__) {
+ if (getSmartType() != Object.getType()) {
+ std::string validation_info = "Incorrect type, expected: " +
+ SmartObject::typeToString(getSmartType()) +
+ ", got: " +
+ SmartObject::typeToString(Object.getType());
+ report__->set_validation_info(validation_info);
+ return Errors::INVALID_VALUE;
+ } else {
+ return Errors::OK;
+ }
}
template <typename Type>
diff --git a/src/components/smart_objects/include/smart_objects/enum_schema_item.h b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
index a0d6d94017..524d966188 100644
--- a/src/components/smart_objects/include/smart_objects/enum_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/enum_schema_item.h
@@ -65,12 +65,21 @@ class TEnumSchemaItem : public CDefaultSchemaItem<EnumType> {
const TSchemaItemParameter<EnumType>& DefaultValue =
TSchemaItemParameter<EnumType>());
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
* @return NsSmartObjects::Errors::eType
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
/**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
+ /**
* @brief Apply schema.
* This implementation checks if enumeration is represented as string
* and tries to convert it to integer according to element-to-string
@@ -207,11 +216,32 @@ utils::SharedPtr<TEnumSchemaItem<EnumType> > TEnumSchemaItem<EnumType>::create(
template <typename EnumType>
Errors::eType TEnumSchemaItem<EnumType>::validate(const SmartObject& Object) {
+ rpc::ValidationReport report("RPC");
+ return validate(Object, &report);
+}
+
+template <typename EnumType>
+Errors::eType TEnumSchemaItem<EnumType>::validate(
+ const SmartObject& Object, rpc::ValidationReport* report__) {
if (SmartType_Integer != Object.getType()) {
+ std::string validation_info;
+ if (SmartType_String == Object.getType()) {
+ validation_info = "Invalid enum value: " + Object.asString();
+ } else {
+ validation_info = "Incorrect type, expected: " +
+ SmartObject::typeToString(SmartType_Integer) +
+ " (enum), got: " +
+ SmartObject::typeToString(Object.getType());
+ }
+ report__->set_validation_info(validation_info);
return Errors::INVALID_VALUE;
}
if (mAllowedElements.find(static_cast<EnumType>(Object.asInt())) ==
mAllowedElements.end()) {
+ std::stringstream stream;
+ stream << "Invalid enum value: " << Object.asInt();
+ std::string validation_info = stream.str();
+ report__->set_validation_info(validation_info);
return Errors::OUT_OF_RANGE;
}
return Errors::OK;
diff --git a/src/components/smart_objects/include/smart_objects/number_schema_item.h b/src/components/smart_objects/include/smart_objects/number_schema_item.h
index 01d6c08daa..d549b9891a 100644
--- a/src/components/smart_objects/include/smart_objects/number_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/number_schema_item.h
@@ -65,11 +65,20 @@ class TNumberSchemaItem : public CDefaultSchemaItem<NumberType> {
TSchemaItemParameter<NumberType>());
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
- * @return NsSmartObjects::Errors::eType
+ * @return Errors::ERROR
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ /**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return Errors::ERROR
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
private:
/**
@@ -128,7 +137,21 @@ bool TNumberSchemaItem<NumberType>::isValidNumberType(SmartType type) {
template <typename NumberType>
Errors::eType TNumberSchemaItem<NumberType>::validate(
const SmartObject& Object) {
+ rpc::ValidationReport report("RPC");
+ return validate(Object, &report);
+}
+
+template <typename NumberType>
+Errors::eType TNumberSchemaItem<NumberType>::validate(
+ const SmartObject& Object, rpc::ValidationReport* report__) {
if (!isValidNumberType(Object.getType())) {
+ SmartType expectedType = (typeid(double) == typeid(Object.getType()))
+ ? SmartType_Double
+ : SmartType_Integer;
+ std::string validation_info =
+ "Incorrect type, expected: " + SmartObject::typeToString(expectedType) +
+ ", got: " + SmartObject::typeToString(Object.getType());
+ report__->set_validation_info(validation_info);
return Errors::INVALID_VALUE;
}
NumberType value(0);
@@ -148,10 +171,20 @@ Errors::eType TNumberSchemaItem<NumberType>::validate(
NumberType rangeLimit;
if (mMinValue.getValue(rangeLimit) && (value < rangeLimit)) {
+ std::stringstream stream;
+ stream << "Value too small, got: " << value
+ << ", minimum allowed: " << rangeLimit;
+ std::string validation_info = stream.str();
+ report__->set_validation_info(validation_info);
return Errors::OUT_OF_RANGE;
}
if (mMaxValue.getValue(rangeLimit) && (value > rangeLimit)) {
+ std::stringstream stream;
+ stream << "Value too large, got: " << value
+ << ", maximum allowed: " << rangeLimit;
+ std::string validation_info = stream.str();
+ report__->set_validation_info(validation_info);
return Errors::OUT_OF_RANGE;
}
return Errors::OK;
diff --git a/src/components/smart_objects/include/smart_objects/object_schema_item.h b/src/components/smart_objects/include/smart_objects/object_schema_item.h
index 549166e723..8922caba45 100644
--- a/src/components/smart_objects/include/smart_objects/object_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/object_schema_item.h
@@ -84,12 +84,21 @@ class CObjectSchemaItem : public ISchemaItem {
**/
static utils::SharedPtr<CObjectSchemaItem> create(const Members& Members);
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
* @return NsSmartObjects::Errors::eType
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
/**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
+ /**
* @brief Apply schema.
* @param Object Object to apply schema.
* @param RemoveFakeParameters contains true if need to remove fake parameters
diff --git a/src/components/smart_objects/include/smart_objects/schema_item.h b/src/components/smart_objects/include/smart_objects/schema_item.h
index 08610f244e..446c7fa65f 100644
--- a/src/components/smart_objects/include/smart_objects/schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/schema_item.h
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include "utils/shared_ptr.h"
+#include "rpc_base/validation_report.h"
#include "smart_objects/errors.h"
@@ -47,13 +48,27 @@ class SmartObject;
class ISchemaItem {
public:
/**
- * @brief Validate object.
+ * @deprecated
+ *
+ * @brief Validate smart object.
+ *
+ * @param Object Object to validate.
+ *
+ * @return NsSmartObjects::Errors::eType
+ **/
+ DEPRECATED virtual Errors::eType validate(const SmartObject& Object);
+
+ /**
+ * @brief Validate smart object.
*
* @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * message if an error occurs
*
* @return NsSmartObjects::Errors::eType
**/
- virtual Errors::eType validate(const SmartObject& Object);
+ virtual Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__);
/**
* @brief Set default value to an object.
diff --git a/src/components/smart_objects/include/smart_objects/smart_object.h b/src/components/smart_objects/include/smart_objects/smart_object.h
index 98e58fffd1..cc2bc7e22c 100644
--- a/src/components/smart_objects/include/smart_objects/smart_object.h
+++ b/src/components/smart_objects/include/smart_objects/smart_object.h
@@ -40,6 +40,7 @@
#include "smart_objects/smart_schema.h"
#include "utils/custom_string.h"
+#include "rpc_base/validation_report.h"
namespace NsSmartDeviceLink {
namespace NsSmartObjects {
@@ -670,11 +671,20 @@ class SmartObject FINAL {
bool isValid() const;
/**
+ * @deprecated
* @brief Validates object according to attached schema.
*
* @return Result of validation.
*/
- Errors::eType validate();
+ DEPRECATED Errors::eType validate();
+
+ /**
+ * @brief Validates object according to attached schema.
+ *
+ * @param report__ object for reporting errors during validation
+ * @return Result of validation.
+ */
+ Errors::eType validate(rpc::ValidationReport* report__);
/**
* @brief Sets new schema
@@ -727,6 +737,35 @@ class SmartObject FINAL {
return !(*this == Other);
}
+ static std::string typeToString(SmartType type) {
+ switch (type) {
+ case SmartType_Null:
+ return "Null";
+ case SmartType_Boolean:
+ return "Boolean";
+ case SmartType_Integer:
+ return "Integer";
+ case SmartType_Character:
+ return "Character";
+ case SmartType_String:
+ return "String";
+ case SmartType_Double:
+ return "Double";
+ case SmartType_Map:
+ return "Object";
+ case SmartType_Array:
+ return "Array";
+ case SmartType_Binary:
+ return "Binary_Data";
+ case SmartType_UInteger:
+ return "Unsigned_Integer";
+ case SmartType_Invalid:
+ return "Invalid_Type";
+ default:
+ return "Unknown_Type";
+ }
+ }
+
protected:
static std::string OperatorToTransform(const SmartMap::value_type& pair);
/**
diff --git a/src/components/smart_objects/include/smart_objects/smart_schema.h b/src/components/smart_objects/include/smart_objects/smart_schema.h
index 52dfa12004..ada5646043 100644
--- a/src/components/smart_objects/include/smart_objects/smart_schema.h
+++ b/src/components/smart_objects/include/smart_objects/smart_schema.h
@@ -61,13 +61,26 @@ class CSmartSchema FINAL {
explicit CSmartSchema(const ISchemaItemPtr SchemaItem);
/**
+ * @deprecated
+ *
* @brief Validate smart object.
*
- * @param Object SmartObject to validate.
+ * @param Object Object to validate.
*
- * @return Result of validation.
- */
- Errors::eType validate(const SmartObject& Object) const;
+ * @return NsSmartObjects::Errors::eType
+ **/
+ DEPRECATED Errors::eType validate(const SmartObject& Object) const;
+
+ /**
+ * @brief Validate smart object.
+ *
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ *
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) const;
/**
* @brief Set new root schema item.
diff --git a/src/components/smart_objects/include/smart_objects/string_schema_item.h b/src/components/smart_objects/include/smart_objects/string_schema_item.h
index 7fad8491a5..6c98dcc3b3 100644
--- a/src/components/smart_objects/include/smart_objects/string_schema_item.h
+++ b/src/components/smart_objects/include/smart_objects/string_schema_item.h
@@ -62,11 +62,20 @@ class CStringSchemaItem : public CDefaultSchemaItem<std::string> {
const TSchemaItemParameter<std::string>& DefaultValue =
TSchemaItemParameter<std::string>());
/**
+ * @deprecated
* @brief Validate smart object.
* @param Object Object to validate.
* @return NsSmartObjects::Errors::eType
**/
Errors::eType validate(const SmartObject& Object) OVERRIDE;
+ /**
+ * @brief Validate smart object.
+ * @param Object Object to validate.
+ * @param report__ object for reporting errors during validation
+ * @return NsSmartObjects::Errors::eType
+ **/
+ Errors::eType validate(const SmartObject& Object,
+ rpc::ValidationReport* report__) OVERRIDE;
private:
/**