From: Rafal Galka Date: Fri, 20 Mar 2015 14:24:03 +0000 (+0100) Subject: [Content] TCT fixes X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~262 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=884dbb19b2505817168e20a8a1b3804ba73f9f9d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Content] TCT fixes [Verification] Following tests should pass: - ContentManager_updateBatch - ContentManager_find_nullableArgs - ContentDirectoryArraySuccessCallback_onsuccess - Content_thumbnailURIs_attribute - Content_rating_attribute - ContentManager_unsetChangeListener - AudioContent_genres_attribute Change-Id: I36ab340d118c92357571fbe887761e2631af0cd2 --- diff --git a/src/content/content_filter.cc b/src/content/content_filter.cc index 9b60c37c..b60c3bdb 100755 --- a/src/content/content_filter.cc +++ b/src/content/content_filter.cc @@ -96,9 +96,9 @@ PlatformResult ContentFilter::buildQuery(const picojson::object& jsFilter, } else { return PlatformResult(ErrorCode::INVALID_VALUES_ERR); } - query.append("\""); if (AttributeMatchFlag::kExists != match_flag) { + query.append("\""); matchValue = escapeValueString(JsonCast(match_value)); if (name == "type") { if (matchValue == "IMAGE") { @@ -112,11 +112,11 @@ PlatformResult ContentFilter::buildQuery(const picojson::object& jsFilter, } } query += matchValue; + query.append("\""); } - query.append("\""); + partialqueries.back().push_back(query); - LoggerD("about to call with condition %s", query.c_str()); return PlatformResult(ErrorCode::NO_ERROR); }); @@ -136,7 +136,6 @@ PlatformResult ContentFilter::buildQuery(const picojson::object& jsFilter, else separator = " AND "; - LoggerD("Composite filter: %i", partialqueries.back().size()); if (partialqueries.back().empty()) { partialqueries.pop_back(); return PlatformResult(ErrorCode::NO_ERROR); @@ -155,6 +154,7 @@ PlatformResult ContentFilter::buildQuery(const picojson::object& jsFilter, finalQuery.append(")"); partialqueries.pop_back(); partialqueries.back().push_back(finalQuery); + return PlatformResult(ErrorCode::NO_ERROR); }); @@ -181,7 +181,6 @@ PlatformResult ContentFilter::buildQuery(const picojson::object& jsFilter, query += "\""; partialqueries.back().push_back(query); - LoggerD("about to call with condition %s", query.c_str()); return PlatformResult(ErrorCode::NO_ERROR); }); diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index 9b0d3f9e..b7b6e993 100755 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -399,9 +399,7 @@ void contentToJson(media_info_h info, picojson::object& o) { } ret = media_info_get_modified_time(info, &tmpDate); if(ret == MEDIA_CONTENT_ERROR_NONE) { - std::stringstream str_date; - str_date << tmpDate; - o["modifiedDate"] = picojson::value(str_date.str()); + o["modifiedDate"] = picojson::value(static_cast(tmpDate)); } } @@ -590,63 +588,59 @@ void ContentManager::getDirectories(const std::shared_ptr& us picojson::value::array pico_dirs; - int ret = MEDIA_CONTENT_ERROR_NONE; + int ret; filter_h filter = NULL; std::vector dirs; ret = media_folder_foreach_folder_from_db(filter, media_foreach_directory_cb, &dirs); - if (ret == MEDIA_CONTENT_ERROR_NONE) { - for(std::vector::iterator it = dirs.begin(); it != dirs.end(); ++it) { - char *name = NULL; - char *id = NULL; - char *path = NULL; - time_t date; - media_content_storage_e storageType; - picojson::value::object o; - - media_folder_get_folder_id(*it, &id); - media_folder_get_name(*it, &name); - media_folder_get_path(*it, &path); - media_folder_get_modified_time(*it, &date); - media_folder_get_storage_type(*it, &storageType); - - o["id"] = picojson::value(std::string(id)); - o["directoryURI"] = picojson::value(std::string(path)); - o["title"] = picojson::value(std::string(name)); - - if (storageType == MEDIA_CONTENT_STORAGE_INTERNAL) { - o["storageType"] = picojson::value(std::string("INTERNAL")); - } else if (storageType == MEDIA_CONTENT_STORAGE_EXTERNAL) { - o["storageType"] = picojson::value(std::string("EXTERNAL")); - } - - char tmp[128]; - ctime_r(&date, tmp); - o["modifiedDate"] = picojson::value(std::string(tmp)); - pico_dirs.push_back(picojson::value(o)); - - free(name); - free(id); - free(path); - } - user_data->isSuccess = true; - user_data->result = picojson::value(pico_dirs); - } - else { - UnknownException err("Getting the directories is failed."); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + UnknownException err("Getting the directories failed."); user_data->isSuccess = false; user_data->result = err.ToJSON(); + return; } + for (std::vector::iterator it = dirs.begin(); it != dirs.end(); ++it) { + char* name = NULL; + char* id = NULL; + char* path = NULL; + time_t date; + media_content_storage_e storageType; + picojson::value::object o; + + media_folder_get_folder_id(*it, &id); + media_folder_get_name(*it, &name); + media_folder_get_path(*it, &path); + media_folder_get_modified_time(*it, &date); + media_folder_get_storage_type(*it, &storageType); + + o["id"] = picojson::value(std::string(id)); + o["directoryURI"] = picojson::value(std::string(path)); + o["title"] = picojson::value(std::string(name)); + + if (storageType == MEDIA_CONTENT_STORAGE_INTERNAL) { + o["storageType"] = picojson::value(std::string("INTERNAL")); + } else if (storageType == MEDIA_CONTENT_STORAGE_EXTERNAL) { + o["storageType"] = picojson::value(std::string("EXTERNAL")); + } + + o["modifiedDate"] = picojson::value(static_cast(date)); + pico_dirs.push_back(picojson::value(o)); + + free(name); + free(id); + free(path); + } + user_data->isSuccess = true; + user_data->result = picojson::value(pico_dirs); } void ContentManager::find(const std::shared_ptr& user_data) { int ret; - double count, offset; - std::string dirId, attributeName, matchFlag, matchValue; + int count, offset; + std::string dirId; std::string sortModeName, sortModeOrder; - int error_code = 0; media_content_order_e order; picojson::value::array arrayContent; @@ -663,25 +657,49 @@ void ContentManager::find(const std::shared_ptr& user_data) { picojson::object argsObject = JsonCast(user_data->args); if (filterMechanism.buildQuery( FromJson(argsObject, "filter"), &query)) { + LOGGER(DEBUG) << "Filter query: " << query; ret = media_filter_set_condition(filter, query.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT); if (MEDIA_CONTENT_ERROR_NONE != ret) { + LoggerD("Platform filter setting failed, error %d", ret); + } + } + } + + if (user_data->args.contains("sortMode")) { + picojson::value vSortMode = user_data->args.get("sortMode"); + + if (!vSortMode.is() && vSortMode.is()) { + sortModeName = vSortMode.get("attributeName").to_str(); + sortModeOrder = vSortMode.get("order").to_str(); + if (!sortModeOrder.empty()) { + if (sortModeOrder == "ASC") { + order = MEDIA_CONTENT_ORDER_ASC; + } else if (sortModeOrder == "DESC") { + order = MEDIA_CONTENT_ORDER_DESC; + } + + ret = media_filter_set_order(filter, order, sortModeName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT); + if (MEDIA_CONTENT_ERROR_NONE != ret) { + LoggerD("Platform SortMode setting failed, error: %d", ret); + } } } } + if (!IsNull(user_data->args.get("count"))) { - count = user_data->args.get("count").get(); + count = static_cast(user_data->args.get("count").get()); } else { count = -1; } if (!IsNull(user_data->args.get("offset"))) { - offset = user_data->args.get("offset").get(); + offset = static_cast(user_data->args.get("offset").get()); } else { offset = -1; } ret = media_filter_set_offset(filter, offset, count); if (MEDIA_CONTENT_ERROR_NONE != ret) { - LoggerD("A platform error occurs in media_filter_set_offset."); + LoggerD("A platform error occurs in media_filter_set_offset: %d", ret); } if (!IsNull(user_data->args.get("directoryId"))) { dirId = user_data->args.get("directoryId").get(); @@ -691,11 +709,11 @@ void ContentManager::find(const std::shared_ptr& user_data) { } if (ret == MEDIA_CONTENT_ERROR_NONE) { - LoggerD("enter"); user_data->isSuccess = true; user_data->result = picojson::value(arrayContent); } else { - UnknownException err("The iteration is failed in platform."); + LoggerD("The iteration failed in platform: %d", ret); + UnknownException err("The iteration failed in platform"); user_data->isSuccess = false; user_data->result = err.ToJSON(); } @@ -835,29 +853,25 @@ int ContentManager::update(picojson::value args) { return ret; } - int ContentManager::updateBatch(picojson::value args) { - int ret; + int ret = 0; std::vector contents = args.get("contents").get(); + for (picojson::value::array::iterator it = contents.begin(); it != contents.end(); it++) { picojson::value content = *it; std::string id = content.get("id").to_str(); media_info_h media = NULL; - ret = media_info_get_media_from_db (id.c_str(), &media); - dlog_print(DLOG_INFO, "DYKIM", "ContentManager::update id:%s",id.c_str()); + ret = media_info_get_media_from_db(id.c_str(), &media); if (media != NULL && ret == MEDIA_CONTENT_ERROR_NONE) { setContent(media, content); ret = media_info_update_to_db(media); - } - else { + } else { return ret; } } return ret; } - - int ContentManager::playlistAdd(std::string playlist_id, std::string content_id) { int ret = MEDIA_CONTENT_ERROR_NONE; diff --git a/src/content/js/datatypes.js b/src/content/js/datatypes.js index b2aadc03..316ca38d 100644 --- a/src/content/js/datatypes.js +++ b/src/content/js/datatypes.js @@ -88,7 +88,7 @@ function ContentDirectory(data) { }, set: function(v) { if (edit_.isAllowed) { - modifiedDate = !type_.isNull(v) ? new Date(v) : null; + modifiedDate = v > 0 ? new Date(v * 1000) : null; } }, enumerable: true @@ -213,7 +213,7 @@ function Content(data) { }, set: function(v) { if (edit_.isAllowed) { - releaseDate = !type_.isNull(v) ? new Date(v) : null; + releaseDate = v > 0 ? new Date(v * 1000) : null; } }, enumerable: true @@ -224,7 +224,7 @@ function Content(data) { }, set: function(v) { if (edit_.isAllowed) { - modifiedDate = !type_.isNull(v) ? new Date(v) : null; + modifiedDate = v > 0 ? new Date(v * 1000) : null; } }, enumerable: true @@ -254,7 +254,7 @@ function Content(data) { return rating; }, set: function(v) { - if (!type_.isNull(v)) { + if (!type_.isNull(v) && v >= 0 && v <= 10) { rating = converter_.toUnsignedLong(v, false); } }, @@ -372,18 +372,7 @@ function VideoContent(data) { } }, enumerable: true - }, - orientation: { - get: function() { - return orientation; - }, - set: function(v) { - if (!type_.isNull(v)) { - orientation = converter_.toEnum(v, Object.keys(ImageContentOrientation), false); - } - }, - enumerable: true - }, + } }); if (type_.isObject(data)) { diff --git a/src/content/js/manager.js b/src/content/js/manager.js index 19cb34c5..3753cb4d 100644 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -34,7 +34,7 @@ ContentManager.prototype.update = function(content) { ContentManager.prototype.updateBatch = function(contents, successCallback, errorCallback) { var args = validator_.validateArgs(arguments, [ - {name: 'contents', type: types_.PLATFORM_OBJECT, values: Content}, + {name: 'contents', type: types_.ARRAY, values: Content}, {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); @@ -60,18 +60,21 @@ ContentManager.prototype.getDirectories = function(successCallback, errorCallbac {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); - var data = { - }; - var callback = function(result) { if (native_.isFailure(result)) { native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback, native_.getResultObject(result)); + + var out = []; + result = native_.getResultObject(result); + for (var i = 0, max = result.length; i < max; i++) { + out.push(new ContentDirectory(result[i])); + } + native_.callIfPossible(args.successCallback, out); }; - native_.call('ContentManager_getDirectories', data, callback); + native_.call('ContentManager_getDirectories', null, callback); }; ContentManager.prototype.find = function(successCallback, errorCallback, directoryId, filter, sortMode, count, offset) { @@ -87,8 +90,8 @@ ContentManager.prototype.find = function(successCallback, errorCallback, directo nullable: true }, {name: 'sortMode', type: types_.PLATFORM_OBJECT, values: tizen.SortMode, optional: true, nullable: true}, - {name: 'count', type: types_.LONG, optional: true}, - {name: 'offset', type: types_.LONG, optional: true} + {name: 'count', type: types_.UNSIGNED_LONG, optional: true, nullable: true}, + {name: 'offset', type: types_.UNSIGNED_LONG, optional: true, nullable: true} ]); var data = {