[Content] Add deprecation to some not frequently used members
[platform/core/api/webapi-plugins.git] / src / content / content_filter.cc
old mode 100755 (executable)
new mode 100644 (file)
index dc6135c..e17ce5b
@@ -1,6 +1,18 @@
-// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
 
 #include "content/content_filter.h"
 
@@ -8,6 +20,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
+#include "common/tools.h"
 
 using common::AttributeMatchFlag;
 using common::CompositeFilterType;
@@ -33,9 +46,12 @@ std::map<std::string, std::string> const attributeNameMap = {
     {"createdDate", "MEDIA_ADDED_TIME"},
     {"releaseDate", "MEDIA_DATETAKEN"},
     {"modifiedDate", "MEDIA_MODIFIED_TIME"},
-    {"geolocation.latitude", "MEDIA_LATITUDE"},
-    {"geolocation.longitude", "MEDIA_LONGITUDE"},
-    {"duration", "MEDIA_DURATION"},
+    {"geolocation.latitude",
+     "MEDIA_LATITUDE"},  // Deprecated since 9.0 //TODO remove after 2 versions
+    {"geolocation.longitude",
+     "MEDIA_LONGITUDE"},  // Deprecated since 9.0 //TODO remove after 2 versions
+    {"duration",
+     "MEDIA_DURATION"},  // Deprecated since 9.0 //TODO remove after 2 versions
     {"album", "MEDIA_ALBUM"},
     {"artists", "MEDIA_ARTIST"},
     {"width", "MEDIA_WIDTH"},
@@ -45,7 +61,7 @@ std::map<std::string, std::string> const attributeNameMap = {
 };
 
 std::string escapeValueString(const std::string& data) {
-  LoggerD("Enter");
+  ScopeLogger();
   std::string out;
   // If string won't be resized, then it will be faster
   out.reserve(data.size());
@@ -68,39 +84,38 @@ std::string escapeValueString(const std::string& data) {
 
 }  // namespace
 
-PlatformResult ContentFilter::MapField(const std::string& name,
-                                       std::string* result) {
-  LoggerD("Enter");
+PlatformResult ContentFilter::MapField(const std::string& name, std::string* result) {
+  ScopeLogger();
   auto it = attributeNameMap.find(name);
-  if (it != attributeNameMap.end())
+  if (it != attributeNameMap.end()) {
+    if (name == "rating" || name == "description" ||
+        name == "geolocation.latitude" || name == "geolocation.longitude" ||
+        name == "duration") {
+      std::string warning = "Filtering by attribute '" + name + "'";
+      common::tools::PrintDeprecationWarningFor(warning.c_str());
+    }
     *result = it->second;
-  else
-  {
-    LoggerE("INVALID_VALUES_ERR");
-    return PlatformResult(ErrorCode::INVALID_VALUES_ERR);
+  } else {
+    return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR);
   }
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
 PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
                                          std::string* queryToCall) {
-  LoggerD("Enter");
-  std::vector<std::vector<std::string> > partialqueries;
+  ScopeLogger();
+  std::vector<std::vector<std::string>> partialqueries;
   partialqueries.push_back(std::vector<std::string>());
 
-  visitor.SetOnAttributeFilter([&](const std::string& name,
-                                   AttributeMatchFlag match_flag,
+  visitor.SetOnAttributeFilter([&](const std::string& name, AttributeMatchFlag match_flag,
                                    const picojson::value& match_value) {
-    LoggerD("entered OnAttributeFilter");
-
-    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+    ScopeLogger("Entered into asynchronous function, visitor.SetOnAttributeFilter's argument");
 
     std::string query;
     std::string matchValue;
 
-    result = MapField(name, &query);
-    if (!result)
-      return result;
+    PlatformResult result = MapField(name, &query);
+    if (!result) return result;
 
     if (AttributeMatchFlag::kExactly == match_flag ||
         AttributeMatchFlag::kFullString == match_flag) {
@@ -112,10 +127,8 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
     } else if (AttributeMatchFlag::kExists == match_flag) {
       query += " IS NOT NULL ";
     } else {
-      LoggerE("INVALID_VALUES_ERR");
-      return PlatformResult(ErrorCode::INVALID_VALUES_ERR);
+      return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR);
     }
-
     if (AttributeMatchFlag::kExists != match_flag) {
       query.append("\"");
       matchValue = escapeValueString(JsonCast<std::string>(match_value));
@@ -129,8 +142,27 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
         } else {  // OTHER
           matchValue = "4";
         }
+      } else if (name == "contentURI") {
+        const char* uri_prefix = "file://";
+        size_t found = matchValue.find(uri_prefix);
+        if (found != std::string::npos) {
+          // simple convertion of URI to globalpath
+          matchValue = matchValue.substr(found + strlen(uri_prefix));
+        }
+      }
+      switch (match_flag) {
+        case AttributeMatchFlag::kStartsWith:
+          query += matchValue + "%";
+          break;
+        case AttributeMatchFlag::kEndsWith:
+          query += "%" + matchValue;
+          break;
+        case AttributeMatchFlag::kContains:
+          query += "%" + matchValue + "%";
+          break;
+        default:
+          query += matchValue;
       }
-      query += matchValue;
       query.append("\"");
     }
 
@@ -140,13 +172,13 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
   });
 
   visitor.SetOnCompositeFilterBegin([&](CompositeFilterType type) {
-    LoggerD("entered OnCompositeFilterBegin");
+    ScopeLogger("Entered into asynchronous function, visitor.SetOnCompositeFilterBegin's argument");
     partialqueries.push_back(std::vector<std::string>());
     return PlatformResult(ErrorCode::NO_ERROR);
   });
 
   visitor.SetOnCompositeFilterEnd([&](CompositeFilterType calType) {
-    LoggerD("entered OnCompositeFilterEnd");
+    ScopeLogger("Entered into asynchronous function, visitor.SetOnCompositeFilterEnd's argument");
     std::string finalQuery;
     std::string separator;
 
@@ -159,8 +191,7 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
       partialqueries.pop_back();
       return PlatformResult(ErrorCode::NO_ERROR);
     }
-    if (partialqueries.back().size() != 1)
-      finalQuery.append("(");
+    if (partialqueries.back().size() != 1) finalQuery.append("(");
 
     for (unsigned long i = 0; i < partialqueries.back().size(); i++) {
       finalQuery += partialqueries.back().at(i);
@@ -169,8 +200,7 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
       }
     }
 
-    if (partialqueries.back().size() != 1)
-      finalQuery.append(")");
+    if (partialqueries.back().size() != 1) finalQuery.append(")");
     partialqueries.pop_back();
     partialqueries.back().push_back(finalQuery);
 
@@ -180,14 +210,12 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
   visitor.SetOnAttributeRangeFilter([&](const std::string& name,
                                         const picojson::value& initial_value,
                                         const picojson::value& end_value) {
-    LoggerD("entered OnAttributeFilter");
+    ScopeLogger("Entered into asynchronous function, visitor.SetOnAttributeRangeFilter's argument");
 
-    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
     std::string query = "";
     std::string paramName;
-    result = MapField(name, &paramName);
-    if (!result)
-      return result;
+    PlatformResult result = MapField(name, &paramName);
+    if (!result) return result;
 
     std::string initialValue = escapeValueString(JsonCast<std::string>(initial_value));
     std::string endValue = escapeValueString(JsonCast<std::string>(end_value));
@@ -205,13 +233,11 @@ PlatformResult ContentFilter::BuildQuery(const picojson::object& jsFilter,
   });
 
   if (!visitor.Visit(jsFilter)) {
-    LoggerE("INVALID_VALUES_ERR");
-    return PlatformResult(ErrorCode::INVALID_VALUES_ERR);
+    return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR);
   }
 
   if (partialqueries.empty()) {
-    LoggerE("Filter parsing error!");
-    return PlatformResult(ErrorCode::SYNTAX_ERR);
+    return LogAndCreateResult(ErrorCode::SYNTAX_ERR);
   }
   if (partialqueries.back().empty()) {
     LoggerD("Resolved to empty string!");