From 17172954f78d7ee42e31b6f86ef411c246e3ce0a Mon Sep 17 00:00:00 2001 From: Michal Michalski Date: Mon, 2 Dec 2019 12:35:18 +0100 Subject: [PATCH] [messaging] Replacing MessageFolder with picojson part 2. + FilterUtils::isMatching() overload for picojson::value. + Removed some getters/setters from MeessageFolder. + Removed unused FoldersChangeCallback::getFilter() method. + Simplified implementation of MessageFolder::isMatchingAttribute(). + Removed stringToMessageFolderType() unused function. [Verification] tct-messaging-*-tizen-tests 100% pass. Signed-off-by: Michal Michalski Change-Id: I578dcbd7b9d4fb5650f0eca1ecb264a78aff8962 --- src/messaging/MsgCommon/AbstractFilter.cpp | 10 +++ src/messaging/MsgCommon/AbstractFilter.h | 2 + src/messaging/folders_change_callback.cc | 4 - src/messaging/folders_change_callback.h | 1 - src/messaging/message_folder.cc | 113 ++++++----------------------- src/messaging/message_folder.h | 12 --- 6 files changed, 36 insertions(+), 106 deletions(-) diff --git a/src/messaging/MsgCommon/AbstractFilter.cpp b/src/messaging/MsgCommon/AbstractFilter.cpp index 3acdf31..be6aca8 100644 --- a/src/messaging/MsgCommon/AbstractFilter.cpp +++ b/src/messaging/MsgCommon/AbstractFilter.cpp @@ -178,6 +178,16 @@ bool FilterUtils::isMatching(const Any& match_value, const bool value, Attribute return false; } +bool FilterUtils::isMatching(const Any& filter_value, const picojson::value& value, + common::AttributeMatchFlag flag) { + ScopeLogger(); + if (value.is()) return isMatching(filter_value, value.get(), flag); + if (value.is()) return isMatching(filter_value, value.get(), flag); + if (value.is()) + return isMatching(filter_value, static_cast(value.get()), flag); + return false; +} + bool FilterUtils::isAnyStringMatching(const std::string& key, const std::vector& values, AttributeMatchFlag flag) { diff --git a/src/messaging/MsgCommon/AbstractFilter.h b/src/messaging/MsgCommon/AbstractFilter.h index feea786..0a22f03 100644 --- a/src/messaging/MsgCommon/AbstractFilter.h +++ b/src/messaging/MsgCommon/AbstractFilter.h @@ -112,6 +112,8 @@ bool isMatching(const Any& filter_value, const std::string& value, common::Attri bool isMatching(const Any& filter_value, const bool value, common::AttributeMatchFlag flag); bool isMatching(const Any& filter_value, const unsigned long value, common::AttributeMatchFlag flag); +bool isMatching(const Any& filter_value, const picojson::value& value, + common::AttributeMatchFlag flag); } // namespace FilterUtils diff --git a/src/messaging/folders_change_callback.cc b/src/messaging/folders_change_callback.cc index 9c81cbc..0c4dd0b 100644 --- a/src/messaging/folders_change_callback.cc +++ b/src/messaging/folders_change_callback.cc @@ -80,10 +80,6 @@ void FoldersChangeCallback::setFilter(tizen::AbstractFilterPtr filter) { m_filter = filter; } -tizen::AbstractFilterPtr FoldersChangeCallback::getFilter() const { - return m_filter; -} - int FoldersChangeCallback::getServiceId() const { return m_id; } diff --git a/src/messaging/folders_change_callback.h b/src/messaging/folders_change_callback.h index 732a2b2..683dc9e 100644 --- a/src/messaging/folders_change_callback.h +++ b/src/messaging/folders_change_callback.h @@ -38,7 +38,6 @@ class FoldersChangeCallback { void removed(const FolderPtrVector& folders); void setFilter(tizen::AbstractFilterPtr filter); - tizen::AbstractFilterPtr getFilter() const; int getServiceId() const; MessageType getServiceType() const; diff --git a/src/messaging/message_folder.cc b/src/messaging/message_folder.cc index b016ec3..09eb68d 100644 --- a/src/messaging/message_folder.cc +++ b/src/messaging/message_folder.cc @@ -74,36 +74,19 @@ std::string messageFolderTypeToString(MessageFolderType type) { } } -MessageFolderType stringToMessageFolderType(const std::string& type) { - ScopeLogger(); - if (FOLDER_TYPE_INBOX == type) { - return MessageFolderType::MESSAGE_FOLDER_TYPE_INBOX; - } - if (FOLDER_TYPE_OUTBOX == type) { - return MessageFolderType::MESSAGE_FOLDER_TYPE_OUTBOX; - } - if (FOLDER_TYPE_DRAFTS == type) { - return MessageFolderType::MESSAGE_FOLDER_TYPE_DRAFTS; - } - if (FOLDER_TYPE_SENTBOX == type) { - return MessageFolderType::MESSAGE_FOLDER_TYPE_SENTBOX; - } - return MessageFolderType::MESSAGE_FOLDER_TYPE_NOTSTANDARD; -} - MessageFolder::MessageFolder(const std::string& id, const std::string& parent_id, const std::string& service_id, const std::string& content_type, const std::string& name, const std::string& path, MessageFolderType type, bool synchronizable) { ScopeLogger(); - attributes["id"] = picojson::value(id); - attributes["parentId"] = picojson::value(parent_id); - attributes["serviceId"] = picojson::value(service_id); - attributes["contentType"] = picojson::value(content_type); - attributes["name"] = picojson::value(name); - attributes["path"] = picojson::value(path); - attributes["type"] = picojson::value(static_cast(type)); - attributes["synchronizable"] = picojson::value(synchronizable); + attributes[MESSAGE_FOLDER_ATTRIBUTE_ID] = picojson::value(id); + attributes[MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID] = picojson::value(parent_id); + attributes[MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID] = picojson::value(service_id); + attributes[MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE] = picojson::value(content_type); + attributes[MESSAGE_FOLDER_ATTRIBUTE_NAME] = picojson::value(name); + attributes[MESSAGE_FOLDER_ATTRIBUTE_PATH] = picojson::value(path); + attributes[MESSAGE_FOLDER_ATTRIBUTE_TYPE] = picojson::value(static_cast(type)); + attributes[MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE] = picojson::value(synchronizable); } MessageFolder::MessageFolder(email_mailbox_t mailbox) @@ -119,57 +102,18 @@ MessageFolder::MessageFolder(const picojson::value& json) { } std::string MessageFolder::getId() const { - return attributes.at("id").get(); -} - -std::string MessageFolder::getParentId() const { - return attributes.at("parentId").get(); -} - -bool MessageFolder::isParentIdSet() const { - return attributes.at("parentId").is() && - not attributes.at("parentId").get().empty(); -} - -void MessageFolder::setParentId(const std::string& parentId) { - attributes["parentId"] = picojson::value(parentId); -} - -std::string MessageFolder::getServiceId() const { - return attributes.at("serviceId").get(); -} - -std::string MessageFolder::getContentType() const { - return attributes.at("contentType").get(); -} - -std::string MessageFolder::getName() const { - return attributes.at("name").get(); -} - -void MessageFolder::setName(const std::string& value) { - attributes["name"] = picojson::value(value); -} - -std::string MessageFolder::getPath() const { - return attributes.at("path").get(); + return attributes.at(MESSAGE_FOLDER_ATTRIBUTE_ID).get(); } MessageFolderType MessageFolder::getType() const { - return static_cast(static_cast(attributes.at("type").get())); -} - -bool MessageFolder::getSynchronizable() const { - return attributes.at("synchronizable").get(); -} - -void MessageFolder::setSynchronizable(const bool& value) { - attributes.at("synchronizable") = picojson::value(value); + return static_cast( + static_cast(attributes.at(MESSAGE_FOLDER_ATTRIBUTE_TYPE).get())); } picojson::value MessageFolder::toJSON() const { picojson::value json(attributes); - json.get()["type"] = picojson::value(messageFolderTypeToString(getType())); + json.get()[MESSAGE_FOLDER_ATTRIBUTE_TYPE] = + picojson::value(messageFolderTypeToString(getType())); return json; } @@ -180,30 +124,21 @@ bool MessageFolder::isMatchingAttribute(const std::string& attribute_name, LoggerD("attribute_name: (%s), match_flag: (%s), match_value: (%s)", attribute_name.c_str(), common::AttributeMatchFlagToString(match_flag).c_str(), match_value->toString().c_str()); + const auto attr = attributes.find(attribute_name); + if (attr == attributes.end()) { + LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str()); + return false; + } + if (common::AttributeMatchFlag::kExists == match_flag) { - return attributes.find(attribute_name) != attributes.end(); + return true; } - if (MESSAGE_FOLDER_ATTRIBUTE_ID == attribute_name) { - return FilterUtils::isMatching(*match_value, getId(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID == attribute_name) { - return FilterUtils::isMatching(*match_value, getParentId(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID == attribute_name) { - return FilterUtils::isMatching(*match_value, getServiceId(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE == attribute_name) { - return FilterUtils::isMatching(*match_value, getContentType(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_NAME == attribute_name) { - return FilterUtils::isMatching(*match_value, getName(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_PATH == attribute_name) { - return FilterUtils::isMatching(*match_value, getPath(), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_TYPE == attribute_name) { + if (MESSAGE_FOLDER_ATTRIBUTE_TYPE == attribute_name) { return FilterUtils::isMatching(*match_value, messageFolderTypeToString(getType()), match_flag); - } else if (MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE == attribute_name) { - return FilterUtils::isMatching(*match_value, getSynchronizable(), match_flag); } - LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str()); - return false; + return FilterUtils::isMatching(*match_value, attr->second, match_flag); } bool MessageFolder::isMatchingAttributeRange(const std::string& attribute_name, @@ -225,11 +160,11 @@ FolderPtrVector filterFolders(tizen::AbstractFilterPtr filter, for (const auto& fp : source_folders) { if (filter->isMatching(fp.get())) { LoggerD("folder id:%s, folder name: %s, match: %s", fp->getId().c_str(), - fp->getName().c_str(), "true"); + fp->attributes.at(MESSAGE_FOLDER_ATTRIBUTE_NAME).get().c_str(), "true"); filtered_folders.push_back(fp); } else { LoggerD("folder id:%s, folder name: %s, match: %s", fp->getId().c_str(), - fp->getName().c_str(), "false"); + fp->attributes.at(MESSAGE_FOLDER_ATTRIBUTE_NAME).get().c_str(), "false"); } } diff --git a/src/messaging/message_folder.h b/src/messaging/message_folder.h index 6007128..9e81901 100644 --- a/src/messaging/message_folder.h +++ b/src/messaging/message_folder.h @@ -47,17 +47,7 @@ class MessageFolder : public tizen::FilterableObject { MessageFolder(const picojson::value& json); std::string getId() const; - std::string getParentId() const; - bool isParentIdSet() const; - void setParentId(const std::string& parentId); - std::string getServiceId() const; - std::string getContentType() const; - std::string getName() const; - void setName(const std::string& value); - std::string getPath() const; MessageFolderType getType() const; - bool getSynchronizable() const; - void setSynchronizable(const bool& value); picojson::value toJSON() const; virtual bool isMatchingAttribute(const std::string& attribute_name, @@ -67,12 +57,10 @@ class MessageFolder : public tizen::FilterableObject { tizen::AnyPtr initial_value, tizen::AnyPtr end_value) const override; - private: picojson::object attributes; }; std::string messageFolderTypeToString(MessageFolderType); -MessageFolderType stringToMessageFolderType(std::string type); typedef std::vector> FolderPtrVector; -- 2.7.4