From: Rafal Galka Date: Thu, 19 Mar 2015 15:23:22 +0000 (+0100) Subject: [content] TCT fixes after js refactoring X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~264 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=316feb8455d96c843e40b91838a9fa99011fd333;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [content] TCT fixes after js refactoring [Verification] TCT 2.4 result: 113/230 Change-Id: Ie3e8c79de738be2d65e81aed7e2da9c0c0fa6132 --- diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc index 42c660c1..b7949b80 100755 --- a/src/content/content_instance.cc +++ b/src/content/content_instance.cc @@ -226,16 +226,16 @@ static void changedContentCallback(media_content_error_e error, void ContentInstance::ContentManagerUpdate(const picojson::value& args, picojson::object& out) { int ret; - if(ContentManager::getInstance()->isConnected()) { + if (ContentManager::getInstance()->isConnected()) { ret = ContentManager::getInstance()->update(args); - if(ret != 0) { - ReportError(ContentManager::getInstance()->convertError(ret),out); + if (ret != 0) { + ReportError(ContentManager::getInstance()->convertError(ret), out); } - } - else { - ReportError(common::UnknownException("DB connection is failed."),out); + } else { + ReportError(common::UnknownException("DB connection is failed."), out); } } + void ContentInstance::ContentManagerUpdatebatch(const picojson::value& args, picojson::object& out) { LoggerE("entered"); double callbackId = args.get("callbackId").get(); diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index be0b63f1..9b0d3f9e 100755 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -406,76 +405,80 @@ void contentToJson(media_info_h info, picojson::object& o) { } } -static int setContent(media_info_h media, picojson::value content) { +static int setContent(media_info_h media, const picojson::value& content) { + LOGGER(DEBUG) << "entered"; int ret; std::string name = content.get("name").to_str(); std::string description = content.get("description").to_str(); - std::string rating = content.get("rating").to_str(); - std::string is_fav = content.get("isFavorite").to_str(); - if (media != NULL) { - media_content_type_e type; - ret = media_info_get_media_type(media, &type); - if (ret != MEDIA_CONTENT_ERROR_NONE ) { - return ret; - } - ret = media_info_set_display_name(media, name.c_str()); - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating name is failed."); - } - ret = media_info_set_description(media, description.c_str()); - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating description is failed."); - } - ret = media_info_set_rating(media, std::stoi(rating)); - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating rating is failed."); - } + int rating = std::stoi(content.get("rating").to_str()); + bool is_fav = content.get("isFavorite").get(); - if (is_fav == "true") { - ret = media_info_set_favorite(media, true); - } - else if (is_fav == "false") { - ret = media_info_set_favorite(media, false); - } + if (NULL == media) { + return MEDIA_CONTENT_ERROR_DB_FAILED; + } - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating favorite is failed."); - } - if (type == MEDIA_CONTENT_TYPE_IMAGE) { - std::string orientation = content.get("orientation").to_str(); - auto orientationToSet = orientationMap.find(orientation); - - if (orientationToSet != orientationMap.end()) { - image_meta_h img; - if(MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) && - MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) && - MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) { - LoggerD("orientation update was successful"); - } else { - LoggerD("orientation update failed"); - } - } - } - if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) { - picojson::value geo = content.get("geolocation"); - double latitude = atof(geo.get("latitude").to_str().c_str()); - double longitude = atof(geo.get("longitude").to_str().c_str()); - ret = media_info_set_latitude(media, latitude); - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating geolocation is failed."); - } - ret = media_info_set_longitude(media, longitude); - if ( ret != MEDIA_CONTENT_ERROR_NONE) { - LoggerD("Updating geolocation is failed."); + media_content_type_e type; + ret = media_info_get_media_type(media, &type); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + return ret; + } + + ret = media_info_set_display_name(media, name.c_str()); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating name failed."); + } + + ret = media_info_set_description(media, description.c_str()); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating description failed."); + } + + ret = media_info_set_rating(media, rating); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating rating failed."); + } + + ret = media_info_set_favorite(media, is_fav); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating isFavorite failed."); + } + + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating favorite failed."); + } + + if (type == MEDIA_CONTENT_TYPE_IMAGE) { + std::string orientation = content.get("orientation").to_str(); + auto orientationToSet = orientationMap.find(orientation); + + if (orientationToSet != orientationMap.end()) { + image_meta_h img; + if (MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img) && + MEDIA_CONTENT_ERROR_NONE == image_meta_set_orientation(img, orientationToSet->second) && + MEDIA_CONTENT_ERROR_NONE == image_meta_update_to_db(img)) { + LoggerD("orientation update was successful"); + } else { + LoggerD("orientation update failed"); } } - ret = MEDIA_CONTENT_ERROR_NONE; } - else { - ret = MEDIA_CONTENT_ERROR_DB_FAILED; + + if (type == MEDIA_CONTENT_TYPE_IMAGE || type == MEDIA_CONTENT_TYPE_VIDEO) { + picojson::value geo = content.get("geolocation"); + double latitude = atof(geo.get("latitude").to_str().c_str()); + double longitude = atof(geo.get("longitude").to_str().c_str()); + ret = media_info_set_latitude(media, latitude); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating geolocation is failed."); + } + ret = media_info_set_longitude(media, longitude); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + LoggerD("Updating geolocation is failed."); + } } - return ret; + + return MEDIA_CONTENT_ERROR_NONE; } static bool media_foreach_directory_cb(media_folder_h folder, void *user_data) { @@ -815,20 +818,20 @@ void ContentManager::removePlaylist(std::string playlistId, } int ContentManager::update(picojson::value args) { + LOGGER(DEBUG) << "entered"; + int ret; picojson::value content = args.get("content"); std::string id = content.get("id").to_str(); media_info_h media = NULL; - ret = media_info_get_media_from_db (id.c_str(), &media); - if (media != NULL) { + ret = media_info_get_media_from_db(id.c_str(), &media); + if (ret == MEDIA_CONTENT_ERROR_NONE) { setContent(media, content); ret = media_info_update_to_db(media); + media_info_destroy(media); } - else { - LoggerD("There is no content(%s)",id.c_str()); - ret = MEDIA_CONTENT_ERROR_NONE; - } + return ret; } diff --git a/src/content/js/common.js b/src/content/js/common.js index 15b346fc..0259e130 100644 --- a/src/content/js/common.js +++ b/src/content/js/common.js @@ -27,6 +27,25 @@ var edit_ = new EditManager(); var SCHEMA = 'file://'; +function createContentObject_(data) { + switch (data.type) { + case ContentType.IMAGE: + return new ImageContent(data); + break; + case ContentType.AUDIO: + return new AudioContent(data); + break; + case ContentType.VIDEO: + return new VideoContent(data); + break; + case ContentType.OTHER: + return new Content(data); + break; + } + + throw new WebAPIException(WebAPIException.UNKNOWN_ERR, 'Undefined content type'); +} + function convertUriToPath_(uri) { if (0 === uri.indexOf(SCHEMA)) { return uri.substring(SCHEMA.length); diff --git a/src/content/js/datatypes.js b/src/content/js/datatypes.js index 7003d322..fdfa9496 100644 --- a/src/content/js/datatypes.js +++ b/src/content/js/datatypes.js @@ -218,7 +218,9 @@ function Content(data) { } -function VideoContent() { +function VideoContent(data) { + Content.call(this, data); + // TODO(r.galka) //this.geolocation = null; //SetReadOnlyProperty(this, 'album', null); // read only property @@ -240,7 +242,9 @@ function AudioContentLyrics() { } -function AudioContent() { +function AudioContent(data) { + Content.call(this, data); + // TODO(r.galka) //SetReadOnlyProperty(this, 'album', null); // read only property //SetReadOnlyProperty(this, 'genres', null); // read only property @@ -257,8 +261,14 @@ AudioContent.prototype = new Content(); AudioContent.prototype.constructor = AudioContent; -function ImageContent() { - // TODO(r.galka) +function ImageContent(data) { + Content.call(this, data); + + var geolocation; + var width; + var height; + var orientation; + //this.geolocation = null; //SetReadOnlyProperty(this, 'width', null); // read only property //SetReadOnlyProperty(this, 'height', null); // read only property diff --git a/src/content/js/manager.js b/src/content/js/manager.js index 91ecc8de..19cb34c5 100644 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -5,7 +5,7 @@ function _ContentManagerChangeCallback(result) { if (result.state === 'oncontentadded' || result.state === 'oncontentupdated') { var content = native_.getResultObject(result); - native_.callIfPossible(this[result.state], new Content(content)); + native_.callIfPossible(this[result.state], createContentObject_(content)); } if (result.state === 'oncontentremoved') { native_.callIfPossible(this.oncontentremoved, native_.getResultObject(result)); @@ -18,7 +18,7 @@ function ContentManager() { ContentManager.prototype.update = function(content) { var args = validator_.validateArgs(arguments, [ - {name: 'content', type: types_.PLATFORM_OBJECT, values: tizen.Content} + {name: 'content', type: types_.PLATFORM_OBJECT, values: Content} ]); var data = { @@ -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: tizen.Content}, + {name: 'contents', type: types_.PLATFORM_OBJECT, values: Content}, {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); @@ -68,7 +68,7 @@ ContentManager.prototype.getDirectories = function(successCallback, errorCallbac native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback); + native_.callIfPossible(args.successCallback, native_.getResultObject(result)); }; native_.call('ContentManager_getDirectories', data, callback); @@ -105,7 +105,13 @@ ContentManager.prototype.find = function(successCallback, errorCallback, directo 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(createContentObject_(result[i])); + } + + native_.callIfPossible(args.successCallback, out); }; native_.call('ContentManager_find', data, callback); @@ -190,7 +196,7 @@ ContentManager.prototype.getPlaylists = function(successCallback, errorCallback) native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback); + native_.callIfPossible(args.successCallback, native_.getResultObject(result)); }; native_.call('ContentManager_getPlaylists', data, callback); @@ -201,7 +207,7 @@ ContentManager.prototype.createPlaylist = function(name, successCallback, errorC {name: 'name', type: types_.STRING}, {name: 'successCallback', type: types_.FUNCTION}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}, - {name: 'sourcePlaylist', type: types_.PLATFORM_OBJECT, values: tizen.Playlist, optional: true, nullable: true} + {name: 'sourcePlaylist', type: types_.PLATFORM_OBJECT, values: Playlist, optional: true, nullable: true} ]); var data = { @@ -214,7 +220,7 @@ ContentManager.prototype.createPlaylist = function(name, successCallback, errorC native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback); + native_.callIfPossible(args.successCallback, native_.getResultObject(result)); }; native_.call('ContentManager_createPlaylist', data, callback); diff --git a/src/content/js/playlist.js b/src/content/js/playlist.js index 2722e206..cd6490c9 100644 --- a/src/content/js/playlist.js +++ b/src/content/js/playlist.js @@ -104,7 +104,7 @@ Playlist.prototype.get = function (successCallback, errorCallback, count, offset native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback); + native_.callIfPossible(args.successCallback, native_.getResultObject(result)); }; native_.call('Playlist_get', data, callback);