[Calendar] Fixing multiple bugs in calendar API 12/170812/2
authorMichal Bistyga <m.bistyga@samsung.com>
Thu, 8 Feb 2018 12:41:42 +0000 (13:41 +0100)
committerMichal Bistyga <m.bistyga@samsung.com>
Thu, 22 Feb 2018 11:07:04 +0000 (12:07 +0100)
3 bugs has been fixed:
1) User couldn't add new calendar to database
1a) Resolved by sending new object, no calendar through JSON
2) Calendar object was not updated with id got from native layer
2a) Resolved by returning id to js layer and...
2b) Changing setting its as result.id, not just a result
3) Every event has been set to calendar with id 0
3a) Resolved by utilizing not used calendarId attribute

[Verification]
verified in chrome console
tct-tests 100% passrate

Change-Id: I5edcf33d8dd753fc044d2b61677439145f4a73d1
Signed-off-by: Michal Bistyga <m.bistyga@samsung.com>
src/calendar/calendar_item.cc
src/calendar/calendar_manager.cc
src/calendar/js/calendar_manager.js

index 6ac5c8c17ece0f743c65cbb644b56b0d7788fdbb..9bba6c4b6e5ad22bef43b284e0b120b16b01e65c 100644 (file)
@@ -22,6 +22,7 @@
 #include <sstream>
 #include "common/converter.h"
 #include "common/logger.h"
+#include "common/picojson.h"
 using namespace common;
 namespace extension {
 namespace calendar {
@@ -54,7 +55,7 @@ const PlatformPropertyMap CalendarItem::platform_property_map_ = {
     {"id.uid",
      {{CALENDAR_BOOK_TYPE_EVENT, _calendar_event.id},
       {CALENDAR_BOOK_TYPE_TODO, _calendar_todo.uid}}},
-    {"calendar_id",
+    {"calendarId",
      {{CALENDAR_BOOK_TYPE_EVENT, _calendar_event.calendar_book_id},
       {CALENDAR_BOOK_TYPE_TODO, _calendar_todo.calendar_book_id}}},
     {"description",
@@ -377,7 +378,13 @@ PlatformResult CalendarItem::SetInt(int type, calendar_record_h rec, const std::
     return PlatformResult(ErrorCode::NO_ERROR);
   }
 
-  int value = common::FromJson<double>(in, property.c_str());
+  int value = 0;
+  auto jsonValue = common::FindValue(in, property.c_str());
+  if (jsonValue.is<double>()) {
+    value = common::FromJson<double>(in, property.c_str());
+  } else {  // CalendarId is stored in js as string, while native api use int
+    value = common::stol(common::FromJson<std::string>(in, property.c_str()));
+  }
 
   return SetInt(type, rec, property, value);
 }
@@ -1462,6 +1469,11 @@ PlatformResult CalendarItem::FromJson(int type, calendar_record_h rec, const pic
     return status;
   }
 
+  status = SetInt(type, rec, "calendarId", in);
+  if (status.IsError()) {
+    return status;
+  }
+
   if (type == CALENDAR_BOOK_TYPE_EVENT) {
     status = SetEnum(type, rec, "priority", in, kEventPriority);
     if (status.IsError()) {
@@ -1552,7 +1564,7 @@ PlatformResult CalendarItem::ToJson(int type, calendar_record_h rec, picojson::o
   out["id"] = id_val;
 
   int calendar_id;
-  status = GetInt(type, rec, "calendar_id", &calendar_id);
+  status = GetInt(type, rec, "calendarId", &calendar_id);
   if (status.IsError()) {
     return status;
   }
index 4c2edafcfcbb301a3b5dc5f179d062c28eeb3a88..db72589a01d3c7cfab8bbaeb57500fa6f4b25f43 100644 (file)
@@ -179,8 +179,6 @@ PlatformResult CalendarManager::AddCalendar(const JsonObject& args, JsonObject&
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "DB Connection failed.");
   }
 
-  const JsonObject& calendar = FromJson<JsonObject>(args, "calendar");
-
   calendar_record_h handle = nullptr;
   PlatformResult status = CalendarRecord::CreateCalendar(&handle);
   if (status.IsError()) {
@@ -189,7 +187,7 @@ PlatformResult CalendarManager::AddCalendar(const JsonObject& args, JsonObject&
 
   CalendarRecordPtr record_ptr = CalendarRecordPtr(handle, CalendarRecord::Deleter);
 
-  status = CalendarRecord::CalendarFromJson(record_ptr.get(), calendar);
+  status = CalendarRecord::CalendarFromJson(record_ptr.get(), args);
   if (status.IsError()) {
     return status;
   }
@@ -200,6 +198,7 @@ PlatformResult CalendarManager::AddCalendar(const JsonObject& args, JsonObject&
   if (status.IsError()) {
     return status;
   }
+  out.insert(std::make_pair("id", picojson::value(std::to_string(record_id))));
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
index 37d1652bb2099295b30f6db0f60d50d2c2533479..9f5bcca238a8620383396699d7279583d7dc97ea 100755 (executable)
@@ -141,7 +141,9 @@ CalendarManager.prototype.addCalendar = function() {
   }]);
 
   var callArgs = {
-    calendar: args.calendar
+    name: args.calendar.name,
+    accountId: args.calendar.accountId,
+    type: args.calendar.type
   };
 
   var result = native_.callSync('CalendarManager_addCalendar', callArgs);
@@ -151,7 +153,7 @@ CalendarManager.prototype.addCalendar = function() {
   }
 
   args.calendar.id = new InternalCalendar({
-    id: native_.getResultObject(result)
+    id: native_.getResultObject(result).id
   });
 };