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 LogDebug("organization->getLogoURIIsSet() : " << organization->getLogoURIIsSet());
666 // ContactOrganization.logoURI
667 if(organization->getLogoURIIsSet())
669 LogDebug("organization->getLogoURI() : " << organization->getLogoURI());
670 string logoURI = organization->getLogoURI();
673 // logoURI = ContactUtility::convertUriToPath(logoURI);
674 LogDebug("logoURI.c_str() : " << logoURI.c_str());
676 errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
677 LogDebug("errorCode : " << errorCode);
678 if(errorCode != CONTACTS_ERROR_NONE)
680 LogWarning("importing logoURI N (err:" << errorCode << ", str:" << logoURI << ")");
681 contacts_record_destroy(child_record, true);
687 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.company, child_record);
688 if(errorCode != CONTACTS_ERROR_NONE)
690 LogWarning("Fail to set company value to child_record");
691 contacts_record_destroy(child_record, true);
697 void ContactObjectA2PConverter::importNoteList()
700 contacts_record_h child_record = NULL;
701 unsigned int record_count = 0;
703 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &record_count);
704 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
706 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
709 for(int i=record_count-1; i>=0; i--)
711 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
712 if(errorCode != CONTACTS_ERROR_NONE)
713 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
715 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.note, child_record);
716 if(errorCode != CONTACTS_ERROR_NONE)
717 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
722 StringArrayPtr notes = m_abstractContact->getNotes();
723 if(notes->size() == 0)
726 StringArray::iterator notesIter = notes->begin();
727 for(; notesIter != notes->end(); notesIter++)
729 string note = *notesIter;
738 errorCode = contacts_record_create(_contacts_note._uri, &child_record);
739 if(errorCode != CONTACTS_ERROR_NONE)
741 LogWarning("Fail to create child_record with contacts_record_create(_contacts_note._uri)");
745 errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
746 if(errorCode != CONTACTS_ERROR_NONE)
748 LogWarning("importing note N (err:" << errorCode << ", str:" << note << ")");
749 contacts_record_destroy(child_record, true);
753 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.note, child_record);
754 if(errorCode != CONTACTS_ERROR_NONE)
756 LogWarning("Fail to set note value to child_record");
757 contacts_record_destroy(child_record, true);
763 void ContactObjectA2PConverter::importNumberList()
766 contacts_record_h child_record = NULL;
767 unsigned int record_count = 0;
769 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &record_count);
770 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
772 ThrowMsg(PlatformException, "getting number count (err:" << errorCode << ")");
775 for(int i=record_count-1; i>=0; i--)
777 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
778 if(errorCode != CONTACTS_ERROR_NONE)
779 ThrowMsg(UnknownException, "getting number value A (errorCode:" << errorCode << ")");
781 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.number, child_record);
782 if(errorCode != CONTACTS_ERROR_NONE)
783 ThrowMsg(UnknownException, "removing number value A (errorCode:" << errorCode << ")");
788 ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
789 if(phoneNumbers->size() == 0)
792 ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
793 for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
795 ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
796 ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
798 if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
800 LogDebug("Number was not set.");
804 string number = phoneNumber->getNumber();
806 bool ctsBoolDefault = phoneNumber->getIsDefault();
809 //char *ctsStrCustomType = NULL;
811 ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
812 for(; typesIter != types->end(); typesIter++)
814 ContactPhoneNumberType type = *typesIter;
815 if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
816 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_HOME;
817 else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
818 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_WORK;
819 else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
820 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
821 else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
822 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_FAX;
823 else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
824 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MSG;
825 else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
826 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CELL;
827 else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
828 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PAGER;
829 else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
830 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_BBS;
831 else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
832 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MODEM;
833 else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
834 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CAR;
835 else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
836 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_ISDN;
837 else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
838 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VIDEO;
839 else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
840 ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PCS;
843 // TODO Will be added after type changed to string
844 // ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CUSTOM;
845 // ctsStrCustomType = ...;
851 errorCode = contacts_record_create(_contacts_number._uri, &child_record);
852 if(errorCode != CONTACTS_ERROR_NONE)
854 LogWarning("Fail to create child_record with contacts_record_create(_contacts_number._uri)");
858 errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
859 if(errorCode != CONTACTS_ERROR_NONE)
861 LogWarning("Fail to set number value to child_record number : " << number);
862 contacts_record_destroy(child_record, true);
866 errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
867 if(errorCode != CONTACTS_ERROR_NONE)
869 LogWarning("Fail to set number value to child_record default : " << ctsBoolDefault);
870 contacts_record_destroy(child_record, true);
874 errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
875 if(errorCode != CONTACTS_ERROR_NONE)
877 LogWarning("Fail to set number value to child_record type : " << ctsIntType);
878 contacts_record_destroy(child_record, true);
882 //if(ctsStrCustomType != NULL)
884 // errorCode = contacts_record_set_str(child_record, _contacts_number.label, ctsStrCustomType);
885 // if(errorCode != CONTACTS_ERROR_NONE)
887 // LogWarning("Fail to set number value to child_record custom type : " << ctsStrCustomType);
888 // contacts_record_destroy(child_record, true);
893 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.number, child_record);
894 if(errorCode != CONTACTS_ERROR_NONE)
896 LogWarning("Fail to set number value to child_record");
897 contacts_record_destroy(child_record, true);
903 void ContactObjectA2PConverter::importEmailList()
906 contacts_record_h child_record = NULL;
907 unsigned int record_count = 0;
909 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &record_count);
910 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
912 ThrowMsg(PlatformException, "getting email count (err:" << errorCode << ")");
915 for(int i=record_count-1; i>=0; i--)
917 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
918 if(errorCode != CONTACTS_ERROR_NONE)
919 ThrowMsg(UnknownException, "getting email value A (errorCode:" << errorCode << ")");
921 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.email, child_record);
922 if(errorCode != CONTACTS_ERROR_NONE)
923 ThrowMsg(UnknownException, "removing email value A (errorCode:" << errorCode << ")");
928 ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
929 if(emails->size() == 0)
932 ContactEmailAddressArray::iterator emailsIter = emails->begin();
933 for(; emailsIter != emails->end(); emailsIter++)
935 ContactEmailAddressPtr email = *emailsIter;
936 ContactEmailAddressTypeArrayPtr types = email->getTypes();
938 if(!email->getEmailIsSet() || email->getEmail().empty())
940 LogDebug("email address was not set.");
944 string emailAddress = email->getEmail();
946 bool ctsBoolDefault = email->getIsDefault();
949 //char *ctsStrCustomType = NULL;
951 ContactEmailAddressTypeArray::iterator typesIter = types->begin();
952 for(; typesIter != types->end(); typesIter++)
954 ContactEmailAddressType type = *typesIter;
955 if(type == CONTACT_EMAIL_TYPE_HOME)
956 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
957 else if(type == CONTACT_EMAIL_TYPE_WORK)
958 ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_WORK;
961 // //TODO Will be added after type changed to string
962 // //ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_CUSTOM;
963 // // ctsStrCustomType = ...;
969 errorCode = contacts_record_create(_contacts_email._uri, &child_record);
970 if(errorCode != CONTACTS_ERROR_NONE)
972 LogWarning("Fail to create child_record with contacts_record_create(_contacts_email._uri)");
976 errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
977 if(errorCode != CONTACTS_ERROR_NONE)
979 LogWarning("Fail to set email value to child_record email : " << emailAddress);
980 contacts_record_destroy(child_record, true);
984 errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
985 if(errorCode != CONTACTS_ERROR_NONE)
987 LogWarning("Fail to set email value to child_record default : " << ctsBoolDefault);
988 contacts_record_destroy(child_record, true);
992 errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
993 if(errorCode != CONTACTS_ERROR_NONE)
995 LogWarning("Fail to set email value to child_record type : " << ctsIntType);
996 contacts_record_destroy(child_record, true);
1000 //if(ctsStrCustomType != NULL)
1002 // errorCode = contacts_record_set_str(child_record, _contacts_email.label, ctsStrCustomType);
1003 // if(errorCode != CONTACTS_ERROR_NONE)
1005 // LogWarning("Fail to set email value to child_record custom type : " << ctsStrCustomType);
1006 // contacts_record_destroy(child_record, true);
1011 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.email, child_record);
1012 if(errorCode != CONTACTS_ERROR_NONE)
1014 LogWarning("Fail to set email value to child_record");
1015 contacts_record_destroy(child_record, true);
1021 void ContactObjectA2PConverter::importGrouprelList()
1024 contacts_record_h child_record = NULL;
1025 unsigned int record_count = 0;
1027 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &record_count);
1028 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1030 ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
1033 for(int i=record_count-1; i>=0; i--)
1035 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
1036 if(errorCode != CONTACTS_ERROR_NONE)
1037 ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
1039 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1040 if(errorCode != CONTACTS_ERROR_NONE)
1041 ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
1043 child_record = NULL;
1046 StringArrayPtr groupIds = m_abstractContact->getGroupIds();
1047 if(groupIds->size() == 0)
1050 StringArray::iterator groupIdsIter = groupIds->begin();
1051 for(; groupIdsIter != groupIds->end(); groupIdsIter++)
1053 string groupId = *groupIdsIter;
1055 child_record = NULL;
1057 if(ContactUtility::checkStrIsUInt(groupId))
1059 LogWarning("groupId (" << groupId << ") is wrong.");
1063 int groupIdInt = ContactUtility::strToInt(groupId);
1065 errorCode = contacts_record_create(_contacts_group_relation._uri, &child_record);
1066 if(errorCode != CONTACTS_ERROR_NONE)
1068 LogWarning("Fail to create child_record with contacts_record_create(_contacts_group_relation._uri)");
1072 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
1073 if(errorCode != CONTACTS_ERROR_NONE)
1075 LogWarning("importing group id N (err:" << errorCode << ", str:" << groupIdInt << ")");
1076 contacts_record_destroy(child_record, true);
1080 int contactId = ContactUtility::strToInt(m_abstractContact->getId());
1081 errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
1082 if(errorCode != CONTACTS_ERROR_NONE)
1084 LogWarning("importing group contact_id N (err:" << errorCode << ", str:" << contactId << ")");
1085 contacts_record_destroy(child_record, true);
1089 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
1090 if(errorCode != CONTACTS_ERROR_NONE)
1092 LogWarning("Fail to set group value to child_record");
1093 contacts_record_destroy(child_record, true);
1099 void ContactObjectA2PConverter::importEventList()
1102 contacts_record_h child_record = NULL;
1103 unsigned int record_count = 0;
1105 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &record_count);
1106 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1108 ThrowMsg(PlatformException, "getting event count (err:" << errorCode << ")");
1111 for(int i=record_count-1; i>=0; i--)
1113 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
1114 if(errorCode != CONTACTS_ERROR_NONE)
1115 ThrowMsg(UnknownException, "getting event value A (errorCode:" << errorCode << ")");
1117 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.event, child_record);
1118 if(errorCode != CONTACTS_ERROR_NONE)
1119 ThrowMsg(UnknownException, "removing event value A (errorCode:" << errorCode << ")");
1121 child_record = NULL;
1124 if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
1127 importEventListBirthday();
1129 importEventListAnniversary();
1132 void ContactObjectA2PConverter::importEventListBirthday()
1136 if(!m_abstractContact->getBirthdayIsSet())
1139 tm birthdayTm = m_abstractContact->getBirthday();
1141 if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
1144 int birthday = ContactUtility::toDateDbInt(birthdayTm);
1146 contacts_record_h child_record = NULL;
1148 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1149 if(errorCode != CONTACTS_ERROR_NONE)
1151 LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1155 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
1156 if(errorCode != CONTACTS_ERROR_NONE)
1158 LogWarning("Fail to set event value to child_record type : " << CONTACTS_EVENT_TYPE_BIRTH);
1159 contacts_record_destroy(child_record, true);
1163 errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
1164 if(errorCode != CONTACTS_ERROR_NONE)
1166 LogWarning("Fail to set event value to child_record date : " << birthday);
1167 contacts_record_destroy(child_record, true);
1171 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1172 if(errorCode != CONTACTS_ERROR_NONE)
1174 LogWarning("Fail to set event value to child_record");
1175 contacts_record_destroy(child_record, true);
1180 void ContactObjectA2PConverter::importEventListAnniversary()
1183 contacts_record_h child_record = NULL;
1185 if(m_abstractContact->getAnniversariesNum() == 0)
1188 ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
1190 ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
1191 for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
1193 ContactAnniversaryPtr anniversary = *anniversariesIter;
1195 if(!anniversary->getDateIsSet())
1198 tm dateTm = anniversary->getDate();
1200 if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
1203 int date = ContactUtility::toDateDbInt(dateTm);
1205 child_record = NULL;
1207 errorCode = contacts_record_create(_contacts_event._uri, &child_record);
1208 if(errorCode != CONTACTS_ERROR_NONE)
1210 LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
1214 errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
1215 if(errorCode != CONTACTS_ERROR_NONE)
1217 LogWarning("Fail to set event value to child_record type : CONTACTS_EVENT_TYPE_ANNIVERSARY");
1218 contacts_record_destroy(child_record, true);
1222 errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
1223 if(errorCode != CONTACTS_ERROR_NONE)
1225 LogWarning("Fail to set event value to child_record date : " << date);
1226 contacts_record_destroy(child_record, true);
1230 if(anniversary->getLabelIsSet())
1232 string label = anniversary->getLabel();
1233 errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
1234 if(errorCode != CONTACTS_ERROR_NONE)
1236 LogWarning("Fail to set label value to child_record label : " << label);
1237 contacts_record_destroy(child_record, true);
1243 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
1244 if(errorCode != CONTACTS_ERROR_NONE)
1246 LogWarning("Fail to set event value to child_record");
1247 contacts_record_destroy(child_record, true);
1253 void ContactObjectA2PConverter::importPostalList()
1256 contacts_record_h child_record = NULL;
1257 unsigned int record_count = 0;
1259 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &record_count);
1260 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1262 ThrowMsg(PlatformException, "getting address count (err:" << errorCode << ")");
1265 for(int i=record_count-1; i>=0; i--)
1267 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
1268 if(errorCode != CONTACTS_ERROR_NONE)
1269 ThrowMsg(UnknownException, "getting address value A (errorCode:" << errorCode << ")");
1271 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.address, child_record);
1272 if(errorCode != CONTACTS_ERROR_NONE)
1273 ThrowMsg(UnknownException, "removing address value A (errorCode:" << errorCode << ")");
1275 child_record = NULL;
1278 if(m_abstractContact->getAddressesNum() == 0)
1281 ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
1283 ContactAddressArray::iterator addressesIter = addresses->begin();
1284 for(; addressesIter != addresses->end(); addressesIter++)
1286 ContactAddressPtr address = *addressesIter;
1287 ContactAddressTypeArrayPtr types = address->getTypes();
1289 if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
1290 ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
1291 ( !address->getCityIsSet() || address->getCity().empty() ) &&
1292 ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
1293 ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
1294 ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
1296 LogDebug("No information for address was not set.");
1300 bool ctsBoolDefault = address->getIsDefault();
1303 //char *ctsStrCustomType = NULL;
1305 ContactAddressTypeArray::iterator typesIter = types->begin();
1306 for(; typesIter != types->end(); typesIter++)
1308 ContactAddressType type = *typesIter;
1309 if(type == CONTACT_ADDRESS_TYPE_HOME)
1310 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
1311 else if(type == CONTACT_ADDRESS_TYPE_WORK)
1312 ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_WORK;
1315 // // TODO Will be added after type changed to string
1316 // // ctsIntType = ctsIntType | CTS_POSTAL_TYPE_CUSTOM;
1317 // // ctsStrCustomType = ...;
1321 child_record = NULL;
1323 errorCode = contacts_record_create(_contacts_address._uri, &child_record);
1324 if(errorCode != CONTACTS_ERROR_NONE)
1326 LogWarning("Fail to create child_record with contacts_record_create(_contacts_address._uri)");
1330 if(address->getCountryIsSet())
1332 string country = address->getCountry();
1333 errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
1334 if(errorCode != CONTACTS_ERROR_NONE)
1336 LogWarning("Fail to set country value to child_record str : " << country);
1337 contacts_record_destroy(child_record, true);
1342 if(address->getRegionIsSet())
1344 string region = address->getRegion();
1345 errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
1346 if(errorCode != CONTACTS_ERROR_NONE)
1348 LogWarning("Fail to set region value to child_record str : " << region);
1349 contacts_record_destroy(child_record, true);
1354 if(address->getCityIsSet())
1356 string city = address->getCity();
1357 errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
1358 if(errorCode != CONTACTS_ERROR_NONE)
1360 LogWarning("Fail to set locality value to child_record str : " << city);
1361 contacts_record_destroy(child_record, true);
1366 if(address->getStreetAddressIsSet())
1368 string streetAddress = address->getStreetAddress();
1369 errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
1370 if(errorCode != CONTACTS_ERROR_NONE)
1372 LogWarning("Fail to set street value to child_record str : " << streetAddress);
1373 contacts_record_destroy(child_record, true);
1378 if(address->getAdditionalInformationIsSet())
1380 string additionalInformation = address->getAdditionalInformation();
1381 errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
1382 if(errorCode != CONTACTS_ERROR_NONE)
1384 LogWarning("Fail to set extended value to child_record str : " << additionalInformation);
1385 contacts_record_destroy(child_record, true);
1390 if(address->getPostalCodeIsSet())
1392 string postalCode = address->getPostalCode();
1393 errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
1394 if(errorCode != CONTACTS_ERROR_NONE)
1396 LogWarning("Fail to set postal_code value to child_record str : " << postalCode);
1397 contacts_record_destroy(child_record, true);
1402 errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
1403 if(errorCode != CONTACTS_ERROR_NONE)
1405 LogWarning("Fail to set favorite value to child_record default : " << ctsBoolDefault);
1406 contacts_record_destroy(child_record, true);
1410 errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
1411 if(errorCode != CONTACTS_ERROR_NONE)
1413 LogWarning("Fail to set default value to child_record type : " << ctsIntType);
1414 contacts_record_destroy(child_record, true);
1418 //if(ctsStrCustomType != NULL)
1420 // errorCode = contacts_record_set_str(child_record, _contacts_address.label, ctsStrCustomType);
1421 // if(errorCode != CONTACTS_ERROR_NONE)
1423 // LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
1424 // contacts_record_destroy(child_record, true);
1429 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.address, child_record);
1430 if(errorCode != CONTACTS_ERROR_NONE)
1432 LogWarning("Fail to set address value to child_record");
1433 contacts_record_destroy(child_record, true);
1439 void ContactObjectA2PConverter::importWebAddrList()
1442 contacts_record_h child_record = NULL;
1443 unsigned int record_count = 0;
1445 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &record_count);
1446 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1448 ThrowMsg(PlatformException, "getting url count (err:" << errorCode << ")");
1451 for(int i=record_count-1; i>=0; i--)
1453 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
1454 if(errorCode != CONTACTS_ERROR_NONE)
1455 ThrowMsg(UnknownException, "getting url value A (errorCode:" << errorCode << ")");
1457 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.url, child_record);
1458 if(errorCode != CONTACTS_ERROR_NONE)
1459 ThrowMsg(UnknownException, "removing url value A (errorCode:" << errorCode << ")");
1461 child_record = NULL;
1464 ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
1465 if(webSites->size() == 0)
1468 ContactWebSiteArray::iterator webSiteIter = webSites->begin();
1469 for(; webSiteIter != webSites->end(); webSiteIter++)
1471 ContactWebSitePtr webSite = *webSiteIter;
1472 ContactWebSiteType type = webSite->getType();
1474 if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
1476 LogDebug("url was not set.");
1480 string url = webSite->getUrl();
1483 // char *ctsStrCustomType = NULL;
1485 if(type == WEBSITE_TYPE_HOMEPAGE)
1486 ctsIntType = CONTACTS_URL_TYPE_HOME;
1487 else if(type == WEBSITE_TYPE_BLOG)
1488 ctsIntType = CONTACTS_URL_TYPE_WORK;
1491 // TODO Will be added after type changed to string
1492 // ctsIntType = CONTACTS_URL_TYPE_CUSTOM;
1493 // ctsStrCustomType = ...;
1496 child_record = NULL;
1498 errorCode = contacts_record_create(_contacts_url._uri, &child_record);
1499 if(errorCode != CONTACTS_ERROR_NONE)
1501 LogWarning("Fail to create child_record with contacts_record_create(_contacts_url._uri)");
1505 errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
1506 if(errorCode != CONTACTS_ERROR_NONE)
1508 LogWarning("Fail to set url value to child_record str : " << url);
1509 contacts_record_destroy(child_record, true);
1513 errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
1514 if(errorCode != CONTACTS_ERROR_NONE)
1516 LogWarning("Fail to set default value to child_record type : " << ctsIntType);
1517 contacts_record_destroy(child_record, true);
1521 if(ctsStrCustomType != NULL)
1523 errorCode = contacts_record_set_str(child_record, _contacts_url.label, ctsStrCustomType);
1524 if(errorCode != CONTACTS_ERROR_NONE)
1526 LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
1527 contacts_record_destroy(child_record, true);
1532 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.url, child_record);
1533 if(errorCode != CONTACTS_ERROR_NONE)
1535 LogWarning("Fail to set url value to child_record");
1536 contacts_record_destroy(child_record, true);
1542 void ContactObjectA2PConverter::importNicknameList()
1545 contacts_record_h child_record = NULL;
1546 unsigned int record_count = 0;
1548 errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &record_count);
1549 if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
1551 ThrowMsg(PlatformException, "getting nickname count (err:" << errorCode << ")");
1554 for(int i=record_count-1; i>=0; i--)
1556 errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
1557 if(errorCode != CONTACTS_ERROR_NONE)
1558 ThrowMsg(UnknownException, "getting nickname value A (errorCode:" << errorCode << ")");
1560 errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1561 if(errorCode != CONTACTS_ERROR_NONE)
1562 ThrowMsg(UnknownException, "removing nickname value A (errorCode:" << errorCode << ")");
1564 child_record = NULL;
1567 ContactNamePtr contactName = m_abstractContact->getName();
1568 if(contactName == NULL)
1571 if(contactName->getNicknamesNum() == 0)
1574 StringArrayPtr nicknames = contactName->getNicknames();
1576 StringArray::iterator nicknamesIter = nicknames->begin();
1577 for(; nicknamesIter != nicknames->end(); nicknamesIter++)
1579 string nickname = *nicknamesIter;
1581 if(nickname.empty())
1583 LogDebug("nickname was not set.");
1587 child_record = NULL;
1589 errorCode = contacts_record_create(_contacts_nickname._uri, &child_record);
1590 if(errorCode != CONTACTS_ERROR_NONE)
1592 LogWarning("Fail to create child_record with contacts_record_create(_contacts_nickname._uri)");
1596 errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
1597 if(errorCode != CONTACTS_ERROR_NONE)
1599 LogWarning("Fail to set nickname value to ctsValue str : " << nickname);
1600 contacts_record_destroy(child_record, true);
1604 errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.nickname, child_record);
1605 if(errorCode != CONTACTS_ERROR_NONE)
1607 LogWarning("Fail to set nickname value to child_record");
1608 contacts_record_destroy(child_record, true);