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"
33 using namespace WrtDeviceApis::Commons;
36 static const char *EMPTY_STRING = "";
38 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
40 m_abstractContact(abstractContact),
41 m_platformContact(NULL),
42 m_forScratch(forScratch),
43 m_convertFinished(false),
44 m_platformContactOwnership(false)
48 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
50 contacts_record_h platformContact) :
51 m_abstractContact(abstractContact),
52 m_platformContact(platformContact),
53 m_forScratch(forScratch),
54 m_convertFinished(false),
55 m_platformContactOwnership(false)
59 ContactObjectA2PConverter::~ContactObjectA2PConverter()
61 if(m_platformContactOwnership && m_platformContact != NULL)
63 contacts_record_destroy(m_platformContact, true);
64 m_platformContact = NULL;
65 m_platformContactOwnership = false;
69 contacts_record_h ContactObjectA2PConverter::getPlatformContact()
75 if(m_abstractContact == NULL)
77 LogError("Abstract contact object did not set");
78 ThrowMsg(InvalidArgumentException, "Abstract contact object did not set");
81 if(m_platformContact == NULL)
83 if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
85 int id = ContactUtility::strToInt(m_abstractContact->getId());
86 LogDebug("Load platform object id : " << id);
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 LogDebug("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;
102 LogDebug("for scratch : " << m_forScratch);
106 if(m_convertFinished == false)
107 convertToPlatformObject();
111 LogError("Error while converting - " << _rethrown_exception.GetMessage());
112 ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
115 return m_platformContact;
118 void ContactObjectA2PConverter::convertToPlatformObject()
120 importBaseInfoValue();
126 importGrouprelList();
130 importNicknameList();
132 m_convertFinished = true;
135 void ContactObjectA2PConverter::importBaseInfoValue()
138 contacts_record_h child_record = NULL;
140 const char *newValueStr = NULL;
141 char *oldValueStr = NULL;
142 string abstractValueStr;
146 if(!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty())
148 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
149 if(errorCode != CONTACTS_ERROR_NONE)
150 ThrowMsg(UnknownException, "creating image value A (errorCode:" << errorCode << ")");
151 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
155 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
156 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
158 LogDebug("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
159 errorCode = contacts_record_create(_contacts_image._uri, &child_record);
160 if(errorCode != CONTACTS_ERROR_NONE)
161 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
164 contacts_record_get_str_p(child_record, _contacts_image.path, &oldValueStr);
165 realPath = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
166 m_abstractContact->setPhotoURIRealPath(realPath);
167 abstractValueStr = m_abstractContact->getPhotoURIRealPath();
168 if(oldValueStr != NULL &&
169 (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
171 newValueStr = EMPTY_STRING;
173 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
175 newValueStr = abstractValueStr.c_str();
178 if(newValueStr != NULL)
180 LogDebug("image : " << newValueStr);
181 errorCode = contacts_record_set_str(child_record, _contacts_image.path, newValueStr);
182 if(errorCode != CONTACTS_ERROR_NONE)
184 ThrowMsg(PlatformException, "importing photoURI E (err:" <<
185 errorCode << ", str:" << abstractValueStr << ")");
188 contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
191 // Contact.ringtoneURI
194 contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &oldValueStr);
195 realPath = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
196 m_abstractContact->setRingtoneURIRealPath(realPath);
197 abstractValueStr = m_abstractContact->getRingtoneURIRealPath();
198 if(oldValueStr != NULL &&
199 (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
201 newValueStr = EMPTY_STRING;
203 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
205 newValueStr = abstractValueStr.c_str();
208 if(newValueStr != NULL)
210 errorCode = contacts_record_set_str(m_platformContact, _contacts_contact.ringtone_path, newValueStr);
211 if(errorCode != CONTACTS_ERROR_NONE)
213 ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
214 errorCode << ", str:" << abstractValueStr << ")");
219 void ContactObjectA2PConverter::importNameValue()
222 contacts_record_h child_record = NULL;
224 ContactNamePtr contactName = m_abstractContact->getName();
225 if(contactName == NULL ||
226 (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
227 && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
228 && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
229 && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
230 && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
231 && ( !contactName->getSuffixIsSet() || contactName->getSuffix().empty() )
232 && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() ) ) )
234 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
235 if(errorCode != CONTACTS_ERROR_NONE)
236 ThrowMsg(UnknownException, "creating name value A (errorCode:" << errorCode << ")");
237 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
241 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
242 if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
244 LogDebug("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
245 errorCode = contacts_record_create(_contacts_name._uri, &child_record);
246 if(errorCode != CONTACTS_ERROR_NONE)
247 ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
249 importNameValueToNewValue(child_record, contactName);
253 importNameValueToExistingValue(child_record, contactName);
256 contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
259 void ContactObjectA2PConverter::importNameValueToExistingValue(contacts_record_h child_record, ContactNamePtr &contactName)
263 const char *newValueStr = NULL;
264 char *oldValueStr = NULL;
265 string abstractValueStr;
267 // ContactName.firstName
268 contacts_record_get_str_p(child_record, _contacts_name.first, &oldValueStr);
269 abstractValueStr = contactName->getFirstName();
270 if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
272 newValueStr = EMPTY_STRING;
274 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
276 newValueStr = abstractValueStr.c_str();
279 if(newValueStr != NULL)
281 errorCode = contacts_record_set_str(child_record, _contacts_name.first, newValueStr);
282 if(errorCode != CONTACTS_ERROR_NONE)
284 contacts_record_destroy(child_record, true);
285 ThrowMsg(PlatformException, "importing firstName E (err:" <<
286 errorCode << ", str:" << newValueStr << ")");
290 // ContactName.lastName
293 contacts_record_get_str_p(child_record, _contacts_name.last, &oldValueStr);
294 abstractValueStr = contactName->getLastName();
295 if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
297 newValueStr = EMPTY_STRING;
299 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
301 newValueStr = abstractValueStr.c_str();
304 if(newValueStr != NULL)
306 errorCode = contacts_record_set_str(child_record, _contacts_name.last, newValueStr);
307 if(errorCode != CONTACTS_ERROR_NONE)
309 contacts_record_destroy(child_record, true);
310 ThrowMsg(PlatformException, "importing lastName E (err:" <<
311 errorCode << ", str:" << newValueStr << ")");
315 // ContactName.middleName
318 contacts_record_get_str_p(child_record, _contacts_name.addition, &oldValueStr);
319 abstractValueStr = contactName->getMiddleName();
320 if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
322 newValueStr = EMPTY_STRING;
324 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
326 newValueStr = abstractValueStr.c_str();
329 if(newValueStr != NULL)
331 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, newValueStr);
332 if(errorCode != CONTACTS_ERROR_NONE)
334 contacts_record_destroy(child_record, true);
335 ThrowMsg(PlatformException, "importing middleName E (err:" <<
336 errorCode << ", str:" << newValueStr << ")");
340 // ContactName.prefix
343 contacts_record_get_str_p(child_record, _contacts_name.prefix, &oldValueStr);
344 abstractValueStr = contactName->getPrefix();
345 if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
347 newValueStr = EMPTY_STRING;
349 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
351 newValueStr = abstractValueStr.c_str();
354 if(newValueStr != NULL)
356 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, newValueStr);
357 if(errorCode != CONTACTS_ERROR_NONE)
359 contacts_record_destroy(child_record, true);
360 ThrowMsg(PlatformException, "importing prefix E (err:" <<
361 errorCode << ", str:" << newValueStr << ")");
365 // ContactName.suffix
368 contacts_record_get_str_p(child_record, _contacts_name.suffix, &oldValueStr);
369 abstractValueStr = contactName->getSuffix();
370 if(oldValueStr != NULL && (!contactName->getSuffixIsSet() || abstractValueStr.empty()) )
372 newValueStr = EMPTY_STRING;
374 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
376 newValueStr = abstractValueStr.c_str();
379 if(newValueStr != NULL)
381 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, newValueStr);
382 if(errorCode != CONTACTS_ERROR_NONE)
384 contacts_record_destroy(child_record, true);
385 ThrowMsg(PlatformException, "importing suffix E (err:" <<
386 errorCode << ", str:" << newValueStr << ")");
390 // ContactName.phoneticFirstName
393 contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &oldValueStr);
394 abstractValueStr = contactName->getPhoneticFirstName();
395 if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
397 newValueStr = EMPTY_STRING;
399 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
401 newValueStr = abstractValueStr.c_str();
404 if(newValueStr != NULL)
406 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, newValueStr);
407 if(errorCode != CONTACTS_ERROR_NONE)
409 contacts_record_destroy(child_record, true);
410 ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
411 errorCode << ", str:" << newValueStr << ")");
415 // ContactName.phoneticLastName
418 contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &oldValueStr);
419 abstractValueStr = contactName->getPhoneticLastName();
420 if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
422 newValueStr = EMPTY_STRING;
424 else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
426 newValueStr = abstractValueStr.c_str();
429 if(newValueStr != NULL)
431 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, newValueStr);
432 if(errorCode != CONTACTS_ERROR_NONE)
434 contacts_record_destroy(child_record, true);
435 ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
436 errorCode << ", str:" << newValueStr << ")");
441 void ContactObjectA2PConverter::importNameValueToNewValue(contacts_record_h child_record, ContactNamePtr &contactName)
445 // ContactName.firstName
446 if(contactName->getFirstNameIsSet())
448 string firstName = contactName->getFirstName();
449 if(firstName != EMPTY_STRING)
451 errorCode = contacts_record_set_str(child_record, _contacts_name.first, firstName.c_str());
452 if(errorCode != CONTACTS_ERROR_NONE)
454 contacts_record_destroy(child_record, true);
455 ThrowMsg(PlatformException, "importing firstName N (err:" <<
456 errorCode << ", str:" << firstName << ")");
461 // ContactName.lastName
462 if(contactName->getLastNameIsSet())
464 string lastName = contactName->getLastName();
465 if(lastName != EMPTY_STRING)
467 errorCode = contacts_record_set_str(child_record, _contacts_name.last, lastName.c_str());
468 if(errorCode != CONTACTS_ERROR_NONE)
470 contacts_record_destroy(child_record, true);
471 ThrowMsg(PlatformException, "importing lastName N (err:" <<
472 errorCode << ", str:" << lastName << ")");
477 // ContactName.middleName
478 if(contactName->getMiddleNameIsSet())
480 string middleName = contactName->getMiddleName();
481 if(middleName != EMPTY_STRING)
483 errorCode = contacts_record_set_str(child_record, _contacts_name.addition, middleName.c_str());
484 if(errorCode != CONTACTS_ERROR_NONE)
486 contacts_record_destroy(child_record, true);
487 ThrowMsg(PlatformException, "importing middleName N (err:" <<
488 errorCode << ", str:" << middleName << ")");
493 // ContactName.prefix
494 if(contactName->getPrefixIsSet())
496 string prefix = contactName->getPrefix();
497 if(prefix != EMPTY_STRING)
499 errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, prefix.c_str());
500 if(errorCode != CONTACTS_ERROR_NONE)
502 contacts_record_destroy(child_record, true);
503 ThrowMsg(PlatformException, "importing prefix N (err:" <<
504 errorCode << ", str:" << prefix << ")");
509 // ContactName.suffix
510 if(contactName->getSuffixIsSet())
512 string suffix = contactName->getSuffix();
513 if(suffix != EMPTY_STRING)
515 errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, suffix.c_str());
516 if(errorCode != CONTACTS_ERROR_NONE)
518 contacts_record_destroy(child_record, true);
519 ThrowMsg(PlatformException, "importing suffix N (err:" <<
520 errorCode << ", str:" << suffix << ")");
525 // ContactName.phoneticFirstName
526 if(contactName->getPhoneticFirstNameIsSet())
528 string phoneticFirstName = contactName->getPhoneticFirstName();
529 if(phoneticFirstName != EMPTY_STRING)
531 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, phoneticFirstName.c_str());
532 if(errorCode != CONTACTS_ERROR_NONE)
534 contacts_record_destroy(child_record, true);
535 ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
536 errorCode << ", str:" << phoneticFirstName << ")");
541 // ContactName.phoneticLastName
542 if(contactName->getPhoneticLastNameIsSet())
544 string phoneticLastName = contactName->getPhoneticLastName();
545 if(phoneticLastName != EMPTY_STRING)
547 errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, phoneticLastName.c_str());
548 if(errorCode != CONTACTS_ERROR_NONE)
550 contacts_record_destroy(child_record, true);
551 ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
552 errorCode << ", str:" << phoneticLastName << ")");
558 void ContactObjectA2PConverter::importCompanyList()
561 contacts_record_h child_record = NULL;
562 unsigned int record_count = 0;
564 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &record_count);
565 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
567 ThrowMsg(PlatformException, "getting company count (err:" << errorCode << ")");
570 for(int i=record_count-1; i>=0; i--)
572 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
573 if(errorCode != CONTACTS_ERROR_NONE)
574 ThrowMsg(UnknownException, "getting company value A (errorCode:" << errorCode << ")");
576 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.company, child_record);
577 if(errorCode != CONTACTS_ERROR_NONE)
578 ThrowMsg(UnknownException, "removing company value A (errorCode:" << errorCode << ")");
583 ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
584 if(organizations->size() == 0)
587 ContactOrganizationArray::iterator organizationsIter = organizations->begin();
588 for(; organizationsIter != organizations->end(); organizationsIter++)
590 ContactOrganizationPtr organization = *organizationsIter;
594 errorCode = contacts_record_create(_contacts_company._uri, &child_record);
595 if(errorCode != CONTACTS_ERROR_NONE)
597 LogWarning("Fail to create child_record with contacts_record_create(_contacts_company._uri)");
601 // ContactOrganization.name
602 if(organization->getNameIsSet())
604 string name = organization->getName();
607 errorCode = contacts_record_set_str(child_record, _contacts_company.name, name.c_str());
608 if(errorCode != CONTACTS_ERROR_NONE)
610 LogWarning("importing company name N (err:" << errorCode << ", str:" << name << ")");
611 contacts_record_destroy(child_record, true);
617 // ContactOrganization.department
618 if(organization->getDepartmentIsSet())
620 string department = organization->getDepartment();
621 if(!department.empty())
623 errorCode = contacts_record_set_str(child_record, _contacts_company.department, department.c_str());
624 if(errorCode != CONTACTS_ERROR_NONE)
626 LogWarning("importing department N (err:" << errorCode << ", str:" << department << ")");
627 contacts_record_destroy(child_record, true);
633 // ContactOrganization.title
634 if(organization->getTitleIsSet())
636 string title = organization->getTitle();
639 errorCode = contacts_record_set_str(child_record, _contacts_company.job_title, title.c_str());
640 if(errorCode != CONTACTS_ERROR_NONE)
642 LogWarning("importing title N (err:" << errorCode << ", str:" << title << ")");
643 contacts_record_destroy(child_record, true);
649 // ContactOrganization.role
650 if(organization->getRoleIsSet())
652 string role = organization->getRole();
655 errorCode = contacts_record_set_str(child_record, _contacts_company.role, role.c_str());
656 if(errorCode != CONTACTS_ERROR_NONE)
658 LogWarning("importing role N (err:" << errorCode << ", str:" << role << ")");
659 contacts_record_destroy(child_record, true);
665 // ContactOrganization.logoURI
666 if(organization->getLogoURIIsSet())
668 string logoURI = organization->getLogoURI();
671 logoURI = ContactUtility::convertUriToPath(logoURI);
672 errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
673 if(errorCode != CONTACTS_ERROR_NONE)
675 LogWarning("importing logoURI N (err:" << errorCode << ", str:" << logoURI << ")");
676 contacts_record_destroy(child_record, true);
682 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.company, child_record);
683 if(errorCode != CONTACTS_ERROR_NONE)
685 LogWarning("Fail to set company value to child_record");
686 contacts_record_destroy(child_record, true);
692 void ContactObjectA2PConverter::importNoteList()
695 contacts_record_h child_record = NULL;
696 unsigned int record_count = 0;
698 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &record_count);
699 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
701 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
704 for(int i=record_count-1; i>=0; i--)
706 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
707 if(errorCode != CONTACTS_ERROR_NONE)
708 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
710 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.note, child_record);
711 if(errorCode != CONTACTS_ERROR_NONE)
712 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
717 StringArrayPtr notes = m_abstractContact->getNotes();
718 if(notes->size() == 0)
721 StringArray::iterator notesIter = notes->begin();
722 for(; notesIter != notes->end(); notesIter++)
724 string note = *notesIter;
733 errorCode = contacts_record_create(_contacts_note._uri, &child_record);
734 if(errorCode != CONTACTS_ERROR_NONE)
736 LogWarning("Fail to create child_record with contacts_record_create(_contacts_note._uri)");
740 errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
741 if(errorCode != CONTACTS_ERROR_NONE)
743 LogWarning("importing note N (err:" << errorCode << ", str:" << note << ")");
744 contacts_record_destroy(child_record, true);
748 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.note, child_record);
749 if(errorCode != CONTACTS_ERROR_NONE)
751 LogWarning("Fail to set note value to child_record");
752 contacts_record_destroy(child_record, true);
758 void ContactObjectA2PConverter::importNumberList()
761 contacts_record_h child_record = NULL;
762 unsigned int record_count = 0;
764 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &record_count);
765 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
767 ThrowMsg(PlatformException, "getting number count (err:" << errorCode << ")");
770 for(int i=record_count-1; i>=0; i--)
772 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
773 if(errorCode != CONTACTS_ERROR_NONE)
774 ThrowMsg(UnknownException, "getting number value A (errorCode:" << errorCode << ")");
776 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.number, child_record);
777 if(errorCode != CONTACTS_ERROR_NONE)
778 ThrowMsg(UnknownException, "removing number value A (errorCode:" << errorCode << ")");
783 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
784 if(phoneNumbers->size() == 0)
787 ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
788 for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
790 ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
791 ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
793 if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
795 LogDebug("Number was not set.");
799 string number = phoneNumber->getNumber();
801 bool ctsBoolDefault = phoneNumber->getIsDefault();
804 //char *ctsStrCustomType = NULL;
806 ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
807 for(; typesIter != types->end(); typesIter++)
809 ContactPhoneNumberType type = *typesIter;
810 if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
811 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_HOME;
812 else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
813 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_WORK;
814 else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
815 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
816 else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
817 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_FAX;
818 else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
819 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MSG;
820 else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
821 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CELL;
822 else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
823 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PAGER;
824 else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
825 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_BBS;
826 else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
827 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MODEM;
828 else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
829 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CAR;
830 else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
831 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_ISDN;
832 else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
833 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VIDEO;
834 else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
835 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PCS;
838 // TODO Will be added after type changed to string
839 // ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CUSTOM;
840 // ctsStrCustomType = ...;
846 errorCode = contacts_record_create(_contacts_number._uri, &child_record);
847 if(errorCode != CONTACTS_ERROR_NONE)
849 LogWarning("Fail to create child_record with contacts_record_create(_contacts_number._uri)");
853 errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
854 if(errorCode != CONTACTS_ERROR_NONE)
856 LogWarning("Fail to set number value to child_record number : " << number);
857 contacts_record_destroy(child_record, true);
861 errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
862 if(errorCode != CONTACTS_ERROR_NONE)
864 LogWarning("Fail to set number value to child_record default : " << ctsBoolDefault);
865 contacts_record_destroy(child_record, true);
869 errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
870 if(errorCode != CONTACTS_ERROR_NONE)
872 LogWarning("Fail to set number value to child_record type : " << ctsIntType);
873 contacts_record_destroy(child_record, true);
877 //if(ctsStrCustomType != NULL)
879 // errorCode = contacts_record_set_str(child_record, _contacts_number.label, ctsStrCustomType);
880 // if(errorCode != CONTACTS_ERROR_NONE)
882 // LogWarning("Fail to set number value to child_record custom type : " << ctsStrCustomType);
883 // contacts_record_destroy(child_record, true);
888 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.number, child_record);
889 if(errorCode != CONTACTS_ERROR_NONE)
891 LogWarning("Fail to set number value to child_record");
892 contacts_record_destroy(child_record, true);
898 void ContactObjectA2PConverter::importEmailList()
901 contacts_record_h child_record = NULL;
902 unsigned int record_count = 0;
904 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &record_count);
905 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
907 ThrowMsg(PlatformException, "getting email count (err:" << errorCode << ")");
910 for(int i=record_count-1; i>=0; i--)
912 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
913 if(errorCode != CONTACTS_ERROR_NONE)
914 ThrowMsg(UnknownException, "getting email value A (errorCode:" << errorCode << ")");
916 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.email, child_record);
917 if(errorCode != CONTACTS_ERROR_NONE)
918 ThrowMsg(UnknownException, "removing email value A (errorCode:" << errorCode << ")");
923 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
924 if(emails->size() == 0)
927 ContactEmailAddressArray::iterator emailsIter = emails->begin();
928 for(; emailsIter != emails->end(); emailsIter++)
930 ContactEmailAddressPtr email = *emailsIter;
931 ContactEmailAddressTypeArrayPtr types = email->getTypes();
933 if(!email->getEmailIsSet() || email->getEmail().empty())
935 LogDebug("email address was not set.");
939 string emailAddress = email->getEmail();
941 bool ctsBoolDefault = email->getIsDefault();
944 //char *ctsStrCustomType = NULL;
946 ContactEmailAddressTypeArray::iterator typesIter = types->begin();
947 for(; typesIter != types->end(); typesIter++)
949 ContactEmailAddressType type = *typesIter;
950 if(type == CONTACT_EMAIL_TYPE_HOME)
951 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
952 else if(type == CONTACT_EMAIL_TYPE_WORK)
953 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_WORK;
956 // //TODO Will be added after type changed to string
957 // //ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_CUSTOM;
958 // // ctsStrCustomType = ...;
964 errorCode = contacts_record_create(_contacts_email._uri, &child_record);
965 if(errorCode != CONTACTS_ERROR_NONE)
967 LogWarning("Fail to create child_record with contacts_record_create(_contacts_email._uri)");
971 errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
972 if(errorCode != CONTACTS_ERROR_NONE)
974 LogWarning("Fail to set email value to child_record email : " << emailAddress);
975 contacts_record_destroy(child_record, true);
979 errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
980 if(errorCode != CONTACTS_ERROR_NONE)
982 LogWarning("Fail to set email value to child_record default : " << ctsBoolDefault);
983 contacts_record_destroy(child_record, true);
987 errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
988 if(errorCode != CONTACTS_ERROR_NONE)
990 LogWarning("Fail to set email value to child_record type : " << ctsIntType);
991 contacts_record_destroy(child_record, true);
995 //if(ctsStrCustomType != NULL)
997 // errorCode = contacts_record_set_str(child_record, _contacts_email.label, ctsStrCustomType);
998 // if(errorCode != CONTACTS_ERROR_NONE)
1000 // LogWarning("Fail to set email value to child_record custom type : " << ctsStrCustomType);
1001 // contacts_record_destroy(child_record, true);
1006 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.email, child_record);
1007 if(errorCode != CONTACTS_ERROR_NONE)
1009 LogWarning("Fail to set email value to child_record");
1010 contacts_record_destroy(child_record, true);
1016 void ContactObjectA2PConverter::importGrouprelList()
1019 contacts_record_h child_record = NULL;
1020 unsigned int record_count = 0;
1022 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &record_count);
1023 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1025 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
1028 for(int i=record_count-1; i>=0; i--)
1030 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
1031 if(errorCode != CONTACTS_ERROR_NONE)
1032 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
1034 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1035 if(errorCode != CONTACTS_ERROR_NONE)
1036 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
1038 child_record = NULL;
1041 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
1042 if(groupIds->size() == 0)
1045 StringArray::iterator groupIdsIter = groupIds->begin();
1046 for(; groupIdsIter != groupIds->end(); groupIdsIter++)
1048 string groupId = *groupIdsIter;
1050 child_record = NULL;
1052 if(!ContactUtility::checkStrIsUInt(groupId))
1054 LogWarning("groupId (" << groupId << ") is wrong.");
1058 int groupIdInt = ContactUtility::strToInt(groupId);
1060 errorCode = contacts_record_create(_contacts_group_relation._uri, &child_record);
1061 if(errorCode != CONTACTS_ERROR_NONE)
1063 LogWarning("Fail to create child_record with contacts_record_create(_contacts_group_relation._uri)");
1067 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
1068 if(errorCode != CONTACTS_ERROR_NONE)
1070 LogWarning("importing group id N (err:" << errorCode << ", str:" << groupIdInt << ")");
1071 contacts_record_destroy(child_record, true);
1075 int contactId = ContactUtility::strToInt(m_abstractContact->getId());
1076 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
1077 if(errorCode != CONTACTS_ERROR_NONE)
1079 LogWarning("importing group contact_id N (err:" << errorCode << ", str:" << contactId << ")");
1080 contacts_record_destroy(child_record, true);
1084 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1085 if(errorCode != CONTACTS_ERROR_NONE)
1087 LogWarning("Fail to set group value to child_record");
1088 contacts_record_destroy(child_record, true);
1094 void ContactObjectA2PConverter::importEventList()
1097 contacts_record_h child_record = NULL;
1098 unsigned int record_count = 0;
1100 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &record_count);
1101 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1103 ThrowMsg(PlatformException, "getting event count (err:" << errorCode << ")");
1106 for(int i=record_count-1; i>=0; i--)
1108 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
1109 if(errorCode != CONTACTS_ERROR_NONE)
1110 ThrowMsg(UnknownException, "getting event value A (errorCode:" << errorCode << ")");
1112 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.event, child_record);
1113 if(errorCode != CONTACTS_ERROR_NONE)
1114 ThrowMsg(UnknownException, "removing event value A (errorCode:" << errorCode << ")");
1116 child_record = NULL;
1119 if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
1122 importEventListBirthday();
1124 importEventListAnniversary();
1127 void ContactObjectA2PConverter::importEventListBirthday()
1131 if(!m_abstractContact->getBirthdayIsSet())
1134 tm birthdayTm = m_abstractContact->getBirthday();
1136 if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
1139 int birthday = ContactUtility::toDateDbInt(birthdayTm);
1141 contacts_record_h child_record = NULL;
1143 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1144 if(errorCode != CONTACTS_ERROR_NONE)
1146 LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1150 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
1151 if(errorCode != CONTACTS_ERROR_NONE)
1153 LogWarning("Fail to set event value to child_record type : " << CONTACTS_EVENT_TYPE_BIRTH);
1154 contacts_record_destroy(child_record, true);
1158 errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
1159 if(errorCode != CONTACTS_ERROR_NONE)
1161 LogWarning("Fail to set event value to child_record date : " << birthday);
1162 contacts_record_destroy(child_record, true);
1166 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1167 if(errorCode != CONTACTS_ERROR_NONE)
1169 LogWarning("Fail to set event value to child_record");
1170 contacts_record_destroy(child_record, true);
1175 void ContactObjectA2PConverter::importEventListAnniversary()
1178 contacts_record_h child_record = NULL;
1180 if(m_abstractContact->getAnniversariesNum() == 0)
1183 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
1185 ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
1186 for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
1188 ContactAnniversaryPtr anniversary = *anniversariesIter;
1190 if(!anniversary->getDateIsSet())
1193 tm dateTm = anniversary->getDate();
1195 if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
1198 int date = ContactUtility::toDateDbInt(dateTm);
1200 child_record = NULL;
1202 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1203 if(errorCode != CONTACTS_ERROR_NONE)
1205 LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1209 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
1210 if(errorCode != CONTACTS_ERROR_NONE)
1212 LogWarning("Fail to set event value to child_record type : CONTACTS_EVENT_TYPE_ANNIVERSARY");
1213 contacts_record_destroy(child_record, true);
1217 errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
1218 if(errorCode != CONTACTS_ERROR_NONE)
1220 LogWarning("Fail to set event value to child_record date : " << date);
1221 contacts_record_destroy(child_record, true);
1225 if(anniversary->getLabelIsSet())
1227 string label = anniversary->getLabel();
1228 errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
1229 if(errorCode != CONTACTS_ERROR_NONE)
1231 LogWarning("Fail to set label value to child_record label : " << label);
1232 contacts_record_destroy(child_record, true);
1238 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1239 if(errorCode != CONTACTS_ERROR_NONE)
1241 LogWarning("Fail to set event value to child_record");
1242 contacts_record_destroy(child_record, true);
1248 void ContactObjectA2PConverter::importPostalList()
1251 contacts_record_h child_record = NULL;
1252 unsigned int record_count = 0;
1254 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &record_count);
1255 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1257 ThrowMsg(PlatformException, "getting address count (err:" << errorCode << ")");
1260 for(int i=record_count-1; i>=0; i--)
1262 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
1263 if(errorCode != CONTACTS_ERROR_NONE)
1264 ThrowMsg(UnknownException, "getting address value A (errorCode:" << errorCode << ")");
1266 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.address, child_record);
1267 if(errorCode != CONTACTS_ERROR_NONE)
1268 ThrowMsg(UnknownException, "removing address value A (errorCode:" << errorCode << ")");
1270 child_record = NULL;
1273 if(m_abstractContact->getAddressesNum() == 0)
1276 ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
1278 ContactAddressArray::iterator addressesIter = addresses->begin();
1279 for(; addressesIter != addresses->end(); addressesIter++)
1281 ContactAddressPtr address = *addressesIter;
1282 ContactAddressTypeArrayPtr types = address->getTypes();
1284 if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
1285 ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
1286 ( !address->getCityIsSet() || address->getCity().empty() ) &&
1287 ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
1288 ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
1289 ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
1291 LogDebug("No information for address was not set.");
1295 bool ctsBoolDefault = address->getIsDefault();
1298 //char *ctsStrCustomType = NULL;
1300 ContactAddressTypeArray::iterator typesIter = types->begin();
1301 for(; typesIter != types->end(); typesIter++)
1303 ContactAddressType type = *typesIter;
1304 if(type == CONTACT_ADDRESS_TYPE_HOME)
1305 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1306 else if(type == CONTACT_ADDRESS_TYPE_WORK)
1307 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_WORK;
1310 // // TODO Will be added after type changed to string
1311 // // ctsIntType = ctsIntType | CTS_POSTAL_TYPE_CUSTOM;
1312 // // ctsStrCustomType = ...;
1316 child_record = NULL;
1318 errorCode = contacts_record_create(_contacts_address._uri, &child_record);
1319 if(errorCode != CONTACTS_ERROR_NONE)
1321 LogWarning("Fail to create child_record with contacts_record_create(_contacts_address._uri)");
1325 if(address->getCountryIsSet())
1327 string country = address->getCountry();
1328 errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
1329 if(errorCode != CONTACTS_ERROR_NONE)
1331 LogWarning("Fail to set country value to child_record str : " << country);
1332 contacts_record_destroy(child_record, true);
1337 if(address->getRegionIsSet())
1339 string region = address->getRegion();
1340 errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
1341 if(errorCode != CONTACTS_ERROR_NONE)
1343 LogWarning("Fail to set region value to child_record str : " << region);
1344 contacts_record_destroy(child_record, true);
1349 if(address->getCityIsSet())
1351 string city = address->getCity();
1352 errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
1353 if(errorCode != CONTACTS_ERROR_NONE)
1355 LogWarning("Fail to set locality value to child_record str : " << city);
1356 contacts_record_destroy(child_record, true);
1361 if(address->getStreetAddressIsSet())
1363 string streetAddress = address->getStreetAddress();
1364 errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
1365 if(errorCode != CONTACTS_ERROR_NONE)
1367 LogWarning("Fail to set street value to child_record str : " << streetAddress);
1368 contacts_record_destroy(child_record, true);
1373 if(address->getAdditionalInformationIsSet())
1375 string additionalInformation = address->getAdditionalInformation();
1376 errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
1377 if(errorCode != CONTACTS_ERROR_NONE)
1379 LogWarning("Fail to set extended value to child_record str : " << additionalInformation);
1380 contacts_record_destroy(child_record, true);
1385 if(address->getPostalCodeIsSet())
1387 string postalCode = address->getPostalCode();
1388 errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
1389 if(errorCode != CONTACTS_ERROR_NONE)
1391 LogWarning("Fail to set postal_code value to child_record str : " << postalCode);
1392 contacts_record_destroy(child_record, true);
1397 errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
1398 if(errorCode != CONTACTS_ERROR_NONE)
1400 LogWarning("Fail to set favorite value to child_record default : " << ctsBoolDefault);
1401 contacts_record_destroy(child_record, true);
1405 errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
1406 if(errorCode != CONTACTS_ERROR_NONE)
1408 LogWarning("Fail to set default value to child_record type : " << ctsIntType);
1409 contacts_record_destroy(child_record, true);
1413 //if(ctsStrCustomType != NULL)
1415 // errorCode = contacts_record_set_str(child_record, _contacts_address.label, ctsStrCustomType);
1416 // if(errorCode != CONTACTS_ERROR_NONE)
1418 // LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
1419 // contacts_record_destroy(child_record, true);
1424 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.address, child_record);
1425 if(errorCode != CONTACTS_ERROR_NONE)
1427 LogWarning("Fail to set address value to child_record");
1428 contacts_record_destroy(child_record, true);
1434 void ContactObjectA2PConverter::importWebAddrList()
1437 contacts_record_h child_record = NULL;
1438 unsigned int record_count = 0;
1440 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &record_count);
1441 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1443 ThrowMsg(PlatformException, "getting url count (err:" << errorCode << ")");
1446 for(int i=record_count-1; i>=0; i--)
1448 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
1449 if(errorCode != CONTACTS_ERROR_NONE)
1450 ThrowMsg(UnknownException, "getting url value A (errorCode:" << errorCode << ")");
1452 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.url, child_record);
1453 if(errorCode != CONTACTS_ERROR_NONE)
1454 ThrowMsg(UnknownException, "removing url value A (errorCode:" << errorCode << ")");
1456 child_record = NULL;
1459 ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
1460 if(webSites->size() == 0)
1463 ContactWebSiteArray::iterator webSiteIter = webSites->begin();
1464 for(; webSiteIter != webSites->end(); webSiteIter++)
1466 ContactWebSitePtr webSite = *webSiteIter;
1467 ContactWebSiteType type = webSite->getType();
1469 if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
1471 LogDebug("url was not set.");
1475 string url = webSite->getUrl();
1478 // char *ctsStrCustomType = NULL;
1480 if(type == WEBSITE_TYPE_HOMEPAGE)
1481 ctsIntType = CONTACTS_URL_TYPE_HOME;
1482 else if(type == WEBSITE_TYPE_BLOG)
1483 ctsIntType = CONTACTS_URL_TYPE_WORK;
1486 // TODO Will be added after type changed to string
1487 // ctsIntType = CONTACTS_URL_TYPE_CUSTOM;
1488 // ctsStrCustomType = ...;
1491 child_record = NULL;
1493 errorCode = contacts_record_create(_contacts_url._uri, &child_record);
1494 if(errorCode != CONTACTS_ERROR_NONE)
1496 LogWarning("Fail to create child_record with contacts_record_create(_contacts_url._uri)");
1500 errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
1501 if(errorCode != CONTACTS_ERROR_NONE)
1503 LogWarning("Fail to set url value to child_record str : " << url);
1504 contacts_record_destroy(child_record, true);
1508 errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
1509 if(errorCode != CONTACTS_ERROR_NONE)
1511 LogWarning("Fail to set default value to child_record type : " << ctsIntType);
1512 contacts_record_destroy(child_record, true);
1516 if(ctsStrCustomType != NULL)
1518 errorCode = contacts_record_set_str(child_record, _contacts_url.label, ctsStrCustomType);
1519 if(errorCode != CONTACTS_ERROR_NONE)
1521 LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
1522 contacts_record_destroy(child_record, true);
1527 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.url, child_record);
1528 if(errorCode != CONTACTS_ERROR_NONE)
1530 LogWarning("Fail to set url value to child_record");
1531 contacts_record_destroy(child_record, true);
1537 void ContactObjectA2PConverter::importNicknameList()
1540 contacts_record_h child_record = NULL;
1541 unsigned int record_count = 0;
1543 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &record_count);
1544 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1546 ThrowMsg(PlatformException, "getting nickname count (err:" << errorCode << ")");
1549 for(int i=record_count-1; i>=0; i--)
1551 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
1552 if(errorCode != CONTACTS_ERROR_NONE)
1553 ThrowMsg(UnknownException, "getting nickname value A (errorCode:" << errorCode << ")");
1555 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1556 if(errorCode != CONTACTS_ERROR_NONE)
1557 ThrowMsg(UnknownException, "removing nickname value A (errorCode:" << errorCode << ")");
1559 child_record = NULL;
1562 ContactNamePtr contactName = m_abstractContact->getName();
1563 if(contactName == NULL)
1566 if(contactName->getNicknamesNum() == 0)
1569 StringArrayPtr nicknames = contactName->getNicknames();
1571 StringArray::iterator nicknamesIter = nicknames->begin();
1572 for(; nicknamesIter != nicknames->end(); nicknamesIter++)
1574 string nickname = *nicknamesIter;
1576 if(nickname.empty())
1578 LogDebug("nickname was not set.");
1582 child_record = NULL;
1584 errorCode = contacts_record_create(_contacts_nickname._uri, &child_record);
1585 if(errorCode != CONTACTS_ERROR_NONE)
1587 LogWarning("Fail to create child_record with contacts_record_create(_contacts_nickname._uri)");
1591 errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
1592 if(errorCode != CONTACTS_ERROR_NONE)
1594 LogWarning("Fail to set nickname value to ctsValue str : " << nickname);
1595 contacts_record_destroy(child_record, true);
1599 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1600 if(errorCode != CONTACTS_ERROR_NONE)
1602 LogWarning("Fail to set nickname value to child_record");
1603 contacts_record_destroy(child_record, true);