-// 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"
#include "common/converter.h"
#include "common/logger.h"
+#include "common/tools.h"
using common::AttributeMatchFlag;
using common::CompositeFilterType;
{"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"},
};
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());
} // 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) {
} 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));
} 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("\"");
}
});
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;
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);
}
}
- if (partialqueries.back().size() != 1)
- finalQuery.append(")");
+ if (partialqueries.back().size() != 1) finalQuery.append(")");
partialqueries.pop_back();
partialqueries.back().push_back(finalQuery);
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, ¶mName);
- if (!result)
- return result;
+ PlatformResult result = MapField(name, ¶mName);
+ if (!result) return result;
std::string initialValue = escapeValueString(JsonCast<std::string>(initial_value));
std::string endValue = escapeValueString(JsonCast<std::string>(end_value));
});
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!");