[messaging] Replacing MessageFolder with picojson part 2. 54/219154/9
authorMichal Michalski <m.michalski2@partner.samsung.com>
Mon, 2 Dec 2019 11:35:18 +0000 (12:35 +0100)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Fri, 6 Dec 2019 08:37:03 +0000 (09:37 +0100)
+ 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 <m.michalski2@partner.samsung.com>
Change-Id: I578dcbd7b9d4fb5650f0eca1ecb264a78aff8962

src/messaging/MsgCommon/AbstractFilter.cpp
src/messaging/MsgCommon/AbstractFilter.h
src/messaging/folders_change_callback.cc
src/messaging/folders_change_callback.h
src/messaging/message_folder.cc
src/messaging/message_folder.h

index 3acdf316db8540774cfedb94a634157d9a2bfb57..be6aca88b9bfd872f347d82c12446ad9be2162f9 100644 (file)
@@ -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<std::string>()) return isMatching(filter_value, value.get<std::string>(), flag);
+  if (value.is<bool>()) return isMatching(filter_value, value.get<bool>(), flag);
+  if (value.is<double>())
+    return isMatching(filter_value, static_cast<unsigned long>(value.get<double>()), flag);
+  return false;
+}
+
 bool FilterUtils::isAnyStringMatching(const std::string& key,
                                       const std::vector<std::string>& values,
                                       AttributeMatchFlag flag) {
index feea7865978cb08e982555a79b871959b454a408..0a22f034fb78845dd1022e4a4ce5b63b481ff6a9 100644 (file)
@@ -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
 
index 9c81cbcb3961694b7589277173fa2cdb82a9108c..0c4dd0b9983d4e53b3c074482ceee77d15b47865 100644 (file)
@@ -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;
 }
index 732a2b2d8bee467bc9708a25113aa032e6a1f1d8..683dc9e5dbbb1d0325bc8bda44474d934f4a72da 100644 (file)
@@ -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;
index b016ec348222e3425900a53b01b1cb25a01f2b00..09eb68d9cc1a63748e6022866bf3544bec9eeb89 100644 (file)
@@ -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<double>(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<double>(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>();
-}
-
-std::string MessageFolder::getParentId() const {
-  return attributes.at("parentId").get<std::string>();
-}
-
-bool MessageFolder::isParentIdSet() const {
-  return attributes.at("parentId").is<std::string>() &&
-         not attributes.at("parentId").get<std::string>().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>();
-}
-
-std::string MessageFolder::getContentType() const {
-  return attributes.at("contentType").get<std::string>();
-}
-
-std::string MessageFolder::getName() const {
-  return attributes.at("name").get<std::string>();
-}
-
-void MessageFolder::setName(const std::string& value) {
-  attributes["name"] = picojson::value(value);
-}
-
-std::string MessageFolder::getPath() const {
-  return attributes.at("path").get<std::string>();
+  return attributes.at(MESSAGE_FOLDER_ATTRIBUTE_ID).get<std::string>();
 }
 
 MessageFolderType MessageFolder::getType() const {
-  return static_cast<MessageFolderType>(static_cast<int>(attributes.at("type").get<double>()));
-}
-
-bool MessageFolder::getSynchronizable() const {
-  return attributes.at("synchronizable").get<bool>();
-}
-
-void MessageFolder::setSynchronizable(const bool& value) {
-  attributes.at("synchronizable") = picojson::value(value);
+  return static_cast<MessageFolderType>(
+      static_cast<int>(attributes.at(MESSAGE_FOLDER_ATTRIBUTE_TYPE).get<double>()));
 }
 
 picojson::value MessageFolder::toJSON() const {
   picojson::value json(attributes);
-  json.get<picojson::object>()["type"] = picojson::value(messageFolderTypeToString(getType()));
+  json.get<picojson::object>()[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<std::string>().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<std::string>().c_str(), "false");
     }
   }
 
index 60071280a9c4528c3ae6f0cd6dc16b2f1fba37c3..9e81901940e0065e40e4d4c6acb61361eaf772fd 100644 (file)
@@ -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<std::shared_ptr<MessageFolder>> FolderPtrVector;