[content] TCT fixes after js refactoring
authorRafal Galka <r.galka@samsung.com>
Thu, 19 Mar 2015 15:23:22 +0000 (16:23 +0100)
committerRafal Galka <r.galka@samsung.com>
Fri, 20 Mar 2015 14:33:30 +0000 (23:33 +0900)
[Verification]
TCT 2.4 result: 113/230

Change-Id: Ie3e8c79de738be2d65e81aed7e2da9c0c0fa6132

src/content/content_instance.cc
src/content/content_manager.cc
src/content/js/common.js
src/content/js/datatypes.js
src/content/js/manager.js
src/content/js/playlist.js

index 42c660c15790fb944db7b9f0a3d1db58d88c2898..b7949b80f6e5a64e5bae49a918ddfc8d8dba4c69 100755 (executable)
@@ -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<double>();
index be0b63f1074393ad0ca2e6e12094732e9f079fc2..9b0d3f9ef4bbeb8ce42d15d64053da9f97111b41 100755 (executable)
@@ -6,7 +6,6 @@
 
 #include <algorithm>
 #include <cstring>
-#include <dlog.h>
 #include <map>
 #include <metadata_extractor.h>
 #include <sstream>
@@ -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<bool>();
 
-    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;
 }
 
index 15b346fc1b4f8cd1e2f347561e2c9061073d9691..0259e1308e06d2bf80792a486abaf55b1fc5ef48 100644 (file)
@@ -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);
index 7003d32258af644e527f32d6b7690938985fb79a..fdfa9496a75fe2f0ccaa5c1c4759bade20b8b12e 100644 (file)
@@ -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
index 91ecc8de2068f96a9c1a24a8c2063e6c387122ad..19cb34c50c281d447e3abe99804c03967731892b 100644 (file)
@@ -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);
index 2722e20685deaab795556ce9e21f6b0cbe5bb948..cd6490c975051b8eafb05176a6a50942b77b1963 100644 (file)
@@ -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);