// TODO implement contact filter and sorting.
const JsonObject& address_book = FromJson<JsonObject>(args, "addressBook");
long addressbook_id = common::stol(FromJson<std::string>(address_book, "id"));
- // Read calendar by ID
- int error_code = 0;
+ int error_code;
contacts_query_h query = nullptr;
contacts_filter_h filter = nullptr;
int record_count = 0;
error_code = contacts_list_get_count(list, &record_count);
+ ContactUtil::ErrorChecker(error_code, "Failed contacts_list_get_count");
contacts_list_first(list);
for (unsigned int i = 0; i < record_count; i++) {
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::ErrorChecker(err, "Error during executing contacts_record_create()");
- ContactUtil::ContactsRecordHPtr record(&contacts_record,
- ContactUtil::ContactsDeleter);
+ ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter);
- long addressbook_id =
- common::stol(FromJson<JsonString>(args, "addressBookId"));
+ long addressbook_id = common::stol(FromJson<JsonString>(args, "addressBookId"));
addressbook_id = (IsUnified(addressbook_id)) ? 0 : addressbook_id;
- ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id,
- addressbook_id);
+ ContactUtil::SetIntInRecord(contacts_record, _contacts_group.address_book_id, addressbook_id);
ContactUtil::ExportContactGroupToContactsRecord(contacts_record, group);
int groupId = 0;
ContactUtil::ErrorChecker(err, "Error during insert group record");
out.insert(std::make_pair("id", std::to_string(groupId)));
- out.insert(
- std::make_pair("addressBookId", std::to_string(addressbook_id)));
+ out.insert(std::make_pair("addressBookId", std::to_string(addressbook_id)));
}
void AddressBook_getGroup(const JsonObject& args, JsonObject& out) {
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");
+ LoggerE("Group not exist");
+ throw common::NotFoundException("Group not exist");
}
- ContactUtil::ContactsRecordHPtr record(&contacts_record,
- ContactUtil::ContactsDeleter);
+ ContactUtil::ContactsRecordHPtr record(&contacts_record, ContactUtil::ContactsDeleter);
- long addressbook_id =
- common::stol(FromJson<JsonString>(args, "addressBook", "id"));
+ long addressbook_id = common::stol(FromJson<JsonString>(args, "addressBook", "id"));
if (IsUnified(addressbook_id)) {
int address_book_id = 0;
ContactUtil::GetIntFromRecord(
throw common::InvalidValuesException("Group object is not added");
}
- long addressbook_id =
- common::stol(FromJson<JsonString>(args, "addressBookId"));
- long group_addressbook_id =
- common::stol(FromJson<JsonString>(group, "addressBookId"));
+ long addressbook_id = common::stol(FromJson<JsonString>(args, "addressBookId"));
+ long group_addressbook_id = common::stol(FromJson<JsonString>(group, "addressBookId"));
if (IsUnified(addressbook_id) && (addressbook_id != group_addressbook_id)) {
LoggerE("Wrong address book");
throw common::InvalidValuesException("Wrong address book");
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) {
- LoggerE("Error during executing contacts_db_get_record()");
- throw common::NotFoundException(
- "Error during executing contacts_db_get_record()");
+ int err = contacts_db_get_record(_contacts_group._uri, group_id, &contacts_record);
+ if (CONTACTS_ERROR_NONE != err || nullptr == contacts_record) {
+ LoggerE("Group not exist");
+ throw common::NotFoundException("Group not exist");
}
ContactUtil::ErrorChecker(err,
throw common::InvalidValuesException("Incorrect group id");
}
- int err = CONTACTS_ERROR_NONE;
+ int err;
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) {
- LoggerE("No group");
- throw common::UnknownException("No group");
+ throw common::NotFoundException("Group not exist");
}
int group_addressbook_id = 0;
&group_addressbook_id);
if (group_addressbook_id != addressbook_id) {
- throw common::UnknownException(
- "Contact is not a member of this address book");
+ throw common::UnknownException("Contact is not a member of this address book");
}
}
err = contacts_db_delete_record(_contacts_group._uri, id);
if (CONTACTS_ERROR_INVALID_PARAMETER == err) {
- LoggerE("Problem during db_update_record");
- throw common::NotFoundException("Problem during db_delete_record");
+ throw common::UnknownException("Problem during db_delete_record");
}
ContactUtil::ErrorChecker(err, "Problem during db_delete_record");
}
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);
+ int 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);
}
void ContactManager_get(const JsonObject& args, JsonObject& out) {
ContactUtil::CheckDBConnection();
- long person_id = common::stol(FromJson<JsonString>(args, "personID"));
+ long person_id = common::stol(FromJson<JsonString>(args, "personId"));
- JsonValue val{JsonObject{}};
ContactManager_get_internal(person_id, &out);
}
ContactUtil::CheckDBConnection();
const JsonObject& person = FromJson<JsonObject>(args, "person");
long person_id = common::stol(FromJson<JsonString>(person, "id"));
- int error_code = 0;
contacts_record_h contacts_record = nullptr;
- error_code = contacts_db_get_record(_contacts_person._uri, person_id,
- &contacts_record);
+ int 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");
+ throw NotFoundException("Person not found");
}
ContactUtil::ExportPersonToContactsRecord(contacts_record, person);
};
AddressBook.prototype.get = function() {
- var args = AV.validateArgs(arguments, [
- {
- name: 'id',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'id',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.id)) !== args.id) {
+ // TCT: AddressBook_get_id_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('AddressBook_get', {
// TODO move to only sending the address book id (in all functions)
};
AddressBook.prototype.remove = function() {
- var args = AV.validateArgs(arguments, [
- {
- name: 'id',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'id',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.id)) !== args.id) {
+ // TCT: AddressBook_remove_id_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('AddressBook_remove', {
addressBook: this,
};
AddressBook.prototype.getGroup = function() {
- var args = AV.validateArgs(arguments, [
- {
- name: 'groupId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'groupId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.groupId)) !== args.groupId) {
+ // TCT: AddressBook_getGroup_groupId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
- var result = native_.callSync('AddressBook_getGroup',
- {addressBook: this, id: args.groupId});
+ var result = native_.callSync('AddressBook_getGroup', {
+ addressBook: this,
+ id: args.groupId
+ });
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
};
AddressBook.prototype.removeGroup = function() {
- var args = AV.validateArgs(arguments, [
- {
- name: 'groupId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'groupId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.groupId)) !== args.groupId) {
+ // TCT: AddressBook_removeGroup_groupId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('AddressBook_removeGroup',
{addressBook: this, id: args.groupId});
// Gets the address book with the specified identifier.
ContactManager.prototype.getAddressBook = function() {
- // validation
- var args = AV.validateArgs(arguments, [
- {
- name: 'addressBookId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'addressBookId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.addressBookId)) !== args.addressBookId) {
+ // TCT: ContactManager_getAddressBook_addressBookId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
+ }
var result = native_.callSync('ContactManager_getAddressBook', {
addressBookID: args.addressBookId
}
]);
+ if (String(Converter.toLong(args.personId)) !== args.personId) {
+ // TCT: ContactManager_get_personId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
+
var result = native_.callSync('ContactManager_get', {
- personID: args.personId
+ personId: args.personId
});
_checkError(result);
// Updates a person in the address book synchronously.
ContactManager.prototype.update = function() {
// validation
- var args = AV.validateArgs(arguments, [
- {
- name: 'person',
- type: AV.Types.PLATFORM_OBJECT,
- values: Person,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'person',
+ type: AV.Types.PLATFORM_OBJECT,
+ values: Person,
+ optional: false,
+ nullable: false
+ }]);
var result = native_.callSync('ContactManager_update', { person: args.person });
_checkError(result);
// Removes a person from the contact DB synchronously.
ContactManager.prototype.remove = function() {
// validation
- var args = AV.validateArgs(arguments, [
- {
- name: 'personId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'personId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.personId)) !== args.personId) {
+ // TCT: ContactManager_remove_personId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('ContactManager_remove', {personId: args.personId});
_checkError(result);
// Aggregates another person to this person.
Person.prototype.link = function() {
- var args = AV.validateArgs(arguments, [
- {
- name: 'personId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'personId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.personId)) !== args.personId) {
+ // TCT: Person_link_personId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('Person_link', {
// TODO move to only sending the person id (in all functions)
// Separates a contact from this person.
Person.prototype.unlink = function(contactId) {
- var args = AV.validateArgs(arguments, [
- {
- name: 'contactId',
- type: AV.Types.STRING,
- optional: false,
- nullable: false
- }
- ]);
+ var args = AV.validateArgs(arguments, [{
+ name: 'contactId',
+ type: AV.Types.STRING,
+ optional: false,
+ nullable: false
+ }]);
+
+ if (String(Converter.toLong(args.contactId)) !== args.contactId) {
+ // TCT: Person_unlink_contactId_invalid
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
var result = native_.callSync('Person_unlink', {
// TODO move to only sending the person id (in all functions)