}
void AddressBook_remove(const JsonObject& args, JsonObject&) {
+ LoggerE("entered");
ContactUtil::CheckDBConnection();
- long contact_id = common::stol(FromJson<JsonString>(args, "id"));
+ int contact_id = common::stol(FromJson<JsonString>(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);
+ int err = contacts_db_delete_record(_contacts_contact._uri, contact_id);
if (CONTACTS_ERROR_NO_DATA == err) {
- LoggerW("Remove failed: contact not found, error code: %d", err);
throw common::NotFoundException("Remove failed: contact not found");
} else if (CONTACTS_ERROR_NONE != err) {
- LoggerW("Contacts record delete error, error code: %d", err);
throw common::UnknownException("Contacts record delete error");
}
}
ContactUtil::CheckDBConnection();
- long addressBookId = -1;
const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
- addressBookId = common::stol(FromJson<JsonString>(args, "addressBookId"));
+ long addressBookId = common::stol(FromJson<JsonString>(args, "addressBookId"));
addressBookId = addressBookId == -1 ? 0 : addressBookId;
unsigned length = batch_args.size();
- int error_code = 0;
contacts_list_h contacts_list = NULL;
- error_code = contacts_list_create(&contacts_list);
+ int error_code = contacts_list_create(&contacts_list);
if (CONTACTS_ERROR_NONE != error_code) {
LoggerE("list creation failed, code: %d", error_code);
throw new common::UnknownException("list creation failed");
}
- ContactUtil::ContactsListHPtr contacts_list_ptr(
- &contacts_list, ContactUtil::ContactsListDeleter);
+ ContactUtil::ContactsListHPtr contacts_list_ptr(&contacts_list, ContactUtil::ContactsListDeleter);
for (auto& item : batch_args) {
contacts_record_h contacts_record = nullptr;
LoggerW("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<JsonObject>(item));
- ContactUtil::SetIntInRecord(
- contacts_record, _contacts_contact.address_book_id, addressBookId);
+ ContactUtil::ContactsRecordHPtr x(&contacts_record, ContactUtil::ContactsDeleter);
+ ContactUtil::ExportContactToContactsRecord(contacts_record, JsonCast<JsonObject>(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) {
LoggerE("error during add record to list, code: %d", error_code);
for (unsigned int i = 0; i < count; i++) {
JsonObject out_object;
contacts_record_h contact_record = nullptr;
- error_code =
- contacts_db_get_record(_contacts_contact._uri, ids[i], &contact_record);
+ error_code = contacts_db_get_record(_contacts_contact._uri, ids[i], &contact_record);
if (CONTACTS_ERROR_NONE != error_code) {
if (ids) {
free(ids);
}
}
-void AddressBook_batchFunc(/*NativeFunction impl, */const char* single_arg_name,
- const JsonObject& args/*, JsonObject& out*/) {
- // @todo implement
- throw common::NotFoundException("Not implemented");
+// TODO all batch operations should be implemented using CAPI batch functions
+void AddressBook_batchFunc(NativeFunction impl, const char *single_arg_name,
+ const JsonObject &args, JsonArray &out) {
+ const JsonArray &batch_args = FromJson<JsonArray>(args, "batchArgs");
+ const JsonObject &address_book = FromJson<JsonObject>(args, "addressBook");
+
+ int i = 0;
+ for (auto &item : batch_args) {
+ ++i;
+ JsonObject single_args{};
+
+ single_args.insert(std::make_pair("addressBook", address_book));
+ single_args.insert(std::make_pair(single_arg_name, item));
+
+ JsonObject single_out;
+ impl(single_args, single_out);
+ if (!single_out.empty()) {
+ out.push_back(JsonValue{single_out});
+ }
+ }
}
void AddressBook_find(const JsonObject& args, JsonArray& array) {
REGISTER_SYNC("ContactManager_getAddressBook", ContactManager_getAddressBook);
REGISTER_SYNC("ContactManager_get", ContactManager_get);
REGISTER_SYNC("ContactManager_update", ContactManager_update);
- REGISTER_SYNC("ContactManager_updateBatch", ContactManager_updateBatch);
+ REGISTER_ASYNC("ContactManager_updateBatch", ContactManager_updateBatch);
REGISTER_SYNC("ContactManager_remove", ContactManager_remove);
- REGISTER_SYNC("ContactManager_removeBatch", ContactManager_removeBatch);
+ REGISTER_ASYNC("ContactManager_removeBatch", ContactManager_removeBatch);
REGISTER_ASYNC("ContactManager_find", ContactManager_find);
REGISTER_SYNC("ContactManager_importFromVCard", ContactManager_importFromVCard);
REGISTER_SYNC("ContactManager_startListening", ContactManager_startListening);
// AddressBook
REGISTER_ASYNC("AddressBook_addBatch", AddressBook_addBatch);
+ REGISTER_ASYNC("AddressBook_updateBatch", AddressBook_updateBatch);
+ REGISTER_ASYNC("AddressBook_removeBatch", AddressBook_removeBatch);
REGISTER_SYNC("AddressBook_get", AddressBook_get);
REGISTER_SYNC("AddressBook_add", AddressBook_add);
REGISTER_SYNC("AddressBook_update", AddressBook_update);
const double callback_id = args.get("callbackId").get<double>();
- auto get = [=](const std::shared_ptr<JsonValue>& response)->void {
- try {
- JsonValue result = JsonValue(JsonArray());
- AddressBook::AddressBook_addBatch(common::JsonCast<JsonObject>(args),
- result.get<JsonArray>());
- ReportSuccess(result, response->get<JsonObject>());
- } catch (const PlatformException& e) {
- ReportError(e, response->get<JsonObject>());
- }
+ auto get = [=](const std::shared_ptr <JsonValue> &response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ AddressBook::AddressBook_addBatch(common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+ ReportSuccess(result, response->get<JsonObject>());
+ } catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
+ }
};
- auto get_response = [this, callback_id](const std::shared_ptr<JsonValue>& response) {
- JsonObject& obj = response->get<JsonObject>();
- obj.insert(std::make_pair("callbackId", callback_id));
- PostMessage(response->serialize().c_str());
+ auto get_response = [this, callback_id](const std::shared_ptr <JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
+}
+
+void ContactInstance::AddressBook_removeBatch(const JsonValue &args, JsonObject &out) {
+ LoggerD("entered");
+ // TODO check privileges
+
+ const double callback_id = args.get("callbackId").get<double>();
+
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ // TODO all batch operations should be implemented using CAPI batch functions
+ AddressBook::AddressBook_batchFunc(AddressBook::AddressBook_remove, "id",
+ common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+
+ ReportSuccess(result, response->get<JsonObject>());
+ }
+ catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
+ }
+ };
+
+ auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
+}
+
+void ContactInstance::AddressBook_updateBatch(const JsonValue& args, JsonObject& out) {
+ LoggerD("entered");
+ // TODO check privileges
+
+ const double callback_id = args.get("callbackId").get<double>();
+
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ // TODO all batch operations should be implemented using CAPI batch functions
+ AddressBook::AddressBook_batchFunc(AddressBook::AddressBook_update, "contact",
+ common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+
+ ReportSuccess(result, response->get<JsonObject>());
+ }
+ catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
+ }
+ };
+
+ auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ PostMessage(response->serialize().c_str());
};
TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
LoggerD("entered");
const double callback_id = args.get("callbackId").get<double>();
- auto get = [=](const std::shared_ptr <JsonValue>& response) -> void {
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
try {
JsonValue result = JsonValue(JsonArray());
- AddressBook::AddressBook_find(common::JsonCast<JsonObject>(args),
- result.get<JsonArray>());
- ReportSuccess(result, response->get<picojson::object>());
- } catch (const PlatformException& e) {
- ReportError(e, response->get<picojson::object>());
+ AddressBook::AddressBook_find(JsonCast<JsonObject>(args), result.get<JsonArray>());
+ ReportSuccess(result, response->get<JsonObject>());
+ } catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
}
};
- auto get_response = [this, callback_id](const std::shared_ptr <JsonValue>& response) {
- picojson::object& obj = response->get<picojson::object>();
+ auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
obj.insert(std::make_pair("callbackId", callback_id));
PostMessage(response->serialize().c_str());
-
};
TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
JsonValue result = JsonValue(JsonArray());
ContactManager::ContactManager_getAddressBooks(common::JsonCast<JsonObject>(args),
result.get<JsonArray>());
- ReportSuccess(result, response->get<picojson::object>());
+ ReportSuccess(result, response->get<JsonObject>());
} catch (const PlatformException &e) {
- ReportError(e, response->get<picojson::object>());
+ ReportError(e, response->get<JsonObject>());
}
};
auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
- picojson::object &obj = response->get<picojson::object>();
+ JsonObject &obj = response->get<JsonObject>();
obj.insert(std::make_pair("callbackId", callback_id));
PostMessage(response->serialize().c_str());
};
ReportSuccess(out);
}
-void ContactInstance::ContactManager_updateBatch(const JsonValue& args, JsonObject& out) {
- // @todo implement
+void ContactInstance::ContactManager_updateBatch(const JsonValue &args, JsonObject &out) {
+ LoggerD("entered");
+ // TODO check privileges
+
+ const double callback_id = args.get("callbackId").get<double>();
+
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ // TODO all batch operations should be implemented using CAPI batch functions
+ AddressBook::AddressBook_batchFunc(ContactManager::ContactManager_update, "person",
+ common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+
+ ReportSuccess(result, response->get<JsonObject>());
+ }
+ catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
+ }
+ };
+
+ auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void ContactInstance::ContactManager_remove(const JsonValue& args, JsonObject& out) {
ReportSuccess(out);
}
-void ContactInstance::ContactManager_removeBatch(const JsonValue& args, JsonObject& out) {
- // @todo implement
+void ContactInstance::ContactManager_removeBatch(const JsonValue &args, JsonObject &out) {
+ LoggerD("entered");
+ // TODO check privileges
+
+ const double callback_id = args.get("callbackId").get<double>();
+
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
+ try {
+ JsonValue result = JsonValue(JsonArray());
+ // TODO all batch operations should be implemented using CAPI batch functions
+ AddressBook::AddressBook_batchFunc(ContactManager::ContactManager_remove, "personId",
+ common::JsonCast<JsonObject>(args),
+ result.get<JsonArray>());
+
+ ReportSuccess(result, response->get<JsonObject>());
+ }
+ catch (const PlatformException &e) {
+ ReportError(e, response->get<JsonObject>());
+ }
+ };
+
+ auto get_response = [this, callback_id](const std::shared_ptr<JsonValue> &response) {
+ JsonObject &obj = response->get<JsonObject>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ PostMessage(response->serialize().c_str());
+ };
+
+ TaskQueue::GetInstance().Queue<JsonValue>(get, get_response,
+ std::shared_ptr<JsonValue>(new JsonValue(JsonObject())));
}
void ContactInstance::ContactManager_find(const JsonValue &args, JsonObject &out) {
JsonValue result = JsonValue(JsonArray());
ContactManager::ContactManager_find(common::JsonCast<JsonObject>(args),
result.get<JsonArray>());
- ReportSuccess(result, response->get<picojson::object>());
+ ReportSuccess(result, response->get<JsonObject>());
} catch (const PlatformException &e) {
- ReportError(e, response->get<picojson::object>());
+ ReportError(e, response->get<JsonObject>());
}
};
auto get_response = [this, callback_id](const std::shared_ptr <JsonValue> &response) {
- picojson::object &obj = response->get<picojson::object>();
+ JsonObject &obj = response->get<JsonObject>();
obj.insert(std::make_pair("callbackId", callback_id));
PostMessage(response->serialize().c_str());
};