[Messaging][SMS] Added support for CompositeFilter.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 22 Jan 2015 14:09:29 +0000 (15:09 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 23 Jan 2015 07:00:47 +0000 (08:00 +0100)
[Verification] TCT MessageStorage_sms_findMessages_plainBody_and_id_with_errorCallback should pass.
               TCT pass rate for SMS: 182/182.

Change-Id: I26064c4e17ee807a448f2d21b92a1d071c6c3279
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/messaging/MsgCommon/CompositeFilter.cpp
src/messaging/MsgCommon/CompositeFilter.h
src/messaging/messaging_api.js
src/messaging/messaging_util.cc
src/messaging/messaging_util.h

index 5ecac84d7e16d7e9ace3684dd74b191aadc43742..fc4d9ce8a5bcda51defb5c96fbaac224804abc7c 100644 (file)
@@ -58,6 +58,11 @@ const AbstractFilterPtrVector& CompositeFilter::getFilters() const
     return m_filters;
 }
 
+void CompositeFilter::addFilter(const AbstractFilterPtr& filter)
+{
+    m_filters.push_back(filter);
+}
+
 //void CompositeFilter::setFilters(const AbstractFilterPtrVector &filters)
 //{
 //    if (Common::GlobalContextManager::getInstance()->isAliveGlobalContext(
index 09741b1bc1f162cd40bd2543fa2972e86dcc65f3..e17c09458cb042509ff40cc1ebbfba3f1b5b6e25 100644 (file)
@@ -44,7 +44,8 @@ public:
     CompositeFilterType getType() const;
     void setType(CompositeFilterType type);
     const AbstractFilterPtrVector& getFilters() const;
-    void setFilters(const AbstractFilterPtrVector &filter);
+    void addFilter(const AbstractFilterPtr& filter);
+//    void setFilters(const AbstractFilterPtrVector &filter);
 //    JSFilterArray getJSFilters(JSContextRef ctx);
 //    JSContextRef getContext() const;
 
index 716ec572f9efc2c37623822595dc3ff042c56878..494e8b5b08bbf2ca412ef44b301ed59fac41da48 100644 (file)
@@ -63,10 +63,18 @@ function addTypeToFilter_(data)
     }
 
     if (data instanceof tizen.AttributeFilter) {
-        filter.type = "AttributeFilter";
-    }
-    if (data instanceof tizen.AttributeRangeFilter) {
-        filter.type = "AttributeRangeFilter";
+        filter.filterType = "AttributeFilter";
+    } else if (data instanceof tizen.AttributeRangeFilter) {
+        filter.filterType = "AttributeRangeFilter";
+    } else if (data instanceof tizen.CompositeFilter) {
+        filter.filterType = "CompositeFilter";
+        // recursively convert all sub-filters
+        filter.filters = [];
+        for (var i = 0; i < data.filters.length; ++i) {
+            filter.filters[i] = addTypeToFilter_(data.filters[i]);
+        }
+    } else {
+        filter.filterType = "Unknown";
     }
 
     return filter;
index b1c45494d1b173bf0a8027636380b67518b9112a..8e16b4fd6294a23585ffc7218d5404ca7173cc68 100644 (file)
@@ -107,9 +107,12 @@ const std::string JSON_TO_MATCH_FLAG = "matchFlag";
 const std::string JSON_TO_MATCH_VALUE = "matchValue";
 const std::string JSON_TO_INITIAL_VALUE = "initialValue";
 const std::string JSON_TO_END_VALUE = "endValue";
+const std::string JSON_TO_TYPE = "type";
+const std::string JSON_TO_FILTER_ARRAY = "filters";
 
+const char* JSON_FILTER_TYPE = "filterType";
 const char* JSON_FILTER_ATTRIBUTE_TYPE = "AttributeFilter";
-const char* JSON_FILTER_ATTRIBUTERANGE_TYPE = "AttributeRangeFilter";
+const char* JSON_FILTER_ATTRIBUTE_RANGE_TYPE = "AttributeRangeFilter";
 const char* JSON_FILTER_COMPOSITE_TYPE = "CompositeFilter";
 
 const std::map<std::string, MessageType> stringToTypeMap = {
@@ -673,25 +676,30 @@ tizen::AbstractFilterPtr MessagingUtil::jsonToAbstractFilter(const picojson::obj
 {
     LoggerD("Entered");
 
-    if (json.at(JSON_TO_FILTER).is<picojson::null>()) {
+    const auto it = json.find(JSON_TO_FILTER);
+
+    if (json.end() == it || it->second.is<picojson::null>()) {
         return AbstractFilterPtr();
     }
 
-    auto filter = getValueFromJSONObject<picojson::object>(json, JSON_TO_FILTER);
-    std::string type = getValueFromJSONObject<std::string>(filter, "type");
+    return jsonFilterToAbstractFilter(json.at(JSON_TO_FILTER).get<picojson::object>());
+}
+
+tizen::AbstractFilterPtr MessagingUtil::jsonFilterToAbstractFilter(const picojson::object& filter)
+{
+    const auto& type = filter.at(JSON_FILTER_TYPE).get<std::string>();
 
-    if( JSON_FILTER_ATTRIBUTE_TYPE == type ){
+    if (JSON_FILTER_ATTRIBUTE_TYPE == type) {
         return jsonFilterToAttributeFilter(filter);
     }
-    if( JSON_FILTER_ATTRIBUTERANGE_TYPE == type ){
+    if (JSON_FILTER_ATTRIBUTE_RANGE_TYPE == type) {
         return jsonFilterToAttributeRangeFilter(filter);
     }
-    if( JSON_FILTER_COMPOSITE_TYPE == type ) {
-        //TODO jsonToCompositeFilter
-        LoggerD("Composite filter currently not supported");
+    if (JSON_FILTER_COMPOSITE_TYPE == type) {
+        return jsonFilterToCompositeFilter(filter);
     }
 
-    LoggerE("Unsupported filter type");
+    LoggerE("Unsupported filter type: %s", type.c_str());
     throw common::TypeMismatchException("Unsupported filter type");
     return AbstractFilterPtr();
 }
@@ -749,6 +757,36 @@ tizen::AttributeRangeFilterPtr MessagingUtil::jsonFilterToAttributeRangeFilter(c
     return  attributeRangePtr;
 }
 
+tizen::CompositeFilterPtr MessagingUtil::jsonFilterToCompositeFilter(const picojson::object& filter)
+{
+    LoggerD("Entered");
+
+    using namespace tizen;
+
+    const auto& type = filter.at(JSON_TO_TYPE).get<std::string>();
+
+    CompositeFilterType filterType = CompositeFilterType::UNION;
+
+    if (STR_FILTEROP_OR == type) {
+        filterType = CompositeFilterType::UNION;
+    }
+    else if (STR_FILTEROP_AND == type) {
+        filterType = CompositeFilterType::INTERSECTION;
+    }
+    else {
+        LoggerE("Composite filter type is not recognized: %s", type.c_str());
+        throw common::TypeMismatchException("Composite filter type is not recognized");
+    }
+
+    CompositeFilterPtr compositeFilter{new CompositeFilter(filterType)};
+
+    for (const auto& a : filter.at(JSON_TO_FILTER_ARRAY).get<picojson::array>()) {
+        compositeFilter->addFilter(jsonFilterToAbstractFilter(a.get<picojson::object>()));
+    }
+
+    return compositeFilter;
+}
+
 std::shared_ptr<MessageAttachment> MessagingUtil::jsonToMessageAttachment(const picojson::value& json)
 {
     LoggerD("Entered");
index 849959861b71b138bd29150612cbc34fdf23c959..632231c62a0e34dcba8afbb68985f6ee6022c328 100644 (file)
@@ -157,8 +157,10 @@ public:
     static std::string messageStatusToString(MessageStatus status);
 
 private:
+    static tizen::AbstractFilterPtr jsonFilterToAbstractFilter(const picojson::object& json);
     static tizen::AttributeFilterPtr jsonFilterToAttributeFilter(const picojson::object& json);
     static tizen::AttributeRangeFilterPtr jsonFilterToAttributeRangeFilter(const picojson::object& json);
+    static tizen::CompositeFilterPtr jsonFilterToCompositeFilter(const picojson::object& json);
 };
 
 enum PostPriority {