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 LoggerD("Load platform object id : " << id);
88 errorCode = contacts_db_get_record(_contacts_contact._uri, id, &m_platformContact);
89 if(errorCode != CONTACTS_ERROR_NONE)
90 ThrowMsg(UnknownException, "error on contacts_db_get_record (errorCode:" << errorCode << ")");
94 LoggerD("New platform object has been created");
95 errorCode = contacts_record_create(_contacts_contact._uri, &m_platformContact);
96 if(errorCode != CONTACTS_ERROR_NONE)
97 ThrowMsg(UnknownException, "error on contacts_record_create (errorCode:" << errorCode << ")");
100 m_platformContactOwnership = true;
103 LoggerD("for scratch : " << m_forScratch);
107 if(m_convertFinished == false)
108 convertToPlatformObject();
112 LoggerE("Error while converting - " << _rethrown_exception.GetMessage());
113 ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
116 return m_platformContact;
119 void ContactObjectA2PConverter::convertToPlatformObject()
121 importBaseInfoValue();
127 importGrouprelList();
131 importNicknameList();
133 m_convertFinished = true;
136 void ContactObjectA2PConverter::importBaseInfoValue()
139 contacts_record_h child_record = NULL;
141 const char *newValueStr = NULL;
142 char *oldValueStr = NULL;
143 string abstractValueStr;
147 if(!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty())
149 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
150 if(errorCode != CONTACTS_ERROR_NONE)
151 ThrowMsg(UnknownException, "creating image value A (errorCode:" << errorCode << ")");
152 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
156 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
157 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
159 LoggerD("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
160 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
161 if(errorCode != CONTACTS_ERROR_NONE)
162 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
165 contacts_record_get_str_p(child_record, _contacts_image.path, &oldValueStr);
166 realPath = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
167 m_abstractContact->setPhotoURIRealPath(realPath);
168 abstractValueStr = m_abstractContact->getPhotoURIRealPath();
169 if(oldValueStr != NULL &&
170 (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
172 newValueStr = EMPTY_STRING;
174 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
176 newValueStr = abstractValueStr.c_str();
179 if(newValueStr != NULL)
181 LoggerD("image : " << newValueStr);
182 errorCode = contacts_record_set_str(child_record, _contacts_image.path, newValueStr);
183 if(errorCode != CONTACTS_ERROR_NONE)
185 ThrowMsg(PlatformException, "importing photoURI E (err:" <<
186 errorCode << ", str:" << abstractValueStr << ")");
189 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
192 // Contact.ringtoneURI
195 contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &oldValueStr);
196 realPath = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
197 m_abstractContact->setRingtoneURIRealPath(realPath);
198 abstractValueStr = m_abstractContact->getRingtoneURIRealPath();
199 if(oldValueStr != NULL &&
200 (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
202 newValueStr = EMPTY_STRING;
204 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
206 newValueStr = abstractValueStr.c_str();
209 if(newValueStr != NULL)
211 errorCode = contacts_record_set_str(m_platformContact, _contacts_contact.ringtone_path, newValueStr);
212 if(errorCode != CONTACTS_ERROR_NONE)
214 ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
215 errorCode << ", str:" << abstractValueStr << ")");
220 void ContactObjectA2PConverter::importNameValue()
223 contacts_record_h child_record = NULL;
225 ContactNamePtr contactName = m_abstractContact->getName();
226 if(contactName == NULL ||
227 (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
228 && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
229 && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
230 && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
231 && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
232 && ( !contactName->getSuffixIsSet() || contactName->getSuffix().empty() )
233 && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() ) ) )
235 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
236 if(errorCode != CONTACTS_ERROR_NONE)
237 ThrowMsg(UnknownException, "creating name value A (errorCode:" << errorCode << ")");
238 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
242 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
243 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
245 LoggerD("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
246 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
247 if(errorCode != CONTACTS_ERROR_NONE)
248 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
250 importNameValueToNewValue(child_record, contactName);
254 importNameValueToExistingValue(child_record, contactName);
257 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
260 void ContactObjectA2PConverter::importNameValueToExistingValue(contacts_record_h child_record, ContactNamePtr &contactName)
264 const char *newValueStr = NULL;
265 char *oldValueStr = NULL;
266 string abstractValueStr;
268 // ContactName.firstName
269 contacts_record_get_str_p(child_record, _contacts_name.first, &oldValueStr);
270 abstractValueStr = contactName->getFirstName();
271 if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
273 newValueStr = EMPTY_STRING;
275 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
277 newValueStr = abstractValueStr.c_str();
280 if(newValueStr != NULL)
282 errorCode = contacts_record_set_str(child_record, _contacts_name.first, newValueStr);
283 if(errorCode != CONTACTS_ERROR_NONE)
285 contacts_record_destroy(child_record, true);
286 ThrowMsg(PlatformException, "importing firstName E (err:" <<
287 errorCode << ", str:" << newValueStr << ")");
291 // ContactName.lastName
294 contacts_record_get_str_p(child_record, _contacts_name.last, &oldValueStr);
295 abstractValueStr = contactName->getLastName();
296 if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
298 newValueStr = EMPTY_STRING;
300 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
302 newValueStr = abstractValueStr.c_str();
305 if(newValueStr != NULL)
307 errorCode = contacts_record_set_str(child_record, _contacts_name.last, newValueStr);
308 if(errorCode != CONTACTS_ERROR_NONE)
310 contacts_record_destroy(child_record, true);
311 ThrowMsg(PlatformException, "importing lastName E (err:" <<
312 errorCode << ", str:" << newValueStr << ")");
316 // ContactName.middleName
319 contacts_record_get_str_p(child_record, _contacts_name.addition, &oldValueStr);
320 abstractValueStr = contactName->getMiddleName();
321 if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
323 newValueStr = EMPTY_STRING;
325 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
327 newValueStr = abstractValueStr.c_str();
330 if(newValueStr != NULL)
332 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, newValueStr);
333 if(errorCode != CONTACTS_ERROR_NONE)
335 contacts_record_destroy(child_record, true);
336 ThrowMsg(PlatformException, "importing middleName E (err:" <<
337 errorCode << ", str:" << newValueStr << ")");
341 // ContactName.prefix
344 contacts_record_get_str_p(child_record, _contacts_name.prefix, &oldValueStr);
345 abstractValueStr = contactName->getPrefix();
346 if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
348 newValueStr = EMPTY_STRING;
350 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
352 newValueStr = abstractValueStr.c_str();
355 if(newValueStr != NULL)
357 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, newValueStr);
358 if(errorCode != CONTACTS_ERROR_NONE)
360 contacts_record_destroy(child_record, true);
361 ThrowMsg(PlatformException, "importing prefix E (err:" <<
362 errorCode << ", str:" << newValueStr << ")");
366 // ContactName.suffix
369 contacts_record_get_str_p(child_record, _contacts_name.suffix, &oldValueStr);
370 abstractValueStr = contactName->getSuffix();
371 if(oldValueStr != NULL && (!contactName->getSuffixIsSet() || abstractValueStr.empty()) )
373 newValueStr = EMPTY_STRING;
375 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
377 newValueStr = abstractValueStr.c_str();
380 if(newValueStr != NULL)
382 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, newValueStr);
383 if(errorCode != CONTACTS_ERROR_NONE)
385 contacts_record_destroy(child_record, true);
386 ThrowMsg(PlatformException, "importing suffix E (err:" <<
387 errorCode << ", str:" << newValueStr << ")");
391 // ContactName.phoneticFirstName
394 contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &oldValueStr);
395 abstractValueStr = contactName->getPhoneticFirstName();
396 if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
398 newValueStr = EMPTY_STRING;
400 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
402 newValueStr = abstractValueStr.c_str();
405 if(newValueStr != NULL)
407 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, newValueStr);
408 if(errorCode != CONTACTS_ERROR_NONE)
410 contacts_record_destroy(child_record, true);
411 ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
412 errorCode << ", str:" << newValueStr << ")");
416 // ContactName.phoneticLastName
419 contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &oldValueStr);
420 abstractValueStr = contactName->getPhoneticLastName();
421 if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
423 newValueStr = EMPTY_STRING;
425 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
427 newValueStr = abstractValueStr.c_str();
430 if(newValueStr != NULL)
432 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, newValueStr);
433 if(errorCode != CONTACTS_ERROR_NONE)
435 contacts_record_destroy(child_record, true);
436 ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
437 errorCode << ", str:" << newValueStr << ")");
442 void ContactObjectA2PConverter::importNameValueToNewValue(contacts_record_h child_record, ContactNamePtr &contactName)
446 // ContactName.firstName
447 if(contactName->getFirstNameIsSet())
449 string firstName = contactName->getFirstName();
450 if(firstName != EMPTY_STRING)
452 errorCode = contacts_record_set_str(child_record, _contacts_name.first, firstName.c_str());
453 if(errorCode != CONTACTS_ERROR_NONE)
455 contacts_record_destroy(child_record, true);
456 ThrowMsg(PlatformException, "importing firstName N (err:" <<
457 errorCode << ", str:" << firstName << ")");
462 // ContactName.lastName
463 if(contactName->getLastNameIsSet())
465 string lastName = contactName->getLastName();
466 if(lastName != EMPTY_STRING)
468 errorCode = contacts_record_set_str(child_record, _contacts_name.last, lastName.c_str());
469 if(errorCode != CONTACTS_ERROR_NONE)
471 contacts_record_destroy(child_record, true);
472 ThrowMsg(PlatformException, "importing lastName N (err:" <<
473 errorCode << ", str:" << lastName << ")");
478 // ContactName.middleName
479 if(contactName->getMiddleNameIsSet())
481 string middleName = contactName->getMiddleName();
482 if(middleName != EMPTY_STRING)
484 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, middleName.c_str());
485 if(errorCode != CONTACTS_ERROR_NONE)
487 contacts_record_destroy(child_record, true);
488 ThrowMsg(PlatformException, "importing middleName N (err:" <<
489 errorCode << ", str:" << middleName << ")");
494 // ContactName.prefix
495 if(contactName->getPrefixIsSet())
497 string prefix = contactName->getPrefix();
498 if(prefix != EMPTY_STRING)
500 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, prefix.c_str());
501 if(errorCode != CONTACTS_ERROR_NONE)
503 contacts_record_destroy(child_record, true);
504 ThrowMsg(PlatformException, "importing prefix N (err:" <<
505 errorCode << ", str:" << prefix << ")");
510 // ContactName.suffix
511 if(contactName->getSuffixIsSet())
513 string suffix = contactName->getSuffix();
514 if(suffix != EMPTY_STRING)
516 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, suffix.c_str());
517 if(errorCode != CONTACTS_ERROR_NONE)
519 contacts_record_destroy(child_record, true);
520 ThrowMsg(PlatformException, "importing suffix N (err:" <<
521 errorCode << ", str:" << suffix << ")");
526 // ContactName.phoneticFirstName
527 if(contactName->getPhoneticFirstNameIsSet())
529 string phoneticFirstName = contactName->getPhoneticFirstName();
530 if(phoneticFirstName != EMPTY_STRING)
532 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, phoneticFirstName.c_str());
533 if(errorCode != CONTACTS_ERROR_NONE)
535 contacts_record_destroy(child_record, true);
536 ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
537 errorCode << ", str:" << phoneticFirstName << ")");
542 // ContactName.phoneticLastName
543 if(contactName->getPhoneticLastNameIsSet())
545 string phoneticLastName = contactName->getPhoneticLastName();
546 if(phoneticLastName != EMPTY_STRING)
548 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, phoneticLastName.c_str());
549 if(errorCode != CONTACTS_ERROR_NONE)
551 contacts_record_destroy(child_record, true);
552 ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
553 errorCode << ", str:" << phoneticLastName << ")");
559 void ContactObjectA2PConverter::importCompanyList()
562 contacts_record_h child_record = NULL;
563 unsigned int record_count = 0;
565 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &record_count);
566 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
568 ThrowMsg(PlatformException, "getting company count (err:" << errorCode << ")");
571 for(int i=record_count-1; i>=0; i--)
573 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
574 if(errorCode != CONTACTS_ERROR_NONE)
575 ThrowMsg(UnknownException, "getting company value A (errorCode:" << errorCode << ")");
577 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.company, child_record);
578 if(errorCode != CONTACTS_ERROR_NONE)
579 ThrowMsg(UnknownException, "removing company value A (errorCode:" << errorCode << ")");
584 ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
585 if(organizations->size() == 0)
588 ContactOrganizationArray::iterator organizationsIter = organizations->begin();
589 for(; organizationsIter != organizations->end(); organizationsIter++)
591 ContactOrganizationPtr organization = *organizationsIter;
595 errorCode = contacts_record_create(_contacts_company._uri, &child_record);
596 if(errorCode != CONTACTS_ERROR_NONE)
598 LoggerW("Fail to create child_record with contacts_record_create(_contacts_company._uri)");
602 // ContactOrganization.name
603 if(organization->getNameIsSet())
605 string name = organization->getName();
608 errorCode = contacts_record_set_str(child_record, _contacts_company.name, name.c_str());
609 if(errorCode != CONTACTS_ERROR_NONE)
611 LoggerW("importing company name N (err:" << errorCode << ", str:" << name << ")");
612 contacts_record_destroy(child_record, true);
618 // ContactOrganization.department
619 if(organization->getDepartmentIsSet())
621 string department = organization->getDepartment();
622 if(!department.empty())
624 errorCode = contacts_record_set_str(child_record, _contacts_company.department, department.c_str());
625 if(errorCode != CONTACTS_ERROR_NONE)
627 LoggerW("importing department N (err:" << errorCode << ", str:" << department << ")");
628 contacts_record_destroy(child_record, true);
634 // ContactOrganization.title
635 if(organization->getTitleIsSet())
637 string title = organization->getTitle();
640 errorCode = contacts_record_set_str(child_record, _contacts_company.job_title, title.c_str());
641 if(errorCode != CONTACTS_ERROR_NONE)
643 LoggerW("importing title N (err:" << errorCode << ", str:" << title << ")");
644 contacts_record_destroy(child_record, true);
650 // ContactOrganization.role
651 if(organization->getRoleIsSet())
653 string role = organization->getRole();
656 errorCode = contacts_record_set_str(child_record, _contacts_company.role, role.c_str());
657 if(errorCode != CONTACTS_ERROR_NONE)
659 LoggerW("importing role N (err:" << errorCode << ", str:" << role << ")");
660 contacts_record_destroy(child_record, true);
666 // ContactOrganization.logoURI
667 if(organization->getLogoURIIsSet())
669 string logoURI = organization->getLogoURI();
672 logoURI = ContactUtility::convertUriToPath(logoURI);
673 errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
674 if(errorCode != CONTACTS_ERROR_NONE)
676 LoggerW("importing logoURI N (err:" << errorCode << ", str:" << logoURI << ")");
677 contacts_record_destroy(child_record, true);
683 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.company, child_record);
684 if(errorCode != CONTACTS_ERROR_NONE)
686 LoggerW("Fail to set company value to child_record");
687 contacts_record_destroy(child_record, true);
693 void ContactObjectA2PConverter::importNoteList()
696 contacts_record_h child_record = NULL;
697 unsigned int record_count = 0;
699 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &record_count);
700 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
702 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
705 for(int i=record_count-1; i>=0; i--)
707 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
708 if(errorCode != CONTACTS_ERROR_NONE)
709 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
711 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.note, child_record);
712 if(errorCode != CONTACTS_ERROR_NONE)
713 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
718 StringArrayPtr notes = m_abstractContact->getNotes();
719 if(notes->size() == 0)
722 StringArray::iterator notesIter = notes->begin();
723 for(; notesIter != notes->end(); notesIter++)
725 string note = *notesIter;
734 errorCode = contacts_record_create(_contacts_note._uri, &child_record);
735 if(errorCode != CONTACTS_ERROR_NONE)
737 LoggerW("Fail to create child_record with contacts_record_create(_contacts_note._uri)");
741 errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
742 if(errorCode != CONTACTS_ERROR_NONE)
744 LoggerW("importing note N (err:" << errorCode << ", str:" << note << ")");
745 contacts_record_destroy(child_record, true);
749 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.note, child_record);
750 if(errorCode != CONTACTS_ERROR_NONE)
752 LoggerW("Fail to set note value to child_record");
753 contacts_record_destroy(child_record, true);
759 void ContactObjectA2PConverter::importNumberList()
762 contacts_record_h child_record = NULL;
763 unsigned int record_count = 0;
765 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &record_count);
766 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
768 ThrowMsg(PlatformException, "getting number count (err:" << errorCode << ")");
771 for(int i=record_count-1; i>=0; i--)
773 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
774 if(errorCode != CONTACTS_ERROR_NONE)
775 ThrowMsg(UnknownException, "getting number value A (errorCode:" << errorCode << ")");
777 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.number, child_record);
778 if(errorCode != CONTACTS_ERROR_NONE)
779 ThrowMsg(UnknownException, "removing number value A (errorCode:" << errorCode << ")");
784 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
785 if(phoneNumbers->size() == 0)
788 ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
789 for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
791 ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
792 ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
794 if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
796 LoggerD("Number was not set.");
800 string number = phoneNumber->getNumber();
802 bool ctsBoolDefault = phoneNumber->getIsDefault();
805 //char *ctsStrCustomType = NULL;
807 ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
808 for(; typesIter != types->end(); typesIter++)
810 ContactPhoneNumberType type = *typesIter;
811 if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
812 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_HOME;
813 else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
814 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_WORK;
815 else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
816 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
817 else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
818 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_FAX;
819 else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
820 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MSG;
821 else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
822 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CELL;
823 else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
824 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PAGER;
825 else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
826 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_BBS;
827 else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
828 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MODEM;
829 else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
830 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CAR;
831 else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
832 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_ISDN;
833 else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
834 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VIDEO;
835 else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
836 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PCS;
838 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
843 errorCode = contacts_record_create(_contacts_number._uri, &child_record);
844 if(errorCode != CONTACTS_ERROR_NONE)
846 LoggerW("Fail to create child_record with contacts_record_create(_contacts_number._uri)");
850 errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
851 if(errorCode != CONTACTS_ERROR_NONE)
853 LoggerW("Fail to set number value to child_record number : " << number);
854 contacts_record_destroy(child_record, true);
858 errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
859 if(errorCode != CONTACTS_ERROR_NONE)
861 LoggerW("Fail to set number value to child_record default : " << ctsBoolDefault);
862 contacts_record_destroy(child_record, true);
866 errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
867 if(errorCode != CONTACTS_ERROR_NONE)
869 LoggerW("Fail to set number value to child_record type : " << ctsIntType);
870 contacts_record_destroy(child_record, true);
874 //if(ctsStrCustomType != NULL)
876 // errorCode = contacts_record_set_str(child_record, _contacts_number.label, ctsStrCustomType);
877 // if(errorCode != CONTACTS_ERROR_NONE)
879 // LoggerW("Fail to set number value to child_record custom type : " << ctsStrCustomType);
880 // contacts_record_destroy(child_record, true);
885 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.number, child_record);
886 if(errorCode != CONTACTS_ERROR_NONE)
888 LoggerW("Fail to set number value to child_record");
889 contacts_record_destroy(child_record, true);
895 void ContactObjectA2PConverter::importEmailList()
898 contacts_record_h child_record = NULL;
899 unsigned int record_count = 0;
901 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &record_count);
902 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
904 ThrowMsg(PlatformException, "getting email count (err:" << errorCode << ")");
907 for(int i=record_count-1; i>=0; i--)
909 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
910 if(errorCode != CONTACTS_ERROR_NONE)
911 ThrowMsg(UnknownException, "getting email value A (errorCode:" << errorCode << ")");
913 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.email, child_record);
914 if(errorCode != CONTACTS_ERROR_NONE)
915 ThrowMsg(UnknownException, "removing email value A (errorCode:" << errorCode << ")");
920 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
921 if(emails->size() == 0)
924 ContactEmailAddressArray::iterator emailsIter = emails->begin();
925 for(; emailsIter != emails->end(); emailsIter++)
927 ContactEmailAddressPtr email = *emailsIter;
928 ContactEmailAddressTypeArrayPtr types = email->getTypes();
930 if(!email->getEmailIsSet() || email->getEmail().empty())
932 LoggerD("email address was not set.");
936 string emailAddress = email->getEmail();
938 bool ctsBoolDefault = email->getIsDefault();
941 //char *ctsStrCustomType = NULL;
943 ContactEmailAddressTypeArray::iterator typesIter = types->begin();
944 for(; typesIter != types->end(); typesIter++)
946 ContactEmailAddressType type = *typesIter;
947 if(type == CONTACT_EMAIL_TYPE_HOME)
948 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
949 else if(type == CONTACT_EMAIL_TYPE_WORK)
950 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_WORK;
952 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
957 errorCode = contacts_record_create(_contacts_email._uri, &child_record);
958 if(errorCode != CONTACTS_ERROR_NONE)
960 LoggerW("Fail to create child_record with contacts_record_create(_contacts_email._uri)");
964 errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
965 if(errorCode != CONTACTS_ERROR_NONE)
967 LoggerW("Fail to set email value to child_record email : " << emailAddress);
968 contacts_record_destroy(child_record, true);
972 errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
973 if(errorCode != CONTACTS_ERROR_NONE)
975 LoggerW("Fail to set email value to child_record default : " << ctsBoolDefault);
976 contacts_record_destroy(child_record, true);
980 errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
981 if(errorCode != CONTACTS_ERROR_NONE)
983 LoggerW("Fail to set email value to child_record type : " << ctsIntType);
984 contacts_record_destroy(child_record, true);
988 //if(ctsStrCustomType != NULL)
990 // errorCode = contacts_record_set_str(child_record, _contacts_email.label, ctsStrCustomType);
991 // if(errorCode != CONTACTS_ERROR_NONE)
993 // LoggerW("Fail to set email value to child_record custom type : " << ctsStrCustomType);
994 // contacts_record_destroy(child_record, true);
999 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.email, child_record);
1000 if(errorCode != CONTACTS_ERROR_NONE)
1002 LoggerW("Fail to set email value to child_record");
1003 contacts_record_destroy(child_record, true);
1009 void ContactObjectA2PConverter::importGrouprelList()
1012 contacts_record_h child_record = NULL;
1013 unsigned int record_count = 0;
1015 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &record_count);
1016 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1018 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
1021 for(int i=record_count-1; i>=0; i--)
1023 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
1024 if(errorCode != CONTACTS_ERROR_NONE)
1025 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
1027 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1028 if(errorCode != CONTACTS_ERROR_NONE)
1029 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
1031 child_record = NULL;
1034 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
1035 if(groupIds->size() == 0)
1038 StringArray::iterator groupIdsIter = groupIds->begin();
1039 for(; groupIdsIter != groupIds->end(); groupIdsIter++)
1041 string groupId = *groupIdsIter;
1043 child_record = NULL;
1045 if(!ContactUtility::checkStrIsUInt(groupId))
1047 LoggerW("groupId (" << groupId << ") is wrong.");
1051 int groupIdInt = ContactUtility::strToInt(groupId);
1053 errorCode = contacts_record_create(_contacts_group_relation._uri, &child_record);
1054 if(errorCode != CONTACTS_ERROR_NONE)
1056 LoggerW("Fail to create child_record with contacts_record_create(_contacts_group_relation._uri)");
1060 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
1061 if(errorCode != CONTACTS_ERROR_NONE)
1063 LoggerW("importing group id N (err:" << errorCode << ", str:" << groupIdInt << ")");
1064 contacts_record_destroy(child_record, true);
1068 int contactId = ContactUtility::strToInt(m_abstractContact->getId());
1069 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
1070 if(errorCode != CONTACTS_ERROR_NONE)
1072 LoggerW("importing group contact_id N (err:" << errorCode << ", str:" << contactId << ")");
1073 contacts_record_destroy(child_record, true);
1077 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1078 if(errorCode != CONTACTS_ERROR_NONE)
1080 LoggerW("Fail to set group value to child_record");
1081 contacts_record_destroy(child_record, true);
1087 void ContactObjectA2PConverter::importEventList()
1090 contacts_record_h child_record = NULL;
1091 unsigned int record_count = 0;
1093 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &record_count);
1094 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1096 ThrowMsg(PlatformException, "getting event count (err:" << errorCode << ")");
1099 for(int i=record_count-1; i>=0; i--)
1101 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
1102 if(errorCode != CONTACTS_ERROR_NONE)
1103 ThrowMsg(UnknownException, "getting event value A (errorCode:" << errorCode << ")");
1105 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.event, child_record);
1106 if(errorCode != CONTACTS_ERROR_NONE)
1107 ThrowMsg(UnknownException, "removing event value A (errorCode:" << errorCode << ")");
1109 child_record = NULL;
1112 if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
1115 importEventListBirthday();
1117 importEventListAnniversary();
1120 void ContactObjectA2PConverter::importEventListBirthday()
1124 if(!m_abstractContact->getBirthdayIsSet())
1127 tm birthdayTm = m_abstractContact->getBirthday();
1129 if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
1132 int birthday = ContactUtility::toDateDbInt(birthdayTm);
1134 contacts_record_h child_record = NULL;
1136 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1137 if(errorCode != CONTACTS_ERROR_NONE)
1139 LoggerW("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1143 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
1144 if(errorCode != CONTACTS_ERROR_NONE)
1146 LoggerW("Fail to set event value to child_record type : " << CONTACTS_EVENT_TYPE_BIRTH);
1147 contacts_record_destroy(child_record, true);
1151 errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
1152 if(errorCode != CONTACTS_ERROR_NONE)
1154 LoggerW("Fail to set event value to child_record date : " << birthday);
1155 contacts_record_destroy(child_record, true);
1159 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1160 if(errorCode != CONTACTS_ERROR_NONE)
1162 LoggerW("Fail to set event value to child_record");
1163 contacts_record_destroy(child_record, true);
1168 void ContactObjectA2PConverter::importEventListAnniversary()
1171 contacts_record_h child_record = NULL;
1173 if(m_abstractContact->getAnniversariesNum() == 0)
1176 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
1178 ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
1179 for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
1181 ContactAnniversaryPtr anniversary = *anniversariesIter;
1183 if(!anniversary->getDateIsSet())
1186 tm dateTm = anniversary->getDate();
1188 if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
1191 int date = ContactUtility::toDateDbInt(dateTm);
1193 child_record = NULL;
1195 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1196 if(errorCode != CONTACTS_ERROR_NONE)
1198 LoggerW("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1202 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
1203 if(errorCode != CONTACTS_ERROR_NONE)
1205 LoggerW("Fail to set event value to child_record type : CONTACTS_EVENT_TYPE_ANNIVERSARY");
1206 contacts_record_destroy(child_record, true);
1210 errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
1211 if(errorCode != CONTACTS_ERROR_NONE)
1213 LoggerW("Fail to set event value to child_record date : " << date);
1214 contacts_record_destroy(child_record, true);
1218 if(anniversary->getLabelIsSet())
1220 string label = anniversary->getLabel();
1221 errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
1222 if(errorCode != CONTACTS_ERROR_NONE)
1224 LoggerW("Fail to set label value to child_record label : " << label);
1225 contacts_record_destroy(child_record, true);
1231 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1232 if(errorCode != CONTACTS_ERROR_NONE)
1234 LoggerW("Fail to set event value to child_record");
1235 contacts_record_destroy(child_record, true);
1241 void ContactObjectA2PConverter::importPostalList()
1244 contacts_record_h child_record = NULL;
1245 unsigned int record_count = 0;
1247 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &record_count);
1248 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1250 ThrowMsg(PlatformException, "getting address count (err:" << errorCode << ")");
1253 for(int i=record_count-1; i>=0; i--)
1255 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
1256 if(errorCode != CONTACTS_ERROR_NONE)
1257 ThrowMsg(UnknownException, "getting address value A (errorCode:" << errorCode << ")");
1259 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.address, child_record);
1260 if(errorCode != CONTACTS_ERROR_NONE)
1261 ThrowMsg(UnknownException, "removing address value A (errorCode:" << errorCode << ")");
1263 child_record = NULL;
1266 if(m_abstractContact->getAddressesNum() == 0)
1269 ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
1271 ContactAddressArray::iterator addressesIter = addresses->begin();
1272 for(; addressesIter != addresses->end(); addressesIter++)
1274 ContactAddressPtr address = *addressesIter;
1275 ContactAddressTypeArrayPtr types = address->getTypes();
1277 if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
1278 ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
1279 ( !address->getCityIsSet() || address->getCity().empty() ) &&
1280 ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
1281 ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
1282 ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
1284 LoggerD("No information for address was not set.");
1288 bool ctsBoolDefault = address->getIsDefault();
1291 //char *ctsStrCustomType = NULL;
1293 ContactAddressTypeArray::iterator typesIter = types->begin();
1294 for(; typesIter != types->end(); typesIter++)
1296 ContactAddressType type = *typesIter;
1297 if(type == CONTACT_ADDRESS_TYPE_HOME)
1298 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1299 else if(type == CONTACT_ADDRESS_TYPE_WORK)
1300 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_WORK;
1302 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1305 child_record = NULL;
1307 errorCode = contacts_record_create(_contacts_address._uri, &child_record);
1308 if(errorCode != CONTACTS_ERROR_NONE)
1310 LoggerW("Fail to create child_record with contacts_record_create(_contacts_address._uri)");
1314 if(address->getCountryIsSet())
1316 string country = address->getCountry();
1317 errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
1318 if(errorCode != CONTACTS_ERROR_NONE)
1320 LoggerW("Fail to set country value to child_record str : " << country);
1321 contacts_record_destroy(child_record, true);
1326 if(address->getRegionIsSet())
1328 string region = address->getRegion();
1329 errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
1330 if(errorCode != CONTACTS_ERROR_NONE)
1332 LoggerW("Fail to set region value to child_record str : " << region);
1333 contacts_record_destroy(child_record, true);
1338 if(address->getCityIsSet())
1340 string city = address->getCity();
1341 errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
1342 if(errorCode != CONTACTS_ERROR_NONE)
1344 LoggerW("Fail to set locality value to child_record str : " << city);
1345 contacts_record_destroy(child_record, true);
1350 if(address->getStreetAddressIsSet())
1352 string streetAddress = address->getStreetAddress();
1353 errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
1354 if(errorCode != CONTACTS_ERROR_NONE)
1356 LoggerW("Fail to set street value to child_record str : " << streetAddress);
1357 contacts_record_destroy(child_record, true);
1362 if(address->getAdditionalInformationIsSet())
1364 string additionalInformation = address->getAdditionalInformation();
1365 errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
1366 if(errorCode != CONTACTS_ERROR_NONE)
1368 LoggerW("Fail to set extended value to child_record str : " << additionalInformation);
1369 contacts_record_destroy(child_record, true);
1374 if(address->getPostalCodeIsSet())
1376 string postalCode = address->getPostalCode();
1377 errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
1378 if(errorCode != CONTACTS_ERROR_NONE)
1380 LoggerW("Fail to set postal_code value to child_record str : " << postalCode);
1381 contacts_record_destroy(child_record, true);
1386 errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
1387 if(errorCode != CONTACTS_ERROR_NONE)
1389 LoggerW("Fail to set favorite value to child_record default : " << ctsBoolDefault);
1390 contacts_record_destroy(child_record, true);
1394 errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
1395 if(errorCode != CONTACTS_ERROR_NONE)
1397 LoggerW("Fail to set default value to child_record type : " << ctsIntType);
1398 contacts_record_destroy(child_record, true);
1402 //if(ctsStrCustomType != NULL)
1404 // errorCode = contacts_record_set_str(child_record, _contacts_address.label, ctsStrCustomType);
1405 // if(errorCode != CONTACTS_ERROR_NONE)
1407 // LoggerW("Fail to set custom value to child_record type : " << ctsStrCustomType);
1408 // contacts_record_destroy(child_record, true);
1413 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.address, child_record);
1414 if(errorCode != CONTACTS_ERROR_NONE)
1416 LoggerW("Fail to set address value to child_record");
1417 contacts_record_destroy(child_record, true);
1423 void ContactObjectA2PConverter::importWebAddrList()
1426 contacts_record_h child_record = NULL;
1427 unsigned int record_count = 0;
1429 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &record_count);
1430 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1432 ThrowMsg(PlatformException, "getting url count (err:" << errorCode << ")");
1435 for(int i=record_count-1; i>=0; i--)
1437 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
1438 if(errorCode != CONTACTS_ERROR_NONE)
1439 ThrowMsg(UnknownException, "getting url value A (errorCode:" << errorCode << ")");
1441 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.url, child_record);
1442 if(errorCode != CONTACTS_ERROR_NONE)
1443 ThrowMsg(UnknownException, "removing url value A (errorCode:" << errorCode << ")");
1445 child_record = NULL;
1448 ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
1449 if(webSites->size() == 0)
1452 ContactWebSiteArray::iterator webSiteIter = webSites->begin();
1453 for(; webSiteIter != webSites->end(); webSiteIter++)
1455 ContactWebSitePtr webSite = *webSiteIter;
1456 ContactWebSiteType type = webSite->getType();
1458 if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
1460 LoggerD("url was not set.");
1464 string url = webSite->getUrl();
1467 // char *ctsStrCustomType = NULL;
1469 if(type == WEBSITE_TYPE_HOMEPAGE)
1470 ctsIntType = CONTACTS_URL_TYPE_HOME;
1471 else if(type == WEBSITE_TYPE_BLOG)
1472 ctsIntType = CONTACTS_URL_TYPE_WORK;
1474 ctsIntType = CONTACTS_URL_TYPE_HOME;
1476 child_record = NULL;
1478 errorCode = contacts_record_create(_contacts_url._uri, &child_record);
1479 if(errorCode != CONTACTS_ERROR_NONE)
1481 LoggerW("Fail to create child_record with contacts_record_create(_contacts_url._uri)");
1485 errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
1486 if(errorCode != CONTACTS_ERROR_NONE)
1488 LoggerW("Fail to set url value to child_record str : " << url);
1489 contacts_record_destroy(child_record, true);
1493 errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
1494 if(errorCode != CONTACTS_ERROR_NONE)
1496 LoggerW("Fail to set default value to child_record type : " << ctsIntType);
1497 contacts_record_destroy(child_record, true);
1501 if(ctsStrCustomType != NULL)
1503 errorCode = contacts_record_set_str(child_record, _contacts_url.label, ctsStrCustomType);
1504 if(errorCode != CONTACTS_ERROR_NONE)
1506 LoggerW("Fail to set custom value to child_record type : " << ctsStrCustomType);
1507 contacts_record_destroy(child_record, true);
1512 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.url, child_record);
1513 if(errorCode != CONTACTS_ERROR_NONE)
1515 LoggerW("Fail to set url value to child_record");
1516 contacts_record_destroy(child_record, true);
1522 void ContactObjectA2PConverter::importNicknameList()
1525 contacts_record_h child_record = NULL;
1526 unsigned int record_count = 0;
1528 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &record_count);
1529 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1531 ThrowMsg(PlatformException, "getting nickname count (err:" << errorCode << ")");
1534 for(int i=record_count-1; i>=0; i--)
1536 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
1537 if(errorCode != CONTACTS_ERROR_NONE)
1538 ThrowMsg(UnknownException, "getting nickname value A (errorCode:" << errorCode << ")");
1540 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1541 if(errorCode != CONTACTS_ERROR_NONE)
1542 ThrowMsg(UnknownException, "removing nickname value A (errorCode:" << errorCode << ")");
1544 child_record = NULL;
1547 ContactNamePtr contactName = m_abstractContact->getName();
1548 if(contactName == NULL)
1551 if(contactName->getNicknamesNum() == 0)
1554 StringArrayPtr nicknames = contactName->getNicknames();
1556 StringArray::iterator nicknamesIter = nicknames->begin();
1557 for(; nicknamesIter != nicknames->end(); nicknamesIter++)
1559 string nickname = *nicknamesIter;
1561 if(nickname.empty())
1563 LoggerD("nickname was not set.");
1567 child_record = NULL;
1569 errorCode = contacts_record_create(_contacts_nickname._uri, &child_record);
1570 if(errorCode != CONTACTS_ERROR_NONE)
1572 LoggerW("Fail to create child_record with contacts_record_create(_contacts_nickname._uri)");
1576 errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
1577 if(errorCode != CONTACTS_ERROR_NONE)
1579 LoggerW("Fail to set nickname value to ctsValue str : " << nickname);
1580 contacts_record_destroy(child_record, true);
1584 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1585 if(errorCode != CONTACTS_ERROR_NONE)
1587 LoggerW("Fail to set nickname value to child_record");
1588 contacts_record_destroy(child_record, true);