[Contact] Fix coding style
authorAdam Banasiak <a.banasiak@samsung.com>
Wed, 10 Dec 2014 11:20:11 +0000 (12:20 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 10 Dec 2014 13:28:00 +0000 (22:28 +0900)
Change-Id: I9df59d6b30044e2a0deeaea20e7b4a115497a367
Signed-off-by: Adam Banasiak <a.banasiak@samsung.com>
contact/addressbook.cc
contact/addressbook.h
contact/contact-plugin.cpp
contact/contact_manager.cc
contact/contact_manager.h
contact/contact_util.cc
contact/contact_util.h
contact/person.cc
contact/person.h

index 3cdc1eb..9cd49ba 100644 (file)
@@ -38,766 +38,787 @@ namespace {
 static const long kUnifiedAddressBookId = -1;
 const char* kContactListenerId = "ContactChangeListener";
 
-inline long AddressBookId(const JsonObject& obj)
-{
-    return common::stol(FromJson<json::String>(obj, "addressBook", "id"));
+inline long AddressBookId(const JsonObject& obj) {
+  return common::stol(FromJson<json::String>(obj, "addressBook", "id"));
 }
 
-inline bool IsUnified(const JsonObject& args)
-{
-    return AddressBookId(args) == kUnifiedAddressBookId;
+inline bool IsUnified(const JsonObject& args) {
+  return AddressBookId(args) == kUnifiedAddressBookId;
 }
 
-inline bool IsUnified(long id)
-{
-    return id == kUnifiedAddressBookId;
-}
+inline bool IsUnified(long id) { return id == kUnifiedAddressBookId; }
 
 }  // anonymous namespace
 
-void AddressBook_get(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-
-    int contact_id = common::stol(FromJson<json::String>(args, "id"));
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h contacts_record = nullptr;
-    err = contacts_db_get_record(_contacts_contact._uri, contact_id, &contacts_record);
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Contacts record get error, error code: %d", err);
-        throw common::NotFoundException("Contacts record get error");
-    }
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record,
-                                                        ContactUtil::ContactsDeleter);
-
-    JsonValue result{json::Object{}};
-    auto& result_obj = result.get<json::Object>();
-    result_obj.insert(std::make_pair("id", std::to_string(contact_id)));
-    ContactUtil::ImportContactFromContactsRecord(*contacts_record_ptr, &result_obj);
-    ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &result_obj);
-
-    NativePlugin::ReportSuccess(result, out);
+void AddressBook_get(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+
+  int contact_id = common::stol(FromJson<json::String>(args, "id"));
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h contacts_record = nullptr;
+  err = contacts_db_get_record(_contacts_contact._uri, contact_id,
+                               &contacts_record);
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Contacts record get error, error code: %d", err);
+    throw common::NotFoundException("Contacts record get error");
+  }
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &contacts_record, ContactUtil::ContactsDeleter);
+
+  JsonValue result{json::Object{}};
+  auto& result_obj = result.get<json::Object>();
+  result_obj.insert(std::make_pair("id", std::to_string(contact_id)));
+  ContactUtil::ImportContactFromContactsRecord(*contacts_record_ptr,
+                                               &result_obj);
+  ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &result_obj);
+
+  NativePlugin::ReportSuccess(result, out);
 }
 
-void AddressBook_add(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-
-    const json::Object& contact = FromJson<json::Object>(args, "contact");
-
-    if (!IsNull(contact, "id")) {
-        LOGW("Contact already exists");
-        throw common::UnknownException("Contact already exists");
-    }
-
-    contacts_record_h contacts_record = nullptr;
-    int err = 0;
-    err = contacts_record_create(_contacts_contact._uri, &contacts_record);
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Contacts record create error, error code: %d", err);
-        throw common::UnknownException("Contacts record create error");
-    }
-
-    // contacts_record starts to be protected by unique_ptr
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record,
-                                                        ContactUtil::ContactsDeleter);
-    ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
-
-    int id = -1;
-    err = contacts_db_insert_record(*contacts_record_ptr, &id);
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Contacts db insert error, error code: %d", err);
-        throw common::UnknownException("Contacts db insert error");
-    }
+void AddressBook_add(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+
+  const json::Object& contact = FromJson<json::Object>(args, "contact");
+
+  if (!IsNull(contact, "id")) {
+    LOGW("Contact already exists");
+    throw common::UnknownException("Contact already exists");
+  }
+
+  contacts_record_h contacts_record = nullptr;
+  int err = 0;
+  err = contacts_record_create(_contacts_contact._uri, &contacts_record);
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Contacts record create error, error code: %d", err);
+    throw common::UnknownException("Contacts record create error");
+  }
+
+  // contacts_record starts to be protected by unique_ptr
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &contacts_record, ContactUtil::ContactsDeleter);
+  ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
+
+  int id = -1;
+  err = contacts_db_insert_record(*contacts_record_ptr, &id);
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Contacts db insert error, error code: %d", err);
+    throw common::UnknownException("Contacts db insert error");
+  }
+
+  contacts_record_h reset_record;
+  err = contacts_db_get_record(_contacts_contact._uri, id, &reset_record);
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Contacts record get error, error code: %d", err);
+    throw common::UnknownException("Contacts record get error");
+  }
+  if (nullptr != reset_record) {
+    LOGE("reset");
+    contacts_record_ptr.reset(&reset_record);
+  }
+
+  json::Value result{json::Object{}};
+  json::Object& value_obj = result.get<json::Object>();
+  value_obj.insert(std::make_pair("id", json::Value{std::to_string(id)}));
+
+  ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &value_obj);
+
+  NativePlugin::ReportSuccess(result, out);
+}
 
-    contacts_record_h reset_record;
-    err = contacts_db_get_record(_contacts_contact._uri, id, &reset_record);
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Contacts record get error, error code: %d", err);
-        throw common::UnknownException("Contacts record get error");
+void AddressBook_update(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+
+  const json::Object& contact = FromJson<json::Object>(args, "contact");
+  const json::Object& addressbook = FromJson<json::Object>(args, "addressBook");
+  long contactId = common::stol(FromJson<json::String>(contact, "id"));
+
+  if (IsNull(contact, "id")) {
+    LOGW("Contact doesn't exist");
+    throw common::UnknownException("Contact doesn't exist");
+  }
+
+  if (IsNull(addressbook, "id")) {
+    LOGE("Contact is not saved in database");
+    throw common::InvalidValuesException("Contact is not saved in database");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h to_update = nullptr;
+  err = contacts_db_get_record(_contacts_contact._uri, contactId, &to_update);
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Problem with getting contact. Error: %d", err);
+    throw common::NotFoundException("Problem with getting contact");
+  }
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &to_update, ContactUtil::ContactsDeleter);
+  ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
+  err = contacts_db_update_record(*contacts_record_ptr);
+  if (CONTACTS_ERROR_NONE != err) {
+    if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
+      LOGE("Error during executing contacts_db_update_record(). Error: %d",
+           err);
+      throw common::NotFoundException(
+          "Error during executing contacts_db_update_record().");
     }
-    if (nullptr != reset_record) {
-        LOGE("reset");
-        contacts_record_ptr.reset(&reset_record);
+    if (CONTACTS_ERROR_DB == err) {
+      LOGE("Error during executing contacts_db_update_record(). Error: %d",
+           err);
+      throw common::UnknownException(
+          "Error during executing contacts_db_update_record().");
     }
+  }
 
-    json::Value result{json::Object{}};
-    json::Object& value_obj = result.get<json::Object>();
-    value_obj.insert(std::make_pair("id", json::Value{std::to_string(id)}));
+  json::Value result{json::Object{}};
+  json::Object& value_obj = result.get<json::Object>();
 
-    ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &value_obj);
+  ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &value_obj);
 
-    NativePlugin::ReportSuccess(result, out);
+  NativePlugin::ReportSuccess(result, out);
 }
 
-void AddressBook_update(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+void AddressBook_remove(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+
+  long contact_id = common::stol(FromJson<json::String>(args, "id"));
+
+  if (contact_id < 0) {
+    throw common::InvalidValuesException("Nagative contact id");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_db_delete_record(_contacts_contact._uri, contact_id);
+  if (CONTACTS_ERROR_NO_DATA == err) {
+    LOGW("Remove failed: contact not found, error code: %d", err);
+    throw common::NotFoundException("Remove failed: contact not found");
+  } else if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Contacts record delete error, error code: %d", err);
+    throw common::UnknownException("Contacts record delete error");
+  }
+  NativePlugin::ReportSuccess(out);
+}
 
-    const json::Object& contact = FromJson<json::Object>(args, "contact");
-    const json::Object& addressbook = FromJson<json::Object>(args, "addressBook");
-    long contactId = common::stol(FromJson<json::String>(contact, "id"));
+void AddressBook_addBatch(const json::Object& args, json::Object& out) {
+  LoggerD("Enter");
+  long addressBookId = -1;
+  const json::Array& batch_args = FromJson<json::Array>(args, "batchArgs");
+  addressBookId = common::stol(FromJson<json::String>(args, "addressBookId"));
+  addressBookId = addressBookId == -1 ? 0 : addressBookId;
 
-    if (IsNull(contact, "id")) {
-        LOGW("Contact doesn't exist");
-        throw common::UnknownException("Contact doesn't exist");
+  auto batch_func = [ addressBookId, batch_args ](const shared_json_value &
+                                                  response)->void {
+    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+    json::Object& response_obj = response->get<json::Object>();
+    json::Array& batch_result =
+        response_obj.insert(
+                         std::make_pair("result", json::Value{json::Array{}}))
+            .first->second.get<json::Array>();
+
+    try {
+      unsigned length = batch_args.size();
+      int error_code = 0;
+      contacts_list_h contacts_list = NULL;
+      error_code = contacts_list_create(&contacts_list);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        LOGE("list creation failed, code: %d", error_code);
+        throw new common::UnknownException("list creation failed");
+      }
+      ContactUtil::ContactsListHPtr contacts_list_ptr(
+          &contacts_list, ContactUtil::ContactsListDeleter);
+
+      for (auto& item : batch_args) {
+        contacts_record_h contacts_record = nullptr;
+        int err = 0;
+        err = contacts_record_create(_contacts_contact._uri, &contacts_record);
+        if (CONTACTS_ERROR_NONE != err) {
+          LOGW("Contacts record create error, error code: %d", err);
+          throw common::UnknownException("Contacts record create error");
+        }
+        ContactUtil::ContactsRecordHPtr x(&contacts_record,
+                                          ContactUtil::ContactsDeleter);
+        ContactUtil::ExportContactToContactsRecord(
+            contacts_record, JsonCast<json::Object>(item));
+        ContactUtil::SetIntInRecord(
+            contacts_record, _contacts_contact.address_book_id, addressBookId);
+        error_code = contacts_list_add(*contacts_list_ptr, *(x.release()));
+        if (CONTACTS_ERROR_NONE != error_code) {
+          LOGE("error during add record to list, code: %d", error_code);
+          throw new common::UnknownException("error during add record to list");
+        }
+      }
+
+      int* ids;
+      unsigned int count;
+      error_code = contacts_db_insert_records(*contacts_list_ptr, &ids, &count);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        if (ids) {
+          free(ids);
+          ids = NULL;
+        }
+        LOGE("inserting contacts to db fails, code: %d", error_code);
+        throw new common::UnknownException("inserting contacts to db fails");
+      }
+      if (length != count) {
+        LOGW("Added different number of contacts");
+      }
+
+      for (unsigned int i = 0; i < count; i++) {
+        json::Object out_object;
+        contacts_record_h contact_record = nullptr;
+        error_code = contacts_db_get_record(_contacts_contact._uri, ids[i],
+                                            &contact_record);
+        if (CONTACTS_ERROR_NONE != error_code) {
+          if (ids) {
+            free(ids);
+            ids = NULL;
+          }
+          LOGW("Contacts record get error, error code: %d", error_code);
+          throw common::UnknownException("Contacts record get error");
+        }
+        ContactUtil::ImportContactFromContactsRecord(contact_record,
+                                                     &out_object);
+        batch_result.push_back(json::Value{out_object});
+      }
+      if (ids) {
+        free(ids);
+        ids = NULL;
+      }
+      NativePlugin::ReportSuccess(response_obj);
     }
-
-    if (IsNull(addressbook, "id")) {
-        LOGE("Contact is not saved in database");
-        throw common::InvalidValuesException("Contact is not saved in database");
+    catch (const BasePlatformException& error) {
+      LOGE("Error %s, with msg: %s", error.name().c_str(),
+           error.message().c_str());
+      NativePlugin::ReportError(error, response_obj);
     }
+  };
+  int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
+  auto after_work_func = [=](const shared_json_value& response) {
+    wrt::common::NativeContext::GetInstance()->InvokeCallback(
+        callback_handle, response->serialize());
+  };
+
+  TaskQueue::GetInstance().Queue<json::Value>(
+      batch_func, after_work_func,
+      shared_json_value{new json::Value{json::Object{}}});
+
+  NativePlugin::ReportSuccess(out);
+}
 
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h to_update = nullptr;
-    err = contacts_db_get_record(_contacts_contact._uri, contactId, &to_update);
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Problem with getting contact. Error: %d", err);
-        throw common::NotFoundException("Problem with getting contact");
+void AddressBook_batchFunc(NativeFunction impl, const char* single_arg_name,
+                           const json::Object& args, json::Object& out) {
+  const json::Array& batch_args = FromJson<json::Array>(args, "batchArgs");
+  const json::Object& address_book =
+      FromJson<json::Object>(args, "addressBook");
+
+  auto work_func = [=](const shared_json_value & response)->void {
+    json::Object& response_obj = response->get<json::Object>();
+    json::Array& batch_result =
+        response_obj.insert(
+                         std::make_pair("result", json::Value{json::Array{}}))
+            .first->second.get<json::Array>();
+    try {
+      for (auto& item : batch_args) {
+        json::Object single_args{};
+
+        single_args.insert(std::make_pair("addressBook", address_book));
+        single_args.insert(std::make_pair(single_arg_name, item));
+
+        json::Object single_out;
+        impl(single_args, single_out);
+        batch_result.push_back(json::Value{single_out});
+      }
+      NativePlugin::ReportSuccess(response_obj);
     }
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&to_update, ContactUtil::ContactsDeleter);
-    ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
-    err = contacts_db_update_record(*contacts_record_ptr);
-    if (CONTACTS_ERROR_NONE != err) {
-        if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
-            LOGE("Error during executing contacts_db_update_record(). Error: %d", err);
-            throw common::NotFoundException("Error during executing contacts_db_update_record().");
-        }
-        if (CONTACTS_ERROR_DB == err) {
-            LOGE("Error during executing contacts_db_update_record(). Error: %d", err);
-            throw common::UnknownException("Error during executing contacts_db_update_record().");
-        }
+    catch (const BasePlatformException& e) {
+      NativePlugin::ReportError(e, response_obj);
     }
+  };
 
-    json::Value result{json::Object{}};
-    json::Object& value_obj = result.get<json::Object>();
+  int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
+  auto after_work_func = [=](const shared_json_value& response) {
+    wrt::common::NativeContext::GetInstance()->InvokeCallback(
+        callback_handle, response->serialize());
+  };
 
-    ContactUtil::UpdateAdditionalInformation(contacts_record_ptr, &value_obj);
+  TaskQueue::GetInstance().Queue<json::Value>(
+      work_func, after_work_func,
+      shared_json_value{new json::Value{json::Object{}}});
 
-    NativePlugin::ReportSuccess(result, out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void AddressBook_remove(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+void AddressBook_find(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
 
-    long contact_id = common::stol(FromJson<json::String>(args, "id"));
+  // TODO implement contact filter and sorting.
+  LoggerD("Entered");
+  const json::Object& address_book =
+      FromJson<json::Object>(args, "addressBook");
 
-    if (contact_id < 0) {
-        throw common::InvalidValuesException("Nagative contact id");
-    }
+  int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
 
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_db_delete_record(_contacts_contact._uri, contact_id);
-    if (CONTACTS_ERROR_NO_DATA == err) {
-        LOGW("Remove failed: contact not found, error code: %d", err);
-        throw common::NotFoundException("Remove failed: contact not found");
-    } else if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Contacts record delete error, error code: %d", err);
-        throw common::UnknownException("Contacts record delete error");
+  auto get = [address_book](const shared_json_value & response)->void {
+    LoggerD("Entered");
+    try {
+      long addressbook_id =
+          common::stol(FromJson<json::String>(address_book, "id"));
+      // Read calendar by ID
+      int error_code = 0;
+
+      contacts_query_h query = nullptr;
+      contacts_filter_h filter = nullptr;
+      contacts_list_h list = nullptr;
+
+      error_code = contacts_query_create(_contacts_contact._uri, &query);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_query_create");
+      ContactUtil::ContactsQueryHPtr query_ptr(
+          &query, ContactUtil::ContactsQueryDeleter);
+      error_code = contacts_filter_create(_contacts_contact._uri, &filter);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_create");
+      ContactUtil::ContactsFilterPtr filter_ptr(
+          filter, ContactUtil::ContactsFilterDeleter);
+      error_code =
+          contacts_filter_add_int(filter, _contacts_contact.address_book_id,
+                                  CONTACTS_MATCH_EQUAL, addressbook_id);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
+      error_code = contacts_query_set_filter(query, filter);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
+      error_code = contacts_db_get_records_with_query(query, 0, 0, &list);
+      ContactUtil::ErrorChecker(error_code,
+                                "Failed contacts_db_get_records_with_query");
+      ContactUtil::ContactsListHPtr list_ptr(&list,
+                                             ContactUtil::ContactsListDeleter);
+
+      unsigned int record_count = 0;
+      error_code = contacts_list_get_count(list, &record_count);
+      json::Value result{json::Array{}};
+      json::Array& contacts = result.get<json::Array>();
+      contacts_list_first(list);
+      for (unsigned int i = 0; i < record_count; i++) {
+        contacts_record_h record;
+        error_code = contacts_list_get_current_record_p(list, &record);
+        ContactUtil::ErrorChecker(error_code,
+                                  "Failed contacts_list_get_current_record_p");
+
+        int id_value = 0;
+        error_code =
+            contacts_record_get_int(record, _contacts_contact.id, &id_value);
+        ContactUtil::ErrorChecker(error_code, "Failed contacts_record_get_int");
+
+        contacts.push_back(json::Value(static_cast<double>(id_value)));
+        contacts_list_next(list);
+      }
+
+      NativePlugin::ReportSuccess(result, response->get<json::Object>());
     }
-    NativePlugin::ReportSuccess(out);
-}
+    catch (const BasePlatformException& e) {
+      LoggerE("error: %s: %s", e.name().c_str(), e.message().c_str());
+      NativePlugin::ReportError(e, response->get<json::Object>());
+    }
+  };
 
-void AddressBook_addBatch(const json::Object& args, json::Object& out)
-{
-    LoggerD("Enter");
-    long addressBookId = -1;
-    const json::Array& batch_args = FromJson<json::Array>(args, "batchArgs");
-    addressBookId = common::stol(FromJson<json::String>(args, "addressBookId"));
-    addressBookId = addressBookId == -1 ? 0 : addressBookId;
-
-    auto batch_func = [ addressBookId, batch_args ](const shared_json_value & response)->void
-    {
-        NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-        json::Object& response_obj = response->get<json::Object>();
-        json::Array& batch_result =
-                response_obj.insert(std::make_pair("result", json::Value{json::Array{}}))
-                        .first->second.get<json::Array>();
-
-        try
-        {
-            unsigned length = batch_args.size();
-            int error_code = 0;
-            contacts_list_h contacts_list = NULL;
-            error_code = contacts_list_create(&contacts_list);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                LOGE("list creation failed, code: %d", error_code);
-                throw new common::UnknownException("list creation failed");
-            }
-            ContactUtil::ContactsListHPtr contacts_list_ptr(&contacts_list,
-                                                            ContactUtil::ContactsListDeleter);
-
-            for (auto& item : batch_args) {
-                contacts_record_h contacts_record = nullptr;
-                int err = 0;
-                err = contacts_record_create(_contacts_contact._uri, &contacts_record);
-                if (CONTACTS_ERROR_NONE != err) {
-                    LOGW("Contacts record create error, error code: %d", err);
-                    throw common::UnknownException("Contacts record create error");
-                }
-                ContactUtil::ContactsRecordHPtr x(&contacts_record, ContactUtil::ContactsDeleter);
-                ContactUtil::ExportContactToContactsRecord(contacts_record,
-                                                           JsonCast<json::Object>(item));
-                ContactUtil::SetIntInRecord(contacts_record, _contacts_contact.address_book_id,
-                                            addressBookId);
-                error_code = contacts_list_add(*contacts_list_ptr, *(x.release()));
-                if (CONTACTS_ERROR_NONE != error_code) {
-                    LOGE("error during add record to list, code: %d", error_code);
-                    throw new common::UnknownException("error during add record to list");
-                }
-            }
-
-            int* ids;
-            unsigned int count;
-            error_code = contacts_db_insert_records(*contacts_list_ptr, &ids, &count);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                if (ids) {
-                    free(ids);
-                    ids = NULL;
-                }
-                LOGE("inserting contacts to db fails, code: %d", error_code);
-                throw new common::UnknownException("inserting contacts to db fails");
-            }
-            if (length != count) {
-                LOGW("Added different number of contacts");
-            }
-
-            for (unsigned int i = 0; i < count; i++) {
-                json::Object out_object;
-                contacts_record_h contact_record = nullptr;
-                error_code =
-                        contacts_db_get_record(_contacts_contact._uri, ids[i], &contact_record);
-                if (CONTACTS_ERROR_NONE != error_code) {
-                    if (ids) {
-                        free(ids);
-                        ids = NULL;
-                    }
-                    LOGW("Contacts record get error, error code: %d", error_code);
-                    throw common::UnknownException("Contacts record get error");
-                }
-                ContactUtil::ImportContactFromContactsRecord(contact_record, &out_object);
-                batch_result.push_back(json::Value{out_object});
-            }
-            if (ids) {
-                free(ids);
-                ids = NULL;
-            }
-            NativePlugin::ReportSuccess(response_obj);
-        }
-        catch (const BasePlatformException& error)
-        {
-            LOGE("Error %s, with msg: %s", error.name().c_str(), error.message().c_str());
-            NativePlugin::ReportError(error, response_obj);
-        }
-    };
-    int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
-    auto after_work_func = [=](const shared_json_value& response) {
-        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-                                                                  response->serialize());
-    };
+  auto get_response = [callback_handle](const shared_json_value & response)
+      ->void {
+    wrt::common::NativeContext::GetInstance()->InvokeCallback(
+        callback_handle, response->serialize());
+  };
 
-    TaskQueue::GetInstance().Queue<json::Value>(batch_func, after_work_func,
-                                                shared_json_value{new json::Value{json::Object{}}});
+  TaskQueue::GetInstance().Queue<json::Value>(
+      get, get_response, shared_json_value(new json::Value(json::Object())));
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void AddressBook_batchFunc(NativeFunction impl, const char* single_arg_name,
-                           const json::Object& args, json::Object& out)
-{
-    const json::Array& batch_args = FromJson<json::Array>(args, "batchArgs");
-    const json::Object& address_book = FromJson<json::Object>(args, "addressBook");
-
-    auto work_func = [=](const shared_json_value & response)->void
-    {
-        json::Object& response_obj = response->get<json::Object>();
-        json::Array& batch_result =
-                response_obj.insert(std::make_pair("result", json::Value{json::Array{}}))
-                        .first->second.get<json::Array>();
-        try
-        {
-            for (auto& item : batch_args) {
-                json::Object single_args{};
-
-                single_args.insert(std::make_pair("addressBook", address_book));
-                single_args.insert(std::make_pair(single_arg_name, item));
-
-                json::Object single_out;
-                impl(single_args, single_out);
-                batch_result.push_back(json::Value{single_out});
-            }
-            NativePlugin::ReportSuccess(response_obj);
-        }
-        catch (const BasePlatformException& e)
-        {
-            NativePlugin::ReportError(e, response_obj);
-        }
-    };
-
-    int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
-    auto after_work_func = [=](const shared_json_value& response) {
-        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-                                                                  response->serialize());
-    };
-
-    TaskQueue::GetInstance().Queue<json::Value>(work_func, after_work_func,
-                                                shared_json_value{new json::Value{json::Object{}}});
-
-    NativePlugin::ReportSuccess(out);
+void AddressBook_addGroup(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+  const json::Object& group = FromJson<json::Object>(args, "group");
+  if (!IsNull(group, "id") || !IsNull(group, "addressBookId")) {
+    LOGE("Group object is previously added");
+    throw common::InvalidValuesException("Group object is previously added");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h contacts_record = nullptr;
+  err = contacts_record_create(_contacts_group._uri, &contacts_record);
+  ContactUtil::ErrorChecker(err,
+                            "Error during executing contacts_record_create()");
+
+  ContactUtil::ContactsRecordHPtr record(&contacts_record,
+                                         ContactUtil::ContactsDeleter);
+
+  long addressbook_id =
+      common::stol(FromJson<json::String>(args, "addressBookId"));
+  addressbook_id = (IsUnified(addressbook_id)) ? 0 : addressbook_id;
+  ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id,
+                              addressbook_id);
+
+  ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group);
+  int groupId = 0;
+  err = contacts_db_insert_record(contacts_record, &groupId);
+  ContactUtil::ErrorChecker(err, "Error during insert group record");
+
+  json::Value result{json::Object{}};
+  json::Object& result_obj = result.get<json::Object>();
+  result_obj.insert(std::make_pair("id", std::to_string(groupId)));
+  result_obj.insert(
+      std::make_pair("addressBookId", std::to_string(addressbook_id)));
+  NativePlugin::ReportSuccess(result, out);
 }
 
-void AddressBook_find(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-
-    // TODO implement contact filter and sorting.
-    LoggerD("Entered");
-    const json::Object& address_book = FromJson<json::Object>(args, "addressBook");
-
-    int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
-
-    auto get = [address_book](const shared_json_value & response)->void
-    {
-        LoggerD("Entered");
-        try
-        {
-            long addressbook_id = common::stol(FromJson<json::String>(address_book, "id"));
-            // Read calendar by ID
-            int error_code = 0;
-
-            contacts_query_h query = nullptr;
-            contacts_filter_h filter = nullptr;
-            contacts_list_h list = nullptr;
-
-            error_code = contacts_query_create(_contacts_contact._uri, &query);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_query_create");
-            ContactUtil::ContactsQueryHPtr query_ptr(&query, ContactUtil::ContactsQueryDeleter);
-            error_code = contacts_filter_create(_contacts_contact._uri, &filter);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_create");
-            ContactUtil::ContactsFilterPtr filter_ptr(filter, ContactUtil::ContactsFilterDeleter);
-            error_code = contacts_filter_add_int(filter, _contacts_contact.address_book_id,
-                                                 CONTACTS_MATCH_EQUAL, addressbook_id);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
-            error_code = contacts_query_set_filter(query, filter);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-            error_code = contacts_db_get_records_with_query(query, 0, 0, &list);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_db_get_records_with_query");
-            ContactUtil::ContactsListHPtr list_ptr(&list, ContactUtil::ContactsListDeleter);
-
-            unsigned int record_count = 0;
-            error_code = contacts_list_get_count(list, &record_count);
-            json::Value result{json::Array{}};
-            json::Array& contacts = result.get<json::Array>();
-            contacts_list_first(list);
-            for (unsigned int i = 0; i < record_count; i++) {
-                contacts_record_h record;
-                error_code = contacts_list_get_current_record_p(list, &record);
-                ContactUtil::ErrorChecker(error_code, "Failed contacts_list_get_current_record_p");
-
-                int id_value = 0;
-                error_code = contacts_record_get_int(record, _contacts_contact.id, &id_value);
-                ContactUtil::ErrorChecker(error_code, "Failed contacts_record_get_int");
-
-                contacts.push_back(json::Value(static_cast<double>(id_value)));
-                contacts_list_next(list);
-            }
-
-            NativePlugin::ReportSuccess(result, response->get<json::Object>());
-        }
-        catch (const BasePlatformException& e)
-        {
-            LoggerE("error: %s: %s", e.name().c_str(), e.message().c_str());
-            NativePlugin::ReportError(e, response->get<json::Object>());
-        }
-    };
-
-    auto get_response = [callback_handle](const shared_json_value & response)->void
-    {
-        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-                                                                  response->serialize());
-    };
+void AddressBook_getGroup(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+
+  long id = common::stol(FromJson<json::String>(args, "id"));
+
+  if (id < 0) {
+    throw common::InvalidValuesException("Incorrect group id");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h contacts_record = nullptr;
+  err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
+  if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
+    throw common::NotFoundException("Don't find group with this id");
+  }
+
+  ContactUtil::ContactsRecordHPtr record(&contacts_record,
+                                         ContactUtil::ContactsDeleter);
+
+  long addressbook_id =
+      common::stol(FromJson<json::String>(args, "addressBook", "id"));
+  if (IsUnified(addressbook_id)) {
+    int address_book_id = 0;
+    ContactUtil::GetIntFromRecord(
+        contacts_record, _contacts_group.address_book_id, &address_book_id);
+    if (address_book_id != addressbook_id) {
+      throw common::NotFoundException("No group in this address book.");
+    }
+  }
 
-    TaskQueue::GetInstance().Queue<json::Value>(get, get_response,
-                                                shared_json_value(new json::Value(json::Object())));
+  json::Value result{json::Object{}};
+  ContactUtil::ImportContactGroupFromContactsRecord(
+      contacts_record, &result.get<json::Object>());
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(result, out);
 }
 
-void AddressBook_addGroup(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-    const json::Object& group = FromJson<json::Object>(args, "group");
-    if (!IsNull(group, "id") || !IsNull(group, "addressBookId")) {
-        LOGE("Group object is previously added");
-        throw common::InvalidValuesException("Group object is previously added");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h contacts_record = nullptr;
-    err = contacts_record_create(_contacts_group._uri, &contacts_record);
-    ContactUtil::ErrorChecker(err, "Error during executing contacts_record_create()");
+void AddressBook_updateGroup(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
 
-    ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter);
+  const json::Object& group = FromJson<json::Object>(args, "group");
 
-    long addressbook_id = common::stol(FromJson<json::String>(args, "addressBookId"));
-    addressbook_id = (IsUnified(addressbook_id)) ? 0 : addressbook_id;
-    ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id, addressbook_id);
+  if (IsNull(group, "id") || IsNull(group, "addressBookId")) {
+    LOGE("Group object is not added");
+    throw common::InvalidValuesException("Group object is not added");
+  }
 
-    ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group);
-    int groupId = 0;
-    err = contacts_db_insert_record(contacts_record, &groupId);
-    ContactUtil::ErrorChecker(err, "Error during insert group record");
+  long addressbook_id =
+      common::stol(FromJson<json::String>(args, "addressBookId"));
+  long group_addressbook_id =
+      common::stol(FromJson<json::String>(group, "addressBookId"));
+  if (IsUnified(addressbook_id) && (addressbook_id != group_addressbook_id)) {
+    LOGE("Wrong address book");
+    throw common::InvalidValuesException("Wrong address book");
+  }
 
-    json::Value result{json::Object{}};
-    json::Object& result_obj = result.get<json::Object>();
-    result_obj.insert(std::make_pair("id", std::to_string(groupId)));
-    result_obj.insert(std::make_pair("addressBookId", std::to_string(addressbook_id)));
-    NativePlugin::ReportSuccess(result, out);
+  if (FromJson<bool>(group, "readOnly")) {
+    LOGW("Group is readonly - cancel update");
+    // TODO should this be an error?
+    NativePlugin::ReportSuccess(out);
+    return;
+  }
+
+  long group_id = common::stol(FromJson<json::String>(group, "id"));
+  if (group_id < 0) {
+    throw common::InvalidValuesException("Incorrect group id");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h contacts_record = nullptr;
+  err =
+      contacts_db_get_record(_contacts_group._uri, group_id, &contacts_record);
+  if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
+    LOGE("Error during executing contacts_db_get_record()");
+    throw common::NotFoundException(
+        "Error during executing contacts_db_get_record()");
+  }
+
+  ContactUtil::ErrorChecker(err,
+                            "Error during executing contacts_db_get_record()");
+
+  ContactUtil::ContactsRecordHPtr record(&contacts_record,
+                                         ContactUtil::ContactsDeleter);
+  ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group);
+
+  err = contacts_db_update_record(contacts_record);
+  if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
+    LOGE("Problem during db_update_record");
+    throw common::NotFoundException("Problem during db_update_record");
+  }
+  ContactUtil::ErrorChecker(err, "Problem during db_update_record");
+
+  NativePlugin::ReportSuccess(out);
 }
 
-void AddressBook_getGroup(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+void AddressBook_removeGroup(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
 
-    long id = common::stol(FromJson<json::String>(args, "id"));
-
-    if (id < 0) {
-        throw common::InvalidValuesException("Incorrect group id");
-    }
+  long id = common::stol(FromJson<json::String>(args, "id"));
+  if (id < 0) {
+    throw common::InvalidValuesException("Incorrect group id");
+  }
 
-    int err = CONTACTS_ERROR_NONE;
+  int err = CONTACTS_ERROR_NONE;
+  long addressbook_id = AddressBookId(args);
+  if (!IsUnified(addressbook_id)) {
     contacts_record_h contacts_record = nullptr;
     err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
-    if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
-        throw common::NotFoundException("Don't find group with this id");
+    if (CONTACTS_ERROR_NONE != err || contacts_record == nullptr) {
+      LOGE("No group");
+      throw common::UnknownException("No group");
     }
 
-    ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter);
+    int group_addressbook_id = 0;
+    ContactUtil::GetIntFromRecord(contacts_record,
+                                  _contacts_group.address_book_id,
+                                  &group_addressbook_id);
 
-    long addressbook_id = common::stol(FromJson<json::String>(args, "addressBook", "id"));
-    if (IsUnified(addressbook_id)) {
-        int address_book_id = 0;
-        ContactUtil::GetIntFromRecord(contacts_record, _contacts_group.address_book_id,
-                                      &address_book_id);
-        if (address_book_id != addressbook_id) {
-            throw common::NotFoundException("No group in this address book.");
-        }
+    if (group_addressbook_id != addressbook_id) {
+      throw common::UnknownException(
+          "Contact is not a member of this address book");
     }
-
-    json::Value result{json::Object{}};
-    ContactUtil::ImportContactGroupFromContactsRecord(contacts_record, &result.get<json::Object>());
-
-    NativePlugin::ReportSuccess(result, out);
+  }
+
+  err = contacts_db_delete_record(_contacts_group._uri, id);
+  if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
+    LOGE("Problem during db_update_record");
+    throw common::NotFoundException("Problem during db_delete_record");
+  }
+  ContactUtil::ErrorChecker(err, "Problem during db_delete_record");
+  NativePlugin::ReportSuccess(out);
 }
 
-void AddressBook_updateGroup(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+void AddressBook_getGroups(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
 
-    const json::Object& group = FromJson<json::Object>(args, "group");
+  int err = CONTACTS_ERROR_NONE;
+  contacts_list_h groups_list = nullptr;
+  long addressbook_id = AddressBookId(args);
 
-    if (IsNull(group, "id") || IsNull(group, "addressBookId")) {
-        LOGE("Group object is not added");
-        throw common::InvalidValuesException("Group object is not added");
-    }
+  if (IsUnified(addressbook_id)) {
+    err = contacts_db_get_all_records(_contacts_group._uri, 0, 0, &groups_list);
+    ContactUtil::ErrorChecker(err, "Fail to get group list");
+  } else {
+    contacts_query_h query = nullptr;
+    contacts_filter_h filter = nullptr;
 
-    long addressbook_id = common::stol(FromJson<json::String>(args, "addressBookId"));
-    long group_addressbook_id = common::stol(FromJson<json::String>(group, "addressBookId"));
-    if (IsUnified(addressbook_id) && (addressbook_id != group_addressbook_id)) {
-        LOGE("Wrong address book");
-        throw common::InvalidValuesException("Wrong address book");
-    }
+    err = contacts_query_create(_contacts_group._uri, &query);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_query_create ");
 
-    if (FromJson<bool>(group, "readOnly")) {
-        LOGW("Group is readonly - cancel update");
-        // TODO should this be an error?
-        NativePlugin::ReportSuccess(out);
-        return;
-    }
+    err = contacts_filter_create(_contacts_group._uri, &filter);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_create ");
 
-    long group_id = common::stol(FromJson<json::String>(group, "id"));
-    if (group_id < 0) {
-        throw common::InvalidValuesException("Incorrect group id");
-    }
+    err = contacts_filter_add_int(filter, _contacts_group.address_book_id,
+                                  CONTACTS_MATCH_EQUAL, addressbook_id);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_add_int ");
 
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h contacts_record = nullptr;
-    err = contacts_db_get_record(_contacts_group._uri, group_id, &contacts_record);
-    if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
-        LOGE("Error during executing contacts_db_get_record()");
-        throw common::NotFoundException("Error during executing contacts_db_get_record()");
-    }
+    err = contacts_query_set_filter(query, filter);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_query_set_filter ");
 
-    ContactUtil::ErrorChecker(err, "Error during executing contacts_db_get_record()");
+    err = contacts_db_get_records_with_query(query, 0, 0, &groups_list);
+    ContactUtil::ErrorChecker(
+        err, "Fail to get contacts_db_get_records_with_query ");
 
-    ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter);
-    ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group);
+    err = contacts_filter_destroy(filter);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_destroy ");
 
-    err = contacts_db_update_record(contacts_record);
-    if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
-        LOGE("Problem during db_update_record");
-        throw common::NotFoundException("Problem during db_update_record");
-    }
-    ContactUtil::ErrorChecker(err, "Problem during db_update_record");
+    err = contacts_query_destroy(query);
+    ContactUtil::ErrorChecker(err, "Fail to get contacts_query_destroy ");
+  }
+  unsigned int record_count = 0;
+  err = contacts_list_get_count(groups_list, &record_count);
+  ContactUtil::ErrorChecker(err, "Fail to get contacts_list_get_count ");
 
-    NativePlugin::ReportSuccess(out);
-}
+  contacts_list_first(groups_list);
 
-void AddressBook_removeGroup(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+  json::Value result{json::Array{}};
+  json::Array& array = result.get<json::Array>();
 
-    long id = common::stol(FromJson<json::String>(args, "id"));
-    if (id < 0) {
-        throw common::InvalidValuesException("Incorrect group id");
+  for (unsigned int i = 0; i < record_count; i++) {
+    contacts_record_h contacts_record;
+    err = contacts_list_get_current_record_p(groups_list, &contacts_record);
+    if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
+      LOGE("Fail to get group record ");
+      throw common::UnknownException("Fail to get group record");
     }
 
-    int err = CONTACTS_ERROR_NONE;
-    long addressbook_id = AddressBookId(args);
-    if (!IsUnified(addressbook_id)) {
-        contacts_record_h contacts_record = nullptr;
-        err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
-        if (CONTACTS_ERROR_NONE != err || contacts_record == nullptr) {
-            LOGE("No group");
-            throw common::UnknownException("No group");
-        }
+    JsonValue group{json::Object{}};
+    ContactUtil::ImportContactGroupFromContactsRecord(contacts_record,
+                                                      &group.get<JsonObject>());
+    array.push_back(group);
 
-        int group_addressbook_id = 0;
-        ContactUtil::GetIntFromRecord(contacts_record, _contacts_group.address_book_id,
-                                      &group_addressbook_id);
-
-        if (group_addressbook_id != addressbook_id) {
-            throw common::UnknownException("Contact is not a member of this address book");
-        }
+    err = contacts_list_next(groups_list);
+    if (CONTACTS_ERROR_NONE != err) {
+      LoggerE("Fail to get next address book ");
+      break;
     }
+  }
 
-    err = contacts_db_delete_record(_contacts_group._uri, id);
-    if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
-        LOGE("Problem during db_update_record");
-        throw common::NotFoundException("Problem during db_delete_record");
-    }
-    ContactUtil::ErrorChecker(err, "Problem during db_delete_record");
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(result, out);
 }
 
-void AddressBook_getGroups(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_list_h groups_list = nullptr;
-    long addressbook_id = AddressBookId(args);
-
-    if (IsUnified(addressbook_id)) {
-        err = contacts_db_get_all_records(_contacts_group._uri, 0, 0, &groups_list);
-        ContactUtil::ErrorChecker(err, "Fail to get group list");
-    } else {
-        contacts_query_h query = nullptr;
-        contacts_filter_h filter = nullptr;
-
-        err = contacts_query_create(_contacts_group._uri, &query);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_query_create ");
+namespace {
+void AddressBook_listenerCallback(const char* view_uri, void* user_data) {
+  (void)view_uri;
+  (void)user_data;
 
-        err = contacts_filter_create(_contacts_group._uri, &filter);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_create ");
+  int* last_database_version = static_cast<int*>(user_data);
 
-        err = contacts_filter_add_int(filter, _contacts_group.address_book_id, CONTACTS_MATCH_EQUAL,
-                                      addressbook_id);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_add_int ");
+  contacts_list_h contacts_list = nullptr;
 
-        err = contacts_query_set_filter(query, filter);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_query_set_filter ");
+  int error_code = contacts_db_get_changes_by_version(
+      _contacts_contact_updated_info._uri, kUnifiedAddressBookId,
+      *last_database_version, &contacts_list, last_database_version);
 
-        err = contacts_db_get_records_with_query(query, 0, 0, &groups_list);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_db_get_records_with_query ");
+  ContactUtil::ContactsListHPtr contacts_list_ptr(
+      &contacts_list, ContactUtil::ContactsListDeleter);
 
-        err = contacts_filter_destroy(filter);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_filter_destroy ");
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGE("cannot get changes by version, code: %d", error_code);
+  } else {
+    unsigned int count = 0;
 
-        err = contacts_query_destroy(query);
-        ContactUtil::ErrorChecker(err, "Fail to get contacts_query_destroy ");
+    error_code = contacts_list_get_count(contacts_list, &count);
+    if (CONTACTS_ERROR_NONE != error_code) {
+      LOGW("Cannot get updated contact count, code: %d", error_code);
+      return;
     }
-    unsigned int record_count = 0;
-    err = contacts_list_get_count(groups_list, &record_count);
-    ContactUtil::ErrorChecker(err, "Fail to get contacts_list_get_count ");
-
-    contacts_list_first(groups_list);
-
-    json::Value result{json::Array{}};
-    json::Array& array = result.get<json::Array>();
 
-    for (unsigned int i = 0; i < record_count; i++) {
-        contacts_record_h contacts_record;
-        err = contacts_list_get_current_record_p(groups_list, &contacts_record);
-        if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
-            LOGE("Fail to get group record ");
-            throw common::UnknownException("Fail to get group record");
-        }
-
-        JsonValue group{json::Object{}};
-        ContactUtil::ImportContactGroupFromContactsRecord(contacts_record,
-                                                          &group.get<JsonObject>());
-        array.push_back(group);
-
-        err = contacts_list_next(groups_list);
-        if (CONTACTS_ERROR_NONE != err) {
-            LoggerE("Fail to get next address book ");
-            break;
-        }
+    if (!count) {
+      LOGW("No updated contacts");
+      return;
     }
 
-    NativePlugin::ReportSuccess(result, out);
-}
-
-namespace {
-void AddressBook_listenerCallback(const char* view_uri, void* user_data)
-{
-    (void)view_uri;
-    (void)user_data;
-
-    int* last_database_version = static_cast<int*>(user_data);
-
-    contacts_list_h contacts_list = nullptr;
+    contacts_list_first(contacts_list);
 
-    int error_code = contacts_db_get_changes_by_version(
-            _contacts_contact_updated_info._uri, kUnifiedAddressBookId, *last_database_version,
-            &contacts_list, last_database_version);
+    json::Value result{json::Object{}};
+    json::Object& result_obj = result.get<json::Object>();
+    json::Array& added =
+        result_obj.insert(std::make_pair("added", json::Array{}))
+            .first->second.get<json::Array>();
+    json::Array& updated =
+        result_obj.insert(std::make_pair("updated", json::Array{}))
+            .first->second.get<json::Array>();
+    json::Array& removed =
+        result_obj.insert(std::make_pair("removed", json::Array{}))
+            .first->second.get<json::Array>();
+
+    for (unsigned int i = 0; i < count; i++) {
+      contacts_record_h contact_updated_record = nullptr;
+
+      error_code = contacts_list_get_current_record_p(contacts_list,
+                                                      &contact_updated_record);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        LOGW("fail to get contact from list, code: %d", error_code);
+        return;
+      }
+
+      int changed_id = 0;
+      int changed_ab_id = 0;
+      int changed_type = 0;
+
+      try {
+        ContactUtil::GetIntFromRecord(contact_updated_record,
+                                      _contacts_contact_updated_info.contact_id,
+                                      &changed_id);
+
+        ContactUtil::GetIntFromRecord(
+            contact_updated_record,
+            _contacts_contact_updated_info.address_book_id, &changed_ab_id);
+
+        ContactUtil::GetIntFromRecord(contact_updated_record,
+                                      _contacts_contact_updated_info.type,
+                                      &changed_type);
+      }
+      catch (const BasePlatformException&) {
+        LOGE("failt to get int from record");
+        return;
+      }
 
-    ContactUtil::ContactsListHPtr contacts_list_ptr(&contacts_list,
-                                                    ContactUtil::ContactsListDeleter);
+      if (CONTACTS_CHANGE_INSERTED == changed_type ||
+          CONTACTS_CHANGE_UPDATED == changed_type) {
+        contacts_record_h contacts_record = nullptr;
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGE("cannot get changes by version, code: %d", error_code);
-    } else {
-        unsigned int count = 0;
+        error_code = contacts_db_get_record(_contacts_contact._uri, changed_id,
+                                            &contacts_record);
 
-        error_code = contacts_list_get_count(contacts_list, &count);
         if (CONTACTS_ERROR_NONE != error_code) {
-            LOGW("Cannot get updated contact count, code: %d", error_code);
-            return;
+          LOGW("fail to get contact from record");
+          return;
         }
 
-        if (!count) {
-            LOGW("No updated contacts");
-            return;
-        }
+        ContactUtil::ContactsRecordHPtr contact_record_ptr(
+            &contacts_record, ContactUtil::ContactsDeleter);
 
-        contacts_list_first(contacts_list);
-
-        json::Value result{json::Object{}};
-        json::Object& result_obj = result.get<json::Object>();
-        json::Array& added = result_obj.insert(std::make_pair("added", json::Array{}))
-                                     .first->second.get<json::Array>();
-        json::Array& updated = result_obj.insert(std::make_pair("updated", json::Array{}))
-                                       .first->second.get<json::Array>();
-        json::Array& removed = result_obj.insert(std::make_pair("removed", json::Array{}))
-                                       .first->second.get<json::Array>();
-
-        for (unsigned int i = 0; i < count; i++) {
-            contacts_record_h contact_updated_record = nullptr;
-
-            error_code = contacts_list_get_current_record_p(contacts_list, &contact_updated_record);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                LOGW("fail to get contact from list, code: %d", error_code);
-                return;
-            }
-
-            int changed_id = 0;
-            int changed_ab_id = 0;
-            int changed_type = 0;
-
-            try
-            {
-                ContactUtil::GetIntFromRecord(contact_updated_record,
-                                              _contacts_contact_updated_info.contact_id,
-                                              &changed_id);
-
-                ContactUtil::GetIntFromRecord(contact_updated_record,
-                                              _contacts_contact_updated_info.address_book_id,
-                                              &changed_ab_id);
-
-                ContactUtil::GetIntFromRecord(contact_updated_record,
-                                              _contacts_contact_updated_info.type, &changed_type);
-            }
-            catch (const BasePlatformException&)
-            {
-                LOGE("failt to get int from record");
-                return;
-            }
-
-            if (CONTACTS_CHANGE_INSERTED == changed_type ||
-                CONTACTS_CHANGE_UPDATED == changed_type) {
-                contacts_record_h contacts_record = nullptr;
-
-                error_code = contacts_db_get_record(_contacts_contact._uri, changed_id,
-                                                    &contacts_record);
-
-                if (CONTACTS_ERROR_NONE != error_code) {
-                    LOGW("fail to get contact from record");
-                    return;
-                }
-
-                ContactUtil::ContactsRecordHPtr contact_record_ptr(&contacts_record,
-                                                                   ContactUtil::ContactsDeleter);
-
-                json::Value contact{json::Object{}};
-                ContactUtil::ImportContactFromContactsRecord(*contact_record_ptr,
-                                                             &contact.get<json::Object>());
-
-                if (CONTACTS_CHANGE_INSERTED == changed_type) {
-                    added.push_back(std::move(contact));
-                } else {
-                    updated.push_back(std::move(contact));
-                }
-            } else if (CONTACTS_CHANGE_DELETED == changed_type) {
-                // Need to send the addressbook id with the removed id
-                json::Value removed_data{json::Object{}};
-                json::Object& removed_data_obj = removed_data.get<json::Object>();
-
-                removed_data_obj.insert(std::make_pair("id", std::to_string(changed_id)));
-                removed_data_obj.insert(
-                        std::make_pair("addressBookId", std::to_string(changed_ab_id)));
-                removed.push_back(std::move(removed_data));
-            }
+        json::Value contact{json::Object{}};
+        ContactUtil::ImportContactFromContactsRecord(
+            *contact_record_ptr, &contact.get<json::Object>());
+
+        if (CONTACTS_CHANGE_INSERTED == changed_type) {
+          added.push_back(std::move(contact));
+        } else {
+          updated.push_back(std::move(contact));
         }
-        NativeContext::GetInstance()->FireEvent(kContactListenerId, result.serialize());
+      } else if (CONTACTS_CHANGE_DELETED == changed_type) {
+        // Need to send the addressbook id with the removed id
+        json::Value removed_data{json::Object{}};
+        json::Object& removed_data_obj = removed_data.get<json::Object>();
+
+        removed_data_obj.insert(
+            std::make_pair("id", std::to_string(changed_id)));
+        removed_data_obj.insert(
+            std::make_pair("addressBookId", std::to_string(changed_ab_id)));
+        removed.push_back(std::move(removed_data));
+      }
     }
+    NativeContext::GetInstance()->FireEvent(kContactListenerId,
+                                            result.serialize());
+  }
 }
 }
 
-void AddressBook_startListening(int* current_state, const JsonObject&, JsonObject& out)
-{
-    // Set the initial latest version before registering the callback.
-    // The callback should only be registered once so no race can occur.
-    int error_code = contacts_db_get_current_version(current_state);
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGW("get current version returns error, code: %d", error_code);
-    }
-
-    error_code = contacts_db_add_changed_cb(_contacts_contact._uri, AddressBook_listenerCallback,
-                                            current_state);
-
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGE("Error while registering listener to contacts db, code: %d", error_code);
-        throw UnknownException("Error while registering listener to contacts db");
-    }
-
-    NativePlugin::ReportSuccess(out);
+void AddressBook_startListening(int* current_state, const JsonObject&,
+                                JsonObject& out) {
+  // Set the initial latest version before registering the callback.
+  // The callback should only be registered once so no race can occur.
+  int error_code = contacts_db_get_current_version(current_state);
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGW("get current version returns error, code: %d", error_code);
+  }
+
+  error_code = contacts_db_add_changed_cb(
+      _contacts_contact._uri, AddressBook_listenerCallback, current_state);
+
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGE("Error while registering listener to contacts db, code: %d",
+         error_code);
+    throw UnknownException("Error while registering listener to contacts db");
+  }
+
+  NativePlugin::ReportSuccess(out);
 }
 
-void AddressBook_stopListening(int* current_state, const JsonObject&, JsonObject& out)
-{
-    int error_code = contacts_db_remove_changed_cb(_contacts_contact._uri,
-                                                   AddressBook_listenerCallback, current_state);
+void AddressBook_stopListening(int* current_state, const JsonObject&,
+                               JsonObject& out) {
+  int error_code = contacts_db_remove_changed_cb(
+      _contacts_contact._uri, AddressBook_listenerCallback, current_state);
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGE("Error while removing listener");
-        throw UnknownException("Error while removing listener");
-    }
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGE("Error while removing listener");
+    throw UnknownException("Error while removing listener");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
 }  // AddressBook
index 62e6e6a..4ef3dc1 100644 (file)
@@ -35,11 +35,14 @@ void AddressBook_getGroup(const JsonObject& args, JsonObject& out);
 void AddressBook_updateGroup(const JsonObject& args, JsonObject& out);
 void AddressBook_removeGroup(const JsonObject& args, JsonObject& out);
 void AddressBook_getGroups(const JsonObject& args, JsonObject& out);
-void AddressBook_startListening(int* current_state, const JsonObject& args, JsonObject& out);
-void AddressBook_stopListening(int* current_state, const JsonObject& args, JsonObject& out);
-
-void AddressBook_batchFunc(common::NativeFunction impl, const char* single_arg_name,
-                           const JsonObject& args, JsonObject& out);
+void AddressBook_startListening(int* current_state, const JsonObject& args,
+                                JsonObject& out);
+void AddressBook_stopListening(int* current_state, const JsonObject& args,
+                               JsonObject& out);
+
+void AddressBook_batchFunc(common::NativeFunction impl,
+                           const char* single_arg_name, const JsonObject& args,
+                           JsonObject& out);
 
 void AddressBook_addBatch(const JsonObject& args, JsonObject& out);
 
index 491ba45..e6d9660 100644 (file)
@@ -27,103 +27,100 @@ namespace extension {
 namespace contact {
 
 namespace {
-void CheckReadPrivileges(const JsonObject& /*args*/, JsonObject& /*out*/)
-{
-    common::NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+void CheckReadPrivileges(const JsonObject& /*args*/, JsonObject& /*out*/) {
+  common::NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
 }
 }
 
 class ContactPlugin : public webapi::common::NativePlugin {
-public:
-    ContactPlugin();
-    ~ContactPlugin();
-    virtual void OnLoad();
-
-private:
-    bool connected_;
-    int contact_listener_current_state_;
+ public:
+  ContactPlugin();
+  ~ContactPlugin();
+  virtual void OnLoad();
+
+ private:
+  bool connected_;
+  int contact_listener_current_state_;
 };
 
 EXPORT_NATIVE_PLUGIN(extension::contact::ContactPlugin);
 
 using namespace extension::common;
 
-ContactPlugin::ContactPlugin() : connected_{false}, contact_listener_current_state_{0}
-{
-}
+ContactPlugin::ContactPlugin()
+    : connected_{false}, contact_listener_current_state_{0} {}
 
-ContactPlugin::~ContactPlugin()
-{
-    if (connected_) {
-        contacts_disconnect();
-    }
+ContactPlugin::~ContactPlugin() {
+  if (connected_) {
+    contacts_disconnect();
+  }
 }
 
-void ContactPlugin::OnLoad()
-{
+void ContactPlugin::OnLoad() {
 
-    using namespace AddressBook;
-    using namespace Person;
-    using namespace ContactManager;
+  using namespace AddressBook;
+  using namespace Person;
+  using namespace ContactManager;
 
 #define DISPATCHER_ADDFUNCTION(N) dispatcher_.AddFunction(#N, N);
-    DISPATCHER_ADDFUNCTION(AddressBook_get);
-    DISPATCHER_ADDFUNCTION(AddressBook_add);
-    DISPATCHER_ADDFUNCTION(AddressBook_update);
-    DISPATCHER_ADDFUNCTION(AddressBook_remove);
-    DISPATCHER_ADDFUNCTION(AddressBook_find);
-    DISPATCHER_ADDFUNCTION(AddressBook_getGroup);
-    DISPATCHER_ADDFUNCTION(AddressBook_addGroup);
-    DISPATCHER_ADDFUNCTION(AddressBook_updateGroup);
-    DISPATCHER_ADDFUNCTION(AddressBook_removeGroup);
-    DISPATCHER_ADDFUNCTION(AddressBook_getGroups);
-    DISPATCHER_ADDFUNCTION(AddressBook_addBatch);
-
-    DISPATCHER_ADDFUNCTION(ContactManager_getAddressBooks);
-    DISPATCHER_ADDFUNCTION(ContactManager_find);
-    DISPATCHER_ADDFUNCTION(ContactManager_get);
-    DISPATCHER_ADDFUNCTION(ContactManager_getAddressBook);
-    DISPATCHER_ADDFUNCTION(ContactManager_importFromVCard);
-    DISPATCHER_ADDFUNCTION(ContactManager_remove);
-    DISPATCHER_ADDFUNCTION(ContactManager_update);
-    DISPATCHER_ADDFUNCTION(ContactManager_startListening);
-    DISPATCHER_ADDFUNCTION(ContactManager_stopListening);
-
-    DISPATCHER_ADDFUNCTION(CheckReadPrivileges);
-
-    DISPATCHER_ADDFUNCTION(Person_link);
-    DISPATCHER_ADDFUNCTION(Person_unlink);
+  DISPATCHER_ADDFUNCTION(AddressBook_get);
+  DISPATCHER_ADDFUNCTION(AddressBook_add);
+  DISPATCHER_ADDFUNCTION(AddressBook_update);
+  DISPATCHER_ADDFUNCTION(AddressBook_remove);
+  DISPATCHER_ADDFUNCTION(AddressBook_find);
+  DISPATCHER_ADDFUNCTION(AddressBook_getGroup);
+  DISPATCHER_ADDFUNCTION(AddressBook_addGroup);
+  DISPATCHER_ADDFUNCTION(AddressBook_updateGroup);
+  DISPATCHER_ADDFUNCTION(AddressBook_removeGroup);
+  DISPATCHER_ADDFUNCTION(AddressBook_getGroups);
+  DISPATCHER_ADDFUNCTION(AddressBook_addBatch);
+
+  DISPATCHER_ADDFUNCTION(ContactManager_getAddressBooks);
+  DISPATCHER_ADDFUNCTION(ContactManager_find);
+  DISPATCHER_ADDFUNCTION(ContactManager_get);
+  DISPATCHER_ADDFUNCTION(ContactManager_getAddressBook);
+  DISPATCHER_ADDFUNCTION(ContactManager_importFromVCard);
+  DISPATCHER_ADDFUNCTION(ContactManager_remove);
+  DISPATCHER_ADDFUNCTION(ContactManager_update);
+  DISPATCHER_ADDFUNCTION(ContactManager_startListening);
+  DISPATCHER_ADDFUNCTION(ContactManager_stopListening);
+
+  DISPATCHER_ADDFUNCTION(CheckReadPrivileges);
+
+  DISPATCHER_ADDFUNCTION(Person_link);
+  DISPATCHER_ADDFUNCTION(Person_unlink);
 #undef DISPATCHER_ADDFUNCTION
 
-    using namespace std::placeholders;
-    dispatcher_.AddFunction(
-            "AddressBook_updateBatch",
-            std::bind(AddressBook_batchFunc, AddressBook_update, "contact", _1, _2));
-    dispatcher_.AddFunction("AddressBook_removeBatch",
-                            std::bind(AddressBook_batchFunc, AddressBook_remove, "id", _1, _2));
-
-    dispatcher_.AddFunction(
-            "ContactManager_updateBatch",
-            std::bind(AddressBook_batchFunc, ContactManager_update, "person", _1, _2));
-    dispatcher_.AddFunction(
-            "ContactManager_removeBatch",
-            std::bind(AddressBook_batchFunc, ContactManager_remove, "personId", _1, _2));
-
-    dispatcher_.AddFunction(
-            "AddressBook_startListening",
-            std::bind(AddressBook_startListening, &contact_listener_current_state_, _1, _2));
-    dispatcher_.AddFunction(
-            "AddressBook_stopListening",
-            std::bind(AddressBook_stopListening, &contact_listener_current_state_, _1, _2));
-
-    int err = contacts_connect();
-    // TODO maybe do something if it fails
-    connected_ = err == CONTACTS_ERROR_NONE;
-    if (connected_) {
-        LoggerI("Connection established!");
-    } else {
-        LoggerW("Connection error occured: " << err);
-    }
+  using namespace std::placeholders;
+  dispatcher_.AddFunction(
+      "AddressBook_updateBatch",
+      std::bind(AddressBook_batchFunc, AddressBook_update, "contact", _1, _2));
+  dispatcher_.AddFunction(
+      "AddressBook_removeBatch",
+      std::bind(AddressBook_batchFunc, AddressBook_remove, "id", _1, _2));
+
+  dispatcher_.AddFunction("ContactManager_updateBatch",
+                          std::bind(AddressBook_batchFunc,
+                                    ContactManager_update, "person", _1, _2));
+  dispatcher_.AddFunction("ContactManager_removeBatch",
+                          std::bind(AddressBook_batchFunc,
+                                    ContactManager_remove, "personId", _1, _2));
+
+  dispatcher_.AddFunction("AddressBook_startListening",
+                          std::bind(AddressBook_startListening,
+                                    &contact_listener_current_state_, _1, _2));
+  dispatcher_.AddFunction("AddressBook_stopListening",
+                          std::bind(AddressBook_stopListening,
+                                    &contact_listener_current_state_, _1, _2));
+
+  int err = contacts_connect();
+  // TODO maybe do something if it fails
+  connected_ = err == CONTACTS_ERROR_NONE;
+  if (connected_) {
+    LoggerI("Connection established!");
+  } else {
+    LoggerW("Connection error occured: " << err);
+  }
 }
 
 }  // namespace contact
index 7a27f2e..51fc531 100644 (file)
@@ -40,746 +40,774 @@ const char* kTokenDelimiter = " ,:";
 using namespace extension::common;
 using namespace wrt::common;
 
-void ContactManager_getAddressBooks(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-    typedef std::shared_ptr<json::Value> shared_json_value;
-    auto work_func = [=](const shared_json_value & response)->void
-    {
-        json::Object& response_obj = response->get<json::Object>();
-        json::Array& batch_result =
-                response_obj.insert(std::make_pair("result", json::Value{json::Array{}}))
-                        .first->second.get<json::Array>();
-        try
-        {
-            contacts_list_h address_book_list = nullptr;
-
-            int error_code = contacts_db_get_all_records(_contacts_address_book._uri, 0, 0,
-                                                         &address_book_list);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                LOGE("Fail to get address book list, error: %d", error_code);
-                throw UnknownException("Fail to get address book list");
-            }
-
-            ContactUtil::ContactsListHPtr contacts_list_ptr(&address_book_list,
-                                                            ContactUtil::ContactsListDeleter);
-
-            unsigned int record_count = 0;
-            error_code = contacts_list_get_count(*contacts_list_ptr, &record_count);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                LOGE("Fail to get address book list count, error: %d", error_code);
-                throw UnknownException("Fail to get address book list count");
-            }
+void ContactManager_getAddressBooks(const json::Object& args,
+                                    json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+  typedef std::shared_ptr<json::Value> shared_json_value;
+  auto work_func = [=](const shared_json_value & response)->void {
+    json::Object& response_obj = response->get<json::Object>();
+    json::Array& batch_result =
+        response_obj.insert(
+                         std::make_pair("result", json::Value{json::Array{}}))
+            .first->second.get<json::Array>();
+    try {
+      contacts_list_h address_book_list = nullptr;
+
+      int error_code = contacts_db_get_all_records(_contacts_address_book._uri,
+                                                   0, 0, &address_book_list);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        LOGE("Fail to get address book list, error: %d", error_code);
+        throw UnknownException("Fail to get address book list");
+      }
+
+      ContactUtil::ContactsListHPtr contacts_list_ptr(
+          &address_book_list, ContactUtil::ContactsListDeleter);
+
+      unsigned int record_count = 0;
+      error_code = contacts_list_get_count(*contacts_list_ptr, &record_count);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        LOGE("Fail to get address book list count, error: %d", error_code);
+        throw UnknownException("Fail to get address book list count");
+      }
+
+      error_code = contacts_list_first(*contacts_list_ptr);
+      if (CONTACTS_ERROR_NONE != error_code) {
+        LOGE("Fail to get address book from list, error: %d", error_code);
+        throw UnknownException("Fail to get address book from list");
+      }
+
+      for (unsigned int i = 0; i < record_count; i++) {
+        contacts_record_h contacts_record = nullptr;
+        error_code = contacts_list_get_current_record_p(*contacts_list_ptr,
+                                                        &contacts_record);
+
+        if (CONTACTS_ERROR_NONE != error_code) {
+          LOGW("Fail to get address book record");
+          continue;
+        }
 
-            error_code = contacts_list_first(*contacts_list_ptr);
-            if (CONTACTS_ERROR_NONE != error_code) {
-                LOGE("Fail to get address book from list, error: %d", error_code);
-                throw UnknownException("Fail to get address book from list");
-            }
+        int id = 0;
+        int mode = 0;
+        char* name = nullptr;
+        try {
+          ContactUtil::GetIntFromRecord(contacts_record,
+                                        _contacts_address_book.id, &id);
 
-            for (unsigned int i = 0; i < record_count; i++) {
-                contacts_record_h contacts_record = nullptr;
-                error_code =
-                        contacts_list_get_current_record_p(*contacts_list_ptr, &contacts_record);
-
-                if (CONTACTS_ERROR_NONE != error_code) {
-                    LOGW("Fail to get address book record");
-                    continue;
-                }
-
-                int id = 0;
-                int mode = 0;
-                char* name = nullptr;
-                try
-                {
-                    ContactUtil::GetIntFromRecord(contacts_record, _contacts_address_book.id, &id);
-
-                    ContactUtil::GetIntFromRecord(contacts_record, _contacts_address_book.mode,
-                                                  &mode);
-
-                    ContactUtil::GetStrFromRecord(contacts_record, _contacts_address_book.name,
-                                                  &name);
-                }
-                catch (...)
-                {
-                    LOGW("Fail to get data from address book");
-                    continue;
-                }
-
-                json::Object single_out;
-                single_out.insert(std::make_pair("id", std::to_string(id)));
-                single_out.insert(std::make_pair("name", name));
-                single_out.insert(
-                        std::make_pair("readOnly", CONTACTS_ADDRESS_BOOK_MODE_READONLY == mode));
-                batch_result.push_back(json::Value{single_out});
-
-                contacts_list_next(*contacts_list_ptr);
-            }
+          ContactUtil::GetIntFromRecord(contacts_record,
+                                        _contacts_address_book.mode, &mode);
 
-            NativePlugin::ReportSuccess(response_obj);
+          ContactUtil::GetStrFromRecord(contacts_record,
+                                        _contacts_address_book.name, &name);
         }
-        catch (const BasePlatformException& e)
-        {
-            NativePlugin::ReportError(e, response_obj);
+        catch (...) {
+          LOGW("Fail to get data from address book");
+          continue;
         }
-    };
-
-    int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
-    auto after_work_func = [=](const shared_json_value& response) {
-        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-                                                                  response->serialize());
-    };
 
-    TaskQueue::GetInstance().Queue<json::Value>(
-            work_func, after_work_func,
-            std::shared_ptr<json::Value>{new json::Value{json::Object{}}});
+        json::Object single_out;
+        single_out.insert(std::make_pair("id", std::to_string(id)));
+        single_out.insert(std::make_pair("name", name));
+        single_out.insert(std::make_pair(
+            "readOnly", CONTACTS_ADDRESS_BOOK_MODE_READONLY == mode));
+        batch_result.push_back(json::Value{single_out});
 
-    NativePlugin::ReportSuccess(out);
-}
+        contacts_list_next(*contacts_list_ptr);
+      }
 
-void ContactManager_getAddressBook(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-    long address_book_id;
-    try
-    {
-        address_book_id = common::stol(FromJson<json::String>(args, "addressBookID"));
-    }
-    catch (const common::InvalidValuesException&)
-    {
-        throw common::NotFoundException("Invalid id");
+      NativePlugin::ReportSuccess(response_obj);
     }
-
-    contacts_record_h contacts_record;
-    int error_code =
-            contacts_db_get_record(_contacts_address_book._uri, address_book_id, &contacts_record);
-    if (CONTACTS_ERROR_NONE != error_code || nullptr == contacts_record) {
-        LoggerE("Fail to get addressbook record, error code: %d", error_code);
-        throw NotFoundException("Fail to get address book with given id");
+    catch (const BasePlatformException& e) {
+      NativePlugin::ReportError(e, response_obj);
     }
+  };
 
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record,
-                                                        ContactUtil::ContactsDeleter);
+  int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
+  auto after_work_func = [=](const shared_json_value& response) {
+    wrt::common::NativeContext::GetInstance()->InvokeCallback(
+        callback_handle, response->serialize());
+  };
 
-    int mode = 0;
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_address_book.mode, &mode);
+  TaskQueue::GetInstance().Queue<json::Value>(
+      work_func, after_work_func,
+      std::shared_ptr<json::Value>{new json::Value{json::Object{}}});
 
-    char* name = nullptr;
-    ContactUtil::GetStrFromRecord(contacts_record, _contacts_address_book.name, &name);
+  NativePlugin::ReportSuccess(out);
+}
 
-    json::Value arguments = json::Value(json::Object());
-    json::Object& arguments_obj = arguments.get<json::Object>();
-    arguments_obj.insert(std::make_pair("name", std::string(name)));
-    arguments_obj.insert(std::make_pair(
-            "readOnly", ((CONTACTS_ADDRESS_BOOK_MODE_READONLY == mode) ? "true" : "false")));
-    NativePlugin::ReportSuccess(arguments, out);
+void ContactManager_getAddressBook(const json::Object& args,
+                                   json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+  long address_book_id;
+  try {
+    address_book_id =
+        common::stol(FromJson<json::String>(args, "addressBookID"));
+  }
+  catch (const common::InvalidValuesException&) {
+    throw common::NotFoundException("Invalid id");
+  }
+
+  contacts_record_h contacts_record;
+  int error_code = contacts_db_get_record(_contacts_address_book._uri,
+                                          address_book_id, &contacts_record);
+  if (CONTACTS_ERROR_NONE != error_code || nullptr == contacts_record) {
+    LoggerE("Fail to get addressbook record, error code: %d", error_code);
+    throw NotFoundException("Fail to get address book with given id");
+  }
+
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &contacts_record, ContactUtil::ContactsDeleter);
+
+  int mode = 0;
+  ContactUtil::GetIntFromRecord(contacts_record, _contacts_address_book.mode,
+                                &mode);
+
+  char* name = nullptr;
+  ContactUtil::GetStrFromRecord(contacts_record, _contacts_address_book.name,
+                                &name);
+
+  json::Value arguments = json::Value(json::Object());
+  json::Object& arguments_obj = arguments.get<json::Object>();
+  arguments_obj.insert(std::make_pair("name", std::string(name)));
+  arguments_obj.insert(std::make_pair(
+      "readOnly",
+      ((CONTACTS_ADDRESS_BOOK_MODE_READONLY == mode) ? "true" : "false")));
+  NativePlugin::ReportSuccess(arguments, out);
 }
 
 namespace {
-void ContactManager_get_internal(int person_id, JsonObject* out)
-{
-    int error_code = 0;
-    contacts_record_h contacts_record = nullptr;
-
-    error_code = contacts_db_get_record(_contacts_person._uri, person_id, &contacts_record);
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LoggerE("Person with id: %d, not found, error: %d", person_id, error_code);
-        throw NotFoundException("Person not found");
-    }
+void ContactManager_get_internal(int person_id, JsonObject* out) {
+  int error_code = 0;
+  contacts_record_h contacts_record = nullptr;
+
+  error_code = contacts_db_get_record(_contacts_person._uri, person_id,
+                                      &contacts_record);
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LoggerE("Person with id: %d, not found, error: %d", person_id, error_code);
+    throw NotFoundException("Person not found");
+  }
 
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record,
-                                                        ContactUtil::ContactsDeleter);
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &contacts_record, ContactUtil::ContactsDeleter);
 
-    ContactUtil::ImportPersonFromContactsRecord(contacts_record, out);
+  ContactUtil::ImportPersonFromContactsRecord(contacts_record, out);
 }
 }
 
-void ContactManager_get(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-    long person_id = common::stol(FromJson<json::String>(args, "personID"));
+void ContactManager_get(const json::Object& args, json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
+  long person_id = common::stol(FromJson<json::String>(args, "personID"));
 
-    json::Value val{json::Object{}};
-    ContactManager_get_internal(person_id, &val.get<json::Object>());
+  json::Value val{json::Object{}};
+  ContactManager_get_internal(person_id, &val.get<json::Object>());
 
-    NativePlugin::ReportSuccess(val, out);
+  NativePlugin::ReportSuccess(val, out);
 }
 
-void ContactManager_update(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-    const json::Object& person = FromJson<json::Object>(args, "person");
-    long person_id = common::stol(FromJson<json::String>(person, "id"));
-    int error_code = 0;
+void ContactManager_update(const json::Object& args, json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+  const json::Object& person = FromJson<json::Object>(args, "person");
+  long person_id = common::stol(FromJson<json::String>(person, "id"));
+  int error_code = 0;
 
-    contacts_record_h contacts_record = nullptr;
+  contacts_record_h contacts_record = nullptr;
 
-    error_code = contacts_db_get_record(_contacts_person._uri, person_id, &contacts_record);
+  error_code = contacts_db_get_record(_contacts_person._uri, person_id,
+                                      &contacts_record);
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LoggerE("Error during updating person, error code: %d", error_code);
-        throw UnknownException("Error during updating person");
-    }
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LoggerE("Error during updating person, error code: %d", error_code);
+    throw UnknownException("Error during updating person");
+  }
 
-    ContactUtil::ExportPersonToContactsRecord(contacts_record, person);
-    ContactUtil::ContactsRecordHPtr contacts_record_ptr(&contacts_record,
-                                                        ContactUtil::ContactsDeleter);
+  ContactUtil::ExportPersonToContactsRecord(contacts_record, person);
+  ContactUtil::ContactsRecordHPtr contacts_record_ptr(
+      &contacts_record, ContactUtil::ContactsDeleter);
 
-    error_code = contacts_db_update_record(*contacts_record_ptr);
+  error_code = contacts_db_update_record(*contacts_record_ptr);
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LoggerE("error code: %d", error_code);
-        throw UnknownException("Error during executing contacts_db_update_record()");
-    }
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LoggerE("error code: %d", error_code);
+    throw UnknownException(
+        "Error during executing contacts_db_update_record()");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void ContactManager_remove(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-    long person_id = common::stol(FromJson<json::String>(args, "personId"));
+void ContactManager_remove(const json::Object& args, json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+  long person_id = common::stol(FromJson<json::String>(args, "personId"));
 
-    if (person_id < 0) {
-        throw common::InvalidValuesException("Negative person id");
-    }
+  if (person_id < 0) {
+    throw common::InvalidValuesException("Negative person id");
+  }
 
-    int error_code = contacts_db_delete_record(_contacts_person._uri, person_id);
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LoggerE("Error during removing contact, error: %d", error_code);
-        throw NotFoundException("Error during removing contact");
-    }
+  int error_code = contacts_db_delete_record(_contacts_person._uri, person_id);
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LoggerE("Error during removing contact, error: %d", error_code);
+    throw NotFoundException("Error during removing contact");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void ContactManager_find(const json::Object& args, json::Object& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
-
-    // TODO implement contact sorting.
-    LoggerD("Entered");
-
-    int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
-
-    auto get = [args](const std::shared_ptr<json::Value> & response)->void
-    {
-        LoggerD("Entered");
-        try
-        {
-            int error_code = 0;
-            contacts_query_h contacts_query = nullptr;
-            error_code = contacts_query_create(_contacts_person._uri, &contacts_query);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_query_create");
-
-            ContactUtil::ContactsQueryHPtr contacts_query_ptr(&contacts_query,
-                                                              ContactUtil::ContactsQueryDeleter);
-
-            // Add filter to query
-            std::vector<std::vector<ContactUtil::ContactsFilterPtr>> intermediate_filters(1);
-            if (!IsNull(args, "filter")) {
-                FilterVisitor visitor;
-                visitor.SetOnAttributeFilter([&](const std::string& name,
-                                                 AttributeMatchFlag match_flag,
-                                                 const json::Value& match_value) {
-                    const Person::PersonProperty& property =
-                            Person::PersonProperty_fromString(name);
-
-                    contacts_filter_h contacts_filter = nullptr;
-                    int error_code =
-                            contacts_filter_create(_contacts_person._uri, &contacts_filter);
-                    ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-                    ContactUtil::ContactsFilterPtr contacts_filter_ptr(
-                            contacts_filter, ContactUtil::ContactsFilterDeleter);
-
-                    if (property.type == kPrimitiveTypeBoolean) {
-                        bool value = true;
-                        if (AttributeMatchFlag::kExists != match_flag) {
-                            value = JsonCast<bool>(match_value);
-                        }
-                        error_code = contacts_filter_add_bool(contacts_filter, property.propertyId,
-                                                              value);
-                        ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_bool");
-                    } else if (property.type == kPrimitiveTypeString) {
-                        std::string value = JsonCast<std::string>(match_value);
-
-                        contacts_match_str_flag_e flag = CONTACTS_MATCH_EXISTS;
-                        if (AttributeMatchFlag::kExactly == match_flag) {
-                            flag = CONTACTS_MATCH_EXACTLY;
-                        } else if (AttributeMatchFlag::kFullString == match_flag) {
-                            flag = CONTACTS_MATCH_FULLSTRING;
-                        } else if (AttributeMatchFlag::kContains == match_flag) {
-                            flag = CONTACTS_MATCH_CONTAINS;
-                        } else if (AttributeMatchFlag::kStartsWith == match_flag) {
-                            flag = CONTACTS_MATCH_STARTSWITH;
-                        } else if (AttributeMatchFlag::kEndsWith == match_flag) {
-                            flag = CONTACTS_MATCH_ENDSWITH;
-                        } else if (AttributeMatchFlag::kExists == match_flag) {
-                            flag = CONTACTS_MATCH_EXISTS;
-                            value = "";
-                        }
-                        error_code = contacts_filter_add_str(contacts_filter, property.propertyId,
-                                                             flag, value.c_str());
-                        ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                    } else if (property.type == kPrimitiveTypeLong ||
-                               property.type == kPrimitiveTypeId) {
-                        int value;
-                        if (property.type == kPrimitiveTypeLong) {
-                            value = static_cast<int>(JsonCast<double>(match_value));
-                        } else {
-                            value = common::stol(JsonCast<std::string>(match_value));
-                        }
-                        if (value < 0) {
-                            throw InvalidValuesException("Match value cannot be less than 0");
-                        }
-                        contacts_match_int_flag_e flag;
-                        if (AttributeMatchFlag::kExists == match_flag) {
-                            flag = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
-                            value = 0;
-                        } else if (AttributeMatchFlag::kStartsWith == match_flag ||
-                                   AttributeMatchFlag::kContains == match_flag) {
-                            flag = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
-                        } else if (AttributeMatchFlag::kEndsWith == match_flag) {
-                            flag = CONTACTS_MATCH_LESS_THAN_OR_EQUAL;
-                        } else {
-                            flag = CONTACTS_MATCH_EQUAL;
-                        }
-
-                        error_code = contacts_filter_add_int(contacts_filter, property.propertyId,
-                                                             flag, value);
-                        ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                    } else {
-                        throw UnknownException("Invalid primitive type!");
-                    }
-                    intermediate_filters[intermediate_filters.size() - 1]
-                            .push_back(std::move(contacts_filter_ptr));
-                });
-
-                visitor.SetOnAttributeRangeFilter([&](const std::string& name,
-                                                      const json::Value& initial_value,
-                                                      const json::Value& end_value) {
-                    const Person::PersonProperty& property =
-                            Person::PersonProperty_fromString(name);
-
-                    contacts_filter_h contacts_filter = nullptr;
-                    int error_code =
-                            contacts_filter_create(_contacts_person._uri, &contacts_filter);
-                    ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-                    ContactUtil::ContactsFilterPtr contacts_filter_ptr(
-                            contacts_filter, ContactUtil::ContactsFilterDeleter);
-
-                    bool initial_value_exists = (!IsNull(initial_value));
-                    bool end_value_exists = (!IsNull(end_value));
-
-                    if (property.type == kPrimitiveTypeBoolean) {
-                        bool initial_value_bool = false;
-                        bool end_value_bool = false;
-
-                        if (initial_value_exists) {
-                            initial_value_bool = JsonCast<bool>(initial_value);
-                        }
-                        if (end_value_exists) {
-                            end_value_bool = JsonCast<bool>(end_value);
-                        }
-
-                        if (initial_value_exists && end_value_exists) {
-                            if (initial_value_bool == end_value_bool) {
-                                error_code = contacts_filter_add_bool(
-                                        contacts_filter, property.propertyId, initial_value_bool);
-                                ContactUtil::ErrorChecker(error_code,
-                                                          "Failed contacts_filter_add_bool");
-                            }
-                        } else if (initial_value_exists) {
-                            if (initial_value_bool) {
-                                error_code = contacts_filter_add_bool(contacts_filter,
-                                                                      property.propertyId, true);
-                                ContactUtil::ErrorChecker(error_code,
-                                                          "Failed contacts_filter_add_bool");
-                            }
-                        } else if (end_value_exists) {
-                            if (!end_value_bool) {
-                                error_code = contacts_filter_add_bool(contacts_filter,
-                                                                      property.propertyId, false);
-                                ContactUtil::ErrorChecker(error_code,
-                                                          "Failed contacts_filter_add_bool");
-                            }
-                        }
-                    } else if (property.type == kPrimitiveTypeString) {
-                        std::string initial_value_str;
-                        std::string end_value_str;
-
-                        if (initial_value_exists) {
-                            initial_value_str = JsonCast<std::string>(initial_value);
-                        }
-
-                        if (end_value_exists) {
-                            end_value_str = JsonCast<std::string>(end_value);
-                        }
-
-                        if (initial_value_exists && end_value_exists) {
-                            contacts_filter_h sub_filter = NULL;
-
-                            error_code = contacts_filter_create(_contacts_person._uri, &sub_filter);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-
-                            ContactUtil::ContactsFilterPtr sub_filter_ptr(
-                                    sub_filter, ContactUtil::ContactsFilterDeleter);
-
-                            error_code = contacts_filter_add_str(sub_filter, property.propertyId,
-                                                                 CONTACTS_MATCH_STARTSWITH,
-                                                                 initial_value_str.c_str());
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                            error_code = contacts_filter_add_operator(sub_filter,
-                                                                      CONTACTS_FILTER_OPERATOR_AND);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-
-                            error_code = contacts_filter_add_str(sub_filter, property.propertyId,
-                                                                 CONTACTS_MATCH_ENDSWITH,
-                                                                 end_value_str.c_str());
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-
-                            error_code = contacts_filter_add_filter(contacts_filter, sub_filter);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                        } else if (initial_value_exists) {
-                            error_code = contacts_filter_add_str(
-                                    contacts_filter, property.propertyId, CONTACTS_MATCH_STARTSWITH,
-                                    initial_value_str.c_str());
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                        } else if (end_value_exists) {
-                            error_code = contacts_filter_add_str(
-                                    contacts_filter, property.propertyId, CONTACTS_MATCH_ENDSWITH,
-                                    end_value_str.c_str());
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_str");
-                        }
-                    } else if (property.type == kPrimitiveTypeLong ||
-                               property.type == kPrimitiveTypeId) {
-                        int initial_value_int = 0;
-                        int end_value_int = 0;
-
-                        if (initial_value_exists) {
-                            if (property.type == kPrimitiveTypeLong) {
-                                initial_value_int =
-                                        static_cast<int>(JsonCast<double>(initial_value));
-                            } else {
-                                initial_value_int =
-                                        common::stol(JsonCast<std::string>(initial_value));
-                            }
-                        }
-
-                        if (end_value_exists) {
-                            if (property.type == kPrimitiveTypeLong) {
-                                end_value_int = static_cast<int>(JsonCast<double>(end_value));
-                            } else {
-                                end_value_int = common::stol(JsonCast<std::string>(end_value));
-                            }
-                        }
-
-                        if (initial_value_exists && end_value_exists) {
-                            contacts_filter_h sub_filter = NULL;
-
-                            error_code = contacts_filter_create(_contacts_person._uri, &sub_filter);
-                            ContactUtil::ErrorChecker(error_code,
-                                                      "Failed contacts_filter_add_bool");
-                            ContactUtil::ContactsFilterPtr sub_filter_ptr(
-                                    sub_filter, ContactUtil::ContactsFilterDeleter);
-
-                            error_code = contacts_filter_add_int(
-                                    sub_filter, property.propertyId,
-                                    CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value_int);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
-
-                            error_code = contacts_filter_add_operator(sub_filter,
-                                                                      CONTACTS_FILTER_OPERATOR_AND);
-                            ContactUtil::ErrorChecker(error_code,
-                                                      "Failed contacts_filter_add_operator");
-
-                            error_code = contacts_filter_add_int(sub_filter, property.propertyId,
-                                                                 CONTACTS_MATCH_LESS_THAN_OR_EQUAL,
-                                                                 end_value_int);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
-
-                            error_code = contacts_filter_add_filter(contacts_filter, sub_filter);
-                            ContactUtil::ErrorChecker(error_code,
-                                                      "Failed contacts_filter_add_filter");
-                        } else if (initial_value_exists) {
-                            error_code = contacts_filter_add_int(
-                                    contacts_filter, property.propertyId,
-                                    CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value_int);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
-                        } else if (end_value_exists) {
-                            error_code = contacts_filter_add_int(
-                                    contacts_filter, property.propertyId,
-                                    CONTACTS_MATCH_LESS_THAN_OR_EQUAL, end_value_int);
-                            ContactUtil::ErrorChecker(error_code, "Failed contacts_filter_add_int");
-                        }
-                    } else {
-                        throw UnknownException("Invalid primitive type!");
-                    }
-                    intermediate_filters[intermediate_filters.size() - 1]
-                            .push_back(std::move(contacts_filter_ptr));
-                });
-
-                visitor.SetOnCompositeFilterBegin([&](CompositeFilterType /*type*/) {
-                    intermediate_filters.push_back(std::vector<ContactUtil::ContactsFilterPtr>());
-                });
-
-                visitor.SetOnCompositeFilterEnd([&](CompositeFilterType type) {
-                    if (intermediate_filters.size() == 0) {
-                        throw UnknownException("Reached stack size equal to 0!");
-                    }
-                    // TODO what is this supposed to do? Removing it fixes filtering without any
-                    // apparent consequences.
-                    //                    if (intermediate_filters.back().size()) {
-                    //                        intermediate_filters.pop_back();
-                    //                        return;
-                    //                    }
-
-                    contacts_filter_h merged_filter = nullptr;
-                    int error_code = 0;
-                    error_code = contacts_filter_create(_contacts_person._uri, &merged_filter);
-                    ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-                    ContactUtil::ContactsFilterPtr merged_filter_ptr(
-                            merged_filter, ContactUtil::ContactsFilterDeleter);
-
-                    for (size_t i = 0; i < intermediate_filters.back().size(); ++i) {
-                        error_code = contacts_filter_add_filter(
-                                merged_filter, intermediate_filters.back().at(i).get());
-                        ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-                        if (CompositeFilterType::kIntersection == type) {
-                            error_code = contacts_filter_add_operator(merged_filter,
-                                                                      CONTACTS_FILTER_OPERATOR_AND);
-                            ContactUtil::ErrorChecker(error_code,
-                                                      "Failed contacts_query_set_filter");
-                        } else if (CompositeFilterType::kUnion == type) {
-                            error_code = contacts_filter_add_operator(merged_filter,
-                                                                      CONTACTS_FILTER_OPERATOR_OR);
-                            ContactUtil::ErrorChecker(error_code,
-                                                      "Failed contacts_query_set_filter");
-                        } else {
-                            throw InvalidValuesException("Invalid union type!");
-                        }
-                    }
-
-                    intermediate_filters.pop_back();
-                    intermediate_filters.back().push_back(std::move(merged_filter_ptr));
-                });
-
-                visitor.Visit(FromJson<json::Object>(args, "filter"));
-                // Should compute only one filter always.
-                if ((intermediate_filters.size() != 1) || (intermediate_filters[0].size() != 1)) {
-                    LoggerE("Bad filter evaluation!");
-                    throw UnknownException("Bad filter evaluation!");
-                }
-                // Filter is generated
-                error_code =
-                        contacts_query_set_filter(contacts_query, intermediate_filters[0][0].get());
-                ContactUtil::ErrorChecker(error_code, "Failed contacts_query_set_filter");
-            }
-
-            contacts_list_h person_list = nullptr;
-            error_code = contacts_db_get_records_with_query(contacts_query, 0, 0, &person_list);
+void ContactManager_find(const json::Object& args, json::Object& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactReadPrivileges);
 
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_db_get_records_with_query");
+  // TODO implement contact sorting.
+  LoggerD("Entered");
 
-            ContactUtil::ContactsListHPtr person_list_ptr(&person_list,
-                                                          ContactUtil::ContactsListDeleter);
+  int callback_handle = NativePlugin::GetAsyncCallbackHandle(args);
 
-            unsigned int record_count = 0;
-            error_code = contacts_list_get_count(person_list, &record_count);
-            ContactUtil::ErrorChecker(error_code, "Failed contacts_list_get_count");
+  auto get = [args](const std::shared_ptr<json::Value> & response)->void {
+    LoggerD("Entered");
+    try {
+      int error_code = 0;
+      contacts_query_h contacts_query = nullptr;
+      error_code =
+          contacts_query_create(_contacts_person._uri, &contacts_query);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_query_create");
+
+      ContactUtil::ContactsQueryHPtr contacts_query_ptr(
+          &contacts_query, ContactUtil::ContactsQueryDeleter);
+
+      // Add filter to query
+      std::vector<std::vector<ContactUtil::ContactsFilterPtr>>
+          intermediate_filters(1);
+      if (!IsNull(args, "filter")) {
+        FilterVisitor visitor;
+        visitor.SetOnAttributeFilter([&](const std::string& name,
+                                         AttributeMatchFlag match_flag,
+                                         const json::Value& match_value) {
+          const Person::PersonProperty& property =
+              Person::PersonProperty_fromString(name);
+
+          contacts_filter_h contacts_filter = nullptr;
+          int error_code =
+              contacts_filter_create(_contacts_person._uri, &contacts_filter);
+          ContactUtil::ErrorChecker(error_code,
+                                    "Failed contacts_query_set_filter");
+          ContactUtil::ContactsFilterPtr contacts_filter_ptr(
+              contacts_filter, ContactUtil::ContactsFilterDeleter);
+
+          if (property.type == kPrimitiveTypeBoolean) {
+            bool value = true;
+            if (AttributeMatchFlag::kExists != match_flag) {
+              value = JsonCast<bool>(match_value);
+            }
+            error_code = contacts_filter_add_bool(contacts_filter,
+                                                  property.propertyId, value);
+            ContactUtil::ErrorChecker(error_code,
+                                      "Failed contacts_filter_add_bool");
+          } else if (property.type == kPrimitiveTypeString) {
+            std::string value = JsonCast<std::string>(match_value);
+
+            contacts_match_str_flag_e flag = CONTACTS_MATCH_EXISTS;
+            if (AttributeMatchFlag::kExactly == match_flag) {
+              flag = CONTACTS_MATCH_EXACTLY;
+            } else if (AttributeMatchFlag::kFullString == match_flag) {
+              flag = CONTACTS_MATCH_FULLSTRING;
+            } else if (AttributeMatchFlag::kContains == match_flag) {
+              flag = CONTACTS_MATCH_CONTAINS;
+            } else if (AttributeMatchFlag::kStartsWith == match_flag) {
+              flag = CONTACTS_MATCH_STARTSWITH;
+            } else if (AttributeMatchFlag::kEndsWith == match_flag) {
+              flag = CONTACTS_MATCH_ENDSWITH;
+            } else if (AttributeMatchFlag::kExists == match_flag) {
+              flag = CONTACTS_MATCH_EXISTS;
+              value = "";
+            }
+            error_code = contacts_filter_add_str(
+                contacts_filter, property.propertyId, flag, value.c_str());
+            ContactUtil::ErrorChecker(error_code,
+                                      "Failed contacts_filter_add_str");
+          } else if (property.type == kPrimitiveTypeLong ||
+                     property.type == kPrimitiveTypeId) {
+            int value;
+            if (property.type == kPrimitiveTypeLong) {
+              value = static_cast<int>(JsonCast<double>(match_value));
+            } else {
+              value = common::stol(JsonCast<std::string>(match_value));
+            }
+            if (value < 0) {
+              throw InvalidValuesException("Match value cannot be less than 0");
+            }
+            contacts_match_int_flag_e flag;
+            if (AttributeMatchFlag::kExists == match_flag) {
+              flag = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
+              value = 0;
+            } else if (AttributeMatchFlag::kStartsWith == match_flag ||
+                       AttributeMatchFlag::kContains == match_flag) {
+              flag = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
+            } else if (AttributeMatchFlag::kEndsWith == match_flag) {
+              flag = CONTACTS_MATCH_LESS_THAN_OR_EQUAL;
+            } else {
+              flag = CONTACTS_MATCH_EQUAL;
+            }
 
-            contacts_list_first(person_list);
-            json::Value result{json::Array{}};
-            json::Array& persons = result.get<json::Array>();
+            error_code = contacts_filter_add_int(
+                contacts_filter, property.propertyId, flag, value);
+            ContactUtil::ErrorChecker(error_code,
+                                      "Failed contacts_filter_add_str");
+          } else {
+            throw UnknownException("Invalid primitive type!");
+          }
+          intermediate_filters[intermediate_filters.size() - 1]
+              .push_back(std::move(contacts_filter_ptr));
+        });
+
+        visitor.SetOnAttributeRangeFilter([&](const std::string& name,
+                                              const json::Value& initial_value,
+                                              const json::Value& end_value) {
+          const Person::PersonProperty& property =
+              Person::PersonProperty_fromString(name);
+
+          contacts_filter_h contacts_filter = nullptr;
+          int error_code =
+              contacts_filter_create(_contacts_person._uri, &contacts_filter);
+          ContactUtil::ErrorChecker(error_code,
+                                    "Failed contacts_query_set_filter");
+          ContactUtil::ContactsFilterPtr contacts_filter_ptr(
+              contacts_filter, ContactUtil::ContactsFilterDeleter);
+
+          bool initial_value_exists = (!IsNull(initial_value));
+          bool end_value_exists = (!IsNull(end_value));
+
+          if (property.type == kPrimitiveTypeBoolean) {
+            bool initial_value_bool = false;
+            bool end_value_bool = false;
+
+            if (initial_value_exists) {
+              initial_value_bool = JsonCast<bool>(initial_value);
+            }
+            if (end_value_exists) {
+              end_value_bool = JsonCast<bool>(end_value);
+            }
 
-            for (unsigned int i = 0; i < record_count; i++) {
-                contacts_record_h contacts_record;
-                error_code = contacts_list_get_current_record_p(person_list, &contacts_record);
-                if (error_code != CONTACTS_ERROR_NONE || contacts_record == NULL) {
-                    LoggerW("Failed group record (ret:%d)", error_code);
-                    continue;
-                }
+            if (initial_value_exists && end_value_exists) {
+              if (initial_value_bool == end_value_bool) {
+                error_code = contacts_filter_add_bool(
+                    contacts_filter, property.propertyId, initial_value_bool);
+                ContactUtil::ErrorChecker(error_code,
+                                          "Failed contacts_filter_add_bool");
+              }
+            } else if (initial_value_exists) {
+              if (initial_value_bool) {
+                error_code = contacts_filter_add_bool(
+                    contacts_filter, property.propertyId, true);
+                ContactUtil::ErrorChecker(error_code,
+                                          "Failed contacts_filter_add_bool");
+              }
+            } else if (end_value_exists) {
+              if (!end_value_bool) {
+                error_code = contacts_filter_add_bool(
+                    contacts_filter, property.propertyId, false);
+                ContactUtil::ErrorChecker(error_code,
+                                          "Failed contacts_filter_add_bool");
+              }
+            }
+          } else if (property.type == kPrimitiveTypeString) {
+            std::string initial_value_str;
+            std::string end_value_str;
 
-                int id_value = 0;
-                error_code =
-                        contacts_record_get_int(contacts_record, _contacts_person.id, &id_value);
+            if (initial_value_exists) {
+              initial_value_str = JsonCast<std::string>(initial_value);
+            }
 
-                ContactUtil::ErrorChecker(error_code, "Failed contacts_record_get_int");
+            if (end_value_exists) {
+              end_value_str = JsonCast<std::string>(end_value);
+            }
 
-                persons.push_back(json::Value(static_cast<double>(id_value)));
+            if (initial_value_exists && end_value_exists) {
+              contacts_filter_h sub_filter = NULL;
+
+              error_code =
+                  contacts_filter_create(_contacts_person._uri, &sub_filter);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+
+              ContactUtil::ContactsFilterPtr sub_filter_ptr(
+                  sub_filter, ContactUtil::ContactsFilterDeleter);
+
+              error_code = contacts_filter_add_str(
+                  sub_filter, property.propertyId, CONTACTS_MATCH_STARTSWITH,
+                  initial_value_str.c_str());
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+              error_code = contacts_filter_add_operator(
+                  sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+
+              error_code = contacts_filter_add_str(
+                  sub_filter, property.propertyId, CONTACTS_MATCH_ENDSWITH,
+                  end_value_str.c_str());
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+
+              error_code =
+                  contacts_filter_add_filter(contacts_filter, sub_filter);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+            } else if (initial_value_exists) {
+              error_code = contacts_filter_add_str(
+                  contacts_filter, property.propertyId,
+                  CONTACTS_MATCH_STARTSWITH, initial_value_str.c_str());
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+            } else if (end_value_exists) {
+              error_code = contacts_filter_add_str(
+                  contacts_filter, property.propertyId, CONTACTS_MATCH_ENDSWITH,
+                  end_value_str.c_str());
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_str");
+            }
+          } else if (property.type == kPrimitiveTypeLong ||
+                     property.type == kPrimitiveTypeId) {
+            int initial_value_int = 0;
+            int end_value_int = 0;
+
+            if (initial_value_exists) {
+              if (property.type == kPrimitiveTypeLong) {
+                initial_value_int =
+                    static_cast<int>(JsonCast<double>(initial_value));
+              } else {
+                initial_value_int =
+                    common::stol(JsonCast<std::string>(initial_value));
+              }
+            }
 
-                contacts_list_next(person_list);
+            if (end_value_exists) {
+              if (property.type == kPrimitiveTypeLong) {
+                end_value_int = static_cast<int>(JsonCast<double>(end_value));
+              } else {
+                end_value_int = common::stol(JsonCast<std::string>(end_value));
+              }
             }
 
-            NativePlugin::ReportSuccess(result, response->get<json::Object>());
+            if (initial_value_exists && end_value_exists) {
+              contacts_filter_h sub_filter = NULL;
+
+              error_code =
+                  contacts_filter_create(_contacts_person._uri, &sub_filter);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_bool");
+              ContactUtil::ContactsFilterPtr sub_filter_ptr(
+                  sub_filter, ContactUtil::ContactsFilterDeleter);
+
+              error_code = contacts_filter_add_int(
+                  sub_filter, property.propertyId,
+                  CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value_int);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_int");
+
+              error_code = contacts_filter_add_operator(
+                  sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_operator");
+
+              error_code = contacts_filter_add_int(
+                  sub_filter, property.propertyId,
+                  CONTACTS_MATCH_LESS_THAN_OR_EQUAL, end_value_int);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_int");
+
+              error_code =
+                  contacts_filter_add_filter(contacts_filter, sub_filter);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_filter");
+            } else if (initial_value_exists) {
+              error_code = contacts_filter_add_int(
+                  contacts_filter, property.propertyId,
+                  CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value_int);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_int");
+            } else if (end_value_exists) {
+              error_code = contacts_filter_add_int(
+                  contacts_filter, property.propertyId,
+                  CONTACTS_MATCH_LESS_THAN_OR_EQUAL, end_value_int);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_filter_add_int");
+            }
+          } else {
+            throw UnknownException("Invalid primitive type!");
+          }
+          intermediate_filters[intermediate_filters.size() - 1]
+              .push_back(std::move(contacts_filter_ptr));
+        });
+
+        visitor.SetOnCompositeFilterBegin([&](CompositeFilterType /*type*/) {
+          intermediate_filters.push_back(
+              std::vector<ContactUtil::ContactsFilterPtr>());
+        });
+
+        visitor.SetOnCompositeFilterEnd([&](CompositeFilterType type) {
+          if (intermediate_filters.size() == 0) {
+            throw UnknownException("Reached stack size equal to 0!");
+          }
+          // TODO what is this supposed to do? Removing it fixes filtering
+          // without any
+          // apparent consequences.
+          //                    if (intermediate_filters.back().size()) {
+          //                        intermediate_filters.pop_back();
+          //                        return;
+          //                    }
+
+          contacts_filter_h merged_filter = nullptr;
+          int error_code = 0;
+          error_code =
+              contacts_filter_create(_contacts_person._uri, &merged_filter);
+          ContactUtil::ErrorChecker(error_code,
+                                    "Failed contacts_query_set_filter");
+          ContactUtil::ContactsFilterPtr merged_filter_ptr(
+              merged_filter, ContactUtil::ContactsFilterDeleter);
+
+          for (size_t i = 0; i < intermediate_filters.back().size(); ++i) {
+            error_code = contacts_filter_add_filter(
+                merged_filter, intermediate_filters.back().at(i).get());
+            ContactUtil::ErrorChecker(error_code,
+                                      "Failed contacts_query_set_filter");
+            if (CompositeFilterType::kIntersection == type) {
+              error_code = contacts_filter_add_operator(
+                  merged_filter, CONTACTS_FILTER_OPERATOR_AND);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_query_set_filter");
+            } else if (CompositeFilterType::kUnion == type) {
+              error_code = contacts_filter_add_operator(
+                  merged_filter, CONTACTS_FILTER_OPERATOR_OR);
+              ContactUtil::ErrorChecker(error_code,
+                                        "Failed contacts_query_set_filter");
+            } else {
+              throw InvalidValuesException("Invalid union type!");
+            }
+          }
+
+          intermediate_filters.pop_back();
+          intermediate_filters.back().push_back(std::move(merged_filter_ptr));
+        });
+
+        visitor.Visit(FromJson<json::Object>(args, "filter"));
+        // Should compute only one filter always.
+        if ((intermediate_filters.size() != 1) ||
+            (intermediate_filters[0].size() != 1)) {
+          LoggerE("Bad filter evaluation!");
+          throw UnknownException("Bad filter evaluation!");
         }
-        catch (const BasePlatformException& e)
-        {
-            LoggerE("error: %s: %s", e.name().c_str(), e.message().c_str());
-            NativePlugin::ReportError(e, response->get<json::Object>());
+        // Filter is generated
+        error_code = contacts_query_set_filter(
+            contacts_query, intermediate_filters[0][0].get());
+        ContactUtil::ErrorChecker(error_code,
+                                  "Failed contacts_query_set_filter");
+      }
+
+      contacts_list_h person_list = nullptr;
+      error_code = contacts_db_get_records_with_query(contacts_query, 0, 0,
+                                                      &person_list);
+
+      ContactUtil::ErrorChecker(error_code,
+                                "Failed contacts_db_get_records_with_query");
+
+      ContactUtil::ContactsListHPtr person_list_ptr(
+          &person_list, ContactUtil::ContactsListDeleter);
+
+      unsigned int record_count = 0;
+      error_code = contacts_list_get_count(person_list, &record_count);
+      ContactUtil::ErrorChecker(error_code, "Failed contacts_list_get_count");
+
+      contacts_list_first(person_list);
+      json::Value result{json::Array{}};
+      json::Array& persons = result.get<json::Array>();
+
+      for (unsigned int i = 0; i < record_count; i++) {
+        contacts_record_h contacts_record;
+        error_code =
+            contacts_list_get_current_record_p(person_list, &contacts_record);
+        if (error_code != CONTACTS_ERROR_NONE || contacts_record == NULL) {
+          LoggerW("Failed group record (ret:%d)", error_code);
+          continue;
         }
-    };
 
-    auto get_response = [callback_handle](const std::shared_ptr<json::Value> & response)->void
-    {
-        wrt::common::NativeContext::GetInstance()->InvokeCallback(callback_handle,
-                                                                  response->serialize());
-    };
+        int id_value = 0;
+        error_code = contacts_record_get_int(contacts_record,
+                                             _contacts_person.id, &id_value);
 
-    TaskQueue::GetInstance().Queue<json::Value>(
-            get, get_response, std::shared_ptr<json::Value>(new json::Value(json::Object())));
+        ContactUtil::ErrorChecker(error_code, "Failed contacts_record_get_int");
 
-    NativePlugin::ReportSuccess(out);
-}
+        persons.push_back(json::Value(static_cast<double>(id_value)));
 
-void ContactManager_importFromVCard(const json::Object& args, json::Object& out)
-{
-    // I'm not sure how to call it. Should it be 'Contact', 'vCard' or what?
-    const char* vcard_char_ptr = FromJson<json::String>(args, "contact").c_str();
-
-    contacts_list_h contacts_list = nullptr;
-
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_vcard_parse_to_contacts(vcard_char_ptr, &contacts_list);
-    if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
-        LoggerE("Invalid vCard string");
-        throw UnknownException("Invalid vCard string");
-    } else if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Fail to convert vCard from string");
-        throw UnknownException("Fail to convert vCard from string");
-    }
+        contacts_list_next(person_list);
+      }
 
-    unsigned int record_count = 0;
-    err = contacts_list_get_count(contacts_list, &record_count);
-    if (CONTACTS_ERROR_NONE != err || 0 == record_count) {
-        contacts_list_destroy(contacts_list, true);
-        LoggerE("Invalid vCard string.");
-        throw UnknownException("Invalid vCard string.");
+      NativePlugin::ReportSuccess(result, response->get<json::Object>());
     }
-
-    contacts_record_h contacts_record;
-    contacts_list_first(contacts_list);
-    err = contacts_list_get_current_record_p(contacts_list, &contacts_record);
-    if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
-        contacts_list_destroy(contacts_list, true);
-        LoggerE("Invalid vCard string.");
-        throw UnknownException("Invalid vCard string.");
+    catch (const BasePlatformException& e) {
+      LoggerE("error: %s: %s", e.name().c_str(), e.message().c_str());
+      NativePlugin::ReportError(e, response->get<json::Object>());
     }
+  };
 
-    json::Value result{json::Object{}};
-    ContactUtil::ImportContactFromContactsRecord(contacts_record, &result.get<json::Object>());
-    NativePlugin::ReportSuccess(result, out);
-}
+  auto get_response = [callback_handle](const std::shared_ptr<json::Value> &
+                                        response)->void {
+    wrt::common::NativeContext::GetInstance()->InvokeCallback(
+        callback_handle, response->serialize());
+  };
 
-namespace {
-bool IsNumeric(const char* s)
-{
-    for (; *s; s++) {
-        if (!isdigit(*s)) {
-            return false;
-        }
-    }
-    return true;
+  TaskQueue::GetInstance().Queue<json::Value>(
+      get, get_response,
+      std::shared_ptr<json::Value>(new json::Value(json::Object())));
+
+  NativePlugin::ReportSuccess(out);
 }
 
-void ContactManager_listenerCallback(const char* view_uri, char* changes, void* user_data)
-{
-    (void)view_uri;
-    (void)user_data;
+void ContactManager_importFromVCard(const json::Object& args,
+                                    json::Object& out) {
+  // I'm not sure how to call it. Should it be 'Contact', 'vCard' or what?
+  const char* vcard_char_ptr = FromJson<json::String>(args, "contact").c_str();
+
+  contacts_list_h contacts_list = nullptr;
+
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_vcard_parse_to_contacts(vcard_char_ptr, &contacts_list);
+  if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
+    LoggerE("Invalid vCard string");
+    throw UnknownException("Invalid vCard string");
+  } else if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Fail to convert vCard from string");
+    throw UnknownException("Fail to convert vCard from string");
+  }
+
+  unsigned int record_count = 0;
+  err = contacts_list_get_count(contacts_list, &record_count);
+  if (CONTACTS_ERROR_NONE != err || 0 == record_count) {
+    contacts_list_destroy(contacts_list, true);
+    LoggerE("Invalid vCard string.");
+    throw UnknownException("Invalid vCard string.");
+  }
+
+  contacts_record_h contacts_record;
+  contacts_list_first(contacts_list);
+  err = contacts_list_get_current_record_p(contacts_list, &contacts_record);
+  if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
+    contacts_list_destroy(contacts_list, true);
+    LoggerE("Invalid vCard string.");
+    throw UnknownException("Invalid vCard string.");
+  }
+
+  json::Value result{json::Object{}};
+  ContactUtil::ImportContactFromContactsRecord(contacts_record,
+                                               &result.get<json::Object>());
+  NativePlugin::ReportSuccess(result, out);
+}
 
-    if (nullptr == changes) {
-        LOGW("changes is NULL");
-        return;
-    }
-    if (strlen(changes) == 0) {
-        LOGW("changes is empty");
-        return;
+namespace {
+bool IsNumeric(const char* s) {
+  for (; *s; s++) {
+    if (!isdigit(*s)) {
+      return false;
     }
+  }
+  return true;
+}
 
-    json::Value result{json::Object{}};
-    json::Object& result_obj = result.get<json::Object>();
-    json::Array& added = result_obj.insert(std::make_pair("added", json::Array{}))
-                                 .first->second.get<json::Array>();
-    json::Array& updated = result_obj.insert(std::make_pair("updated", json::Array{}))
-                                   .first->second.get<json::Array>();
-    json::Array& removed = result_obj.insert(std::make_pair("removed", json::Array{}))
-                                   .first->second.get<json::Array>();
-
-    std::unique_ptr<char, void (*)(char*)> tmp(strdup(changes), [](char* p) { free(p); });
-
-    char* token = strtok(tmp.get(), kTokenDelimiter);
-    while (token) {
-        try
-        {
-            if (IsNumeric(token)) {
-                int type = atoi(token);
-                token = strtok(nullptr, kTokenDelimiter);
-                if (!token) {
-                    break;
-                }
-                if (IsNumeric(token)) {
-                    int person_id = atoi(token);
-                    switch (type) {
-                        case CONTACTS_CHANGE_INSERTED: {
-                            added.push_back(json::Value{json::Object{}});
-                            ContactManager_get_internal(person_id,
-                                                        &added.back().get<json::Object>());
-                            break;
-                        }
-                        case CONTACTS_CHANGE_UPDATED: {
-                            updated.push_back(json::Value{json::Object{}});
-                            ContactManager_get_internal(person_id,
-                                                        &updated.back().get<json::Object>());
-                            break;
-                        }
-                        case CONTACTS_CHANGE_DELETED: {
-                            std::string id_str{std::to_string(person_id)};
-                            removed.push_back(json::Value{id_str.c_str()});
-                            break;
-                        }
-                        default: {
-                        }
-                    }
-                }
-            }
+void ContactManager_listenerCallback(const char* view_uri, char* changes,
+                                     void* user_data) {
+  (void)view_uri;
+  (void)user_data;
+
+  if (nullptr == changes) {
+    LOGW("changes is NULL");
+    return;
+  }
+  if (strlen(changes) == 0) {
+    LOGW("changes is empty");
+    return;
+  }
+
+  json::Value result{json::Object{}};
+  json::Object& result_obj = result.get<json::Object>();
+  json::Array& added = result_obj.insert(std::make_pair("added", json::Array{}))
+                           .first->second.get<json::Array>();
+  json::Array& updated =
+      result_obj.insert(std::make_pair("updated", json::Array{}))
+          .first->second.get<json::Array>();
+  json::Array& removed =
+      result_obj.insert(std::make_pair("removed", json::Array{}))
+          .first->second.get<json::Array>();
+
+  std::unique_ptr<char, void (*)(char*)> tmp(strdup(changes),
+                                             [](char* p) { free(p); });
+
+  char* token = strtok(tmp.get(), kTokenDelimiter);
+  while (token) {
+    try {
+      if (IsNumeric(token)) {
+        int type = atoi(token);
+        token = strtok(nullptr, kTokenDelimiter);
+        if (!token) {
+          break;
         }
-        catch (common::BasePlatformException& ex)
-        {
-            LoggerE("Caught exception \"" << ex.name()
-                                          << "\" in listener callback: " << ex.message());
+        if (IsNumeric(token)) {
+          int person_id = atoi(token);
+          switch (type) {
+            case CONTACTS_CHANGE_INSERTED: {
+              added.push_back(json::Value{json::Object{}});
+              ContactManager_get_internal(person_id,
+                                          &added.back().get<json::Object>());
+              break;
+            }
+            case CONTACTS_CHANGE_UPDATED: {
+              updated.push_back(json::Value{json::Object{}});
+              ContactManager_get_internal(person_id,
+                                          &updated.back().get<json::Object>());
+              break;
+            }
+            case CONTACTS_CHANGE_DELETED: {
+              std::string id_str{std::to_string(person_id)};
+              removed.push_back(json::Value{id_str.c_str()});
+              break;
+            }
+            default: {}
+          }
         }
-
-        token = strtok(nullptr, kTokenDelimiter);
+      }
+    }
+    catch (common::BasePlatformException& ex) {
+      LoggerE("Caught exception \"" << ex.name() << "\" in listener callback: "
+                                    << ex.message());
     }
 
-    NativeContext::GetInstance()->FireEvent(kContactPersonListenerId, result.serialize());
+    token = strtok(nullptr, kTokenDelimiter);
+  }
+
+  NativeContext::GetInstance()->FireEvent(kContactPersonListenerId,
+                                          result.serialize());
 }
 }
 
-void ContactManager_startListening(const JsonObject&, JsonObject& out)
-{
-    int error_code = contacts_db_add_changed_cb_with_info(_contacts_person._uri,
-                                                          ContactManager_listenerCallback, nullptr);
+void ContactManager_startListening(const JsonObject&, JsonObject& out) {
+  int error_code = contacts_db_add_changed_cb_with_info(
+      _contacts_person._uri, ContactManager_listenerCallback, nullptr);
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGE("contacts_db_add_changed_cb(_contacts_person._uri) error: %d", error_code);
-        throw UnknownException("Failed to start listening");
-    }
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGE("contacts_db_add_changed_cb(_contacts_person._uri) error: %d",
+         error_code);
+    throw UnknownException("Failed to start listening");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void ContactManager_stopListening(const JsonObject&, JsonObject& out)
-{
-    int error_code = contacts_db_remove_changed_cb_with_info(
-            _contacts_person._uri, ContactManager_listenerCallback, nullptr);
+void ContactManager_stopListening(const JsonObject&, JsonObject& out) {
+  int error_code = contacts_db_remove_changed_cb_with_info(
+      _contacts_person._uri, ContactManager_listenerCallback, nullptr);
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGE("contacts_db_remove_changed_cb(_contacts_person._uri) error: %d", error_code);
-        throw UnknownException("Failed to stop listening");
-    }
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGE("contacts_db_remove_changed_cb(_contacts_person._uri) error: %d",
+         error_code);
+    throw UnknownException("Failed to stop listening");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
 }  // namespace ContactManager
index 538ad96..6a6b923 100644 (file)
@@ -25,8 +25,10 @@ namespace contact {
 namespace ContactManager {
 
 /**
- * Signature: @code void getAddressBooks(successCallback, errorCallback); @endcode
- * JSON: @code data: {method: 'ContactManager_getAddressBook', args: {}} @endcode
+ * Signature: @code void getAddressBooks(successCallback, errorCallback);
+ * @endcode
+ * JSON: @code data: {method: 'ContactManager_getAddressBook', args: {}}
+ * @endcode
  * Invocation: @code native.call(request, result_callback) @endcode
  * Return:
  * @code
@@ -39,7 +41,8 @@ namespace ContactManager {
  * {status: 'success', result: {addressbooks}}
  * @endcode
  */
-void ContactManager_getAddressBooks(const JsonObject& /*args*/, JsonObject& /*out*/);
+void ContactManager_getAddressBooks(const JsonObject& /*args*/,
+                                    JsonObject& /*out*/);
 
 /**
  * Signature: @code AddressBook getAddressBook(addressBookId); @endcode
@@ -81,7 +84,8 @@ void ContactManager_get(const JsonObject& args, JsonObject& out);
 void ContactManager_update(const JsonObject& args, JsonObject& out);
 
 /**
- * Signature: @code void updateBatch(persons, successCallback, errorCallback); @endcode
+ * Signature: @code void updateBatch(persons, successCallback, errorCallback);
+ * @endcode
  * JSON: @code data: {method: 'ContactManager_updateBatch',
  *                    args: {persons: persons}} @endcode
  * Invocation: @code native.call(request, result_callback); @endcode
@@ -96,7 +100,8 @@ void ContactManager_update(const JsonObject& args, JsonObject& out);
  * {status: 'success', result: {persons}}
  * @endcode
  */
-void ContactManager_updateBatch(const JsonObject& /*args*/, JsonObject& /*out*/);
+void ContactManager_updateBatch(const JsonObject& /*args*/,
+                                JsonObject& /*out*/);
 
 /**
  * Signature: @code void remove(personId); @endcode
@@ -112,7 +117,8 @@ void ContactManager_updateBatch(const JsonObject& /*args*/, JsonObject& /*out*/)
 void ContactManager_remove(const JsonObject& args, JsonObject& out);
 
 /**
- * Signature: @code void removeBatch(personIds, successCallback, errorCallback); @endcode
+ * Signature: @code void removeBatch(personIds, successCallback, errorCallback);
+ * @endcode
  * JSON: @code data: {method: 'ContactManager_removeBatch',
  *                    args: {personsIDs: personIds}} @endcode
  * Invocation: @code native.call(request, result_callback); @endcode
@@ -127,10 +133,12 @@ void ContactManager_remove(const JsonObject& args, JsonObject& out);
  * {status: 'success'}
  * @endcode
  */
-void ContactManager_removeBatch(const JsonObject& /*args*/, JsonObject& /*out*/);
+void ContactManager_removeBatch(const JsonObject& /*args*/,
+                                JsonObject& /*out*/);
 
 /**
- * Signature: @code void find(successCallback, errorCallback, filter, sortMode); @endcode
+ * Signature: @code void find(successCallback, errorCallback, filter, sortMode);
+ * @endcode
  * JSON: @code data: {method: 'ContactManager_find',
  *                    args: {filter: filter, sortMode: sortMode}} @endcode
  * Invocation: @code native.call(request, result_callback); @endcode
index a561f1a..57b7529 100644 (file)
@@ -26,57 +26,52 @@ namespace contact {
 namespace ContactUtil {
 
 const char* kContactReadPrivileges = "http://tizen.org/privilege/contact.read";
-const char* kContactWritePrivileges = "http://tizen.org/privilege/contact.write";
+const char* kContactWritePrivileges =
+    "http://tizen.org/privilege/contact.write";
 
 namespace {
 
 static const std::string kSchema("file://");
 
-std::string ConvertUriToPath(const std::string& str)
-{
-    if (str.substr(0, kSchema.size()) == kSchema) {
-        return str.substr(kSchema.size());
-    }
+std::string ConvertUriToPath(const std::string& str) {
+  if (str.substr(0, kSchema.size()) == kSchema) {
+    return str.substr(kSchema.size());
+  }
 
-    return str;
+  return str;
 }
 
-std::string ConvertPathToUri(const std::string& str)
-{
-    if (str.substr(0, kSchema.size()) == kSchema) {
-        return str;
-    }
+std::string ConvertPathToUri(const std::string& str) {
+  if (str.substr(0, kSchema.size()) == kSchema) {
+    return str;
+  }
 
-    return kSchema + str;
+  return kSchema + str;
 }
 }
 
-void ContactsDeleter(contacts_record_h* contacts_record)
-{
-    if (CONTACTS_ERROR_NONE != contacts_record_destroy(*contacts_record, true)) {
-        LOGE("failed to destroy contacts_record_h");
-    }
+void ContactsDeleter(contacts_record_h* contacts_record) {
+  if (CONTACTS_ERROR_NONE != contacts_record_destroy(*contacts_record, true)) {
+    LOGE("failed to destroy contacts_record_h");
+  }
 }
 
-void ContactsListDeleter(contacts_list_h* contacts_list)
-{
-    if (CONTACTS_ERROR_NONE != contacts_list_destroy(*contacts_list, true)) {
-        LOGE("failed to destroy contacts_list_h");
-    }
+void ContactsListDeleter(contacts_list_h* contacts_list) {
+  if (CONTACTS_ERROR_NONE != contacts_list_destroy(*contacts_list, true)) {
+    LOGE("failed to destroy contacts_list_h");
+  }
 }
 
-void ContactsFilterDeleter(contacts_filter_h contacts_filter)
-{
-    if (CONTACTS_ERROR_NONE != contacts_filter_destroy(contacts_filter)) {
-        LOGE("failed to destroy contacts_filter_h");
-    }
+void ContactsFilterDeleter(contacts_filter_h contacts_filter) {
+  if (CONTACTS_ERROR_NONE != contacts_filter_destroy(contacts_filter)) {
+    LOGE("failed to destroy contacts_filter_h");
+  }
 }
 
-void ContactsQueryDeleter(contacts_query_h* contacts_query)
-{
-    if (CONTACTS_ERROR_NONE != contacts_query_destroy(*contacts_query)) {
-        LOGE("failed to destroy contacts_query_h");
-    }
+void ContactsQueryDeleter(contacts_query_h* contacts_query) {
+  if (CONTACTS_ERROR_NONE != contacts_query_destroy(*contacts_query)) {
+    LOGE("failed to destroy contacts_query_h");
+  }
 }
 
 using namespace common;
@@ -116,7 +111,8 @@ static const char kContactRelationshipTypeCustom[] = "CUSTOM";
 static const char kContactRelationshipTypeAssistant[] = "ASSISTANT";
 static const char kContactRelationshipTypeBrother[] = "BROTHER";
 static const char kContactRelationshipTypeChild[] = "CHILD";
-static const char kContactRelationshipTypeDomesticPartner[] = "DOMESTIC_PARTNER";
+static const char kContactRelationshipTypeDomesticPartner[] =
+    "DOMESTIC_PARTNER";
 static const char kContactRelationshipTypeFather[] = "FATHER";
 static const char kContactRelationshipTypeFriend[] = "FRIEND";
 static const char kContactRelationshipTypeManager[] = "MANAGER";
@@ -143,1689 +139,1863 @@ static const char kContactInstantMessageTypeIrc[] = "IRC";
 static const char kContactInstantMessageTypeCustom[] = "CUSTOM";
 }
 
-void ErrorChecker(int err, const char* message)
-{
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGE("%s", message);
-        throw common::UnknownException(message);
-    }
+void ErrorChecker(int err, const char* message) {
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGE("%s", message);
+    throw common::UnknownException(message);
+  }
 }
 
-void GetStrFromRecord(contacts_record_h record, unsigned int property_id, char** value)
-{
-    int err = contacts_record_get_str_p(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during getting contact record");
-    }
+void GetStrFromRecord(contacts_record_h record, unsigned int property_id,
+                      char** value) {
+  int err = contacts_record_get_str_p(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during getting contact record");
+  }
 }
 
-void GetIntFromRecord(contacts_record_h record, unsigned int property_id, int* value)
-{
-    int err = contacts_record_get_int(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during getting contact record");
-    }
+void GetIntFromRecord(contacts_record_h record, unsigned int property_id,
+                      int* value) {
+  int err = contacts_record_get_int(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during getting contact record");
+  }
 }
 
-void GetBoolFromRecord(contacts_record_h record, unsigned int property_id, bool* value)
-{
-    int err = contacts_record_get_bool(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during getting contact record");
-    }
+void GetBoolFromRecord(contacts_record_h record, unsigned int property_id,
+                       bool* value) {
+  int err = contacts_record_get_bool(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during getting contact record");
+  }
 }
 
-void SetStrInRecord(contacts_record_h record, unsigned int property_id, const char* value)
-{
-    int err = contacts_record_set_str(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during setting contact record");
-    }
+void SetStrInRecord(contacts_record_h record, unsigned int property_id,
+                    const char* value) {
+  int err = contacts_record_set_str(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during setting contact record");
+  }
 }
 
-void SetIntInRecord(contacts_record_h record, unsigned int property_id, int value)
-{
-    int err = contacts_record_set_int(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during setting contact record");
-    }
+void SetIntInRecord(contacts_record_h record, unsigned int property_id,
+                    int value) {
+  int err = contacts_record_set_int(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during setting contact record");
+  }
 }
 
-void SetBoolInRecord(contacts_record_h record, unsigned int property_id, bool value)
-{
-    int err = contacts_record_set_bool(record, property_id, value);
-    if (CONTACTS_ERROR_NONE != err) {
-        LoggerE("Error during getting contact record, error code: " << err);
-        throw common::UnknownException("Error during setting contact record");
-    }
+void SetBoolInRecord(contacts_record_h record, unsigned int property_id,
+                     bool value) {
+  int err = contacts_record_set_bool(record, property_id, value);
+  if (CONTACTS_ERROR_NONE != err) {
+    LoggerE("Error during getting contact record, error code: " << err);
+    throw common::UnknownException("Error during setting contact record");
+  }
 }
 
-void ClearAllContactRecord(contacts_record_h contacts_record, unsigned int property_id)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    unsigned int record_count = GetNumberOfChildRecord(contacts_record, property_id);
+void ClearAllContactRecord(contacts_record_h contacts_record,
+                           unsigned int property_id) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
 
-    for (unsigned int i = 0; i < record_count; ++i) {
-        unsigned int actual_index = record_count - 1 - i;
-        contacts_record_h phone_record = nullptr;
-        int err = contacts_record_get_child_record_at_p(contacts_record, property_id, actual_index,
-                                                        &phone_record);
-        ContactUtil::ErrorChecker(err, "Error during getting phone record");
+  unsigned int record_count =
+      GetNumberOfChildRecord(contacts_record, property_id);
 
-        err = contacts_record_remove_child_record(contacts_record, property_id, phone_record);
-        ContactUtil::ErrorChecker(err, "Error during getting phone record");
-    }
+  for (unsigned int i = 0; i < record_count; ++i) {
+    unsigned int actual_index = record_count - 1 - i;
+    contacts_record_h phone_record = nullptr;
+    int err = contacts_record_get_child_record_at_p(
+        contacts_record, property_id, actual_index, &phone_record);
+    ContactUtil::ErrorChecker(err, "Error during getting phone record");
+
+    err = contacts_record_remove_child_record(contacts_record, property_id,
+                                              phone_record);
+    ContactUtil::ErrorChecker(err, "Error during getting phone record");
+  }
 }
 
-unsigned int GetNumberOfChildRecord(contacts_record_h contacts_record, unsigned int property_id)
-{
-    int err = CONTACTS_ERROR_NONE;
-    unsigned int child_count = 0;
-    err = contacts_record_get_child_record_count(contacts_record, property_id, &child_count);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        throw common::UnknownException("Problem during getting child count");
-    }
-
-    return child_count;
+unsigned int GetNumberOfChildRecord(contacts_record_h contacts_record,
+                                    unsigned int property_id) {
+  int err = CONTACTS_ERROR_NONE;
+  unsigned int child_count = 0;
+  err = contacts_record_get_child_record_count(contacts_record, property_id,
+                                               &child_count);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    throw common::UnknownException("Problem during getting child count");
+  }
+
+  return child_count;
 }
 
-JsonValue ImportBirthdayFromContactsRecord(contacts_record_h contacts_record, unsigned int index)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.event, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return {};
-    }
+JsonValue ImportBirthdayFromContactsRecord(contacts_record_h contacts_record,
+                                           unsigned int index) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.event, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return {};
+  }
 
-    int value = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_event.type, &value);
+  int value = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_event.type, &value);
 
-    if (CONTACTS_EVENT_TYPE_BIRTH == value) {
-        int date = 0;
-        ContactUtil::GetIntFromRecord(child_record, _contacts_event.date, &date);
-        return JsonValue{static_cast<double>(date)};
-    }
-    return {};
+  if (CONTACTS_EVENT_TYPE_BIRTH == value) {
+    int date = 0;
+    ContactUtil::GetIntFromRecord(child_record, _contacts_event.date, &date);
+    return JsonValue{static_cast<double>(date)};
+  }
+  return {};
 }
 
-void ExportBirthdayToContactsRecord(contacts_record_h contacts_record, int date)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
+void ExportBirthdayToContactsRecord(contacts_record_h contacts_record,
+                                    int date) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h birthday_record = nullptr;
+  err = contacts_record_create(_contacts_event._uri, &birthday_record);
+  ContactUtil::ErrorChecker(err,
+                            "Failed to create birthday record in database");
+  ContactsRecordHPtr record(&birthday_record, ContactsDeleter);
+
+  ContactUtil::SetIntInRecord(birthday_record, _contacts_event.type,
+                              CONTACTS_EVENT_TYPE_BIRTH);
+
+  ContactUtil::SetIntInRecord(birthday_record, _contacts_event.date, date);
+
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.event, birthday_record);
+  ContactUtil::ErrorChecker(err, "Fail to save birthday record in database");
+  // Do not delete record, it is passed to the platform
+  record.release();
+}
 
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h birthday_record = nullptr;
-    err = contacts_record_create(_contacts_event._uri, &birthday_record);
-    ContactUtil::ErrorChecker(err, "Failed to create birthday record in database");
-    ContactsRecordHPtr record(&birthday_record, ContactsDeleter);
+bool ImportContactNameFromContactsRecord(contacts_record_h contacts_record,
+                                         JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  if (!contacts_record) {
+    LOGW("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+  unsigned int count = 0;
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_record_get_child_record_count(contacts_record,
+                                               _contacts_contact.name, &count);
+  ContactUtil::ErrorChecker(err, "Contacts child record get count error");
 
-    ContactUtil::SetIntInRecord(birthday_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
+  if (count > 1) {
+    LOGE("More than one ContactName for one Contact");
+    throw common::UnknownException("More than one ContactName for one Contact");
+  }
+  LoggerD("Contact name record count: " << count);
 
-    ContactUtil::SetIntInRecord(birthday_record, _contacts_event.date, date);
+  if (count == 0) {
+    return false;
+  }
 
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.event,
-                                           birthday_record);
-    ContactUtil::ErrorChecker(err, "Fail to save birthday record in database");
-    // Do not delete record, it is passed to the platform
-    record.release();
-}
+  contacts_record_h contact_name = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.name, 0, &contact_name);
+  ContactUtil::ErrorChecker(err, "Contacts name record get childerror");
 
-bool ImportContactNameFromContactsRecord(contacts_record_h contacts_record, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    if (!contacts_record) {
-        LOGW("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-    unsigned int count = 0;
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_record_get_child_record_count(contacts_record, _contacts_contact.name, &count);
-    ContactUtil::ErrorChecker(err, "Contacts child record get count error");
-
-    if (count > 1) {
-        LOGE("More than one ContactName for one Contact");
-        throw common::UnknownException("More than one ContactName for one Contact");
-    }
-    LoggerD("Contact name record count: " << count);
+  // Documentation says:
+  //  child_record MUST NOT be released by you.
+  //  It is released when the parent record handle is destroyed.
+  // so it won't be protected by unique_ptr.
 
-    if (count == 0) {
-        return false;
-    }
+  char* char_value = nullptr;
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.prefix,
+                                &char_value);
+  out.insert(std::make_pair("prefix",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    contacts_record_h contact_name = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.name, 0,
-                                                &contact_name);
-    ContactUtil::ErrorChecker(err, "Contacts name record get childerror");
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.suffix,
+                                &char_value);
 
-    // Documentation says:
-    //  child_record MUST NOT be released by you.
-    //  It is released when the parent record handle is destroyed.
-    // so it won't be protected by unique_ptr.
+  out.insert(std::make_pair("suffix",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    char* char_value = nullptr;
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.prefix, &char_value);
-    out.insert(std::make_pair("prefix", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.first,
+                                &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.suffix, &char_value);
+  out.insert(std::make_pair("firstName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(std::make_pair("suffix", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.addition,
+                                &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.first, &char_value);
+  out.insert(std::make_pair("middleName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(std::make_pair("firstName", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.last, &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.addition, &char_value);
+  out.insert(std::make_pair("lastName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(std::make_pair("middleName", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_first,
+                                &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.last, &char_value);
+  out.insert(std::make_pair("phoneticFirstName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(std::make_pair("lastName", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_middle,
+                                &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_first, &char_value);
+  out.insert(std::make_pair("phoneticMiddleName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(
-            std::make_pair("phoneticFirstName", char_value ? JsonValue{char_value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_last,
+                                &char_value);
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_middle, &char_value);
+  out.insert(std::make_pair("phoneticLastName",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 
-    out.insert(
-            std::make_pair("phoneticMiddleName", char_value ? JsonValue{char_value} : JsonValue{}));
+  err = contacts_record_get_child_record_count(
+      contacts_record, _contacts_contact.nickname, &count);
+  ContactUtil::ErrorChecker(err, "Contacts child record get count error");
 
-    ContactUtil::GetStrFromRecord(contact_name, _contacts_name.phonetic_last, &char_value);
+  json::Array& nicknames =
+      out.insert(std::make_pair("nicknames", json::Array()))
+          .first->second.get<json::Array>();
+  for (unsigned int i = 0; i < count; ++i) {
+    contacts_record_h nickname = nullptr;
+    err = contacts_record_get_child_record_at_p(
+        contacts_record, _contacts_contact.nickname, i, &nickname);
+    ContactUtil::ErrorChecker(err, "Contacts nicknames record get child error");
+    ContactUtil::GetStrFromRecord(nickname, _contacts_nickname.name,
+                                  &char_value);
 
-    out.insert(
-            std::make_pair("phoneticLastName", char_value ? JsonValue{char_value} : JsonValue{}));
-
-    err = contacts_record_get_child_record_count(contacts_record, _contacts_contact.nickname,
-                                                 &count);
-    ContactUtil::ErrorChecker(err, "Contacts child record get count error");
-
-    json::Array& nicknames =
-            out.insert(std::make_pair("nicknames", json::Array())).first->second.get<json::Array>();
-    for (unsigned int i = 0; i < count; ++i) {
-        contacts_record_h nickname = nullptr;
-        err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.nickname, i,
-                                                    &nickname);
-        ContactUtil::ErrorChecker(err, "Contacts nicknames record get child error");
-        ContactUtil::GetStrFromRecord(nickname, _contacts_nickname.name, &char_value);
-
-        if (char_value) {
-            nicknames.push_back(JsonValue{char_value});
-        }
+    if (char_value) {
+      nicknames.push_back(JsonValue{char_value});
     }
+  }
 
-    return true;
+  return true;
 }
 
-void ExportContactNameToContactsRecord(contacts_record_h contacts_record, const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGW("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h contact_name = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.name, 0,
-                                                &contact_name);
-    bool update = true;
-    if (CONTACTS_ERROR_NONE != err && nullptr == contact_name) {
-        err = contacts_record_create(_contacts_name._uri, &contact_name);
-        ContactUtil::ErrorChecker(err, "Contacts record create error");
-        update = false;
-    }
-    // contact_name starts to be protected by unique_ptr
-    ContactsRecordHPtr contacts_name_ptr(&contact_name, ContactsDeleter);
-
-    if (!IsNull(in, "prefix")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.prefix,
-                                    FromJson<json::String>(in, "prefix").c_str());
-    }
-    if (!IsNull(in, "suffix")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.suffix,
-                                    FromJson<json::String>(in, "suffix").c_str());
-    }
-    if (!IsNull(in, "firstName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.first,
-                                    FromJson<json::String>(in, "firstName").c_str());
-    }
-    if (!IsNull(in, "middleName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.addition,
-                                    FromJson<json::String>(in, "middleName").c_str());
-    }
-    if (!IsNull(in, "lastName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.last,
-                                    FromJson<json::String>(in, "lastName").c_str());
-    }
-    if (!IsNull(in, "phoneticFirstName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.phonetic_first,
-                                    FromJson<json::String>(in, "phoneticFirstName").c_str());
-    }
-    if (!IsNull(in, "phoneticMiddleName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.phonetic_middle,
-                                    FromJson<json::String>(in, "phoneticMiddleName").c_str());
-    }
-    if (!IsNull(in, "phoneticLastName")) {
-        ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.phonetic_last,
-                                    FromJson<json::String>(in, "phoneticLastName").c_str());
-    }
-
-    // contact_name is being added as a child to contacts_record
-    // and in future will be destroyed by contacts_record's contactsDeleter
+void ExportContactNameToContactsRecord(contacts_record_h contacts_record,
+                                       const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGW("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h contact_name = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.name, 0, &contact_name);
+  bool update = true;
+  if (CONTACTS_ERROR_NONE != err && nullptr == contact_name) {
+    err = contacts_record_create(_contacts_name._uri, &contact_name);
+    ContactUtil::ErrorChecker(err, "Contacts record create error");
+    update = false;
+  }
+  // contact_name starts to be protected by unique_ptr
+  ContactsRecordHPtr contacts_name_ptr(&contact_name, ContactsDeleter);
+
+  if (!IsNull(in, "prefix")) {
+    ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.prefix,
+                                FromJson<json::String>(in, "prefix").c_str());
+  }
+  if (!IsNull(in, "suffix")) {
+    ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.suffix,
+                                FromJson<json::String>(in, "suffix").c_str());
+  }
+  if (!IsNull(in, "firstName")) {
+    ContactUtil::SetStrInRecord(
+        *contacts_name_ptr, _contacts_name.first,
+        FromJson<json::String>(in, "firstName").c_str());
+  }
+  if (!IsNull(in, "middleName")) {
+    ContactUtil::SetStrInRecord(
+        *contacts_name_ptr, _contacts_name.addition,
+        FromJson<json::String>(in, "middleName").c_str());
+  }
+  if (!IsNull(in, "lastName")) {
+    ContactUtil::SetStrInRecord(*contacts_name_ptr, _contacts_name.last,
+                                FromJson<json::String>(in, "lastName").c_str());
+  }
+  if (!IsNull(in, "phoneticFirstName")) {
+    ContactUtil::SetStrInRecord(
+        *contacts_name_ptr, _contacts_name.phonetic_first,
+        FromJson<json::String>(in, "phoneticFirstName").c_str());
+  }
+  if (!IsNull(in, "phoneticMiddleName")) {
+    ContactUtil::SetStrInRecord(
+        *contacts_name_ptr, _contacts_name.phonetic_middle,
+        FromJson<json::String>(in, "phoneticMiddleName").c_str());
+  }
+  if (!IsNull(in, "phoneticLastName")) {
+    ContactUtil::SetStrInRecord(
+        *contacts_name_ptr, _contacts_name.phonetic_last,
+        FromJson<json::String>(in, "phoneticLastName").c_str());
+  }
+
+  // contact_name is being added as a child to contacts_record
+  // and in future will be destroyed by contacts_record's contactsDeleter
+  if (!update) {
+    err = contacts_record_add_child_record(
+        contacts_record, _contacts_contact.name, *contacts_name_ptr);
+    ContactUtil::ErrorChecker(err, "Contacts record add child error");
+  }
+  // and now unique_ptr can be released - contacts_name is protected
+  // by its parent (contacts_record)
+  contacts_name_ptr.release();
+
+  const json::Array& nicknames = FromJson<json::Array>(in, "nicknames");
+
+  for (auto& nickname : nicknames) {
+    contacts_record_h nickname_record = nullptr;
+    err = contacts_record_get_child_record_at_p(
+        contacts_record, _contacts_contact.nickname, 0, &nickname_record);
+    if (CONTACTS_ERROR_NONE != err && nullptr == nickname_record) {
+      err = contacts_record_create(_contacts_nickname._uri, &nickname_record);
+      ContactUtil::ErrorChecker(err, "Contacts record create error");
+      update = false;
+    }
+    ContactsRecordHPtr nickname_ptr(&nickname_record, ContactsDeleter);
+
+    ContactUtil::SetStrInRecord(*nickname_ptr, _contacts_nickname.name,
+                                JsonCast<json::String>(nickname).c_str());
     if (!update) {
-        err = contacts_record_add_child_record(contacts_record, _contacts_contact.name,
-                                               *contacts_name_ptr);
-        ContactUtil::ErrorChecker(err, "Contacts record add child error");
-    }
-    // and now unique_ptr can be released - contacts_name is protected
-    // by its parent (contacts_record)
-    contacts_name_ptr.release();
-
-    const json::Array& nicknames = FromJson<json::Array>(in, "nicknames");
-
-    for (auto& nickname : nicknames) {
-        contacts_record_h nickname_record = nullptr;
-        err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.nickname, 0,
-                                                    &nickname_record);
-        if (CONTACTS_ERROR_NONE != err && nullptr == nickname_record) {
-            err = contacts_record_create(_contacts_nickname._uri, &nickname_record);
-            ContactUtil::ErrorChecker(err, "Contacts record create error");
-            update = false;
-        }
-        ContactsRecordHPtr nickname_ptr(&nickname_record, ContactsDeleter);
-
-        ContactUtil::SetStrInRecord(*nickname_ptr, _contacts_nickname.name,
-                                    JsonCast<json::String>(nickname).c_str());
-        if (!update) {
-            err = contacts_record_add_child_record(contacts_record, _contacts_contact.nickname,
-                                                   *nickname_ptr);
-            ContactUtil::ErrorChecker(err, "Contacts record add child error");
-        }
-        // Do not delete record, it is passed to the platform
-        nickname_ptr.release();
+      err = contacts_record_add_child_record(
+          contacts_record, _contacts_contact.nickname, *nickname_ptr);
+      ContactUtil::ErrorChecker(err, "Contacts record add child error");
     }
+    // Do not delete record, it is passed to the platform
+    nickname_ptr.release();
+  }
 
-    // TODO update displayName in JS!
+  // TODO update displayName in JS!
 }
 
-void ImportContactEmailAddressFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.email, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* email = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_email.email, &email);
-    if (!email) {
-        return;
-    }
-    out.insert(std::make_pair("email", JsonValue{email}));
-
-    bool is_default = false;
-    ContactUtil::GetBoolFromRecord(child_record, _contacts_email.is_default, &is_default);
-    out.insert(std::make_pair("isDefault", JsonValue{is_default}));
-
-    char* label = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_email.label, &label);
-    out.insert(std::make_pair("label", label ? json::Value{label} : json::Value{}));
-
-    int type = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_email.type, &type);
-
-    JsonArray types;
-    if (type & CONTACTS_EMAIL_TYPE_HOME) {
-        types.push_back(JsonValue{kContactEmailAddressTypeHome});
-    }
-    if (type & CONTACTS_EMAIL_TYPE_WORK) {
-        types.push_back(JsonValue{kContactEmailAddressTypeWork});
-    }
-    if (type & CONTACTS_EMAIL_TYPE_OTHER) {
-        types.push_back(JsonValue{kContactEmailAddressTypeOther});
-    }
-    if (type & CONTACTS_EMAIL_TYPE_CUSTOM) {
-        types.push_back(JsonValue{kContactEmailAddressTypeCustom});
-    }
-
-    if (0 == types.size()) {
-        types.push_back(JsonValue{kContactEmailAddressTypeHome});
-    }
-
-    out.insert(std::make_pair("types", JsonValue{types}));
+void ImportContactEmailAddressFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.email, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* email = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_email.email, &email);
+  if (!email) {
+    return;
+  }
+  out.insert(std::make_pair("email", JsonValue{email}));
+
+  bool is_default = false;
+  ContactUtil::GetBoolFromRecord(child_record, _contacts_email.is_default,
+                                 &is_default);
+  out.insert(std::make_pair("isDefault", JsonValue{is_default}));
+
+  char* label = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_email.label, &label);
+  out.insert(
+      std::make_pair("label", label ? json::Value{label} : json::Value{}));
+
+  int type = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_email.type, &type);
+
+  JsonArray types;
+  if (type & CONTACTS_EMAIL_TYPE_HOME) {
+    types.push_back(JsonValue{kContactEmailAddressTypeHome});
+  }
+  if (type & CONTACTS_EMAIL_TYPE_WORK) {
+    types.push_back(JsonValue{kContactEmailAddressTypeWork});
+  }
+  if (type & CONTACTS_EMAIL_TYPE_OTHER) {
+    types.push_back(JsonValue{kContactEmailAddressTypeOther});
+  }
+  if (type & CONTACTS_EMAIL_TYPE_CUSTOM) {
+    types.push_back(JsonValue{kContactEmailAddressTypeCustom});
+  }
+
+  if (0 == types.size()) {
+    types.push_back(JsonValue{kContactEmailAddressTypeHome});
+  }
+
+  out.insert(std::make_pair("types", JsonValue{types}));
 }
 
-void ExportContactEmailAddressToContactsRecord(contacts_record_h contacts_record,
-                                               const json::Object& in)
-{
-    contacts_record_h c_email_record_h = nullptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_record_create(_contacts_email._uri, &c_email_record_h);
-    ContactUtil::ErrorChecker(err, "Failed to create email record in database");
-    ContactsRecordHPtr record(&c_email_record_h, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(c_email_record_h, _contacts_email.email,
-                                FromJson<json::String>(in, "email").c_str());
-    ContactUtil::SetBoolInRecord(c_email_record_h, _contacts_email.is_default,
-                                 FromJson<bool>(in, "isDefault"));
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(c_email_record_h, _contacts_email.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    int type_to_set = 0;
-
-    auto& types = FromJson<json::Array>(in, "types");
-    for (auto& type : types) {
-        auto type_str = JsonCast<json::String>(type);
-        if (type_str == kContactEmailAddressTypeWork) {
-            type_to_set |= CONTACTS_EMAIL_TYPE_WORK;
-        } else if (type_str == kContactEmailAddressTypeOther) {
-            type_to_set |= CONTACTS_EMAIL_TYPE_OTHER;
-        } else if (type_str == kContactEmailAddressTypeCustom) {
-            type_to_set |= CONTACTS_EMAIL_TYPE_CUSTOM;
-        } else {
-            type_to_set |= CONTACTS_EMAIL_TYPE_HOME;
-        }
+void ExportContactEmailAddressToContactsRecord(
+    contacts_record_h contacts_record, const json::Object& in) {
+  contacts_record_h c_email_record_h = nullptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_record_create(_contacts_email._uri, &c_email_record_h);
+  ContactUtil::ErrorChecker(err, "Failed to create email record in database");
+  ContactsRecordHPtr record(&c_email_record_h, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(c_email_record_h, _contacts_email.email,
+                              FromJson<json::String>(in, "email").c_str());
+  ContactUtil::SetBoolInRecord(c_email_record_h, _contacts_email.is_default,
+                               FromJson<bool>(in, "isDefault"));
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(c_email_record_h, _contacts_email.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  int type_to_set = 0;
+
+  auto& types = FromJson<json::Array>(in, "types");
+  for (auto& type : types) {
+    auto type_str = JsonCast<json::String>(type);
+    if (type_str == kContactEmailAddressTypeWork) {
+      type_to_set |= CONTACTS_EMAIL_TYPE_WORK;
+    } else if (type_str == kContactEmailAddressTypeOther) {
+      type_to_set |= CONTACTS_EMAIL_TYPE_OTHER;
+    } else if (type_str == kContactEmailAddressTypeCustom) {
+      type_to_set |= CONTACTS_EMAIL_TYPE_CUSTOM;
+    } else {
+      type_to_set |= CONTACTS_EMAIL_TYPE_HOME;
     }
-    ContactUtil::SetIntInRecord(c_email_record_h, _contacts_email.type, type_to_set);
+  }
+  ContactUtil::SetIntInRecord(c_email_record_h, _contacts_email.type,
+                              type_to_set);
 
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.email,
-                                           c_email_record_h);
-    ContactUtil::ErrorChecker(err, "Fail to save email record into database");
-    // Do not delete record, it is passed to the platform
-    record.release();
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.email, c_email_record_h);
+  ContactUtil::ErrorChecker(err, "Fail to save email record into database");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-void ImportContactPhoneNumberFromContactsRecord(contacts_record_h contacts_record,
-                                                unsigned int index, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.number, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* phone = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_number.number, &phone);
-
-    out.insert(std::make_pair("number", JsonValue{phone}));
-
-    bool is_default = false;
-    ContactUtil::GetBoolFromRecord(child_record, _contacts_number.is_default, &is_default);
-    out.insert(std::make_pair("isDefault", JsonValue{is_default}));
-    int type = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_number.type, &type);
-
-    JsonArray types;
-    if (type & CONTACTS_NUMBER_TYPE_HOME) {
-        types.push_back(JsonValue{kContactPhoneTypeHome});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_WORK) {
-        types.push_back(JsonValue{kContactPhoneTypeWork});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_VOICE) {
-        types.push_back(JsonValue{kContactPhoneTypeVoice});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_FAX) {
-        types.push_back(JsonValue{kContactPhoneTypeFax});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_MSG) {
-        types.push_back(JsonValue{kContactPhoneTypeMsg});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_CELL) {
-        types.push_back(JsonValue{kContactPhoneTypeCell});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_PAGER) {
-        types.push_back(JsonValue{kContactPhoneTypePager});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_BBS) {
-        types.push_back(JsonValue{kContactPhoneTypeBbs});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_MODEM) {
-        types.push_back(JsonValue{kContactPhoneTypeModem});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_CAR) {
-        types.push_back(JsonValue{kContactPhoneTypeCar});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_ISDN) {
-        types.push_back(JsonValue{kContactPhoneTypeIsdn});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_VIDEO) {
-        types.push_back(JsonValue{kContactPhoneTypeVideo});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_PCS) {
-        types.push_back(JsonValue{kContactPhoneTypePcs});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_ASSISTANT) {
-        types.push_back(JsonValue{kContactPhoneTypeAssistant});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_OTHER) {
-        types.push_back(JsonValue{kContactPhoneTypeOther});
-    }
-    if (type & CONTACTS_NUMBER_TYPE_CUSTOM) {
-        types.push_back(JsonValue{kContactPhoneTypeCustom});
-    }
-    if (0 == types.size()) {
-        types.push_back(JsonValue{kContactPhoneTypeVoice});
-    }
-    out.insert(std::make_pair("types", types));
-
-    char* label = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_number.label, &label);
-    out.insert(std::make_pair("label", label ? JsonValue{label} : JsonValue{}));
+void ImportContactPhoneNumberFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.number, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* phone = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_number.number, &phone);
+
+  out.insert(std::make_pair("number", JsonValue{phone}));
+
+  bool is_default = false;
+  ContactUtil::GetBoolFromRecord(child_record, _contacts_number.is_default,
+                                 &is_default);
+  out.insert(std::make_pair("isDefault", JsonValue{is_default}));
+  int type = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_number.type, &type);
+
+  JsonArray types;
+  if (type & CONTACTS_NUMBER_TYPE_HOME) {
+    types.push_back(JsonValue{kContactPhoneTypeHome});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_WORK) {
+    types.push_back(JsonValue{kContactPhoneTypeWork});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_VOICE) {
+    types.push_back(JsonValue{kContactPhoneTypeVoice});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_FAX) {
+    types.push_back(JsonValue{kContactPhoneTypeFax});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_MSG) {
+    types.push_back(JsonValue{kContactPhoneTypeMsg});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_CELL) {
+    types.push_back(JsonValue{kContactPhoneTypeCell});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_PAGER) {
+    types.push_back(JsonValue{kContactPhoneTypePager});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_BBS) {
+    types.push_back(JsonValue{kContactPhoneTypeBbs});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_MODEM) {
+    types.push_back(JsonValue{kContactPhoneTypeModem});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_CAR) {
+    types.push_back(JsonValue{kContactPhoneTypeCar});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_ISDN) {
+    types.push_back(JsonValue{kContactPhoneTypeIsdn});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_VIDEO) {
+    types.push_back(JsonValue{kContactPhoneTypeVideo});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_PCS) {
+    types.push_back(JsonValue{kContactPhoneTypePcs});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_ASSISTANT) {
+    types.push_back(JsonValue{kContactPhoneTypeAssistant});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_OTHER) {
+    types.push_back(JsonValue{kContactPhoneTypeOther});
+  }
+  if (type & CONTACTS_NUMBER_TYPE_CUSTOM) {
+    types.push_back(JsonValue{kContactPhoneTypeCustom});
+  }
+  if (0 == types.size()) {
+    types.push_back(JsonValue{kContactPhoneTypeVoice});
+  }
+  out.insert(std::make_pair("types", types));
+
+  char* label = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_number.label, &label);
+  out.insert(std::make_pair("label", label ? JsonValue{label} : JsonValue{}));
 }
 
 void ExportContactPhoneNumberToContactsRecord(contacts_record_h contacts_record,
-                                              const json::Object& in)
-{
-    contacts_record_h phone_record = nullptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_record_create(_contacts_number._uri, &phone_record);
-    ContactUtil::ErrorChecker(err, "Fail to create phone_record in database");
-    ContactsRecordHPtr record(&phone_record, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(phone_record, _contacts_number.number,
-                                FromJson<json::String>(in, "number").c_str());
-
-    ContactUtil::SetBoolInRecord(phone_record, _contacts_number.is_default,
-                                 FromJson<bool>(in, "isDefault"));
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(phone_record, _contacts_address.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    int type_to_set = 0;
-    const json::Array& types = FromJson<json::Array>(in, "types");
-    for (auto& type : types) {
-        auto& type_str = JsonCast<json::String>(type);
-        if (type_str == kContactPhoneTypeHome) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_HOME;
-        } else if (type_str == kContactPhoneTypeWork) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_WORK;
-        } else if (type_str == kContactPhoneTypeVoice) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_VOICE;
-        } else if (type_str == kContactPhoneTypeFax) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_FAX;
-        } else if (type_str == kContactPhoneTypeMsg) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_MSG;
-        } else if (type_str == kContactPhoneTypeCell) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_CELL;
-        } else if (type_str == kContactPhoneTypePager) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_PAGER;
-        } else if (type_str == kContactPhoneTypeBbs) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_BBS;
-        } else if (type_str == kContactPhoneTypeModem) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_MODEM;
-        } else if (type_str == kContactPhoneTypeCar) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_CAR;
-        } else if (type_str == kContactPhoneTypeIsdn) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_ISDN;
-        } else if (type_str == kContactPhoneTypeVideo) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_VIDEO;
-        } else if (type_str == kContactPhoneTypePcs) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_PCS;
-        } else if (type_str == kContactPhoneTypeAssistant) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_ASSISTANT;
-        } else if (type_str == kContactPhoneTypeOther) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_OTHER;
-        } else if (type_str == kContactPhoneTypeCustom) {
-            type_to_set |= CONTACTS_NUMBER_TYPE_CUSTOM;
-        } else {
-            type_to_set |= CONTACTS_NUMBER_TYPE_VOICE;
-        }
+                                              const json::Object& in) {
+  contacts_record_h phone_record = nullptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_record_create(_contacts_number._uri, &phone_record);
+  ContactUtil::ErrorChecker(err, "Fail to create phone_record in database");
+  ContactsRecordHPtr record(&phone_record, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(phone_record, _contacts_number.number,
+                              FromJson<json::String>(in, "number").c_str());
+
+  ContactUtil::SetBoolInRecord(phone_record, _contacts_number.is_default,
+                               FromJson<bool>(in, "isDefault"));
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(phone_record, _contacts_address.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  int type_to_set = 0;
+  const json::Array& types = FromJson<json::Array>(in, "types");
+  for (auto& type : types) {
+    auto& type_str = JsonCast<json::String>(type);
+    if (type_str == kContactPhoneTypeHome) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_HOME;
+    } else if (type_str == kContactPhoneTypeWork) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_WORK;
+    } else if (type_str == kContactPhoneTypeVoice) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_VOICE;
+    } else if (type_str == kContactPhoneTypeFax) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_FAX;
+    } else if (type_str == kContactPhoneTypeMsg) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_MSG;
+    } else if (type_str == kContactPhoneTypeCell) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_CELL;
+    } else if (type_str == kContactPhoneTypePager) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_PAGER;
+    } else if (type_str == kContactPhoneTypeBbs) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_BBS;
+    } else if (type_str == kContactPhoneTypeModem) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_MODEM;
+    } else if (type_str == kContactPhoneTypeCar) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_CAR;
+    } else if (type_str == kContactPhoneTypeIsdn) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_ISDN;
+    } else if (type_str == kContactPhoneTypeVideo) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_VIDEO;
+    } else if (type_str == kContactPhoneTypePcs) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_PCS;
+    } else if (type_str == kContactPhoneTypeAssistant) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_ASSISTANT;
+    } else if (type_str == kContactPhoneTypeOther) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_OTHER;
+    } else if (type_str == kContactPhoneTypeCustom) {
+      type_to_set |= CONTACTS_NUMBER_TYPE_CUSTOM;
+    } else {
+      type_to_set |= CONTACTS_NUMBER_TYPE_VOICE;
     }
+  }
 
-    ContactUtil::SetIntInRecord(phone_record, _contacts_number.type, type_to_set);
+  ContactUtil::SetIntInRecord(phone_record, _contacts_number.type, type_to_set);
 
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.number, phone_record);
-    ContactUtil::ErrorChecker(err, "Fail to set number value to phone_record");
-    // Do not delete record, it is passed to the platform
-    record.release();
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.number, phone_record);
+  ContactUtil::ErrorChecker(err, "Fail to set number value to phone_record");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-void ImportContactOrganizationFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.company, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* char_value = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_company.name, &char_value);
-    out.insert(std::make_pair("name", char_value ? JsonValue{char_value} : JsonValue{}));
-
-    ContactUtil::GetStrFromRecord(child_record, _contacts_company.department, &char_value);
-    out.insert(std::make_pair("department", char_value ? JsonValue{char_value} : JsonValue{}));
-
-    ContactUtil::GetStrFromRecord(child_record, _contacts_company.job_title, &char_value);
-    out.insert(std::make_pair("title", char_value ? JsonValue{char_value} : JsonValue{}));
-
-    ContactUtil::GetStrFromRecord(child_record, _contacts_company.role, &char_value);
-    out.insert(std::make_pair("role", char_value ? JsonValue{char_value} : JsonValue{}));
-
-    ContactUtil::GetStrFromRecord(child_record, _contacts_company.logo, &char_value);
-    out.insert(std::make_pair("logoURI", char_value ? JsonValue{char_value} : JsonValue{}));
+void ImportContactOrganizationFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.company, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* char_value = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_company.name,
+                                &char_value);
+  out.insert(
+      std::make_pair("name", char_value ? JsonValue{char_value} : JsonValue{}));
+
+  ContactUtil::GetStrFromRecord(child_record, _contacts_company.department,
+                                &char_value);
+  out.insert(std::make_pair("department",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
+
+  ContactUtil::GetStrFromRecord(child_record, _contacts_company.job_title,
+                                &char_value);
+  out.insert(std::make_pair("title",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
+
+  ContactUtil::GetStrFromRecord(child_record, _contacts_company.role,
+                                &char_value);
+  out.insert(
+      std::make_pair("role", char_value ? JsonValue{char_value} : JsonValue{}));
+
+  ContactUtil::GetStrFromRecord(child_record, _contacts_company.logo,
+                                &char_value);
+  out.insert(std::make_pair("logoURI",
+                            char_value ? JsonValue{char_value} : JsonValue{}));
 }
 
-void ExportContactOrganizationToContactsRecord(contacts_record_h contacts_record,
-                                               const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    contacts_record_h organization_record = nullptr;
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_record_create(_contacts_company._uri, &organization_record);
-    ContactUtil::ErrorChecker(err, "Failed to create organization record in database");
-    ContactsRecordHPtr record(&organization_record, ContactsDeleter);
-
-    if (!IsNull(in, "name")) {
-        ContactUtil::SetStrInRecord(organization_record, _contacts_company.name,
-                                    FromJson<json::String>(in, "name").c_str());
-    }
-    if (!IsNull(in, "department")) {
-        ContactUtil::SetStrInRecord(organization_record, _contacts_company.department,
-                                    FromJson<json::String>(in, "department").c_str());
-    }
-    if (!IsNull(in, "title")) {
-        ContactUtil::SetStrInRecord(organization_record, _contacts_company.job_title,
-                                    FromJson<json::String>(in, "title").c_str());
-    }
-    if (!IsNull(in, "role")) {
-        ContactUtil::SetStrInRecord(organization_record, _contacts_company.role,
-                                    FromJson<json::String>(in, "role").c_str());
-    }
-    if (!IsNull(in, "logoURI")) {
-        std::string path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "logoURI"));
-        ContactUtil::SetStrInRecord(organization_record, _contacts_company.logo, path.c_str());
-    }
-
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.company,
-                                           organization_record);
-    ContactUtil::ErrorChecker(err, "Fail to set company value to child_record");
-    // Do not delete record, it is passed to the platform
-    record.release();
+void ExportContactOrganizationToContactsRecord(
+    contacts_record_h contacts_record, const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  contacts_record_h organization_record = nullptr;
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_record_create(_contacts_company._uri, &organization_record);
+  ContactUtil::ErrorChecker(err,
+                            "Failed to create organization record in database");
+  ContactsRecordHPtr record(&organization_record, ContactsDeleter);
+
+  if (!IsNull(in, "name")) {
+    ContactUtil::SetStrInRecord(organization_record, _contacts_company.name,
+                                FromJson<json::String>(in, "name").c_str());
+  }
+  if (!IsNull(in, "department")) {
+    ContactUtil::SetStrInRecord(
+        organization_record, _contacts_company.department,
+        FromJson<json::String>(in, "department").c_str());
+  }
+  if (!IsNull(in, "title")) {
+    ContactUtil::SetStrInRecord(organization_record,
+                                _contacts_company.job_title,
+                                FromJson<json::String>(in, "title").c_str());
+  }
+  if (!IsNull(in, "role")) {
+    ContactUtil::SetStrInRecord(organization_record, _contacts_company.role,
+                                FromJson<json::String>(in, "role").c_str());
+  }
+  if (!IsNull(in, "logoURI")) {
+    std::string path =
+        ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "logoURI"));
+    ContactUtil::SetStrInRecord(organization_record, _contacts_company.logo,
+                                path.c_str());
+  }
+
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.company, organization_record);
+  ContactUtil::ErrorChecker(err, "Fail to set company value to child_record");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-void ImportContactWebSiteFromContactsRecord(contacts_record_h contacts_record, unsigned int index,
-                                            JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.url, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* char_value = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_url.url, &char_value);
-    out.insert(std::make_pair("logoURI", char_value ? char_value : ""));
-
-    int type = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_url.type, &type);
-
-    out.insert(std::make_pair("logoURI", (CONTACTS_URL_TYPE_HOME == type)
-                                                 ? kContactWebSiteTypeHomePage
-                                                 : kContactWebSiteTypeBlog));
+void ImportContactWebSiteFromContactsRecord(contacts_record_h contacts_record,
+                                            unsigned int index,
+                                            JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.url, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* char_value = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_url.url, &char_value);
+  out.insert(std::make_pair("logoURI", char_value ? char_value : ""));
+
+  int type = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_url.type, &type);
+
+  out.insert(std::make_pair("logoURI", (CONTACTS_URL_TYPE_HOME == type)
+                                           ? kContactWebSiteTypeHomePage
+                                           : kContactWebSiteTypeBlog));
 }
 
-void ExportContactWebSiteToContactsRecord(contacts_record_h contacts_record, const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    if (IsNull(in, "url")) {
-        LOGD("WebSite urls are not set");
-        return;
-    }
-
-    const std::string& url = FromJson<json::String>(in, "url");
-    if (url.empty()) {
-        LOGD("WebSite urls are not set");
-        return;
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h website_record_h = nullptr;
-    err = contacts_record_create(_contacts_url._uri, &website_record_h);
-    ContactUtil::ErrorChecker(err, "Fail to create website record in database.");
-    ContactsRecordHPtr record(&website_record_h, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(website_record_h, _contacts_url.url, url.c_str());
-
-    int type_to_set = (FromJson<json::String>(in, "type") == kContactWebSiteTypeHomePage)
-                              ? CONTACTS_URL_TYPE_HOME
-                              : CONTACTS_URL_TYPE_WORK;
-
-    ContactUtil::SetIntInRecord(website_record_h, _contacts_url.type, type_to_set);
-
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.url,
-                                           website_record_h);
-    ContactUtil::ErrorChecker(err, "Problem during saving WebSite urls into database.");
-    // Do not delete record, it is passed to the platform
-    record.release();
+void ExportContactWebSiteToContactsRecord(contacts_record_h contacts_record,
+                                          const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  if (IsNull(in, "url")) {
+    LOGD("WebSite urls are not set");
+    return;
+  }
+
+  const std::string& url = FromJson<json::String>(in, "url");
+  if (url.empty()) {
+    LOGD("WebSite urls are not set");
+    return;
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h website_record_h = nullptr;
+  err = contacts_record_create(_contacts_url._uri, &website_record_h);
+  ContactUtil::ErrorChecker(err, "Fail to create website record in database.");
+  ContactsRecordHPtr record(&website_record_h, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(website_record_h, _contacts_url.url, url.c_str());
+
+  int type_to_set =
+      (FromJson<json::String>(in, "type") == kContactWebSiteTypeHomePage)
+          ? CONTACTS_URL_TYPE_HOME
+          : CONTACTS_URL_TYPE_WORK;
+
+  ContactUtil::SetIntInRecord(website_record_h, _contacts_url.type,
+                              type_to_set);
+
+  err = contacts_record_add_child_record(contacts_record, _contacts_contact.url,
+                                         website_record_h);
+  ContactUtil::ErrorChecker(
+      err, "Problem during saving WebSite urls into database.");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-bool ImportContactAnniversariesFromContactsRecord(contacts_record_h contacts_record,
-                                                  unsigned int index, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.event, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return false;
-    }
-
-    int value = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_event.type, &value);
+bool ImportContactAnniversariesFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.event, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return false;
+  }
+
+  int value = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_event.type, &value);
+
+  if (CONTACTS_EVENT_TYPE_BIRTH == value) {
+    return false;
+  }
+
+  if (CONTACTS_EVENT_TYPE_ANNIVERSARY == value) {
+    ContactUtil::GetIntFromRecord(child_record, _contacts_event.date, &value);
+    out.insert(std::make_pair("date", JsonValue{static_cast<double>(value)}));
 
-    if (CONTACTS_EVENT_TYPE_BIRTH == value) {
-        return false;
-    }
-
-    if (CONTACTS_EVENT_TYPE_ANNIVERSARY == value) {
-        ContactUtil::GetIntFromRecord(child_record, _contacts_event.date, &value);
-        out.insert(std::make_pair("date", JsonValue{static_cast<double>(value)}));
-
-        char* label = nullptr;
-        ContactUtil::GetStrFromRecord(child_record, _contacts_event.label, &label);
+    char* label = nullptr;
+    ContactUtil::GetStrFromRecord(child_record, _contacts_event.label, &label);
 
-        out.insert(std::make_pair("label", label ? json::Value{label} : json::Value{}));
-    }
-    return true;
+    out.insert(
+        std::make_pair("label", label ? json::Value{label} : json::Value{}));
+  }
+  return true;
 }
 
-void ExportContactAnniversariesToContactsRecord(contacts_record_h contacts_record,
-                                                const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int date = static_cast<int>(FromJson<double>(in, "date"));
-    if (date == 0) {
-        return;
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h anniversary_record = nullptr;
-    err = contacts_record_create(_contacts_event._uri, &anniversary_record);
-    ContactUtil::ErrorChecker(err, "Failed to create anniversary record in database");
-    ContactsRecordHPtr record(&anniversary_record, ContactsDeleter);
-
-    ContactUtil::SetIntInRecord(anniversary_record, _contacts_event.type,
-                                CONTACTS_EVENT_TYPE_ANNIVERSARY);
-
-    ContactUtil::SetIntInRecord(anniversary_record, _contacts_event.date, date);
-
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(anniversary_record, _contacts_event.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.event,
-                                           anniversary_record);
-    ContactUtil::ErrorChecker(err, "Fail to save anniversary record in database");
-    // Do not delete record, it is passed to the platform
-    record.release();
+void ExportContactAnniversariesToContactsRecord(
+    contacts_record_h contacts_record, const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int date = static_cast<int>(FromJson<double>(in, "date"));
+  if (date == 0) {
+    return;
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h anniversary_record = nullptr;
+  err = contacts_record_create(_contacts_event._uri, &anniversary_record);
+  ContactUtil::ErrorChecker(err,
+                            "Failed to create anniversary record in database");
+  ContactsRecordHPtr record(&anniversary_record, ContactsDeleter);
+
+  ContactUtil::SetIntInRecord(anniversary_record, _contacts_event.type,
+                              CONTACTS_EVENT_TYPE_ANNIVERSARY);
+
+  ContactUtil::SetIntInRecord(anniversary_record, _contacts_event.date, date);
+
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(anniversary_record, _contacts_event.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.event, anniversary_record);
+  ContactUtil::ErrorChecker(err, "Fail to save anniversary record in database");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-void ImportContactRelationshipFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, json::Object* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.relationship,
-                                                index, &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* relative = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_relationship.name, &relative);
-    if (!relative) {
-        return;
-    }
-
-    out.insert(std::make_pair("relativeName", json::String{relative}));
-
-    int type = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_relationship.type, &type);
-
-    // TODO Move out.insert outside of switch statement.
-    switch (type) {
-        case CONTACTS_RELATIONSHIP_TYPE_CUSTOM:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeCustom}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_ASSISTANT:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeAssistant}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_BROTHER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeBrother}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_CHILD:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeChild}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
-            out.insert(
-                    std::make_pair("type", json::String{kContactRelationshipTypeDomesticPartner}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_FATHER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeFather}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_FRIEND:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeFriend}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_MANAGER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeManager}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_MOTHER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeMother}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_PARENT:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeParent}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_PARTNER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypePartner}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeReferredBy}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_RELATIVE:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeRelative}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_SISTER:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeSister}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_SPOUSE:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeSpouse}));
-            break;
-        case CONTACTS_RELATIONSHIP_TYPE_OTHER:
-        default:
-            out.insert(std::make_pair("type", json::String{kContactRelationshipTypeOther}));
-            break;
-    }
-
-    char* label = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_relationship.label, &label);
-    out.insert(std::make_pair("label", label ? json::Value{label} : json::Value{}));
+void ImportContactRelationshipFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    json::Object* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.relationship, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* relative = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_relationship.name,
+                                &relative);
+  if (!relative) {
+    return;
+  }
+
+  out.insert(std::make_pair("relativeName", json::String{relative}));
+
+  int type = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_relationship.type,
+                                &type);
+
+  // TODO Move out.insert outside of switch statement.
+  switch (type) {
+    case CONTACTS_RELATIONSHIP_TYPE_CUSTOM:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeCustom}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_ASSISTANT:
+      out.insert(std::make_pair(
+          "type", json::String{kContactRelationshipTypeAssistant}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_BROTHER:
+      out.insert(std::make_pair("type",
+                                json::String{kContactRelationshipTypeBrother}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_CHILD:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeChild}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER:
+      out.insert(std::make_pair(
+          "type", json::String{kContactRelationshipTypeDomesticPartner}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_FATHER:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeFather}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_FRIEND:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeFriend}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_MANAGER:
+      out.insert(std::make_pair("type",
+                                json::String{kContactRelationshipTypeManager}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_MOTHER:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeMother}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_PARENT:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeParent}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_PARTNER:
+      out.insert(std::make_pair("type",
+                                json::String{kContactRelationshipTypePartner}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY:
+      out.insert(std::make_pair(
+          "type", json::String{kContactRelationshipTypeReferredBy}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_RELATIVE:
+      out.insert(std::make_pair(
+          "type", json::String{kContactRelationshipTypeRelative}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_SISTER:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeSister}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_SPOUSE:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeSpouse}));
+      break;
+    case CONTACTS_RELATIONSHIP_TYPE_OTHER:
+    default:
+      out.insert(
+          std::make_pair("type", json::String{kContactRelationshipTypeOther}));
+      break;
+  }
+
+  char* label = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_relationship.label,
+                                &label);
+  out.insert(
+      std::make_pair("label", label ? json::Value{label} : json::Value{}));
 }
 
-void ExportContactRelationshipToContactsRecord(contacts_record_h contacts_record,
-                                               const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_create(_contacts_relationship._uri, &child_record);
-    ContactUtil::ErrorChecker(err, "Fail to create child_record in database");
-    ContactsRecordHPtr record(&child_record, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(child_record, _contacts_relationship.name,
-                                FromJson<json::String>(in, "relativeName").c_str());
-
-    const json::String& type = FromJson<json::String>(in, "type");
-    int type_to_set;
-    if (type == kContactRelationshipTypeAssistant) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
-    } else if (type == kContactRelationshipTypeBrother) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
-    } else if (type == kContactRelationshipTypeChild) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_CHILD;
-    } else if (type == kContactRelationshipTypeDomesticPartner) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
-    } else if (type == kContactRelationshipTypeFather) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_FATHER;
-    } else if (type == kContactRelationshipTypeFriend) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
-    } else if (type == kContactRelationshipTypeManager) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
-    } else if (type == kContactRelationshipTypeMother) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
-    } else if (type == kContactRelationshipTypeParent) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_PARENT;
-    } else if (type == kContactRelationshipTypePartner) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
-    } else if (type == kContactRelationshipTypeReferredBy) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
-    } else if (type == kContactRelationshipTypeRelative) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
-    } else if (type == kContactRelationshipTypeSister) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_SISTER;
-    } else if (type == kContactRelationshipTypeSpouse) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
-    } else if (type == kContactRelationshipTypeCustom) {
-        type_to_set = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
-    } else {
-        type_to_set = CONTACTS_MESSENGER_TYPE_OTHER;
-    }
-
-    ContactUtil::SetIntInRecord(child_record, _contacts_relationship.type, type_to_set);
-
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(child_record, _contacts_relationship.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.relationship,
-                                           child_record);
-    ContactUtil::ErrorChecker(err, "Fail to set number value to child_record");
-    record.release();
+void ExportContactRelationshipToContactsRecord(
+    contacts_record_h contacts_record, const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_create(_contacts_relationship._uri, &child_record);
+  ContactUtil::ErrorChecker(err, "Fail to create child_record in database");
+  ContactsRecordHPtr record(&child_record, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(
+      child_record, _contacts_relationship.name,
+      FromJson<json::String>(in, "relativeName").c_str());
+
+  const json::String& type = FromJson<json::String>(in, "type");
+  int type_to_set;
+  if (type == kContactRelationshipTypeAssistant) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_ASSISTANT;
+  } else if (type == kContactRelationshipTypeBrother) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_BROTHER;
+  } else if (type == kContactRelationshipTypeChild) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_CHILD;
+  } else if (type == kContactRelationshipTypeDomesticPartner) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_DOMESTIC_PARTNER;
+  } else if (type == kContactRelationshipTypeFather) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_FATHER;
+  } else if (type == kContactRelationshipTypeFriend) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_FRIEND;
+  } else if (type == kContactRelationshipTypeManager) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_MANAGER;
+  } else if (type == kContactRelationshipTypeMother) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_MOTHER;
+  } else if (type == kContactRelationshipTypeParent) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_PARENT;
+  } else if (type == kContactRelationshipTypePartner) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_PARTNER;
+  } else if (type == kContactRelationshipTypeReferredBy) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_REFERRED_BY;
+  } else if (type == kContactRelationshipTypeRelative) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_RELATIVE;
+  } else if (type == kContactRelationshipTypeSister) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_SISTER;
+  } else if (type == kContactRelationshipTypeSpouse) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_SPOUSE;
+  } else if (type == kContactRelationshipTypeCustom) {
+    type_to_set = CONTACTS_RELATIONSHIP_TYPE_CUSTOM;
+  } else {
+    type_to_set = CONTACTS_MESSENGER_TYPE_OTHER;
+  }
+
+  ContactUtil::SetIntInRecord(child_record, _contacts_relationship.type,
+                              type_to_set);
+
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(child_record, _contacts_relationship.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.relationship, child_record);
+  ContactUtil::ErrorChecker(err, "Fail to set number value to child_record");
+  record.release();
 }
 
-void ImportContactInstantMessengerFromContactsRecord(contacts_record_h contacts_record,
-                                                     unsigned int index, json::Object* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.messenger, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        LoggerW("Skipping message with index " << index << ". error code: " << err);
-        return;
-    }
-
-    char* im_address = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_messenger.im_id, &im_address);
-    if (!im_address) {
-        LoggerW("Skipping message with index " << index << ". missing im address");
-        return;
-    }
-
-    out.insert(std::make_pair("imAddress", json::Value{im_address}));
-
-    int type = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_messenger.type, &type);
-
-    // TODO Move out.insert outside of switch statement.
-    switch (type) {
-        case CONTACTS_MESSENGER_TYPE_CUSTOM:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeCustom}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_GOOGLE:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeGoogle}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_WLM:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeWlm}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_YAHOO:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeYahoo}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_FACEBOOK:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeFacebook}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_ICQ:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeIcq}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_AIM:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeAim}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_QQ:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeQq}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_JABBER:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeJabber}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_SKYPE:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeSkype}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_IRC:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeIrc}));
-            break;
-        case CONTACTS_MESSENGER_TYPE_OTHER:
-        default:
-            out.insert(std::make_pair("type", json::Value{kContactInstantMessageTypeOther}));
-            break;
-    }
-
-    char* label = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_messenger.label, &label);
-    out.insert(std::make_pair("label", label ? json::Value{label} : json::Value{}));
+void ImportContactInstantMessengerFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index,
+    json::Object* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.messenger, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    LoggerW("Skipping message with index " << index << ". error code: " << err);
+    return;
+  }
+
+  char* im_address = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_messenger.im_id,
+                                &im_address);
+  if (!im_address) {
+    LoggerW("Skipping message with index " << index << ". missing im address");
+    return;
+  }
+
+  out.insert(std::make_pair("imAddress", json::Value{im_address}));
+
+  int type = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_messenger.type, &type);
+
+  // TODO Move out.insert outside of switch statement.
+  switch (type) {
+    case CONTACTS_MESSENGER_TYPE_CUSTOM:
+      out.insert(std::make_pair("type",
+                                json::Value{kContactInstantMessageTypeCustom}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_GOOGLE:
+      out.insert(std::make_pair("type",
+                                json::Value{kContactInstantMessageTypeGoogle}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_WLM:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeWlm}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_YAHOO:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeYahoo}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_FACEBOOK:
+      out.insert(std::make_pair(
+          "type", json::Value{kContactInstantMessageTypeFacebook}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_ICQ:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeIcq}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_AIM:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeAim}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_QQ:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeQq}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_JABBER:
+      out.insert(std::make_pair("type",
+                                json::Value{kContactInstantMessageTypeJabber}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_SKYPE:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeSkype}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_IRC:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeIrc}));
+      break;
+    case CONTACTS_MESSENGER_TYPE_OTHER:
+    default:
+      out.insert(
+          std::make_pair("type", json::Value{kContactInstantMessageTypeOther}));
+      break;
+  }
+
+  char* label = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_messenger.label,
+                                &label);
+  out.insert(
+      std::make_pair("label", label ? json::Value{label} : json::Value{}));
 }
 
-void ExportContactInstantMessengerToContactsRecord(contacts_record_h contacts_record,
-                                                   const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_create(_contacts_messenger._uri, &child_record);
-    ContactUtil::ErrorChecker(err, "Fail to create child_record in database");
-    ContactsRecordHPtr record(&child_record, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(child_record, _contacts_messenger.im_id,
-                                FromJson<json::String>(in, "imAddress").c_str());
-
-    int type_to_set = 0;
-    const json::String& type = FromJson<json::String>(in, "type");
-    if (type == kContactInstantMessageTypeGoogle) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_GOOGLE;
-    } else if (type == kContactInstantMessageTypeWlm) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_WLM;
-    } else if (type == kContactInstantMessageTypeYahoo) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_YAHOO;
-    } else if (type == kContactInstantMessageTypeFacebook) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_FACEBOOK;
-    } else if (type == kContactInstantMessageTypeIcq) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_ICQ;
-    } else if (type == kContactInstantMessageTypeAim) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_AIM;
-    } else if (type == kContactInstantMessageTypeQq) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_QQ;
-    } else if (type == kContactInstantMessageTypeJabber) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_JABBER;
-    } else if (type == kContactInstantMessageTypeSkype) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_SKYPE;
-    } else if (type == kContactInstantMessageTypeIrc) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_IRC;
-    } else if (type == kContactInstantMessageTypeCustom) {
-        type_to_set = CONTACTS_MESSENGER_TYPE_CUSTOM;
-    } else {
-        type_to_set = CONTACTS_MESSENGER_TYPE_OTHER;
-    }
-
-    ContactUtil::SetIntInRecord(child_record, _contacts_messenger.type, type_to_set);
-
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(child_record, _contacts_messenger.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.messenger,
-                                           child_record);
-    ContactUtil::ErrorChecker(err, "Fail to set number value to child_record");
-    record.release();
+void ExportContactInstantMessengerToContactsRecord(
+    contacts_record_h contacts_record, const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_create(_contacts_messenger._uri, &child_record);
+  ContactUtil::ErrorChecker(err, "Fail to create child_record in database");
+  ContactsRecordHPtr record(&child_record, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(child_record, _contacts_messenger.im_id,
+                              FromJson<json::String>(in, "imAddress").c_str());
+
+  int type_to_set = 0;
+  const json::String& type = FromJson<json::String>(in, "type");
+  if (type == kContactInstantMessageTypeGoogle) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_GOOGLE;
+  } else if (type == kContactInstantMessageTypeWlm) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_WLM;
+  } else if (type == kContactInstantMessageTypeYahoo) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_YAHOO;
+  } else if (type == kContactInstantMessageTypeFacebook) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_FACEBOOK;
+  } else if (type == kContactInstantMessageTypeIcq) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_ICQ;
+  } else if (type == kContactInstantMessageTypeAim) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_AIM;
+  } else if (type == kContactInstantMessageTypeQq) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_QQ;
+  } else if (type == kContactInstantMessageTypeJabber) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_JABBER;
+  } else if (type == kContactInstantMessageTypeSkype) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_SKYPE;
+  } else if (type == kContactInstantMessageTypeIrc) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_IRC;
+  } else if (type == kContactInstantMessageTypeCustom) {
+    type_to_set = CONTACTS_MESSENGER_TYPE_CUSTOM;
+  } else {
+    type_to_set = CONTACTS_MESSENGER_TYPE_OTHER;
+  }
+
+  ContactUtil::SetIntInRecord(child_record, _contacts_messenger.type,
+                              type_to_set);
+
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(child_record, _contacts_messenger.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.messenger, child_record);
+  ContactUtil::ErrorChecker(err, "Fail to set number value to child_record");
+  record.release();
 }
 
-void ImportContactAddressFromContactsRecord(contacts_record_h contacts_record, unsigned int index,
-                                            JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h child_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.address, index,
-                                                &child_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return;
-    }
-
-    char* value = nullptr;
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.country, &value);
-    out.insert(std::make_pair("country", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.region, &value);
-    out.insert(std::make_pair("region", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.locality, &value);
-    out.insert(std::make_pair("city", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.street, &value);
-    out.insert(std::make_pair("streetAddress", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.extended, &value);
-    out.insert(std::make_pair("additionalInformation", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.postal_code, &value);
-    out.insert(std::make_pair("postalCode", value ? JsonValue{value} : JsonValue{}));
-    ContactUtil::GetStrFromRecord(child_record, _contacts_address.label, &value);
-    out.insert(std::make_pair("label", value ? JsonValue{value} : JsonValue{}));
-
-    bool bool_value = false;
-    ContactUtil::GetBoolFromRecord(child_record, _contacts_address.is_default, &bool_value);
-    out.insert(std::make_pair("isDefault", JsonValue{bool_value}));
-
-    int int_value = 0;
-    ContactUtil::GetIntFromRecord(child_record, _contacts_address.type, &int_value);
-
-    JsonArray types;
-    if (int_value & CONTACTS_ADDRESS_TYPE_HOME) {
-        types.push_back(JsonValue{kContactAddressTypeHome});
-    }
-    if (int_value & CONTACTS_ADDRESS_TYPE_WORK) {
-        types.push_back(JsonValue{kContactAddressTypeWork});
-    }
-    if (int_value & CONTACTS_ADDRESS_TYPE_OTHER) {
-        types.push_back(JsonValue{kContactAddressTypeOther});
-    }
-    if (int_value & CONTACTS_ADDRESS_TYPE_CUSTOM) {
-        types.push_back(JsonValue{kContactAddressTypeCustom});
-    }
-
-    if (0 == types.size()) {
-        types.push_back(JsonValue{kContactAddressTypeHome});
-    }
-    out.insert(std::make_pair("types", types));
+void ImportContactAddressFromContactsRecord(contacts_record_h contacts_record,
+                                            unsigned int index,
+                                            JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h child_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.address, index, &child_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
+    return;
+  }
+
+  char* value = nullptr;
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.country,
+                                &value);
+  out.insert(std::make_pair("country", value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.region, &value);
+  out.insert(std::make_pair("region", value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.locality,
+                                &value);
+  out.insert(std::make_pair("city", value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.street, &value);
+  out.insert(
+      std::make_pair("streetAddress", value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.extended,
+                                &value);
+  out.insert(std::make_pair("additionalInformation",
+                            value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.postal_code,
+                                &value);
+  out.insert(
+      std::make_pair("postalCode", value ? JsonValue{value} : JsonValue{}));
+  ContactUtil::GetStrFromRecord(child_record, _contacts_address.label, &value);
+  out.insert(std::make_pair("label", value ? JsonValue{value} : JsonValue{}));
+
+  bool bool_value = false;
+  ContactUtil::GetBoolFromRecord(child_record, _contacts_address.is_default,
+                                 &bool_value);
+  out.insert(std::make_pair("isDefault", JsonValue{bool_value}));
+
+  int int_value = 0;
+  ContactUtil::GetIntFromRecord(child_record, _contacts_address.type,
+                                &int_value);
+
+  JsonArray types;
+  if (int_value & CONTACTS_ADDRESS_TYPE_HOME) {
+    types.push_back(JsonValue{kContactAddressTypeHome});
+  }
+  if (int_value & CONTACTS_ADDRESS_TYPE_WORK) {
+    types.push_back(JsonValue{kContactAddressTypeWork});
+  }
+  if (int_value & CONTACTS_ADDRESS_TYPE_OTHER) {
+    types.push_back(JsonValue{kContactAddressTypeOther});
+  }
+  if (int_value & CONTACTS_ADDRESS_TYPE_CUSTOM) {
+    types.push_back(JsonValue{kContactAddressTypeCustom});
+  }
+
+  if (0 == types.size()) {
+    types.push_back(JsonValue{kContactAddressTypeHome});
+  }
+  out.insert(std::make_pair("types", types));
 }
 
-void ExportContactAddressToContactsRecord(contacts_record_h contacts_record, const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h address_record = nullptr;
-    err = contacts_record_create(_contacts_address._uri, &address_record);
-    ContactUtil::ErrorChecker(err, "Failed to create address record in database");
-    ContactsRecordHPtr record(&address_record, ContactsDeleter);
-
-    if (!IsNull(in, "country")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.country,
-                                    FromJson<json::String>(in, "country").c_str());
-    }
-    if (!IsNull(in, "region")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.region,
-                                    FromJson<json::String>(in, "region").c_str());
-    }
-    if (!IsNull(in, "city")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.locality,
-                                    FromJson<json::String>(in, "city").c_str());
-    }
-    if (!IsNull(in, "streetAddress")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.street,
-                                    FromJson<json::String>(in, "streetAddress").c_str());
-    }
-    if (!IsNull(in, "additionalInformation")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.extended,
-                                    FromJson<json::String>(in, "additionalInformation").c_str());
-    }
-    if (!IsNull(in, "postalCode")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.postal_code,
-                                    FromJson<json::String>(in, "postalCode").c_str());
-    }
-    if (!IsNull(in, "label")) {
-        ContactUtil::SetStrInRecord(address_record, _contacts_address.label,
-                                    FromJson<json::String>(in, "label").c_str());
-    }
-
-    ContactUtil::SetBoolInRecord(address_record, _contacts_address.is_default,
-                                 FromJson<bool>(in, "isDefault"));
-
-    int type_to_set = 0;
-    const json::Array& types = FromJson<json::Array>(in, "types");
-    for (auto& type : types) {
-        auto& type_str = JsonCast<json::String>(type);
-        if (type_str == kContactAddressTypeWork) {
-            type_to_set |= CONTACTS_ADDRESS_TYPE_WORK;
-        } else if (type_str == kContactAddressTypeOther) {
-            type_to_set |= CONTACTS_ADDRESS_TYPE_OTHER;
-        } else if (type_str == kContactAddressTypeCustom) {
-            type_to_set |= CONTACTS_ADDRESS_TYPE_CUSTOM;
-        } else {
-            type_to_set |= CONTACTS_ADDRESS_TYPE_HOME;
-        }
+void ExportContactAddressToContactsRecord(contacts_record_h contacts_record,
+                                          const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h address_record = nullptr;
+  err = contacts_record_create(_contacts_address._uri, &address_record);
+  ContactUtil::ErrorChecker(err, "Failed to create address record in database");
+  ContactsRecordHPtr record(&address_record, ContactsDeleter);
+
+  if (!IsNull(in, "country")) {
+    ContactUtil::SetStrInRecord(address_record, _contacts_address.country,
+                                FromJson<json::String>(in, "country").c_str());
+  }
+  if (!IsNull(in, "region")) {
+    ContactUtil::SetStrInRecord(address_record, _contacts_address.region,
+                                FromJson<json::String>(in, "region").c_str());
+  }
+  if (!IsNull(in, "city")) {
+    ContactUtil::SetStrInRecord(address_record, _contacts_address.locality,
+                                FromJson<json::String>(in, "city").c_str());
+  }
+  if (!IsNull(in, "streetAddress")) {
+    ContactUtil::SetStrInRecord(
+        address_record, _contacts_address.street,
+        FromJson<json::String>(in, "streetAddress").c_str());
+  }
+  if (!IsNull(in, "additionalInformation")) {
+    ContactUtil::SetStrInRecord(
+        address_record, _contacts_address.extended,
+        FromJson<json::String>(in, "additionalInformation").c_str());
+  }
+  if (!IsNull(in, "postalCode")) {
+    ContactUtil::SetStrInRecord(
+        address_record, _contacts_address.postal_code,
+        FromJson<json::String>(in, "postalCode").c_str());
+  }
+  if (!IsNull(in, "label")) {
+    ContactUtil::SetStrInRecord(address_record, _contacts_address.label,
+                                FromJson<json::String>(in, "label").c_str());
+  }
+
+  ContactUtil::SetBoolInRecord(address_record, _contacts_address.is_default,
+                               FromJson<bool>(in, "isDefault"));
+
+  int type_to_set = 0;
+  const json::Array& types = FromJson<json::Array>(in, "types");
+  for (auto& type : types) {
+    auto& type_str = JsonCast<json::String>(type);
+    if (type_str == kContactAddressTypeWork) {
+      type_to_set |= CONTACTS_ADDRESS_TYPE_WORK;
+    } else if (type_str == kContactAddressTypeOther) {
+      type_to_set |= CONTACTS_ADDRESS_TYPE_OTHER;
+    } else if (type_str == kContactAddressTypeCustom) {
+      type_to_set |= CONTACTS_ADDRESS_TYPE_CUSTOM;
+    } else {
+      type_to_set |= CONTACTS_ADDRESS_TYPE_HOME;
     }
+  }
 
-    ContactUtil::SetIntInRecord(address_record, _contacts_address.type, type_to_set);
+  ContactUtil::SetIntInRecord(address_record, _contacts_address.type,
+                              type_to_set);
 
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.address,
-                                           address_record);
-    ContactUtil::ErrorChecker(err, "Fail to save address record in database");
-    // Do not delete record, it is passed to the platform
-    record.release();
+  err = contacts_record_add_child_record(
+      contacts_record, _contacts_contact.address, address_record);
+  ContactUtil::ErrorChecker(err, "Fail to save address record in database");
+  // Do not delete record, it is passed to the platform
+  record.release();
 }
 
-JsonValue ImportContactNotesFromContactsRecord(contacts_record_h contacts_record,
-                                               unsigned int index)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    contacts_record_h notes_record = nullptr;
-    err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.note, index,
-                                                &notes_record);
-    if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
-        return {};
-    }
-
-    char* note = nullptr;
-    ContactUtil::GetStrFromRecord(notes_record, _contacts_note.note, &note);
-
-    if (note) {
-        return JsonValue{note};
-    }
+JsonValue ImportContactNotesFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  contacts_record_h notes_record = nullptr;
+  err = contacts_record_get_child_record_at_p(
+      contacts_record, _contacts_contact.note, index, &notes_record);
+  if (CONTACTS_ERROR_NONE != err && CONTACTS_ERROR_NO_DATA != err) {
     return {};
-}
-
-void ExportNotesToContactsRecord(contacts_record_h contacts_record, const std::string& value)
-{
-    contacts_record_h notes_record = nullptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int err = CONTACTS_ERROR_NONE;
-    err = contacts_record_create(_contacts_note._uri, &notes_record);
-    ContactUtil::ErrorChecker(err, "Fail to create note record in database");
-    ContactsRecordHPtr record(&notes_record, ContactsDeleter);
-
-    ContactUtil::SetStrInRecord(notes_record, _contacts_note.note, value.c_str());
+  }
 
-    err = contacts_record_add_child_record(contacts_record, _contacts_contact.note, notes_record);
-    ContactUtil::ErrorChecker(err, "Fail to save note record in database");
+  char* note = nullptr;
+  ContactUtil::GetStrFromRecord(notes_record, _contacts_note.note, &note);
 
-    // Do not delete record, it is passed to the platform
-    record.release();
+  if (note) {
+    return JsonValue{note};
+  }
+  return {};
 }
 
-void ImportContactFromContactsRecord(contacts_record_h contacts_record, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGW("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    int id = 0;
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.id, &id);
-    out.insert(std::make_pair("id", JsonValue{std::to_string(id)}));
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.address_book_id, &id);
-    out.insert(std::make_pair("addressBookId", JsonValue{std::to_string(id)}));
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.person_id, &id);
-    out.insert(std::make_pair("personId", JsonValue{std::to_string(id)}));
-
-    bool is_favorite = false;
-    ContactUtil::GetBoolFromRecord(contacts_record, _contacts_contact.is_favorite, &is_favorite);
-    out.insert(std::make_pair("isFavorite", JsonValue{is_favorite}));
-
-    int last_update = 0;
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.changed_time, &last_update);
-    out.insert(std::make_pair("lastUpdated", JsonValue{static_cast<double>(last_update)}));
-
-    //### ContactName: ###
-    JsonObject name;
-    if (ImportContactNameFromContactsRecord(contacts_record, &name)) {
-        out.insert(std::make_pair("name", name));
-    } else {
-        out.insert(std::make_pair("name", json::Value{}));
-    }
-
-    typedef void (*ImportFunc)(contacts_record_h, unsigned int, JsonObject*);
-    struct ImportData {
-        const char* name;
-        unsigned int property_id;
-        ImportFunc import_func;
-    };
-    ImportData imports[] = {
-            {"emails", _contacts_contact.email, ImportContactEmailAddressFromContactsRecord},
-            {"phoneNumbers", _contacts_contact.number, ImportContactPhoneNumberFromContactsRecord},
-            {"organizations", _contacts_contact.company,
-             ImportContactOrganizationFromContactsRecord},
-            {"urls", _contacts_contact.url, ImportContactWebSiteFromContactsRecord},
-            {"addresses", _contacts_contact.address, ImportContactAddressFromContactsRecord},
-            {"messengers", _contacts_contact.messenger,
-             ImportContactInstantMessengerFromContactsRecord},
-            {"relationships", _contacts_contact.relationship,
-             ImportContactRelationshipFromContactsRecord}, };
-
-    for (auto& data : imports) {
-        json::Array& array = out.insert(std::make_pair(data.name, json::Array()))
-                                     .first->second.get<json::Array>();
-
-        for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(contacts_record,
-                                                                         data.property_id);
-             i < n; ++i) {
-            JsonValue val{json::Object{}};
-            data.import_func(contacts_record, i, &val.get<JsonObject>());
-            array.push_back(val);
-        }
-    }
+void ExportNotesToContactsRecord(contacts_record_h contacts_record,
+                                 const std::string& value) {
+  contacts_record_h notes_record = nullptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int err = CONTACTS_ERROR_NONE;
+  err = contacts_record_create(_contacts_note._uri, &notes_record);
+  ContactUtil::ErrorChecker(err, "Fail to create note record in database");
+  ContactsRecordHPtr record(&notes_record, ContactsDeleter);
+
+  ContactUtil::SetStrInRecord(notes_record, _contacts_note.note, value.c_str());
+
+  err = contacts_record_add_child_record(contacts_record,
+                                         _contacts_contact.note, notes_record);
+  ContactUtil::ErrorChecker(err, "Fail to save note record in database");
+
+  // Do not delete record, it is passed to the platform
+  record.release();
+}
 
-    //### ContactAnniversary: ###
-    json::Array& anniversaries = out.insert(std::make_pair("anniversaries", json::Array()))
-                                         .first->second.get<json::Array>();
-    for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(contacts_record,
-                                                                     _contacts_contact.event);
+void ImportContactFromContactsRecord(contacts_record_h contacts_record,
+                                     JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGW("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  int id = 0;
+  ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.id, &id);
+  out.insert(std::make_pair("id", JsonValue{std::to_string(id)}));
+  ContactUtil::GetIntFromRecord(contacts_record,
+                                _contacts_contact.address_book_id, &id);
+  out.insert(std::make_pair("addressBookId", JsonValue{std::to_string(id)}));
+  ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.person_id,
+                                &id);
+  out.insert(std::make_pair("personId", JsonValue{std::to_string(id)}));
+
+  bool is_favorite = false;
+  ContactUtil::GetBoolFromRecord(contacts_record, _contacts_contact.is_favorite,
+                                 &is_favorite);
+  out.insert(std::make_pair("isFavorite", JsonValue{is_favorite}));
+
+  int last_update = 0;
+  ContactUtil::GetIntFromRecord(contacts_record, _contacts_contact.changed_time,
+                                &last_update);
+  out.insert(std::make_pair("lastUpdated",
+                            JsonValue{static_cast<double>(last_update)}));
+
+  //### ContactName: ###
+  JsonObject name;
+  if (ImportContactNameFromContactsRecord(contacts_record, &name)) {
+    out.insert(std::make_pair("name", name));
+  } else {
+    out.insert(std::make_pair("name", json::Value{}));
+  }
+
+  typedef void (*ImportFunc)(contacts_record_h, unsigned int, JsonObject*);
+  struct ImportData {
+    const char* name;
+    unsigned int property_id;
+    ImportFunc import_func;
+  };
+  ImportData imports[] = {
+      {"emails", _contacts_contact.email,
+       ImportContactEmailAddressFromContactsRecord},
+      {"phoneNumbers", _contacts_contact.number,
+       ImportContactPhoneNumberFromContactsRecord},
+      {"organizations", _contacts_contact.company,
+       ImportContactOrganizationFromContactsRecord},
+      {"urls", _contacts_contact.url, ImportContactWebSiteFromContactsRecord},
+      {"addresses", _contacts_contact.address,
+       ImportContactAddressFromContactsRecord},
+      {"messengers", _contacts_contact.messenger,
+       ImportContactInstantMessengerFromContactsRecord},
+      {"relationships", _contacts_contact.relationship,
+       ImportContactRelationshipFromContactsRecord}, };
+
+  for (auto& data : imports) {
+    json::Array& array = out.insert(std::make_pair(data.name, json::Array()))
+                             .first->second.get<json::Array>();
+
+    for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(
+                                 contacts_record, data.property_id);
          i < n; ++i) {
-        JsonValue anniversary{json::Object{}};
-        if (ImportContactAnniversariesFromContactsRecord(contacts_record, i,
-                                                         &anniversary.get<JsonObject>())) {
-            anniversaries.push_back(anniversary);
-        } else {
-            out.insert(std::make_pair("birthday", anniversaries));
-        }
-    }
+      JsonValue val{json::Object{}};
+      data.import_func(contacts_record, i, &val.get<JsonObject>());
+      array.push_back(val);
+    }
+  }
+
+  //### ContactAnniversary: ###
+  json::Array& anniversaries =
+      out.insert(std::make_pair("anniversaries", json::Array()))
+          .first->second.get<json::Array>();
+  for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(
+                               contacts_record, _contacts_contact.event);
+       i < n; ++i) {
+    JsonValue anniversary{json::Object{}};
+    if (ImportContactAnniversariesFromContactsRecord(
+            contacts_record, i, &anniversary.get<JsonObject>())) {
+      anniversaries.push_back(anniversary);
+    } else {
+      out.insert(std::make_pair("birthday", anniversaries));
+    }
+  }
+
+  //### m_notes: ###
+  json::Array& notes = out.insert(std::make_pair("notes", json::Array()))
+                           .first->second.get<json::Array>();
+  for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(
+                               contacts_record, _contacts_contact.note);
+       i < n; ++i) {
+    notes.push_back(ImportContactNotesFromContactsRecord(contacts_record, i));
+  }
+
+  //### m_photo_uri ###
+  //### m_ringtone_uri ###
+  {
+    char* value = nullptr;
+    ContactUtil::GetStrFromRecord(
+        contacts_record, _contacts_contact.image_thumbnail_path, &value);
 
-    //### m_notes: ###
-    json::Array& notes =
-            out.insert(std::make_pair("notes", json::Array())).first->second.get<json::Array>();
-    for (unsigned int i = 0, n = ContactUtil::GetNumberOfChildRecord(contacts_record,
-                                                                     _contacts_contact.note);
-         i < n; ++i) {
-        notes.push_back(ImportContactNotesFromContactsRecord(contacts_record, i));
-    }
+    std::make_pair("photoURI", value ? JsonValue{value} : JsonValue{});
 
-    //### m_photo_uri ###
-    //### m_ringtone_uri ###
-    {
-        char* value = nullptr;
-        ContactUtil::GetStrFromRecord(contacts_record, _contacts_contact.image_thumbnail_path,
-                                      &value);
-
-        std::make_pair("photoURI", value ? JsonValue{value} : JsonValue{});
-
-        ContactUtil::GetStrFromRecord(contacts_record, _contacts_contact.ringtone_path, &value);
-        std::make_pair("ringtoneURI", value ? JsonValue{value} : JsonValue{});
-        value = nullptr;
-        ContactUtil::GetStrFromRecord(contacts_record, _contacts_contact.message_alert, &value);
-        out.insert(std::make_pair("messageAlertURI",
-                                  value ? json::Value{ConvertPathToUri(value)} : json::Value{}));
-        value = nullptr;
-        ContactUtil::GetStrFromRecord(contacts_record, _contacts_contact.vibration, &value);
-        out.insert(std::make_pair("vibrationURI",
-                                  value ? json::Value{ConvertPathToUri(value)} : json::Value{}));
-    }
+    ContactUtil::GetStrFromRecord(contacts_record,
+                                  _contacts_contact.ringtone_path, &value);
+    std::make_pair("ringtoneURI", value ? JsonValue{value} : JsonValue{});
+    value = nullptr;
+    ContactUtil::GetStrFromRecord(contacts_record,
+                                  _contacts_contact.message_alert, &value);
+    out.insert(std::make_pair(
+        "messageAlertURI",
+        value ? json::Value{ConvertPathToUri(value)} : json::Value{}));
+    value = nullptr;
+    ContactUtil::GetStrFromRecord(contacts_record, _contacts_contact.vibration,
+                                  &value);
+    out.insert(std::make_pair(
+        "vibrationURI",
+        value ? json::Value{ConvertPathToUri(value)} : json::Value{}));
+  }
 }
 
-void ExportContactToContactsRecord(contacts_record_h contacts_record, const json::Object& in)
-{
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGW("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    //### ContactName: ###
-    if (!IsNull(in, "name")) {
-        ExportContactNameToContactsRecord(contacts_record, FromJson<json::Object>(in, "name"));
-    }
-
-    typedef void (*ExportFunc)(contacts_record_h, const json::Object&);
-    struct ExportDataHelper {
-        unsigned int property_id;
-        const char* name;
-        ExportFunc export_func;
-    };
-    const ExportDataHelper exports[] = {
-            {_contacts_contact.email, "emails", ExportContactEmailAddressToContactsRecord},
-            {_contacts_contact.number, "phoneNumbers", ExportContactPhoneNumberToContactsRecord},
-            {_contacts_contact.company, "organizations", ExportContactOrganizationToContactsRecord},
-            {_contacts_contact.url, "urls", ExportContactWebSiteToContactsRecord},
-            {_contacts_contact.event, "anniversaries", ExportContactAnniversariesToContactsRecord},
-            {_contacts_contact.address, "addresses", ExportContactAddressToContactsRecord},
-            {_contacts_contact.messenger, "messengers",
-             ExportContactInstantMessengerToContactsRecord},
-            {_contacts_contact.relationship, "relationships",
-             ExportContactRelationshipToContactsRecord}, };
-
-    for (auto& data : exports) {
-        ContactUtil::ClearAllContactRecord(contacts_record, data.property_id);
-        const json::Array& elements = FromJson<json::Array>(in, data.name);
-        for (auto& element : elements) {
-            data.export_func(contacts_record, JsonCast<json::Object>(element));
-        }
-    }
-
-    {
-        //### m_notes: ###
-        ContactUtil::ClearAllContactRecord(contacts_record, _contacts_contact.note);
-        const json::Array& elements = FromJson<json::Array>(in, "notes");
-        for (auto& element : elements) {
-            auto& str = JsonCast<json::String>(element);
-            if (str.empty()) {
-                continue;
-            }
-            ExportNotesToContactsRecord(contacts_record, str);
-        }
-    }
-
-    // Contact.photoURI
-    if (IsNull(in, "photoURI")) {
-        contacts_record_h child_record = nullptr;
-        int err = contacts_record_create(_contacts_image._uri, &child_record);
-        ContactUtil::ErrorChecker(err, "Fail to create image uri record in database.");
-        ContactsRecordHPtr record(&child_record, ContactsDeleter);
-        err = contacts_record_add_child_record(contacts_record, _contacts_contact.image,
-                                               child_record);
-        ContactUtil::ErrorChecker(err, "Fail to add child to image uri.");
-        // Do not delete record, it is passed to the platform
-        record.release();
-    } else {
-        bool is_first = false;
-        contacts_record_h child_record = nullptr;
-        int err = contacts_record_get_child_record_at_p(contacts_record, _contacts_contact.image, 0,
-                                                        &child_record);
-        if (CONTACTS_ERROR_NONE != err || nullptr == child_record) {
-            err = contacts_record_create(_contacts_image._uri, &child_record);
-            ContactUtil::ErrorChecker(err, "Fail to create image uri record in database.");
-            is_first = true;
-        }
-        ContactsRecordHPtr record(&child_record, ContactsDeleter);
-        // TODO this was never used anywhere in the old module. Can this be removed?
-        // char *old_value_str = nullptr;
-        // ContactUtil::getStrFromRecord(child_record, _contacts_image.path, &old_value_str);
-
-        std::string real_path;
-        if (!IsNull(in, "photoURI")) {
-            real_path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "photoURI"));
-            ContactUtil::SetStrInRecord(child_record, _contacts_image.path, real_path.c_str());
-        }
-
-        if (is_first) {
-            err = contacts_record_add_child_record(contacts_record, _contacts_contact.image,
-                                                   child_record);
-            ContactUtil::ErrorChecker(err, "Fail to add child to image uri.");
-        }
-        // Do not delete record, it is passed to the platform
-        record.release();
+void ExportContactToContactsRecord(contacts_record_h contacts_record,
+                                   const json::Object& in) {
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGW("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  //### ContactName: ###
+  if (!IsNull(in, "name")) {
+    ExportContactNameToContactsRecord(contacts_record,
+                                      FromJson<json::Object>(in, "name"));
+  }
+
+  typedef void (*ExportFunc)(contacts_record_h, const json::Object&);
+  struct ExportDataHelper {
+    unsigned int property_id;
+    const char* name;
+    ExportFunc export_func;
+  };
+  const ExportDataHelper exports[] = {
+      {_contacts_contact.email, "emails",
+       ExportContactEmailAddressToContactsRecord},
+      {_contacts_contact.number, "phoneNumbers",
+       ExportContactPhoneNumberToContactsRecord},
+      {_contacts_contact.company, "organizations",
+       ExportContactOrganizationToContactsRecord},
+      {_contacts_contact.url, "urls", ExportContactWebSiteToContactsRecord},
+      {_contacts_contact.event, "anniversaries",
+       ExportContactAnniversariesToContactsRecord},
+      {_contacts_contact.address, "addresses",
+       ExportContactAddressToContactsRecord},
+      {_contacts_contact.messenger, "messengers",
+       ExportContactInstantMessengerToContactsRecord},
+      {_contacts_contact.relationship, "relationships",
+       ExportContactRelationshipToContactsRecord}, };
+
+  for (auto& data : exports) {
+    ContactUtil::ClearAllContactRecord(contacts_record, data.property_id);
+    const json::Array& elements = FromJson<json::Array>(in, data.name);
+    for (auto& element : elements) {
+      data.export_func(contacts_record, JsonCast<json::Object>(element));
+    }
+  }
+
+  {
+    //### m_notes: ###
+    ContactUtil::ClearAllContactRecord(contacts_record, _contacts_contact.note);
+    const json::Array& elements = FromJson<json::Array>(in, "notes");
+    for (auto& element : elements) {
+      auto& str = JsonCast<json::String>(element);
+      if (str.empty()) {
+        continue;
+      }
+      ExportNotesToContactsRecord(contacts_record, str);
+    }
+  }
+
+  // Contact.photoURI
+  if (IsNull(in, "photoURI")) {
+    contacts_record_h child_record = nullptr;
+    int err = contacts_record_create(_contacts_image._uri, &child_record);
+    ContactUtil::ErrorChecker(err,
+                              "Fail to create image uri record in database.");
+    ContactsRecordHPtr record(&child_record, ContactsDeleter);
+    err = contacts_record_add_child_record(
+        contacts_record, _contacts_contact.image, child_record);
+    ContactUtil::ErrorChecker(err, "Fail to add child to image uri.");
+    // Do not delete record, it is passed to the platform
+    record.release();
+  } else {
+    bool is_first = false;
+    contacts_record_h child_record = nullptr;
+    int err = contacts_record_get_child_record_at_p(
+        contacts_record, _contacts_contact.image, 0, &child_record);
+    if (CONTACTS_ERROR_NONE != err || nullptr == child_record) {
+      err = contacts_record_create(_contacts_image._uri, &child_record);
+      ContactUtil::ErrorChecker(err,
+                                "Fail to create image uri record in database.");
+      is_first = true;
     }
+    ContactsRecordHPtr record(&child_record, ContactsDeleter);
+    // TODO this was never used anywhere in the old module. Can this be removed?
+    // char *old_value_str = nullptr;
+    // ContactUtil::getStrFromRecord(child_record, _contacts_image.path,
+    // &old_value_str);
 
     std::string real_path;
-    // Contact.ringtoneURI
-    if (!IsNull(in, "ringtoneURI")) {
-        real_path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "ringtoneURI"));
-        ContactUtil::SetStrInRecord(contacts_record, _contacts_contact.ringtone_path,
-                                    real_path.c_str());
-    }
-    // Contact.messageAlertURI
-    if (!IsNull(in, "messageAlertURI")) {
-        real_path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "messageAlertURI"));
-        ContactUtil::SetStrInRecord(contacts_record, _contacts_contact.message_alert,
-                                    real_path.c_str());
+    if (!IsNull(in, "photoURI")) {
+      real_path =
+          ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "photoURI"));
+      ContactUtil::SetStrInRecord(child_record, _contacts_image.path,
+                                  real_path.c_str());
     }
 
-    // Contact.vibrationURI
-    if (!IsNull(in, "vibrationURI")) {
-        real_path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "vibrationURI"));
-        ContactUtil::SetStrInRecord(contacts_record, _contacts_contact.vibration,
-                                    real_path.c_str());
+    if (is_first) {
+      err = contacts_record_add_child_record(
+          contacts_record, _contacts_contact.image, child_record);
+      ContactUtil::ErrorChecker(err, "Fail to add child to image uri.");
     }
+    // Do not delete record, it is passed to the platform
+    record.release();
+  }
+
+  std::string real_path;
+  // Contact.ringtoneURI
+  if (!IsNull(in, "ringtoneURI")) {
+    real_path = ContactUtil::ConvertUriToPath(
+        FromJson<json::String>(in, "ringtoneURI"));
+    ContactUtil::SetStrInRecord(
+        contacts_record, _contacts_contact.ringtone_path, real_path.c_str());
+  }
+  // Contact.messageAlertURI
+  if (!IsNull(in, "messageAlertURI")) {
+    real_path = ContactUtil::ConvertUriToPath(
+        FromJson<json::String>(in, "messageAlertURI"));
+    ContactUtil::SetStrInRecord(
+        contacts_record, _contacts_contact.message_alert, real_path.c_str());
+  }
+
+  // Contact.vibrationURI
+  if (!IsNull(in, "vibrationURI")) {
+    real_path = ContactUtil::ConvertUriToPath(
+        FromJson<json::String>(in, "vibrationURI"));
+    ContactUtil::SetStrInRecord(contacts_record, _contacts_contact.vibration,
+                                real_path.c_str());
+  }
 }
 
-void ImportContactGroupFromContactsRecord(contacts_record_h contacts_record, json::Object* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    // contacts_record is protected by unique_ptr and its ownership is not passed here
-    if (!contacts_record) {
-        LOGE("Contacts record is null");
-        throw common::UnknownException("Contacts record is null");
-    }
-
-    // id
-    int int_val = 0;
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_group.id, &int_val);
-    out.insert(std::make_pair("id", json::Value{std::to_string(int_val)}));
-
-    // addressBookId
-    ContactUtil::GetIntFromRecord(contacts_record, _contacts_group.address_book_id, &int_val);
-    out.insert(std::make_pair("addressBookId", json::Value{std::to_string(int_val)}));
-
-    // name
-    char* value = nullptr;
-    ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.name, &value);
-    out.insert(std::make_pair("name", value ? JsonValue{value} : JsonValue{}));
-
-    // photoURI
-    value = nullptr;
-    ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.image_path, &value);
-    out.insert(std::make_pair("photoURI", value ? JsonValue{value} : JsonValue{}));
-
-    // ringtoneURI
-    value = nullptr;
-    ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.ringtone_path, &value);
-    out.insert(std::make_pair("ringtoneURI", value ? JsonValue{value} : JsonValue{}));
-
-    // is_read_only
-    bool bool_value = false;
-    ContactUtil::GetBoolFromRecord(contacts_record, _contacts_group.is_read_only, &bool_value);
-    out.insert(std::make_pair("readOnly", json::Value{bool_value}));
+void ImportContactGroupFromContactsRecord(contacts_record_h contacts_record,
+                                          json::Object* out_ptr) {
+  json::Object& out = *out_ptr;
+  // contacts_record is protected by unique_ptr and its ownership is not passed
+  // here
+  if (!contacts_record) {
+    LOGE("Contacts record is null");
+    throw common::UnknownException("Contacts record is null");
+  }
+
+  // id
+  int int_val = 0;
+  ContactUtil::GetIntFromRecord(contacts_record, _contacts_group.id, &int_val);
+  out.insert(std::make_pair("id", json::Value{std::to_string(int_val)}));
+
+  // addressBookId
+  ContactUtil::GetIntFromRecord(contacts_record,
+                                _contacts_group.address_book_id, &int_val);
+  out.insert(
+      std::make_pair("addressBookId", json::Value{std::to_string(int_val)}));
+
+  // name
+  char* value = nullptr;
+  ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.name, &value);
+  out.insert(std::make_pair("name", value ? JsonValue{value} : JsonValue{}));
+
+  // photoURI
+  value = nullptr;
+  ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.image_path,
+                                &value);
+  out.insert(
+      std::make_pair("photoURI", value ? JsonValue{value} : JsonValue{}));
+
+  // ringtoneURI
+  value = nullptr;
+  ContactUtil::GetStrFromRecord(contacts_record, _contacts_group.ringtone_path,
+                                &value);
+  out.insert(
+      std::make_pair("ringtoneURI", value ? JsonValue{value} : JsonValue{}));
+
+  // is_read_only
+  bool bool_value = false;
+  ContactUtil::GetBoolFromRecord(contacts_record, _contacts_group.is_read_only,
+                                 &bool_value);
+  out.insert(std::make_pair("readOnly", json::Value{bool_value}));
 }
 
-void ExportContactGroupToContactsRecord(contacts_record_h contacts_record, const json::Object& in)
-{
-    // name
-    ContactUtil::SetStrInRecord(contacts_record, _contacts_group.name,
-                                FromJson<json::String>(in, "name").c_str());
-
-    std::string real_path;
-    // photoURI
-    if (!IsNull(in, "photoURI")) {
-        real_path = ConvertUriToPath(FromJson<json::String>(in, "photoURI"));
-        ContactUtil::SetStrInRecord(contacts_record, _contacts_group.image_path, real_path.c_str());
-    }
-    // ringtoneURI
-    if (!IsNull(in, "ringtoneURI")) {
-        real_path = ContactUtil::ConvertUriToPath(FromJson<json::String>(in, "ringtoneURI"));
-        // NOTE in the original code real path was not read
-        ContactUtil::SetStrInRecord(contacts_record, _contacts_group.ringtone_path,
-                                    real_path.c_str());
-    }
+void ExportContactGroupToContactsRecord(contacts_record_h contacts_record,
+                                        const json::Object& in) {
+  // name
+  ContactUtil::SetStrInRecord(contacts_record, _contacts_group.name,
+                              FromJson<json::String>(in, "name").c_str());
+
+  std::string real_path;
+  // photoURI
+  if (!IsNull(in, "photoURI")) {
+    real_path = ConvertUriToPath(FromJson<json::String>(in, "photoURI"));
+    ContactUtil::SetStrInRecord(contacts_record, _contacts_group.image_path,
+                                real_path.c_str());
+  }
+  // ringtoneURI
+  if (!IsNull(in, "ringtoneURI")) {
+    real_path = ContactUtil::ConvertUriToPath(
+        FromJson<json::String>(in, "ringtoneURI"));
+    // NOTE in the original code real path was not read
+    ContactUtil::SetStrInRecord(contacts_record, _contacts_group.ringtone_path,
+                                real_path.c_str());
+  }
 }
 
 /**
  * @brief   Fills Person object with values from record
  * @param[in]   contacts_record_h  Record which is used to fill Person
  */
-void ImportPersonFromContactsRecord(contacts_record_h record, json::Object* out_ptr)
-{
-    if (nullptr == record) {
-        LoggerW("Platform person record did not set");
-        throw InvalidValuesException("Platform person record did not set");
-    }
-
-    json::Object& arguments_obj = *out_ptr;
-
-    int int_value = 0;
-    // id
-    ContactUtil::GetIntFromRecord(record, _contacts_person.id, &int_value);
-    arguments_obj.insert(std::make_pair("id", json::Value(std::to_string(int_value))));
-
-    char* char_value = nullptr;
-    // displayName
-    ContactUtil::GetStrFromRecord(record, _contacts_person.display_name, &char_value);
-    arguments_obj.insert(
-            std::make_pair("displayName", char_value ? json::Value(char_value) : json::Value{}));
-
-    // contactCount
-    ContactUtil::GetIntFromRecord(record, _contacts_person.link_count, &int_value);
-    arguments_obj.insert(
-            std::make_pair("contactCount", json::Value(static_cast<double>(int_value))));
-
-    bool bool_value = false;
-    // hasPhoneNumber
-    ContactUtil::GetBoolFromRecord(record, _contacts_person.has_phonenumber, &bool_value);
-    arguments_obj.insert(std::make_pair("hasPhoneNumber", json::Value(bool_value)));
-
-    // hasEmail
-    ContactUtil::GetBoolFromRecord(record, _contacts_person.has_email, &bool_value);
-    arguments_obj.insert(std::make_pair("hasEmail", json::Value(bool_value)));
-
-    // isFavorite
-    ContactUtil::GetBoolFromRecord(record, _contacts_person.is_favorite, &bool_value);
-    arguments_obj.insert(std::make_pair("isFavorite", json::Value(bool_value)));
-
-    // photoURI
-    ContactUtil::GetStrFromRecord(record, _contacts_person.image_thumbnail_path, &char_value);
-    arguments_obj.insert(
-            std::make_pair("photoURI", char_value ? json::Value(char_value) : json::Value{}));
-
-    // ringtoneURI
-    ContactUtil::GetStrFromRecord(record, _contacts_person.ringtone_path, &char_value);
-    arguments_obj.insert(
-            std::make_pair("ringtoneURI", char_value ? json::Value(char_value) : json::Value{}));
-
-    // displayContactId
-    ContactUtil::GetIntFromRecord(record, _contacts_person.display_contact_id, &int_value);
-    arguments_obj.insert(std::make_pair("displayContactId", std::to_string(int_value)));
+void ImportPersonFromContactsRecord(contacts_record_h record,
+                                    json::Object* out_ptr) {
+  if (nullptr == record) {
+    LoggerW("Platform person record did not set");
+    throw InvalidValuesException("Platform person record did not set");
+  }
+
+  json::Object& arguments_obj = *out_ptr;
+
+  int int_value = 0;
+  // id
+  ContactUtil::GetIntFromRecord(record, _contacts_person.id, &int_value);
+  arguments_obj.insert(
+      std::make_pair("id", json::Value(std::to_string(int_value))));
+
+  char* char_value = nullptr;
+  // displayName
+  ContactUtil::GetStrFromRecord(record, _contacts_person.display_name,
+                                &char_value);
+  arguments_obj.insert(std::make_pair(
+      "displayName", char_value ? json::Value(char_value) : json::Value{}));
+
+  // contactCount
+  ContactUtil::GetIntFromRecord(record, _contacts_person.link_count,
+                                &int_value);
+  arguments_obj.insert(std::make_pair(
+      "contactCount", json::Value(static_cast<double>(int_value))));
+
+  bool bool_value = false;
+  // hasPhoneNumber
+  ContactUtil::GetBoolFromRecord(record, _contacts_person.has_phonenumber,
+                                 &bool_value);
+  arguments_obj.insert(
+      std::make_pair("hasPhoneNumber", json::Value(bool_value)));
+
+  // hasEmail
+  ContactUtil::GetBoolFromRecord(record, _contacts_person.has_email,
+                                 &bool_value);
+  arguments_obj.insert(std::make_pair("hasEmail", json::Value(bool_value)));
+
+  // isFavorite
+  ContactUtil::GetBoolFromRecord(record, _contacts_person.is_favorite,
+                                 &bool_value);
+  arguments_obj.insert(std::make_pair("isFavorite", json::Value(bool_value)));
+
+  // photoURI
+  ContactUtil::GetStrFromRecord(record, _contacts_person.image_thumbnail_path,
+                                &char_value);
+  arguments_obj.insert(std::make_pair(
+      "photoURI", char_value ? json::Value(char_value) : json::Value{}));
+
+  // ringtoneURI
+  ContactUtil::GetStrFromRecord(record, _contacts_person.ringtone_path,
+                                &char_value);
+  arguments_obj.insert(std::make_pair(
+      "ringtoneURI", char_value ? json::Value(char_value) : json::Value{}));
+
+  // displayContactId
+  ContactUtil::GetIntFromRecord(record, _contacts_person.display_contact_id,
+                                &int_value);
+  arguments_obj.insert(
+      std::make_pair("displayContactId", std::to_string(int_value)));
 }
 
 /**
  * @brief   Updates contacts_record_h with values from Person object
  * @param[out]   contacts_record_h  Record which is updated
  */
-void ExportPersonToContactsRecord(contacts_record_h record, const json::Object& args)
-{
-    if (nullptr == record) {
-        LoggerE("Platform person object did not set");
-        throw UnknownException("Platform person object did not set");
-    }
-
-    ContactUtil::SetBoolInRecord(record, _contacts_person.is_favorite,
-                                 FromJson<bool>(args, "isFavorite"));
-    try
-    {
-        if (!IsNull(args, "photoURI") && !FromJson<json::String>(args, "photoURI").empty()) {
-            ContactUtil::SetStrInRecord(record, _contacts_person.image_thumbnail_path,
-                                        FromJson<json::String>(args, "photoURI").c_str());
-        } else {
-            ContactUtil::SetStrInRecord(record, _contacts_person.image_thumbnail_path, "");
-        }
-    }
-    catch (const BasePlatformException& ex)
-    {
-        LoggerD("Platform field is readonly. " << ex.message());
-    }
-    if (!IsNull(args, "ringtoneURI")) {
-        ContactUtil::SetStrInRecord(record, _contacts_person.ringtone_path,
-                                    FromJson<json::String>(args, "ringtoneURI").c_str());
+void ExportPersonToContactsRecord(contacts_record_h record,
+                                  const json::Object& args) {
+  if (nullptr == record) {
+    LoggerE("Platform person object did not set");
+    throw UnknownException("Platform person object did not set");
+  }
+
+  ContactUtil::SetBoolInRecord(record, _contacts_person.is_favorite,
+                               FromJson<bool>(args, "isFavorite"));
+  try {
+    if (!IsNull(args, "photoURI") &&
+        !FromJson<json::String>(args, "photoURI").empty()) {
+      ContactUtil::SetStrInRecord(
+          record, _contacts_person.image_thumbnail_path,
+          FromJson<json::String>(args, "photoURI").c_str());
     } else {
-        ContactUtil::SetStrInRecord(record, _contacts_person.ringtone_path, "");
-    }
-    if (!IsNull(args, "displayContactId")) {
-        ContactUtil::SetIntInRecord(record, _contacts_person.display_contact_id,
-                                    common::stol(FromJson<json::String>(args, "displayContactId")));
-    }
+      ContactUtil::SetStrInRecord(record, _contacts_person.image_thumbnail_path,
+                                  "");
+    }
+  }
+  catch (const BasePlatformException& ex) {
+    LoggerD("Platform field is readonly. " << ex.message());
+  }
+  if (!IsNull(args, "ringtoneURI")) {
+    ContactUtil::SetStrInRecord(
+        record, _contacts_person.ringtone_path,
+        FromJson<json::String>(args, "ringtoneURI").c_str());
+  } else {
+    ContactUtil::SetStrInRecord(record, _contacts_person.ringtone_path, "");
+  }
+  if (!IsNull(args, "displayContactId")) {
+    ContactUtil::SetIntInRecord(
+        record, _contacts_person.display_contact_id,
+        common::stol(FromJson<json::String>(args, "displayContactId")));
+  }
 }
 
-void UpdateAdditionalInformation(const ContactsRecordHPtr& contacts_record_ptr, JsonObject* out_ptr)
-{
-    json::Object& out = *out_ptr;
-    int int_value = -1;
-    ContactUtil::GetIntFromRecord(*contacts_record_ptr, _contacts_contact.person_id, &int_value);
-    out.insert(std::make_pair("personId", json::Value{std::to_string(int_value)}));
-    ContactUtil::GetIntFromRecord(*contacts_record_ptr, _contacts_contact.address_book_id,
-                                  &int_value);
-    out.insert(std::make_pair("addressBookId", json::Value{std::to_string(int_value)}));
-    ContactUtil::GetIntFromRecord(*contacts_record_ptr, _contacts_contact.changed_time, &int_value);
-    out.insert(std::make_pair("lastUpdated", json::Value{static_cast<double>(int_value)}));
-    bool bool_value = false;
-    ContactUtil::GetBoolFromRecord(*contacts_record_ptr, _contacts_contact.is_favorite,
-                                   &bool_value);
-    out.insert(std::make_pair("isFavorite", json::Value{bool_value}));
+void UpdateAdditionalInformation(const ContactsRecordHPtr& contacts_record_ptr,
+                                 JsonObject* out_ptr) {
+  json::Object& out = *out_ptr;
+  int int_value = -1;
+  ContactUtil::GetIntFromRecord(*contacts_record_ptr,
+                                _contacts_contact.person_id, &int_value);
+  out.insert(
+      std::make_pair("personId", json::Value{std::to_string(int_value)}));
+  ContactUtil::GetIntFromRecord(*contacts_record_ptr,
+                                _contacts_contact.address_book_id, &int_value);
+  out.insert(
+      std::make_pair("addressBookId", json::Value{std::to_string(int_value)}));
+  ContactUtil::GetIntFromRecord(*contacts_record_ptr,
+                                _contacts_contact.changed_time, &int_value);
+  out.insert(std::make_pair("lastUpdated",
+                            json::Value{static_cast<double>(int_value)}));
+  bool bool_value = false;
+  ContactUtil::GetBoolFromRecord(*contacts_record_ptr,
+                                 _contacts_contact.is_favorite, &bool_value);
+  out.insert(std::make_pair("isFavorite", json::Value{bool_value}));
 }
 
 }  // ContactUtil
index 489db31..ad4481f 100644 (file)
@@ -37,86 +37,113 @@ extern const char *kContactReadPrivileges;
 extern const char *kContactWritePrivileges;
 
 void ContactsDeleter(contacts_record_h *contacts_record);
-typedef std::unique_ptr<contacts_record_h, void (*)(contacts_record_h *)> ContactsRecordHPtr;
+typedef std::unique_ptr<contacts_record_h, void (*)(contacts_record_h *)>
+    ContactsRecordHPtr;
 
 void ContactsListDeleter(contacts_list_h *contacts_list);
-typedef std::unique_ptr<contacts_list_h, void (*)(contacts_list_h *)> ContactsListHPtr;
+typedef std::unique_ptr<contacts_list_h, void (*)(contacts_list_h *)>
+    ContactsListHPtr;
 
 void ContactsFilterDeleter(contacts_filter_h contacts_filter);
-typedef std::unique_ptr<std::remove_pointer<contacts_filter_h>::type, void (*)(contacts_filter_h)>
-        ContactsFilterPtr;
+typedef std::unique_ptr<std::remove_pointer<contacts_filter_h>::type,
+                        void (*)(contacts_filter_h)> ContactsFilterPtr;
 
 void ContactsQueryDeleter(contacts_query_h *contacts_query);
-typedef std::unique_ptr<contacts_query_h, void (*)(contacts_query_h *)> ContactsQueryHPtr;
+typedef std::unique_ptr<contacts_query_h, void (*)(contacts_query_h *)>
+    ContactsQueryHPtr;
 
 void ErrorChecker(int err, const char *message);
 
-void GetStrFromRecord(contacts_record_h record, unsigned int property_id, char **value);
+void GetStrFromRecord(contacts_record_h record, unsigned int property_id,
+                      char **value);
 
-void GetIntFromRecord(contacts_record_h record, unsigned int property_id, int *value);
+void GetIntFromRecord(contacts_record_h record, unsigned int property_id,
+                      int *value);
 
-void GetBoolFromRecord(contacts_record_h record, unsigned int property_id, bool *value);
+void GetBoolFromRecord(contacts_record_h record, unsigned int property_id,
+                       bool *value);
 
-void SetStrInRecord(contacts_record_h record, unsigned int property_id, const char *value);
+void SetStrInRecord(contacts_record_h record, unsigned int property_id,
+                    const char *value);
 
-void SetIntInRecord(contacts_record_h record, unsigned int property_id, int value);
+void SetIntInRecord(contacts_record_h record, unsigned int property_id,
+                    int value);
 
-void SetBoolInRecord(contacts_record_h record, unsigned int property_id, bool value);
+void SetBoolInRecord(contacts_record_h record, unsigned int property_id,
+                     bool value);
 
-void ClearAllContactRecord(contacts_record_h contacts_record, unsigned int property_id);
+void ClearAllContactRecord(contacts_record_h contacts_record,
+                           unsigned int property_id);
 
-unsigned int GetNumberOfChildRecord(contacts_record_h contacts_record, unsigned int property_id);
+unsigned int GetNumberOfChildRecord(contacts_record_h contacts_record,
+                                    unsigned int property_id);
 
-void UpdateAdditionalInformation(const ContactsRecordHPtr &contacts_record_ptr, JsonObject *out);
+void UpdateAdditionalInformation(const ContactsRecordHPtr &contacts_record_ptr,
+                                 JsonObject *out);
 
-JsonValue ImportBirthdayFromContactsRecord(contacts_record_h contacts_record, unsigned int index);
-void ExportBirthdayToContactsRecord(contacts_record_h contacts_record, int date);
-bool ImportContactNameFromContactsRecord(contacts_record_h contacts_record, JsonObject *out);
-void ExportContactNameToContactsRecord(contacts_record_h contacts_record, const JsonObject &in);
-void ImportContactEmailAddressFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, JsonObject *out);
-void ExportContactEmailAddressToContactsRecord(contacts_record_h contacts_record,
-                                               const JsonObject &in);
+JsonValue ImportBirthdayFromContactsRecord(contacts_record_h contacts_record,
+                                           unsigned int index);
+void ExportBirthdayToContactsRecord(contacts_record_h contacts_record,
+                                    int date);
+bool ImportContactNameFromContactsRecord(contacts_record_h contacts_record,
+                                         JsonObject *out);
+void ExportContactNameToContactsRecord(contacts_record_h contacts_record,
+                                       const JsonObject &in);
+void ImportContactEmailAddressFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
+void ExportContactEmailAddressToContactsRecord(
+    contacts_record_h contacts_record, const JsonObject &in);
 
-void ImportContactAddressFromContactsRecord(contacts_record_h contacts_record, unsigned int index,
+void ImportContactAddressFromContactsRecord(contacts_record_h contacts_record,
+                                            unsigned int index,
                                             JsonObject *out);
-void ExportContactAddressToContactsRecord(contacts_record_h contacts_record, const JsonObject &in);
-void ImportContactPhoneNumberFromContactsRecord(contacts_record_h contacts_record,
-                                                unsigned int index, JsonObject *out);
+void ExportContactAddressToContactsRecord(contacts_record_h contacts_record,
+                                          const JsonObject &in);
+void ImportContactPhoneNumberFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
 void ExportContactPhoneNumberToContactsRecord(contacts_record_h contacts_record,
                                               const JsonObject &in);
-void ImportContactOrganizationFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, JsonObject *out);
-void ExportContactOrganizationToContactsRecord(contacts_record_h contacts_record,
-                                               const JsonObject &in);
-void ImportContactWebSiteFromContactsRecord(contacts_record_h contacts_record, unsigned int index,
+void ImportContactOrganizationFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
+void ExportContactOrganizationToContactsRecord(
+    contacts_record_h contacts_record, const JsonObject &in);
+void ImportContactWebSiteFromContactsRecord(contacts_record_h contacts_record,
+                                            unsigned int index,
                                             JsonObject *out);
-void ExportContactWebSiteToContactsRecord(contacts_record_h contacts_record, const JsonObject &in);
-bool ImportContactAnniversariesFromContactsRecord(contacts_record_h contacts_record,
-                                                  unsigned int index, JsonObject *out);
-void ExportContactAnniversariesToContactsRecord(contacts_record_h contacts_record,
-                                                const JsonObject &in);
-void ImportContactRelationshipFromContactsRecord(contacts_record_h contacts_record,
-                                                 unsigned int index, JsonObject *out);
-void ExportContactRelationshipToContactsRecord(contacts_record_h contacts_record,
-                                               const JsonObject &in);
-void ImportContactInstantMessengerFromContactsRecord(contacts_record_h contacts_record,
-                                                     unsigned int index, JsonObject *out);
-void ExportContactInstantMessengerToContactsRecord(contacts_record_h contacts_record,
-                                                   const JsonObject &in);
-
-JsonValue ImportContactNotesFromContactsRecord(contacts_record_h contacts_record,
-                                               unsigned int index);
-JsonValue ImportContactNotesFromContactsRecord(contacts_record_h contacts_record,
-                                               unsigned int index);
-void ExportNotesToContactsRecord(contacts_record_h contacts_record, const std::string &value);
-void ImportContactFromContactsRecord(contacts_record_h contacts_record, JsonObject *out);
-void ExportPersonToContactsRecord(contacts_record_h record, const JsonObject &args);
-
-void ExportContactToContactsRecord(contacts_record_h contacts_record, const JsonObject &in);
-void ImportContactGroupFromContactsRecord(contacts_record_h contacts_record, JsonObject *out);
-void ExportContactGroupToContactsRecord(contacts_record_h contacts_record, const JsonObject &in);
-void ImportPersonFromContactsRecord(contacts_record_h contacts_record, JsonObject *out);
+void ExportContactWebSiteToContactsRecord(contacts_record_h contacts_record,
+                                          const JsonObject &in);
+bool ImportContactAnniversariesFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
+void ExportContactAnniversariesToContactsRecord(
+    contacts_record_h contacts_record, const JsonObject &in);
+void ImportContactRelationshipFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
+void ExportContactRelationshipToContactsRecord(
+    contacts_record_h contacts_record, const JsonObject &in);
+void ImportContactInstantMessengerFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index, JsonObject *out);
+void ExportContactInstantMessengerToContactsRecord(
+    contacts_record_h contacts_record, const JsonObject &in);
+
+JsonValue ImportContactNotesFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index);
+JsonValue ImportContactNotesFromContactsRecord(
+    contacts_record_h contacts_record, unsigned int index);
+void ExportNotesToContactsRecord(contacts_record_h contacts_record,
+                                 const std::string &value);
+void ImportContactFromContactsRecord(contacts_record_h contacts_record,
+                                     JsonObject *out);
+void ExportPersonToContactsRecord(contacts_record_h record,
+                                  const JsonObject &args);
+
+void ExportContactToContactsRecord(contacts_record_h contacts_record,
+                                   const JsonObject &in);
+void ImportContactGroupFromContactsRecord(contacts_record_h contacts_record,
+                                          JsonObject *out);
+void ExportContactGroupToContactsRecord(contacts_record_h contacts_record,
+                                        const JsonObject &in);
+void ImportPersonFromContactsRecord(contacts_record_h contacts_record,
+                                    JsonObject *out);
 
 }  // ContactUtil
 }  // contact
index f271c8b..2e477d7 100644 (file)
@@ -38,101 +38,101 @@ static const PersonPropertyMap personPropertyMap = {
     {"displayContactId",        { _contacts_person.display_contact_id,  kPrimitiveTypeId } },
 };
 
-void Person_link(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
+void Person_link(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
 
-    long id = common::stol(FromJson<json::String>(args, "id"));
-    long person_id = common::stol(FromJson<json::String>(args, "person", "id"));
+  long id = common::stol(FromJson<json::String>(args, "id"));
+  long person_id = common::stol(FromJson<json::String>(args, "person", "id"));
 
-    contacts_record_h contacts_record = nullptr;
+  contacts_record_h contacts_record = nullptr;
 
-    int err = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
-    contacts_record_destroy(contacts_record, true);
-    contacts_record = nullptr;
+  int err = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
+  contacts_record_destroy(contacts_record, true);
+  contacts_record = nullptr;
 
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("Person was not found, error code: %d", err);
-        throw common::NotFoundException("Person not found");
-    }
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("Person was not found, error code: %d", err);
+    throw common::NotFoundException("Person not found");
+  }
 
-    err = contacts_person_link_person(person_id, id);
+  err = contacts_person_link_person(person_id, id);
 
-    if (CONTACTS_ERROR_NONE != err) {
-        LOGW("person link fails, error code: %d", err);
-        throw common::UnknownException("Error during executing person link()");
-    }
+  if (CONTACTS_ERROR_NONE != err) {
+    LOGW("person link fails, error code: %d", err);
+    throw common::UnknownException("Error during executing person link()");
+  }
 
-    NativePlugin::ReportSuccess(out);
+  NativePlugin::ReportSuccess(out);
 }
 
-void Person_unlink(const JsonObject& args, JsonObject& out)
-{
-    NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
-
-    long contact_id = common::stol(FromJson<json::String>(args, "id"));
+void Person_unlink(const JsonObject& args, JsonObject& out) {
+  NativePlugin::CheckAccess(ContactUtil::kContactWritePrivileges);
 
-    contacts_record_h contacts_record = nullptr;
-    int error_code =
-            contacts_db_get_record(_contacts_simple_contact._uri, contact_id, &contacts_record);
+  long contact_id = common::stol(FromJson<json::String>(args, "id"));
 
-    if (CONTACTS_ERROR_NONE != error_code) {
-        contacts_record_destroy(contacts_record, true);
-        contacts_record = nullptr;
-        LOGW("Contact not found, error code: %d", error_code);
-        throw common::InvalidValuesException("Contact not found");
-    }
+  contacts_record_h contacts_record = nullptr;
+  int error_code = contacts_db_get_record(_contacts_simple_contact._uri,
+                                          contact_id, &contacts_record);
 
-    int contacts_person_id = 0;
-    error_code = contacts_record_get_int(contacts_record, _contacts_simple_contact.person_id,
-                                         &contacts_person_id);
+  if (CONTACTS_ERROR_NONE != error_code) {
     contacts_record_destroy(contacts_record, true);
     contacts_record = nullptr;
-
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGW("Contact is not a member of person, error code: %d", error_code);
-        throw common::UnknownException("Contact is not a member of person");
-    }
-
-    long person_id = common::stol(FromJson<json::String>(args, "person", "id"));
-    if (contacts_person_id != person_id) {
-        LOGW("Contact is not a member of person (wrong id's)");
-        throw common::InvalidValuesException("Contact is not a member of person");
-    }
-
-    int new_person_id = 0;
-
-    error_code = contacts_person_unlink_contact(person_id, contact_id, &new_person_id);
-    if (CONTACTS_ERROR_NONE != error_code) {
-        LOGW("Error during executing unlink(), error code: %d", error_code);
-        throw common::UnknownException("Error during executing unlink()");
-    }
-
-    error_code = contacts_db_get_record(_contacts_person._uri, new_person_id, &contacts_record);
-    if (CONTACTS_ERROR_NONE != error_code) {
-        contacts_record_destroy(contacts_record, true);
-        contacts_record = nullptr;
-        LOGW("Person not found, error code: %d", error_code);
-        throw common::UnknownException("Person not found");
-    }
-
-    json::Value person{json::Object{}};
-    ContactUtil::ImportPersonFromContactsRecord(contacts_record, &person.get<json::Object>());
-
+    LOGW("Contact not found, error code: %d", error_code);
+    throw common::InvalidValuesException("Contact not found");
+  }
+
+  int contacts_person_id = 0;
+  error_code = contacts_record_get_int(
+      contacts_record, _contacts_simple_contact.person_id, &contacts_person_id);
+  contacts_record_destroy(contacts_record, true);
+  contacts_record = nullptr;
+
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGW("Contact is not a member of person, error code: %d", error_code);
+    throw common::UnknownException("Contact is not a member of person");
+  }
+
+  long person_id = common::stol(FromJson<json::String>(args, "person", "id"));
+  if (contacts_person_id != person_id) {
+    LOGW("Contact is not a member of person (wrong id's)");
+    throw common::InvalidValuesException("Contact is not a member of person");
+  }
+
+  int new_person_id = 0;
+
+  error_code =
+      contacts_person_unlink_contact(person_id, contact_id, &new_person_id);
+  if (CONTACTS_ERROR_NONE != error_code) {
+    LOGW("Error during executing unlink(), error code: %d", error_code);
+    throw common::UnknownException("Error during executing unlink()");
+  }
+
+  error_code = contacts_db_get_record(_contacts_person._uri, new_person_id,
+                                      &contacts_record);
+  if (CONTACTS_ERROR_NONE != error_code) {
     contacts_record_destroy(contacts_record, true);
     contacts_record = nullptr;
+    LOGW("Person not found, error code: %d", error_code);
+    throw common::UnknownException("Person not found");
+  }
+
+  json::Value person{json::Object{}};
+  ContactUtil::ImportPersonFromContactsRecord(contacts_record,
+                                              &person.get<json::Object>());
+
+  contacts_record_destroy(contacts_record, true);
+  contacts_record = nullptr;
 
-    NativePlugin::ReportSuccess(person, out);
+  NativePlugin::ReportSuccess(person, out);
 }
 
-const PersonProperty& PersonProperty_fromString(const std::string& name)
-{
-    auto iter = personPropertyMap.find(name);
-    if (iter == personPropertyMap.end()) {
-        LoggerE("Invalid property name (not in map): %s", name.c_str());
-        throw InvalidValuesException("Invalid property name");
-    }
-    return iter->second;
+const PersonProperty& PersonProperty_fromString(const std::string& name) {
+  auto iter = personPropertyMap.find(name);
+  if (iter == personPropertyMap.end()) {
+    LoggerE("Invalid property name (not in map): %s", name.c_str());
+    throw InvalidValuesException("Invalid property name");
+  }
+  return iter->second;
 }
 
 }  // Person
index 2916bab..e9fde46 100644 (file)
@@ -25,8 +25,8 @@ namespace contact {
 namespace Person {
 
 struct PersonProperty {
-    const unsigned int propertyId;
-    const webapi::common::PrimitiveType type;
+  const unsigned int propertyId;
+  const webapi::common::PrimitiveType type;
 };
 
 typedef std::map<std::string, PersonProperty> PersonPropertyMap;