[Content] TCT fixes
authorRafal Galka <r.galka@samsung.com>
Fri, 20 Mar 2015 14:24:03 +0000 (15:24 +0100)
committerRafal Galka <r.galka@samsung.com>
Fri, 20 Mar 2015 14:35:48 +0000 (23:35 +0900)
[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

src/content/content_filter.cc
src/content/content_manager.cc
src/content/js/datatypes.js
src/content/js/manager.js

index 9b60c37c6c095424f2f8914189bf2a1d70f8a6ec..b60c3bdbc5a1bfaacddceb0abc58523b152a86f0 100755 (executable)
@@ -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<std::string>(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);
   });
 
index 9b0d3f9ef4bbeb8ce42d15d64053da9f97111b41..b7b6e99330265d02e2a630edbbea6b816b4ad830 100755 (executable)
@@ -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<double>(tmpDate));
   }
 }
 
@@ -590,63 +588,59 @@ void ContentManager::getDirectories(const std::shared_ptr<ReplyCallbackData>& us
 
   picojson::value::array pico_dirs;
 
-  int ret = MEDIA_CONTENT_ERROR_NONE;
+  int ret;
   filter_h filter = NULL;
   std::vector<media_folder_h> dirs;
 
   ret = media_folder_foreach_folder_from_db(filter, media_foreach_directory_cb, &dirs);
 
-  if (ret == MEDIA_CONTENT_ERROR_NONE) {
-    for(std::vector<media_folder_h>::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<media_folder_h>::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<double>(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<ReplyCallbackData>& 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<ReplyCallbackData>& user_data) {
     picojson::object argsObject = JsonCast<picojson::object>(user_data->args);
     if (filterMechanism.buildQuery(
         FromJson<picojson::object>(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<picojson::null>() && vSortMode.is<picojson::object>()) {
+      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<double>();
+    count = static_cast<int>(user_data->args.get("count").get<double>());
   } else {
     count = -1;
   }
   if (!IsNull(user_data->args.get("offset"))) {
-    offset = user_data->args.get("offset").get<double>();
+    offset = static_cast<int>(user_data->args.get("offset").get<double>());
   } 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<std::string>();
@@ -691,11 +709,11 @@ void ContentManager::find(const std::shared_ptr<ReplyCallbackData>& 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<picojson::value> contents = args.get("contents").get<picojson::array>();
+
   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;
 
index b2aadc0354243a60a0bfa0a18e498b51d352958d..316ca38d0882be646dcbe180e26215fb0539b70f 100644 (file)
@@ -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)) {
index 19cb34c50c281d447e3abe99804c03967731892b..3753cb4d727157d595908d19963cf90abdea68f4 100644 (file)
@@ -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 = {