From: Pawel Andruszkiewicz
Date: Thu, 22 Jan 2015 14:09:29 +0000 (+0100)
Subject: [Messaging][SMS] Added support for CompositeFilter.
X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~567^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f9b36be6497b6dbd117f0eaf0125a32b0f530e9e;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Messaging][SMS] Added support for CompositeFilter.
[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
---
diff --git a/src/messaging/MsgCommon/CompositeFilter.cpp b/src/messaging/MsgCommon/CompositeFilter.cpp
index 5ecac84d..fc4d9ce8 100644
--- a/src/messaging/MsgCommon/CompositeFilter.cpp
+++ b/src/messaging/MsgCommon/CompositeFilter.cpp
@@ -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(
diff --git a/src/messaging/MsgCommon/CompositeFilter.h b/src/messaging/MsgCommon/CompositeFilter.h
index 09741b1b..e17c0945 100644
--- a/src/messaging/MsgCommon/CompositeFilter.h
+++ b/src/messaging/MsgCommon/CompositeFilter.h
@@ -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;
diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js
index 716ec572..494e8b5b 100644
--- a/src/messaging/messaging_api.js
+++ b/src/messaging/messaging_api.js
@@ -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;
diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc
index b1c45494..8e16b4fd 100644
--- a/src/messaging/messaging_util.cc
+++ b/src/messaging/messaging_util.cc
@@ -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 stringToTypeMap = {
@@ -673,25 +676,30 @@ tizen::AbstractFilterPtr MessagingUtil::jsonToAbstractFilter(const picojson::obj
{
LoggerD("Entered");
- if (json.at(JSON_TO_FILTER).is()) {
+ const auto it = json.find(JSON_TO_FILTER);
+
+ if (json.end() == it || it->second.is()) {
return AbstractFilterPtr();
}
- auto filter = getValueFromJSONObject(json, JSON_TO_FILTER);
- std::string type = getValueFromJSONObject(filter, "type");
+ return jsonFilterToAbstractFilter(json.at(JSON_TO_FILTER).get());
+}
+
+tizen::AbstractFilterPtr MessagingUtil::jsonFilterToAbstractFilter(const picojson::object& filter)
+{
+ const auto& type = filter.at(JSON_FILTER_TYPE).get();
- 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();
+
+ 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()) {
+ compositeFilter->addFilter(jsonFilterToAbstractFilter(a.get()));
+ }
+
+ return compositeFilter;
+}
+
std::shared_ptr MessagingUtil::jsonToMessageAttachment(const picojson::value& json)
{
LoggerD("Entered");
diff --git a/src/messaging/messaging_util.h b/src/messaging/messaging_util.h
index 84995986..632231c6 100644
--- a/src/messaging/messaging_util.h
+++ b/src/messaging/messaging_util.h
@@ -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 {