[Account] Fixes for getExtendedData() and setExtendedData().
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 13 Feb 2015 14:40:05 +0000 (15:40 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 13 Feb 2015 14:40:05 +0000 (15:40 +0100)
Change-Id: Icc708e6ce3a9f4db7f614b11dd197c7954de975c

src/account/account_api.js
src/account/account_manager.cc

index 009479dfb5b4fb301f4f7720d0622a993ca3f22c..43669e9c10fbebd4ca359b466a950ed35181987e 100644 (file)
@@ -87,13 +87,11 @@ Account.prototype.setExtendedData = function() {
 
 
 Account.prototype.getExtendedData = function() {
-    if (T_.isFunction(arguments[0])) {
+    if (T_.isFunction(arguments[0]) || arguments.length > 1) {
         var args = validator_.validateArgs(arguments, [
             {
                 name : 'successCallback',
-                type : types_.FUNCTION,
-                optional : false,
-                nullable : false
+                type : types_.FUNCTION
             },
             {
                 name : 'errorCallback',
@@ -112,6 +110,10 @@ Account.prototype.getExtendedData = function() {
                         args.errorCallback(native_.getErrorObject(result));
                     }
                 } else {
+                    var data = native_.getResultObject(result);
+                    for (var i = 0; i < data.length; ++i) {
+                        Object.freeze(data[i]);
+                    }
                     args.successCallback(native_.getResultObject(result));
                 }
             }
index b30356ddd0035b1e1de22b8ead02aa6e2b9e95f7..fc5250f16687f089b0339b60384b78912dedf2c6 100644 (file)
@@ -422,7 +422,8 @@ void AccountManager::GetExtendedData(int account_id, const std::string& key, pic
   if (ACCOUNT_ERROR_NONE != ret) {
     if (ACCOUNT_ERROR_RECORD_NOT_FOUND == ret) {
       LoggerE("There is no extended data value for %s", key.c_str());
-      REPORT_ERROR(out, NotFoundException("There is no extended data value for specified key"));
+      out["status"] = picojson::value("success");
+      out["result"] = picojson::value();
     } else {
       LoggerE("Failed to get custom field");
       REPORT_ERROR(out, UnknownException(GetErrorMsg(ret)));
@@ -493,6 +494,13 @@ void AccountManager::SetExtendedData(int account_id, const std::string& key, con
   if (ACCOUNT_ERROR_NONE != ret) {
     LoggerE("Failed to set custom field");
     REPORT_ERROR(out, UnknownException(GetErrorMsg(ret)));
+    return;
+  }
+
+  ret = account_update_to_db_by_id(account, account_id);
+  if (ACCOUNT_ERROR_NONE != ret) {
+    LoggerE("Failed to update account in database");
+    REPORT_ERROR(out, UnknownException(GetErrorMsg(ret)));
   } else {
     out["status"] = picojson::value("success");
   }