2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file ContactObjectA2PConverter.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
22 * @brief Converter (ContactPtr -> contacts_record_h)
25 #include "ContactObjectA2PConverter.h"
27 #include <Commons/Exception.h>
28 #include "ContactUtility.h"
34 using namespace WrtDeviceApis::Commons;
37 static const char *EMPTY_STRING = "";
39 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
41 m_abstractContact(abstractContact),
42 m_platformContact(NULL),
43 m_forScratch(forScratch),
44 m_convertFinished(false),
45 m_platformContactOwnership(false)
49 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
51 contacts_record_h platformContact) :
52 m_abstractContact(abstractContact),
53 m_platformContact(platformContact),
54 m_forScratch(forScratch),
55 m_convertFinished(false),
56 m_platformContactOwnership(false)
60 ContactObjectA2PConverter::~ContactObjectA2PConverter()
62 if(m_platformContactOwnership && m_platformContact != NULL)
64 contacts_record_destroy(m_platformContact, true);
65 m_platformContact = NULL;
66 m_platformContactOwnership = false;
70 contacts_record_h ContactObjectA2PConverter::getPlatformContact()
76 if(m_abstractContact == NULL)
78 LoggerE("Abstract contact object did not set");
79 ThrowMsg(InvalidArgumentException, "Abstract contact object did not set");
82 if(m_platformContact == NULL)
84 if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
86 int id = ContactUtility::strToInt(m_abstractContact->getId());
87 errorCode = contacts_db_get_record(_contacts_contact._uri, id, &m_platformContact);
88 if(errorCode != CONTACTS_ERROR_NONE)
89 ThrowMsg(UnknownException, "error on contacts_db_get_record (errorCode:" << errorCode << ")");
93 LoggerD("New platform object has been created");
94 errorCode = contacts_record_create(_contacts_contact._uri, &m_platformContact);
95 if(errorCode != CONTACTS_ERROR_NONE)
96 ThrowMsg(UnknownException, "error on contacts_record_create (errorCode:" << errorCode << ")");
99 m_platformContactOwnership = true;
104 if(m_convertFinished == false)
105 convertToPlatformObject();
109 LoggerE("Error while converting - " << _rethrown_exception.GetMessage());
110 ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
113 return m_platformContact;
116 void ContactObjectA2PConverter::convertToPlatformObject()
118 importBaseInfoValue();
124 importGrouprelList();
128 importNicknameList();
130 m_convertFinished = true;
133 void ContactObjectA2PConverter::importBaseInfoValue()
136 contacts_record_h child_record = NULL;
138 const char *newValueStr = NULL;
139 char *oldValueStr = NULL;
140 string abstractValueStr;
144 if(!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty())
146 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
147 if(errorCode != CONTACTS_ERROR_NONE)
148 ThrowMsg(UnknownException, "creating image value A (errorCode:" << errorCode << ")");
149 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
153 bool is_first = false;
154 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
155 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
157 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
158 if(errorCode != CONTACTS_ERROR_NONE)
159 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
163 contacts_record_get_str_p(child_record, _contacts_image.path, &oldValueStr);
164 realPath = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
165 m_abstractContact->setPhotoURIRealPath(realPath);
166 abstractValueStr = m_abstractContact->getPhotoURIRealPath();
167 if(oldValueStr != NULL &&
168 (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
170 newValueStr = EMPTY_STRING;
172 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
174 newValueStr = abstractValueStr.c_str();
177 if(newValueStr != NULL)
179 errorCode = contacts_record_set_str(child_record, _contacts_image.path, newValueStr);
180 if(errorCode != CONTACTS_ERROR_NONE)
182 ThrowMsg(PlatformException, "importing photoURI E (err:" << errorCode);
187 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
190 // Contact.ringtoneURI
193 contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &oldValueStr);
194 realPath = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
195 m_abstractContact->setRingtoneURIRealPath(realPath);
196 abstractValueStr = m_abstractContact->getRingtoneURIRealPath();
197 if(oldValueStr != NULL &&
198 (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
200 newValueStr = EMPTY_STRING;
202 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
204 newValueStr = abstractValueStr.c_str();
207 if(newValueStr != NULL)
209 errorCode = contacts_record_set_str(m_platformContact, _contacts_contact.ringtone_path, newValueStr);
210 if(errorCode != CONTACTS_ERROR_NONE)
212 ThrowMsg(PlatformException, "importing ringtoneURI E (err:" << errorCode);
217 void ContactObjectA2PConverter::importNameValue()
220 contacts_record_h child_record = NULL;
222 ContactNamePtr contactName = m_abstractContact->getName();
223 if(contactName == NULL ||
224 (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
225 && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
226 && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
227 && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
228 && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
229 && ( !contactName->getSuffixIsSet() || contactName->getSuffix().empty() )
230 && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() ) ) )
232 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
233 if(errorCode != CONTACTS_ERROR_NONE)
234 ThrowMsg(UnknownException, "creating name value A (errorCode:" << errorCode << ")");
235 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
239 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
240 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
242 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
243 if(errorCode != CONTACTS_ERROR_NONE)
244 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
246 importNameValueToNewValue(child_record, contactName);
250 importNameValueToExistingValue(child_record, contactName);
253 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
256 void ContactObjectA2PConverter::importNameValueToExistingValue(contacts_record_h child_record, ContactNamePtr &contactName)
260 const char *newValueStr = NULL;
261 char *oldValueStr = NULL;
262 string abstractValueStr;
264 // ContactName.firstName
265 contacts_record_get_str_p(child_record, _contacts_name.first, &oldValueStr);
266 abstractValueStr = contactName->getFirstName();
267 if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
269 newValueStr = EMPTY_STRING;
271 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
273 newValueStr = abstractValueStr.c_str();
276 if(newValueStr != NULL)
278 errorCode = contacts_record_set_str(child_record, _contacts_name.first, newValueStr);
279 if(errorCode != CONTACTS_ERROR_NONE)
281 contacts_record_destroy(child_record, true);
282 ThrowMsg(PlatformException, "importing firstName E (err:" << errorCode);
286 // ContactName.lastName
289 contacts_record_get_str_p(child_record, _contacts_name.last, &oldValueStr);
290 abstractValueStr = contactName->getLastName();
291 if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
293 newValueStr = EMPTY_STRING;
295 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
297 newValueStr = abstractValueStr.c_str();
300 if(newValueStr != NULL)
302 errorCode = contacts_record_set_str(child_record, _contacts_name.last, newValueStr);
303 if(errorCode != CONTACTS_ERROR_NONE)
305 contacts_record_destroy(child_record, true);
306 ThrowMsg(PlatformException, "importing lastName E (err:" << errorCode);
310 // ContactName.middleName
313 contacts_record_get_str_p(child_record, _contacts_name.addition, &oldValueStr);
314 abstractValueStr = contactName->getMiddleName();
315 if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
317 newValueStr = EMPTY_STRING;
319 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
321 newValueStr = abstractValueStr.c_str();
324 if(newValueStr != NULL)
326 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, newValueStr);
327 if(errorCode != CONTACTS_ERROR_NONE)
329 contacts_record_destroy(child_record, true);
330 ThrowMsg(PlatformException, "importing middleName E (err:" << errorCode);
334 // ContactName.prefix
337 contacts_record_get_str_p(child_record, _contacts_name.prefix, &oldValueStr);
338 abstractValueStr = contactName->getPrefix();
339 if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
341 newValueStr = EMPTY_STRING;
343 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
345 newValueStr = abstractValueStr.c_str();
348 if(newValueStr != NULL)
350 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, newValueStr);
351 if(errorCode != CONTACTS_ERROR_NONE)
353 contacts_record_destroy(child_record, true);
354 ThrowMsg(PlatformException, "importing prefix E (err:" << errorCode);
358 // ContactName.suffix
361 contacts_record_get_str_p(child_record, _contacts_name.suffix, &oldValueStr);
362 abstractValueStr = contactName->getSuffix();
363 if(oldValueStr != NULL && (!contactName->getSuffixIsSet() || abstractValueStr.empty()) )
365 newValueStr = EMPTY_STRING;
367 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
369 newValueStr = abstractValueStr.c_str();
372 if(newValueStr != NULL)
374 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, newValueStr);
375 if(errorCode != CONTACTS_ERROR_NONE)
377 contacts_record_destroy(child_record, true);
378 ThrowMsg(PlatformException, "importing suffix E (err:" << errorCode);
382 // ContactName.phoneticFirstName
385 contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &oldValueStr);
386 abstractValueStr = contactName->getPhoneticFirstName();
387 if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
389 newValueStr = EMPTY_STRING;
391 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
393 newValueStr = abstractValueStr.c_str();
396 if(newValueStr != NULL)
398 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, newValueStr);
399 if(errorCode != CONTACTS_ERROR_NONE)
401 contacts_record_destroy(child_record, true);
402 ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" << errorCode);
406 // ContactName.phoneticLastName
409 contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &oldValueStr);
410 abstractValueStr = contactName->getPhoneticLastName();
411 if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
413 newValueStr = EMPTY_STRING;
415 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
417 newValueStr = abstractValueStr.c_str();
420 if(newValueStr != NULL)
422 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, newValueStr);
423 if(errorCode != CONTACTS_ERROR_NONE)
425 contacts_record_destroy(child_record, true);
426 ThrowMsg(PlatformException, "importing phoneticLastName E (err:" << errorCode);
431 void ContactObjectA2PConverter::importNameValueToNewValue(contacts_record_h child_record, ContactNamePtr &contactName)
435 // ContactName.firstName
436 if(contactName->getFirstNameIsSet())
438 string firstName = contactName->getFirstName();
439 if(firstName != EMPTY_STRING)
441 errorCode = contacts_record_set_str(child_record, _contacts_name.first, firstName.c_str());
442 if(errorCode != CONTACTS_ERROR_NONE)
444 contacts_record_destroy(child_record, true);
445 ThrowMsg(PlatformException, "importing firstName N (err:" << errorCode);
450 // ContactName.lastName
451 if(contactName->getLastNameIsSet())
453 string lastName = contactName->getLastName();
454 if(lastName != EMPTY_STRING)
456 errorCode = contacts_record_set_str(child_record, _contacts_name.last, lastName.c_str());
457 if(errorCode != CONTACTS_ERROR_NONE)
459 contacts_record_destroy(child_record, true);
460 ThrowMsg(PlatformException, "importing lastName N (err:" << errorCode);
465 // ContactName.middleName
466 if(contactName->getMiddleNameIsSet())
468 string middleName = contactName->getMiddleName();
469 if(middleName != EMPTY_STRING)
471 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, middleName.c_str());
472 if(errorCode != CONTACTS_ERROR_NONE)
474 contacts_record_destroy(child_record, true);
475 ThrowMsg(PlatformException, "importing middleName N (err:" << errorCode);
480 // ContactName.prefix
481 if(contactName->getPrefixIsSet())
483 string prefix = contactName->getPrefix();
484 if(prefix != EMPTY_STRING)
486 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, prefix.c_str());
487 if(errorCode != CONTACTS_ERROR_NONE)
489 contacts_record_destroy(child_record, true);
490 ThrowMsg(PlatformException, "importing prefix N (err:" << errorCode);
495 // ContactName.suffix
496 if(contactName->getSuffixIsSet())
498 string suffix = contactName->getSuffix();
499 if(suffix != EMPTY_STRING)
501 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, suffix.c_str());
502 if(errorCode != CONTACTS_ERROR_NONE)
504 contacts_record_destroy(child_record, true);
505 ThrowMsg(PlatformException, "importing suffix N (err:" << errorCode);
510 // ContactName.phoneticFirstName
511 if(contactName->getPhoneticFirstNameIsSet())
513 string phoneticFirstName = contactName->getPhoneticFirstName();
514 if(phoneticFirstName != EMPTY_STRING)
516 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, phoneticFirstName.c_str());
517 if(errorCode != CONTACTS_ERROR_NONE)
519 contacts_record_destroy(child_record, true);
520 ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" << errorCode);
525 // ContactName.phoneticLastName
526 if(contactName->getPhoneticLastNameIsSet())
528 string phoneticLastName = contactName->getPhoneticLastName();
529 if(phoneticLastName != EMPTY_STRING)
531 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, phoneticLastName.c_str());
532 if(errorCode != CONTACTS_ERROR_NONE)
534 contacts_record_destroy(child_record, true);
535 ThrowMsg(PlatformException, "importing phoneticLastName N (err:" << errorCode);
541 void ContactObjectA2PConverter::importCompanyList()
544 contacts_record_h child_record = NULL;
545 unsigned int record_count = 0;
547 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &record_count);
548 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
550 ThrowMsg(PlatformException, "getting company count (err:" << errorCode << ")");
553 for(int i=record_count-1; i>=0; i--)
555 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
556 if(errorCode != CONTACTS_ERROR_NONE)
557 ThrowMsg(UnknownException, "getting company value A (errorCode:" << errorCode << ")");
559 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.company, child_record);
560 if(errorCode != CONTACTS_ERROR_NONE)
561 ThrowMsg(UnknownException, "removing company value A (errorCode:" << errorCode << ")");
566 ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
567 if(organizations->size() == 0)
570 ContactOrganizationArray::iterator organizationsIter = organizations->begin();
571 for(; organizationsIter != organizations->end(); organizationsIter++)
573 ContactOrganizationPtr organization = *organizationsIter;
577 errorCode = contacts_record_create(_contacts_company._uri, &child_record);
578 if(errorCode != CONTACTS_ERROR_NONE)
580 LoggerW("Fail to create child_record with contacts_record_create(_contacts_company._uri)");
584 // ContactOrganization.name
585 if(organization->getNameIsSet())
587 string name = organization->getName();
590 errorCode = contacts_record_set_str(child_record, _contacts_company.name, name.c_str());
591 if(errorCode != CONTACTS_ERROR_NONE)
593 LoggerW("importing company name N (err:" << errorCode);
594 contacts_record_destroy(child_record, true);
600 // ContactOrganization.department
601 if(organization->getDepartmentIsSet())
603 string department = organization->getDepartment();
604 if(!department.empty())
606 errorCode = contacts_record_set_str(child_record, _contacts_company.department, department.c_str());
607 if(errorCode != CONTACTS_ERROR_NONE)
609 LoggerW("importing department N (err:" << errorCode);
610 contacts_record_destroy(child_record, true);
616 // ContactOrganization.title
617 if(organization->getTitleIsSet())
619 string title = organization->getTitle();
622 errorCode = contacts_record_set_str(child_record, _contacts_company.job_title, title.c_str());
623 if(errorCode != CONTACTS_ERROR_NONE)
625 LoggerW("importing title N (err:" << errorCode);
626 contacts_record_destroy(child_record, true);
632 // ContactOrganization.role
633 if(organization->getRoleIsSet())
635 string role = organization->getRole();
638 errorCode = contacts_record_set_str(child_record, _contacts_company.role, role.c_str());
639 if(errorCode != CONTACTS_ERROR_NONE)
641 LoggerW("importing role N (err:" << errorCode);
642 contacts_record_destroy(child_record, true);
648 // ContactOrganization.logoURI
649 if(organization->getLogoURIIsSet())
651 string logoURI = organization->getLogoURI();
654 logoURI = ContactUtility::convertUriToPath(logoURI);
655 errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
656 if(errorCode != CONTACTS_ERROR_NONE)
658 LoggerW("importing logoURI N (err:" << errorCode);
659 contacts_record_destroy(child_record, true);
665 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.company, child_record);
666 if(errorCode != CONTACTS_ERROR_NONE)
668 LoggerW("Fail to set company value to child_record");
669 contacts_record_destroy(child_record, true);
675 void ContactObjectA2PConverter::importNoteList()
678 contacts_record_h child_record = NULL;
679 unsigned int record_count = 0;
681 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &record_count);
682 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
684 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
687 for(int i=record_count-1; i>=0; i--)
689 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
690 if(errorCode != CONTACTS_ERROR_NONE)
691 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
693 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.note, child_record);
694 if(errorCode != CONTACTS_ERROR_NONE)
695 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
700 StringArrayPtr notes = m_abstractContact->getNotes();
701 if(notes->size() == 0)
704 StringArray::iterator notesIter = notes->begin();
705 for(; notesIter != notes->end(); notesIter++)
707 string note = *notesIter;
716 errorCode = contacts_record_create(_contacts_note._uri, &child_record);
717 if(errorCode != CONTACTS_ERROR_NONE)
719 LoggerW("Fail to create child_record with contacts_record_create(_contacts_note._uri)");
723 errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
724 if(errorCode != CONTACTS_ERROR_NONE)
726 LoggerW("importing note N (err:" << errorCode);
727 contacts_record_destroy(child_record, true);
731 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.note, child_record);
732 if(errorCode != CONTACTS_ERROR_NONE)
734 LoggerW("Fail to set note value to child_record");
735 contacts_record_destroy(child_record, true);
741 void ContactObjectA2PConverter::importNumberList()
744 contacts_record_h child_record = NULL;
745 unsigned int record_count = 0;
747 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &record_count);
748 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
750 ThrowMsg(PlatformException, "getting number count (err:" << errorCode << ")");
753 for(int i=record_count-1; i>=0; i--)
755 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
756 if(errorCode != CONTACTS_ERROR_NONE)
757 ThrowMsg(UnknownException, "getting number value A (errorCode:" << errorCode << ")");
759 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.number, child_record);
760 if(errorCode != CONTACTS_ERROR_NONE)
761 ThrowMsg(UnknownException, "removing number value A (errorCode:" << errorCode << ")");
766 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
767 if(phoneNumbers->size() == 0)
770 ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
771 for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
773 ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
774 ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
776 if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
778 LoggerD("Number was not set.");
782 string number = phoneNumber->getNumber();
784 bool ctsBoolDefault = phoneNumber->getIsDefault();
787 //char *ctsStrCustomType = NULL;
789 ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
790 for(; typesIter != types->end(); typesIter++)
792 ContactPhoneNumberType type = *typesIter;
793 if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
794 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_HOME;
795 else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
796 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_WORK;
797 else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
798 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
799 else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
800 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_FAX;
801 else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
802 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MSG;
803 else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
804 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CELL;
805 else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
806 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PAGER;
807 else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
808 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_BBS;
809 else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
810 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MODEM;
811 else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
812 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CAR;
813 else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
814 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_ISDN;
815 else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
816 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VIDEO;
817 else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
818 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PCS;
820 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
825 errorCode = contacts_record_create(_contacts_number._uri, &child_record);
826 if(errorCode != CONTACTS_ERROR_NONE)
828 LoggerW("Fail to create child_record with contacts_record_create(_contacts_number._uri)");
832 errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
833 if(errorCode != CONTACTS_ERROR_NONE)
835 LoggerW("Fail to set number value to child_record number");
836 contacts_record_destroy(child_record, true);
840 errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
841 if(errorCode != CONTACTS_ERROR_NONE)
843 LoggerW("Fail to set number value to child_record default ");
844 contacts_record_destroy(child_record, true);
848 errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
849 if(errorCode != CONTACTS_ERROR_NONE)
851 LoggerW("Fail to set number value to child_record type ");
852 contacts_record_destroy(child_record, true);
856 //if(ctsStrCustomType != NULL)
858 // errorCode = contacts_record_set_str(child_record, _contacts_number.label, ctsStrCustomType);
859 // if(errorCode != CONTACTS_ERROR_NONE)
861 // LoggerW("Fail to set number value to child_record custom type : " << ctsStrCustomType);
862 // contacts_record_destroy(child_record, true);
867 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.number, child_record);
868 if(errorCode != CONTACTS_ERROR_NONE)
870 LoggerW("Fail to set number value to child_record");
871 contacts_record_destroy(child_record, true);
877 void ContactObjectA2PConverter::importEmailList()
880 contacts_record_h child_record = NULL;
881 unsigned int record_count = 0;
883 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &record_count);
884 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
886 ThrowMsg(PlatformException, "getting email count (err:" << errorCode << ")");
889 for(int i=record_count-1; i>=0; i--)
891 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
892 if(errorCode != CONTACTS_ERROR_NONE)
893 ThrowMsg(UnknownException, "getting email value A (errorCode:" << errorCode << ")");
895 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.email, child_record);
896 if(errorCode != CONTACTS_ERROR_NONE)
897 ThrowMsg(UnknownException, "removing email value A (errorCode:" << errorCode << ")");
902 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
903 if(emails->size() == 0)
906 ContactEmailAddressArray::iterator emailsIter = emails->begin();
907 for(; emailsIter != emails->end(); emailsIter++)
909 ContactEmailAddressPtr email = *emailsIter;
910 ContactEmailAddressTypeArrayPtr types = email->getTypes();
912 if(!email->getEmailIsSet() || email->getEmail().empty())
914 LoggerD("email address was not set.");
918 string emailAddress = email->getEmail();
920 bool ctsBoolDefault = email->getIsDefault();
923 //char *ctsStrCustomType = NULL;
925 ContactEmailAddressTypeArray::iterator typesIter = types->begin();
926 for(; typesIter != types->end(); typesIter++)
928 ContactEmailAddressType type = *typesIter;
929 if(type == CONTACT_EMAIL_TYPE_HOME)
930 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
931 else if(type == CONTACT_EMAIL_TYPE_WORK)
932 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_WORK;
934 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
939 errorCode = contacts_record_create(_contacts_email._uri, &child_record);
940 if(errorCode != CONTACTS_ERROR_NONE)
942 LoggerW("Fail to create child_record with contacts_record_create(_contacts_email._uri)");
946 errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
947 if(errorCode != CONTACTS_ERROR_NONE)
949 LoggerW("Fail to set email value to child_record email ");
950 contacts_record_destroy(child_record, true);
954 errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
955 if(errorCode != CONTACTS_ERROR_NONE)
957 LoggerW("Fail to set email value to child_record default ");
958 contacts_record_destroy(child_record, true);
962 errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
963 if(errorCode != CONTACTS_ERROR_NONE)
965 LoggerW("Fail to set email value to child_record type ");
966 contacts_record_destroy(child_record, true);
970 //if(ctsStrCustomType != NULL)
972 // errorCode = contacts_record_set_str(child_record, _contacts_email.label, ctsStrCustomType);
973 // if(errorCode != CONTACTS_ERROR_NONE)
975 // LoggerW("Fail to set email value to child_record custom type : " << ctsStrCustomType);
976 // contacts_record_destroy(child_record, true);
981 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.email, child_record);
982 if(errorCode != CONTACTS_ERROR_NONE)
984 LoggerW("Fail to set email value to child_record");
985 contacts_record_destroy(child_record, true);
991 void ContactObjectA2PConverter::importGrouprelList()
994 contacts_record_h child_record = NULL;
995 unsigned int record_count = 0;
997 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &record_count);
998 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1000 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
1003 for(int i=record_count-1; i>=0; i--)
1005 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
1006 if(errorCode != CONTACTS_ERROR_NONE)
1007 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
1009 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1010 if(errorCode != CONTACTS_ERROR_NONE)
1011 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
1013 child_record = NULL;
1016 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
1017 if(groupIds->size() == 0)
1020 StringArray::iterator groupIdsIter = groupIds->begin();
1021 for(; groupIdsIter != groupIds->end(); groupIdsIter++)
1023 string groupId = *groupIdsIter;
1025 child_record = NULL;
1027 if(!ContactUtility::checkStrIsUInt(groupId))
1030 int groupIdInt = ContactUtility::strToInt(groupId);
1032 errorCode = contacts_record_create(_contacts_group_relation._uri, &child_record);
1033 if(errorCode != CONTACTS_ERROR_NONE)
1035 LoggerW("Fail to create child_record with contacts_record_create(_contacts_group_relation._uri)");
1039 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
1040 if(errorCode != CONTACTS_ERROR_NONE)
1042 LoggerW("importing group id N (err:" << errorCode);
1043 contacts_record_destroy(child_record, true);
1047 int contactId = ContactUtility::strToInt(m_abstractContact->getId());
1048 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
1049 if(errorCode != CONTACTS_ERROR_NONE)
1051 LoggerW("importing group contact_id N (err:" << errorCode);
1052 contacts_record_destroy(child_record, true);
1056 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1057 if(errorCode != CONTACTS_ERROR_NONE)
1059 LoggerW("Fail to set group value to child_record");
1060 contacts_record_destroy(child_record, true);
1066 void ContactObjectA2PConverter::importEventList()
1069 contacts_record_h child_record = NULL;
1070 unsigned int record_count = 0;
1072 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &record_count);
1073 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1075 ThrowMsg(PlatformException, "getting event count (err:" << errorCode << ")");
1078 for(int i=record_count-1; i>=0; i--)
1080 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
1081 if(errorCode != CONTACTS_ERROR_NONE)
1082 ThrowMsg(UnknownException, "getting event value A (errorCode:" << errorCode << ")");
1084 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.event, child_record);
1085 if(errorCode != CONTACTS_ERROR_NONE)
1086 ThrowMsg(UnknownException, "removing event value A (errorCode:" << errorCode << ")");
1088 child_record = NULL;
1091 if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
1094 importEventListBirthday();
1096 importEventListAnniversary();
1099 void ContactObjectA2PConverter::importEventListBirthday()
1103 if(!m_abstractContact->getBirthdayIsSet())
1106 tm birthdayTm = m_abstractContact->getBirthday();
1108 if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
1111 int birthday = ContactUtility::toDateDbInt(birthdayTm);
1113 contacts_record_h child_record = NULL;
1115 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1116 if(errorCode != CONTACTS_ERROR_NONE)
1118 LoggerW("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1122 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
1123 if(errorCode != CONTACTS_ERROR_NONE)
1125 LoggerW("Fail to set event value to child_record type, birthday");
1126 contacts_record_destroy(child_record, true);
1130 errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
1131 if(errorCode != CONTACTS_ERROR_NONE)
1133 LoggerW("Fail to set event value to child_record date");
1134 contacts_record_destroy(child_record, true);
1138 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1139 if(errorCode != CONTACTS_ERROR_NONE)
1141 LoggerW("Fail to set event value to child_record");
1142 contacts_record_destroy(child_record, true);
1147 void ContactObjectA2PConverter::importEventListAnniversary()
1150 contacts_record_h child_record = NULL;
1152 if(m_abstractContact->getAnniversariesNum() == 0)
1155 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
1157 ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
1158 for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
1160 ContactAnniversaryPtr anniversary = *anniversariesIter;
1162 if(!anniversary->getDateIsSet())
1165 tm dateTm = anniversary->getDate();
1167 if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
1170 int date = ContactUtility::toDateDbInt(dateTm);
1172 child_record = NULL;
1174 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1175 if(errorCode != CONTACTS_ERROR_NONE)
1177 LoggerW("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1181 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
1182 if(errorCode != CONTACTS_ERROR_NONE)
1184 LoggerW("Fail to set event value to child_record type : CONTACTS_EVENT_TYPE_ANNIVERSARY");
1185 contacts_record_destroy(child_record, true);
1189 errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
1190 if(errorCode != CONTACTS_ERROR_NONE)
1192 LoggerW("Fail to set event value to child_record date");
1193 contacts_record_destroy(child_record, true);
1197 if(anniversary->getLabelIsSet())
1199 string label = anniversary->getLabel();
1200 errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
1201 if(errorCode != CONTACTS_ERROR_NONE)
1203 LoggerW("Fail to set label value to child_record label");
1204 contacts_record_destroy(child_record, true);
1210 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1211 if(errorCode != CONTACTS_ERROR_NONE)
1213 LoggerW("Fail to set event value to child_record");
1214 contacts_record_destroy(child_record, true);
1220 void ContactObjectA2PConverter::importPostalList()
1223 contacts_record_h child_record = NULL;
1224 unsigned int record_count = 0;
1226 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &record_count);
1227 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1229 ThrowMsg(PlatformException, "getting address count (err:" << errorCode << ")");
1232 for(int i=record_count-1; i>=0; i--)
1234 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
1235 if(errorCode != CONTACTS_ERROR_NONE)
1236 ThrowMsg(UnknownException, "getting address value A (errorCode:" << errorCode << ")");
1238 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.address, child_record);
1239 if(errorCode != CONTACTS_ERROR_NONE)
1240 ThrowMsg(UnknownException, "removing address value A (errorCode:" << errorCode << ")");
1242 child_record = NULL;
1245 if(m_abstractContact->getAddressesNum() == 0)
1248 ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
1250 ContactAddressArray::iterator addressesIter = addresses->begin();
1251 for(; addressesIter != addresses->end(); addressesIter++)
1253 ContactAddressPtr address = *addressesIter;
1254 ContactAddressTypeArrayPtr types = address->getTypes();
1256 if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
1257 ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
1258 ( !address->getCityIsSet() || address->getCity().empty() ) &&
1259 ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
1260 ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
1261 ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
1263 LoggerD("No information for address was not set.");
1267 bool ctsBoolDefault = address->getIsDefault();
1270 //char *ctsStrCustomType = NULL;
1272 ContactAddressTypeArray::iterator typesIter = types->begin();
1273 for(; typesIter != types->end(); typesIter++)
1275 ContactAddressType type = *typesIter;
1276 if(type == CONTACT_ADDRESS_TYPE_HOME)
1277 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1278 else if(type == CONTACT_ADDRESS_TYPE_WORK)
1279 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_WORK;
1281 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1284 child_record = NULL;
1286 errorCode = contacts_record_create(_contacts_address._uri, &child_record);
1287 if(errorCode != CONTACTS_ERROR_NONE)
1289 LoggerW("Fail to create child_record with contacts_record_create(_contacts_address._uri)");
1293 if(address->getCountryIsSet())
1295 string country = address->getCountry();
1296 errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
1297 if(errorCode != CONTACTS_ERROR_NONE)
1299 LoggerW("Fail to set country value to child_record str country ");
1300 contacts_record_destroy(child_record, true);
1305 if(address->getRegionIsSet())
1307 string region = address->getRegion();
1308 errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
1309 if(errorCode != CONTACTS_ERROR_NONE)
1311 LoggerW("Fail to set region value to child_record str region ");
1312 contacts_record_destroy(child_record, true);
1317 if(address->getCityIsSet())
1319 string city = address->getCity();
1320 errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
1321 if(errorCode != CONTACTS_ERROR_NONE)
1323 LoggerW("Fail to set locality value to child_record str locality ");
1324 contacts_record_destroy(child_record, true);
1329 if(address->getStreetAddressIsSet())
1331 string streetAddress = address->getStreetAddress();
1332 errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
1333 if(errorCode != CONTACTS_ERROR_NONE)
1335 LoggerW("Fail to set street value to child_record str streetAddress ");
1336 contacts_record_destroy(child_record, true);
1341 if(address->getAdditionalInformationIsSet())
1343 string additionalInformation = address->getAdditionalInformation();
1344 errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
1345 if(errorCode != CONTACTS_ERROR_NONE)
1347 LoggerW("Fail to set extended value to child_record str additionalInformation ");
1348 contacts_record_destroy(child_record, true);
1353 if(address->getPostalCodeIsSet())
1355 string postalCode = address->getPostalCode();
1356 errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
1357 if(errorCode != CONTACTS_ERROR_NONE)
1359 LoggerW("Fail to set postal_code value to child_record str postalCode ");
1360 contacts_record_destroy(child_record, true);
1365 errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
1366 if(errorCode != CONTACTS_ERROR_NONE)
1368 LoggerW("Fail to set favorite value to child_record default ");
1369 contacts_record_destroy(child_record, true);
1373 errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
1374 if(errorCode != CONTACTS_ERROR_NONE)
1376 LoggerW("Fail to set default value to child_record type ");
1377 contacts_record_destroy(child_record, true);
1381 //if(ctsStrCustomType != NULL)
1383 // errorCode = contacts_record_set_str(child_record, _contacts_address.label, ctsStrCustomType);
1384 // if(errorCode != CONTACTS_ERROR_NONE)
1386 // LoggerW("Fail to set custom value to child_record type : " << ctsStrCustomType);
1387 // contacts_record_destroy(child_record, true);
1392 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.address, child_record);
1393 if(errorCode != CONTACTS_ERROR_NONE)
1395 LoggerW("Fail to set address value to child_record");
1396 contacts_record_destroy(child_record, true);
1402 void ContactObjectA2PConverter::importWebAddrList()
1405 contacts_record_h child_record = NULL;
1406 unsigned int record_count = 0;
1408 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &record_count);
1409 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1411 ThrowMsg(PlatformException, "getting url count (err:" << errorCode << ")");
1414 for(int i=record_count-1; i>=0; i--)
1416 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
1417 if(errorCode != CONTACTS_ERROR_NONE)
1418 ThrowMsg(UnknownException, "getting url value A (errorCode:" << errorCode << ")");
1420 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.url, child_record);
1421 if(errorCode != CONTACTS_ERROR_NONE)
1422 ThrowMsg(UnknownException, "removing url value A (errorCode:" << errorCode << ")");
1424 child_record = NULL;
1427 ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
1428 if(webSites->size() == 0)
1431 ContactWebSiteArray::iterator webSiteIter = webSites->begin();
1432 for(; webSiteIter != webSites->end(); webSiteIter++)
1434 ContactWebSitePtr webSite = *webSiteIter;
1435 ContactWebSiteType type = webSite->getType();
1437 if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
1439 LoggerD("url was not set.");
1443 string url = webSite->getUrl();
1446 // char *ctsStrCustomType = NULL;
1448 if(type == WEBSITE_TYPE_HOMEPAGE)
1449 ctsIntType = CONTACTS_URL_TYPE_HOME;
1450 else if(type == WEBSITE_TYPE_BLOG)
1451 ctsIntType = CONTACTS_URL_TYPE_WORK;
1453 ctsIntType = CONTACTS_URL_TYPE_HOME;
1455 child_record = NULL;
1457 errorCode = contacts_record_create(_contacts_url._uri, &child_record);
1458 if(errorCode != CONTACTS_ERROR_NONE)
1460 LoggerW("Fail to create child_record with contacts_record_create(_contacts_url._uri)");
1464 errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
1465 if(errorCode != CONTACTS_ERROR_NONE)
1467 LoggerW("Fail to set url value to child_record str url");
1468 contacts_record_destroy(child_record, true);
1472 errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
1473 if(errorCode != CONTACTS_ERROR_NONE)
1475 LoggerW("Fail to set default value to child_record type ");
1476 contacts_record_destroy(child_record, true);
1480 if(ctsStrCustomType != NULL)
1482 errorCode = contacts_record_set_str(child_record, _contacts_url.label, ctsStrCustomType);
1483 if(errorCode != CONTACTS_ERROR_NONE)
1485 LoggerW("Fail to set custom value to child_record type : " << ctsStrCustomType);
1486 contacts_record_destroy(child_record, true);
1491 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.url, child_record);
1492 if(errorCode != CONTACTS_ERROR_NONE)
1494 LoggerW("Fail to set url value to child_record");
1495 contacts_record_destroy(child_record, true);
1501 void ContactObjectA2PConverter::importNicknameList()
1504 contacts_record_h child_record = NULL;
1505 unsigned int record_count = 0;
1507 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &record_count);
1508 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1510 ThrowMsg(PlatformException, "getting nickname count (err:" << errorCode << ")");
1513 for(int i=record_count-1; i>=0; i--)
1515 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
1516 if(errorCode != CONTACTS_ERROR_NONE)
1517 ThrowMsg(UnknownException, "getting nickname value A (errorCode:" << errorCode << ")");
1519 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1520 if(errorCode != CONTACTS_ERROR_NONE)
1521 ThrowMsg(UnknownException, "removing nickname value A (errorCode:" << errorCode << ")");
1523 child_record = NULL;
1526 ContactNamePtr contactName = m_abstractContact->getName();
1527 if(contactName == NULL)
1530 if(contactName->getNicknamesNum() == 0)
1533 StringArrayPtr nicknames = contactName->getNicknames();
1535 StringArray::iterator nicknamesIter = nicknames->begin();
1536 for(; nicknamesIter != nicknames->end(); nicknamesIter++)
1538 string nickname = *nicknamesIter;
1540 if(nickname.empty())
1542 LoggerD("nickname was not set.");
1546 child_record = NULL;
1548 errorCode = contacts_record_create(_contacts_nickname._uri, &child_record);
1549 if(errorCode != CONTACTS_ERROR_NONE)
1551 LoggerW("Fail to create child_record with contacts_record_create(_contacts_nickname._uri)");
1555 errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
1556 if(errorCode != CONTACTS_ERROR_NONE)
1558 LoggerW("Fail to set nickname value to ctsValue str nickname ");
1559 contacts_record_destroy(child_record, true);
1563 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1564 if(errorCode != CONTACTS_ERROR_NONE)
1566 LoggerW("Fail to set nickname value to child_record");
1567 contacts_record_destroy(child_record, true);