b7b187a6102a71839cb5ebf27d3832b9b3f1fb97
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Contact / ContactObjectA2PConverter.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        ContactObjectA2PConverter.cpp
18  * @author      Kisub Song (kisubs.song@samsung.com)
19  * @version     0.1
20  * @brief       Converter (TizenApis::Api::Contact::ContactPtr -> CTSstruct*)
21  */
22
23 #include "ContactObjectA2PConverter.h"
24
25 #include <Commons/Exception.h>
26 #include "ContactUtility.h"
27 #include "query-svc/query-service.h"
28
29 namespace TizenApis {
30 namespace Platform {
31 namespace Contact {
32
33 using namespace TizenApis::Api::Contact;
34 using namespace WrtDeviceApis::Commons;
35 using namespace std;
36
37 static const char *EMPTY_STRING = "";
38
39 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
40                 bool forScratch) :
41                 m_abstractContact(abstractContact),
42                 m_platformContact(NULL),
43                 m_forScratch(forScratch),
44                 m_convertFinished(false),
45                 m_platformContactOwnership(false)
46 {
47 }
48
49 ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
50                 bool forScratch,
51                 CTSstruct* platformContact) :
52                 m_abstractContact(abstractContact),
53                 m_platformContact(platformContact),
54                 m_forScratch(forScratch),
55                 m_convertFinished(false),
56                 m_platformContactOwnership(false)
57 {
58 }
59
60 ContactObjectA2PConverter::~ContactObjectA2PConverter()
61 {
62         if(m_platformContactOwnership && m_platformContact != NULL)
63         {
64                 contacts_svc_struct_free(m_platformContact);
65                 m_platformContact = NULL;
66                 m_platformContactOwnership = false;
67         }
68 }
69
70 CTSstruct* ContactObjectA2PConverter::getPlatformContact()
71 {
72         LogDebug("enter");
73
74         if(m_abstractContact == NULL)
75         {
76                 LogError("Abstract contact object did not set");
77                 ThrowMsg(InvalidArgumentException, "Abstract contact object did not set");
78         }
79
80         if(m_platformContact == NULL)
81         {
82                 if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
83                 {
84                         int id = ContactUtility::strToInt(m_abstractContact->getId());
85                         LogDebug("Load platform object id : " << id);
86                         contacts_svc_get_contact(id, &m_platformContact);
87                 }
88                 else
89                 {
90                         LogDebug("New platform object has been created");
91                         m_platformContact = contacts_svc_struct_new(CTS_STRUCT_CONTACT);
92                 }
93
94                 m_platformContactOwnership = true;
95         }
96
97         LogDebug("for scratch : " << m_forScratch);
98
99         Try
100         {
101                 if(m_convertFinished == false)
102                         convertToPlatformObject();
103         }
104         Catch(Exception)
105         {
106                 LogError("Error while converting - " << _rethrown_exception.GetMessage());
107                 ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
108         }
109
110         return m_platformContact;
111 }
112
113 void ContactObjectA2PConverter::convertToPlatformObject()
114 {
115         importBaseInfoValue();
116         importNameValue();
117         importCompanyValue();
118 //      importNoteValue();
119         importNumberList();
120         importEmailList();
121         importGrouprelList();
122         importEventList();
123         importPostalList();
124         importWebAddrList();
125         importNicknameList();
126
127         m_convertFinished = true;
128 }
129
130 void ContactObjectA2PConverter::importBaseInfoValue()
131 {
132         int errorCode = 0;
133         CTSvalue *ctsValue = NULL;
134
135         errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, &ctsValue);
136         if(errorCode != CTS_SUCCESS || ctsValue == NULL)
137         {
138                 ctsValue = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO);
139                 if(ctsValue == NULL)
140                         ThrowMsg(UnknownException, "creating base info value (ctsValue:NULL)");
141
142                 importBaseInfoValueToNewValue(ctsValue);
143         }
144         else
145         {
146                 importBaseInfoValueToExistingValue(ctsValue);
147         }
148
149         contacts_svc_struct_store_value(m_platformContact, CTS_CF_BASE_INFO_VALUE, ctsValue);
150         contacts_svc_value_free(ctsValue);
151 }
152
153 void ContactObjectA2PConverter::importBaseInfoValueToExistingValue(CTSvalue *ctsValue)
154 {
155         int errorCode = 0;
156
157         const char *newValueStr = NULL;
158         const char *oldValueStr = NULL;
159         string abstractValueStr;
160
161         // Contact.photoURI
162         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR);
163         abstractValueStr = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
164         if(oldValueStr != NULL &&
165                         (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
166         {
167                 newValueStr = EMPTY_STRING;
168         }
169         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
170         {
171                 newValueStr = abstractValueStr.c_str();
172         }
173
174         if(newValueStr != NULL)
175         {
176                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR, newValueStr);
177                 if(errorCode != CTS_SUCCESS)
178                 {
179                         contacts_svc_value_free(ctsValue);
180                         ThrowMsg(PlatformException, "importing photoURI E (err:" <<
181                                         errorCode << ", str:" << abstractValueStr << ")");
182                 }
183         }
184
185         // Contact.ringtoneURI
186         newValueStr = NULL;
187         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR);
188         abstractValueStr = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
189         if(oldValueStr != NULL &&
190                         (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
191         {
192                 newValueStr = EMPTY_STRING;
193         }
194         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
195         {
196                 newValueStr = abstractValueStr.c_str();
197         }
198
199         if(newValueStr != NULL)
200         {
201                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR, newValueStr);
202                 if(errorCode != CTS_SUCCESS)
203                 {
204                         contacts_svc_value_free(ctsValue);
205                         ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
206                                         errorCode << ", str:" << abstractValueStr << ")");
207                 }
208         }
209
210         // Contact.note
211         newValueStr = NULL;
212         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_BASE_VAL_NOTE_STR);
213         abstractValueStr = m_abstractContact->getNote();
214         if(oldValueStr != NULL && (!m_abstractContact->getNoteIsSet() || abstractValueStr.empty()) )
215         {
216                 newValueStr = EMPTY_STRING;
217         }
218         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
219         {
220                 newValueStr = abstractValueStr.c_str();
221         }
222
223         if(newValueStr != NULL)
224         {
225                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_NOTE_STR, newValueStr);
226                 if(errorCode != CTS_SUCCESS)
227                 {
228                         contacts_svc_value_free(ctsValue);
229                         ThrowMsg(PlatformException, "importing note E (err:" <<
230                                         errorCode << ", str:" << newValueStr << ")");
231                 }
232         }
233 }
234
235 void ContactObjectA2PConverter::importBaseInfoValueToNewValue(CTSvalue *ctsValue)
236 {
237         int errorCode = 0;
238
239         // Contact.photoURI
240         if(m_abstractContact->getPhotoURIIsSet())
241         {
242                 string photoURI = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
243                 if(!photoURI.empty())
244                 {
245                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_IMG_PATH_STR, photoURI.c_str());
246                         if(errorCode != CTS_SUCCESS)
247                         {
248                                 contacts_svc_value_free(ctsValue);
249                                 ThrowMsg(PlatformException, "importing photoURI N (err: " <<
250                                                 errorCode << ", str:" << photoURI << ")");
251                         }
252                 }
253         }
254
255         // Contact.ringtoneURI
256         if(m_abstractContact->getRingtoneURIIsSet())
257         {
258                 string ringtoneURI = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
259                 if(!ringtoneURI.empty())
260                 {
261                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_RINGTONE_PATH_STR, ringtoneURI.c_str());
262                         if(errorCode != CTS_SUCCESS)
263                         {
264                                 contacts_svc_value_free(ctsValue);
265                                 ThrowMsg(PlatformException, "importing ringtoneURI N (err:" <<
266                                                 errorCode << ", str:" << ringtoneURI << ")");
267                         }
268                 }
269         }
270
271         // Contact.note
272         if(m_abstractContact->getNoteIsSet())
273         {
274                 string note = m_abstractContact->getNote();
275                 if(note != EMPTY_STRING)
276                 {
277                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_BASE_VAL_NOTE_STR, note.c_str());
278                         if(errorCode != CTS_SUCCESS)
279                         {
280                                 contacts_svc_value_free(ctsValue);
281                                 ThrowMsg(PlatformException, "importing note N (err:" <<
282                                                 errorCode << ", str:" << note << ")");
283                         }
284                 }
285         }
286 }
287
288 void ContactObjectA2PConverter::importNameValue()
289 {
290         int errorCode = 0;
291         CTSvalue *ctsValue = NULL;
292
293         ContactNamePtr contactName = m_abstractContact->getName();
294         if(contactName == NULL ||
295                         (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
296                         && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
297                         && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
298 //                      && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
299 //                      && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
300                         && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() )
301                         && ( !contactName->getDisplayNameIsSet() || contactName->getDisplayName().empty() ) ) )
302         {
303                 ctsValue = contacts_svc_value_new(CTS_VALUE_NAME);
304                 if(ctsValue == NULL)
305                         ThrowMsg(UnknownException, "creating name value A (ctsValue:NULL)");
306                 contacts_svc_struct_store_value(m_platformContact, CTS_CF_NAME_VALUE, ctsValue);
307                 return;
308         }
309
310         errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NAME_VALUE, &ctsValue);
311         if(errorCode != CTS_SUCCESS || ctsValue == NULL)
312         {
313                 ctsValue = contacts_svc_value_new(CTS_VALUE_NAME);
314                 if(ctsValue == NULL)
315                         ThrowMsg(UnknownException, "creating name value B (ctsValue:NULL)");
316
317                 importNameValueToNewValue(ctsValue, contactName);
318         }
319         else
320         {
321                 importNameValueToExistingValue(ctsValue, contactName);
322         }
323
324         contacts_svc_struct_store_value(m_platformContact, CTS_CF_NAME_VALUE, ctsValue);
325         contacts_svc_value_free(ctsValue);
326 }
327
328 void ContactObjectA2PConverter::importNameValueToExistingValue(CTSvalue *ctsValue, ContactNamePtr &contactName)
329 {
330         int errorCode = 0;
331
332         const char *newValueStr = NULL;
333         const char *oldValueStr = NULL;
334         string abstractValueStr;
335
336         // ContactName.firstName
337         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_FIRST_STR);
338         abstractValueStr = contactName->getFirstName();
339         if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
340         {
341                 newValueStr = EMPTY_STRING;
342         }
343         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
344         {
345                 newValueStr = abstractValueStr.c_str();
346         }
347
348         if(newValueStr != NULL)
349         {
350                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_FIRST_STR, newValueStr);
351                 if(errorCode != CTS_SUCCESS)
352                 {
353                         contacts_svc_value_free(ctsValue);
354                         ThrowMsg(PlatformException, "importing firstName E (err:" <<
355                                         errorCode << ", str:" << newValueStr << ")");
356                 }
357         }
358
359         // ContactName.lastName
360         newValueStr = NULL;
361         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_LAST_STR);
362         abstractValueStr = contactName->getLastName();
363         if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
364         {
365                 newValueStr = EMPTY_STRING;
366         }
367         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
368         {
369                 newValueStr = abstractValueStr.c_str();
370         }
371
372         if(newValueStr != NULL)
373         {
374                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_LAST_STR, newValueStr);
375                 if(errorCode != CTS_SUCCESS)
376                 {
377                         contacts_svc_value_free(ctsValue);
378                         ThrowMsg(PlatformException, "importing lastName E (err:" <<
379                                         errorCode << ", str:" << newValueStr << ")");
380                 }
381         }
382
383         // ContactName.middleName
384         newValueStr = NULL;
385         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_ADDITION_STR);
386         abstractValueStr = contactName->getMiddleName();
387         if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
388         {
389                 newValueStr = EMPTY_STRING;
390         }
391         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
392         {
393                 newValueStr = abstractValueStr.c_str();
394         }
395
396         if(newValueStr != NULL)
397         {
398                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_ADDITION_STR, newValueStr);
399                 if(errorCode != CTS_SUCCESS)
400                 {
401                         contacts_svc_value_free(ctsValue);
402                         ThrowMsg(PlatformException, "importing middleName E (err:" <<
403                                         errorCode << ", str:" << newValueStr << ")");
404                 }
405         }
406
407         // ContactName.prefix
408         newValueStr = NULL;
409         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PREFIX_STR);
410         abstractValueStr = contactName->getPrefix();
411         if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
412         {
413                 newValueStr = EMPTY_STRING;
414         }
415         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
416         {
417                 newValueStr = abstractValueStr.c_str();
418         }
419
420         if(newValueStr != NULL)
421         {
422                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PREFIX_STR, newValueStr);
423                 if(errorCode != CTS_SUCCESS)
424                 {
425                         contacts_svc_value_free(ctsValue);
426                         ThrowMsg(PlatformException, "importing prefix E (err:" <<
427                                         errorCode << ", str:" << newValueStr << ")");
428                 }
429         }
430
431 //      // ContactName.phoneticFirstName
432 //      newValueStr = NULL;
433 //      oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR);
434 //      abstractValueStr = contactName->getPhoneticFirstName();
435 //      if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
436 //      {
437 //              newValueStr = EMPTY_STRING;
438 //      }
439 //      else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
440 //      {
441 //              newValueStr = abstractValueStr.c_str();
442 //      }
443 //
444 //      if(newValueStr != NULL)
445 //      {
446 //              errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR, newValueStr);
447 //              if(errorCode != CTS_SUCCESS)
448 //              {
449 //                      contacts_svc_value_free(ctsValue);
450 //                      ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
451 //                                      errorCode << ", str:" << newValueStr << ")");
452 //              }
453 //      }
454 //
455 //      // ContactName.phoneticLastName
456 //      newValueStr = NULL;
457 //      oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR);
458 //      abstractValueStr = contactName->getPhoneticLastName();
459 //      if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
460 //      {
461 //              newValueStr = EMPTY_STRING;
462 //      }
463 //      else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
464 //      {
465 //              newValueStr = abstractValueStr.c_str();
466 //      }
467 //
468 //      if(newValueStr != NULL)
469 //      {
470 //              errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR, newValueStr);
471 //              if(errorCode != CTS_SUCCESS)
472 //              {
473 //                      contacts_svc_value_free(ctsValue);
474 //                      ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
475 //                                      errorCode << ", str:" << newValueStr << ")");
476 //              }
477 //      }
478
479         // ContactName.displayName
480         newValueStr = NULL;
481         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR);
482         abstractValueStr = contactName->getDisplayName();
483         if(oldValueStr != NULL && (!contactName->getDisplayNameIsSet() || abstractValueStr.empty()) )
484         {
485                 newValueStr = EMPTY_STRING;
486         }
487         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
488         {
489                 newValueStr = abstractValueStr.c_str();
490         }
491
492         if(newValueStr != NULL)
493         {
494                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR, newValueStr);
495                 if(errorCode != CTS_SUCCESS)
496                 {
497                         contacts_svc_value_free(ctsValue);
498                         ThrowMsg(PlatformException, "importing displayName E (err:" <<
499                                         errorCode << ", str:" << newValueStr << ")");
500                 }
501         }
502 }
503
504 void ContactObjectA2PConverter::importNameValueToNewValue(CTSvalue *ctsValue, ContactNamePtr &contactName)
505 {
506         int errorCode = 0;
507
508         // ContactName.firstName
509         if(contactName->getFirstNameIsSet())
510         {
511                 string firstName = contactName->getFirstName();
512                 if(firstName != EMPTY_STRING)
513                 {
514                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_FIRST_STR, firstName.c_str());
515                         if(errorCode != CTS_SUCCESS)
516                         {
517                                 contacts_svc_value_free(ctsValue);
518                                 ThrowMsg(PlatformException, "importing firstName N (err:" <<
519                                                 errorCode << ", str:" << firstName << ")");
520                         }
521                 }
522         }
523
524         // ContactName.lastName
525         if(contactName->getLastNameIsSet())
526         {
527                 string lastName = contactName->getLastName();
528                 if(lastName != EMPTY_STRING)
529                 {
530                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_LAST_STR, lastName.c_str());
531                         if(errorCode != CTS_SUCCESS)
532                         {
533                                 contacts_svc_value_free(ctsValue);
534                                 ThrowMsg(PlatformException, "importing lastName N (err:" <<
535                                                 errorCode << ", str:" << lastName << ")");
536                         }
537                 }
538         }
539
540         // ContactName.middleName
541         if(contactName->getMiddleNameIsSet())
542         {
543                 string middleName = contactName->getMiddleName();
544                 if(middleName != EMPTY_STRING)
545                 {
546                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_ADDITION_STR, middleName.c_str());
547                         if(errorCode != CTS_SUCCESS)
548                         {
549                                 contacts_svc_value_free(ctsValue);
550                                 ThrowMsg(PlatformException, "importing middleName N (err:" <<
551                                                 errorCode << ", str:" << middleName << ")");
552                         }
553                 }
554         }
555
556         // ContactName.prefix
557         if(contactName->getPrefixIsSet())
558         {
559                 string prefix = contactName->getPrefix();
560                 if(prefix != EMPTY_STRING)
561                 {
562                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PREFIX_STR, prefix.c_str());
563                         if(errorCode != CTS_SUCCESS)
564                         {
565                                 contacts_svc_value_free(ctsValue);
566                                 ThrowMsg(PlatformException, "importing prefix N (err:" <<
567                                                 errorCode << ", str:" << prefix << ")");
568                         }
569                 }
570         }
571
572 //      // ContactName.phoneticFirstName
573 //      if(contactName->getPhoneticFirstNameIsSet())
574 //      {
575 //              string phoneticFirstName = contactName->getPhoneticFirstName();
576 //              if(phoneticFirstName != EMPTY_STRING)
577 //              {
578 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_FIRST_STR, phoneticFirstName.c_str());
579 //                      if(errorCode != CTS_SUCCESS)
580 //                      {
581 //                              contacts_svc_value_free(ctsValue);
582 //                              ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
583 //                                              errorCode << ", str:" << phoneticFirstName << ")");
584 //                      }
585 //              }
586 //      }
587 //
588 //      // ContactName.phoneticLastName
589 //      if(contactName->getPhoneticLastNameIsSet())
590 //      {
591 //              string phoneticLastName = contactName->getPhoneticLastName();
592 //              if(phoneticLastName != EMPTY_STRING)
593 //              {
594 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_PHONETIC_LAST_STR, phoneticLastName.c_str());
595 //                      if(errorCode != CTS_SUCCESS)
596 //                      {
597 //                              contacts_svc_value_free(ctsValue);
598 //                              ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
599 //                                              errorCode << ", str:" << phoneticLastName << ")");
600 //                      }
601 //              }
602 //      }
603
604         // ContactName.displayName
605         if(contactName->getDisplayNameIsSet())
606         {
607                 string displayName = contactName->getDisplayName();
608                 if(displayName != EMPTY_STRING)
609                 {
610                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_NAME_VAL_DISPLAY_STR, displayName.c_str());
611                         if(errorCode != CTS_SUCCESS)
612                         {
613                                 contacts_svc_value_free(ctsValue);
614                                 ThrowMsg(PlatformException, "importing displayName N (err:" <<
615                                                 errorCode << ", str:" << displayName << ")");
616                         }
617                 }
618         }
619 }
620
621 void ContactObjectA2PConverter::importCompanyValue()
622 {
623         int errorCode = 0;
624         CTSvalue *ctsValue = NULL;
625
626         ContactOrganizationPtr contactOrganization = m_abstractContact->getOrganization();
627         if(contactOrganization == NULL ||
628                         ( (!contactOrganization->getNameIsSet() || contactOrganization->getName().empty() )
629                         && (!contactOrganization->getDepartmentIsSet() || contactOrganization->getDepartment().empty() )
630                         && (!contactOrganization->getTitleIsSet() || contactOrganization->getTitle().empty() )
631                         && (!contactOrganization->getRoleIsSet() || contactOrganization->getRole().empty() ) ) )
632         {
633                 ctsValue = contacts_svc_value_new(CTS_VALUE_COMPANY);
634                 if(ctsValue == NULL)
635                         ThrowMsg(UnknownException, "creating company value A");
636                 contacts_svc_struct_store_value(m_platformContact, CTS_CF_COMPANY_VALUE, ctsValue);
637                 return;
638         }
639
640         errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_COMPANY_VALUE, &ctsValue);
641         if(errorCode != CTS_SUCCESS || ctsValue == NULL)
642         {
643                 ctsValue = contacts_svc_value_new(CTS_VALUE_COMPANY);
644                 if(ctsValue == NULL)
645                         ThrowMsg(UnknownException, "creating company value B");
646
647                 importCompanyValueToNewValue(ctsValue, contactOrganization);
648         }
649         else
650         {
651                 importCompanyValueToExistingValue(ctsValue, contactOrganization);
652         }
653
654
655         contacts_svc_struct_store_value(m_platformContact, CTS_CF_COMPANY_VALUE, ctsValue);
656         contacts_svc_value_free(ctsValue);
657 }
658
659 void ContactObjectA2PConverter::importCompanyValueToExistingValue(CTSvalue *ctsValue, ContactOrganizationPtr &contactOrganization)
660 {
661         int errorCode = 0;
662
663         const char *newValueStr = NULL;
664         const char *oldValueStr = NULL;
665         string abstractValueStr;
666
667         // ContactOrganization.name
668         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_NAME_STR);
669         abstractValueStr = contactOrganization->getName();
670         if(oldValueStr != NULL && (!contactOrganization->getNameIsSet() || abstractValueStr.empty()) )
671         {
672                 newValueStr = EMPTY_STRING;
673         }
674         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
675         {
676                 newValueStr = abstractValueStr.c_str();
677         }
678
679         if(newValueStr != NULL)
680         {
681                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_NAME_STR, newValueStr);
682                 if(errorCode != CTS_SUCCESS)
683                 {
684                         contacts_svc_value_free(ctsValue);
685                         ThrowMsg(PlatformException, "importing company name E (err:" <<
686                                         errorCode << ", str:" << newValueStr << ")");
687                 }
688         }
689
690         // ContactOrganization.department
691         newValueStr = NULL;
692         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR);
693         abstractValueStr = contactOrganization->getDepartment();
694         if(oldValueStr != NULL && (!contactOrganization->getDepartmentIsSet() || abstractValueStr.empty()) )
695         {
696                 newValueStr = EMPTY_STRING;
697         }
698         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
699         {
700                 newValueStr = abstractValueStr.c_str();
701         }
702
703         if(newValueStr != NULL)
704         {
705                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR, newValueStr);
706                 if(errorCode != CTS_SUCCESS)
707                 {
708                         contacts_svc_value_free(ctsValue);
709                         ThrowMsg(PlatformException, "importing department E (err:" <<
710                                         errorCode << ", str:" << newValueStr << ")");
711                 }
712         }
713
714         // ContactOrganization.title
715         newValueStr = NULL;
716         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR);
717         abstractValueStr = contactOrganization->getTitle();
718         if(oldValueStr != NULL && (!contactOrganization->getTitleIsSet() || abstractValueStr.empty()) )
719         {
720                 newValueStr = EMPTY_STRING;
721         }
722         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
723         {
724                 newValueStr = abstractValueStr.c_str();
725         }
726
727         if(newValueStr != NULL)
728         {
729                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR, newValueStr);
730                 if(errorCode != CTS_SUCCESS)
731                 {
732                         contacts_svc_value_free(ctsValue);
733                         ThrowMsg(PlatformException, "importing jobTitle E (err:" <<
734                                         errorCode << ", str:" << newValueStr << ")");
735                 }
736         }
737
738         // ContactOrganization.role
739         newValueStr = NULL;
740         oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR);
741         abstractValueStr = contactOrganization->getRole();
742         if(oldValueStr != NULL && (!contactOrganization->getRoleIsSet() || abstractValueStr.empty()) )
743         {
744                 newValueStr = EMPTY_STRING;
745         }
746         else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
747         {
748                 newValueStr = abstractValueStr.c_str();
749         }
750
751         if(newValueStr != NULL)
752         {
753                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR, newValueStr);
754                 if(errorCode != CTS_SUCCESS)
755                 {
756                         contacts_svc_value_free(ctsValue);
757                         ThrowMsg(PlatformException, "importing role E (err:" <<
758                                         errorCode << ", str:" << newValueStr << ")");
759                 }
760         }
761 }
762
763 void ContactObjectA2PConverter::importCompanyValueToNewValue(CTSvalue *ctsValue, ContactOrganizationPtr &contactOrganization)
764 {
765         int errorCode = 0;
766
767         // ContactOrganization.name
768         if(contactOrganization->getNameIsSet())
769         {
770                 string name = contactOrganization->getName();
771                 if(!name.empty())
772                 {
773                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_NAME_STR, name.c_str());
774                         if(errorCode != CTS_SUCCESS)
775                         {
776                                 contacts_svc_value_free(ctsValue);
777                                 ThrowMsg(PlatformException, "importing company name N (err:" <<
778                                                 errorCode << ", str:" << name << ")");
779                         }
780                 }
781         }
782
783         // ContactOrganization.department
784         if(contactOrganization->getDepartmentIsSet())
785         {
786                 string department = contactOrganization->getDepartment();
787                 if(!department.empty())
788                 {
789                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_DEPARTMENT_STR, department.c_str());
790                         if(errorCode != CTS_SUCCESS)
791                         {
792                                 contacts_svc_value_free(ctsValue);
793                                 ThrowMsg(PlatformException, "importing department N (err:" <<
794                                                 errorCode << ", str:" << department << ")");
795                         }
796                 }
797         }
798
799         // ContactOrganization.title
800         if(contactOrganization->getTitleIsSet())
801         {
802                 string title = contactOrganization->getTitle();
803                 if(!title.empty())
804                 {
805                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_JOB_TITLE_STR, title.c_str());
806                         if(errorCode != CTS_SUCCESS)
807                         {
808                                 contacts_svc_value_free(ctsValue);
809                                 ThrowMsg(PlatformException, "importing title N (err:" <<
810                                                 errorCode << ", str:" << title << ")");
811                         }
812                 }
813         }
814
815         // ContactOrganization.role
816         if(contactOrganization->getRoleIsSet())
817         {
818                 string role = contactOrganization->getRole();
819                 if(!role.empty())
820                 {
821                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_COMPANY_VAL_ROLE_STR, role.c_str());
822                         if(errorCode != CTS_SUCCESS)
823                         {
824                                 contacts_svc_value_free(ctsValue);
825                                 ThrowMsg(PlatformException, "importing role N (err:" <<
826                                                 errorCode << ", str:" << role << ")");
827                         }
828                 }
829         }
830 }
831
832 //void ContactObjectA2PConverter::importNoteValue()
833 //{
834 //      int errorCode = 0;
835 //      CTSvalue *ctsValue = NULL;
836 //
837 //      errorCode = contacts_svc_struct_get_value(m_platformContact, CTS_CF_NOTE_VALUE, &ctsValue);
838 //      if(errorCode != CTS_SUCCESS || ctsValue == NULL)
839 //      {
840 //              ctsValue = contacts_svc_value_new(CTS_VALUE_NOTE);
841 //              if(ctsValue == NULL)
842 //                      ThrowMsg(UnknownException, "creating note value (ctsValue:NULL)");
843 //
844 //              importNoteValueToNewValue(ctsValue);
845 //      }
846 //      else
847 //      {
848 //              importNoteValueToExistingValue(ctsValue);
849 //      }
850 //
851 //      contacts_svc_struct_store_value(m_platformContact, CTS_CF_NOTE_VALUE, ctsValue);
852 //      contacts_svc_value_free(ctsValue);
853 //}
854 //
855 //void ContactObjectA2PConverter::importNoteValueToExistingValue(CTSvalue *ctsValue)
856 //{
857 //      int errorCode = 0;
858 //
859 //      const char *newValueStr = NULL;
860 //      const char *oldValueStr = NULL;
861 //
862 //      // note
863 //      oldValueStr = contacts_svc_value_get_str(ctsValue, CTS_NOTE_VAL_NOTE_STR);
864 //      string note = m_abstractContact->getNote();
865 //      if(oldValueStr != NULL && (!m_abstractContact->getNoteIsSet() || note.empty()) )
866 //      {
867 //              newValueStr = EMPTY_STRING;
868 //      }
869 //      else if(oldValueStr == NULL || note != oldValueStr)
870 //      {
871 //              newValueStr = note.c_str();
872 //      }
873 //
874 //      if(newValueStr != NULL)
875 //      {
876 //              errorCode = contacts_svc_value_set_str(ctsValue, CTS_NOTE_VAL_NOTE_STR, newValueStr);
877 //              if(errorCode != CTS_SUCCESS)
878 //              {
879 //                      contacts_svc_value_free(ctsValue);
880 //                      ThrowMsg(PlatformException, "importing note E (err:" <<
881 //                                      errorCode << ", str:" << newValueStr << ")");
882 //              }
883 //      }
884 //}
885 //
886 //void ContactObjectA2PConverter::importNoteValueToNewValue(CTSvalue *ctsValue)
887 //{
888 //      int errorCode = 0;
889 //
890 //      if(m_abstractContact->getNoteIsSet())
891 //      {
892 //              string note = m_abstractContact->getNote();
893 //              if(!note.empty())
894 //              {
895 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_NOTE_VAL_NOTE_STR, note.c_str());
896 //                      if(errorCode != CTS_SUCCESS)
897 //                      {
898 //                              contacts_svc_value_free(ctsValue);
899 //                              ThrowMsg(PlatformException, "importing note N (err:" <<
900 //                                              errorCode << ", str:" << note << ")");
901 //                      }
902 //              }
903 //      }
904 //}
905
906 void ContactObjectA2PConverter::importNumberList()
907 {
908         int errorCode = 0;
909
910         GSList *gsList = NULL;
911         GSList *gsListIter = NULL;
912
913         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NUMBER_LIST, &gsList);
914         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
915         {
916                 ThrowMsg(PlatformException, "getting number list (err:" <<
917                                 errorCode << ", gsList:" << gsList << ")");
918         }
919
920         gsListIter = gsList;
921         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
922         {
923                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
924                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NUM_VAL_DELETE_BOOL, true);
925                 if(errorCode != CTS_SUCCESS)
926                 {
927                         ThrowMsg(PlatformException, "clearing number list (err:" << errorCode << ")");
928                 }
929         }
930
931         ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
932         if(phoneNumbers->size() == 0)
933                 return;
934
935         ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
936         for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
937         {
938                 ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
939                 ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
940
941                 if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
942                 {
943                         LogDebug("Number was not set.");
944                         continue;
945                 }
946
947                 string number = phoneNumber->getNumber();
948
949                 int ctsIntType = 0;
950                 bool ctsBoolDefault = false;
951                 char *ctsStrCustomType = NULL;
952
953                 ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
954                 for(; typesIter != types->end(); typesIter++)
955                 {
956                         ContactPhoneNumberType type = *typesIter;
957                         if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
958                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_HOME;
959                         else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
960                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_WORK;
961                         else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
962                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_VOICE;
963                         else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
964                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_FAX;
965                         else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
966                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_MSG;
967                         else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
968                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_CELL;
969                         else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
970                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_PAGER;
971                         else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
972                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_BBS;
973                         else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
974                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_MODEM;
975                         else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
976                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_CAR;
977                         else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
978                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_ISDN;
979                         else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
980                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_VIDEO;
981                         else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
982                                 ctsIntType = ctsIntType | CTS_NUM_TYPE_PCS;
983                         else if(type == CONTACT_PHONE_NUMBER_TYPE_PREF)
984                                 ctsBoolDefault = true;
985                         else
986                         {
987                                 // TODO Will be added after type changed to string
988                                 // ctsIntType = ctsIntType | CTS_NUM_TYPE_CUSTOM;
989                                 // ctsStrCustomType = ...;
990                         }
991                 }
992
993                 CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_NUMBER);
994                 if(ctsValue == NULL)
995                 {
996                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_NUMBER)");
997                         continue;
998                 }
999
1000                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NUM_VAL_NUMBER_STR, number.c_str());
1001                 if(errorCode != CTS_SUCCESS)
1002                 {
1003                         LogWarning("Fail to set number value to ctsValue str : " << number);
1004                         contacts_svc_value_free(ctsValue);
1005                         continue;
1006                 }
1007
1008                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NUM_VAL_DEFAULT_BOOL, ctsBoolDefault);
1009                 if(errorCode != CTS_SUCCESS)
1010                 {
1011                         LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
1012                         contacts_svc_value_free(ctsValue);
1013                         continue;
1014                 }
1015
1016                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_NUM_VAL_TYPE_INT, ctsIntType);
1017                 if(errorCode != CTS_SUCCESS)
1018                 {
1019                         LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
1020                         contacts_svc_value_free(ctsValue);
1021                         continue;
1022                 }
1023
1024 //              if(ctsStrCustomType != NULL)
1025 //              {
1026 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_NUM_VAL_LABEL_STR, ctsStrCustomType);
1027 //                      if(errorCode != CTS_SUCCESS)
1028 //                      {
1029 //                              LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
1030 //                              contacts_svc_value_free(ctsValue);
1031 //                              continue;
1032 //                      }
1033 //              }
1034
1035                 gsList = g_slist_append(gsList, ctsValue);
1036         }
1037
1038         contacts_svc_struct_store_list(m_platformContact, CTS_CF_NUMBER_LIST, gsList);
1039
1040         for (; gsList; gsList = g_slist_next(gsList))
1041                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1042
1043         g_slist_free(gsList);
1044 }
1045
1046 void ContactObjectA2PConverter::importEmailList()
1047 {
1048         int errorCode = 0;
1049
1050         GSList *gsList = NULL;
1051         GSList *gsListIter = NULL;
1052
1053         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EMAIL_LIST, &gsList);
1054         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1055         {
1056                 ThrowMsg(PlatformException, "getting email list (err:" <<
1057                                 errorCode << ", gsList:" << gsList << ")");
1058         }
1059
1060         gsListIter = gsList;
1061         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1062         {
1063                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1064                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EMAIL_VAL_DELETE_BOOL, true);
1065                 if(errorCode != CTS_SUCCESS)
1066                 {
1067                         ThrowMsg(PlatformException, "clearing email list (err:" << errorCode << ")");
1068                 }
1069         }
1070
1071         ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
1072         if(emails->size() == 0)
1073                 return;
1074
1075         ContactEmailAddressArray::iterator emailsIter = emails->begin();
1076         for(; emailsIter != emails->end(); emailsIter++)
1077         {
1078                 ContactEmailAddressPtr email = *emailsIter;
1079                 ContactEmailAddressTypeArrayPtr types = email->getTypes();
1080
1081                 if(!email->getEmailIsSet() || email->getEmail().empty())
1082                 {
1083                         LogDebug("email address was not set.");
1084                         continue;
1085                 }
1086
1087                 string emailAddress = email->getEmail();
1088
1089                 int ctsIntType = 0;
1090                 bool ctsBoolDefault = false;
1091                 char *ctsStrCustomType = NULL;
1092
1093                 ContactEmailAddressTypeArray::iterator typesIter = types->begin();
1094                 for(; typesIter != types->end(); typesIter++)
1095                 {
1096                         ContactEmailAddressType type = *typesIter;
1097                         if(type == CONTACT_EMAIL_TYPE_HOME)
1098                                 ctsIntType = ctsIntType | CTS_EMAIL_TYPE_HOME;
1099                         else if(type == CONTACT_EMAIL_TYPE_WORK)
1100                                 ctsIntType = ctsIntType | CTS_EMAIL_TYPE_WORK;
1101                         else if(type == CONTACT_EMAIL_TYPE_PREF)
1102                                 ctsBoolDefault = true;
1103                         else
1104                         {
1105                                 // TODO Will be added after type changed to string
1106                                 // ctsIntType = ctsIntType | CTS_EMAIL_TYPE_CUSTOM;
1107                                 // ctsStrCustomType = ...;
1108                         }
1109                 }
1110
1111                 CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_EMAIL);
1112                 if(ctsValue == NULL)
1113                 {
1114                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EMAIL)");
1115                         continue;
1116                 }
1117
1118                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_EMAIL_VAL_ADDR_STR, emailAddress.c_str());
1119                 if(errorCode != CTS_SUCCESS)
1120                 {
1121                         LogWarning("Fail to set email value to ctsValue str : " << emailAddress);
1122                         contacts_svc_value_free(ctsValue);
1123                         continue;
1124                 }
1125
1126                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EMAIL_VAL_DEFAULT_BOOL, ctsBoolDefault);
1127                 if(errorCode != CTS_SUCCESS)
1128                 {
1129                         LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
1130                         contacts_svc_value_free(ctsValue);
1131                         continue;
1132                 }
1133
1134                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_EMAIL_VAL_TYPE_INT, ctsIntType);
1135                 if(errorCode != CTS_SUCCESS)
1136                 {
1137                         LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
1138                         contacts_svc_value_free(ctsValue);
1139                         continue;
1140                 }
1141
1142 //              if(ctsStrCustomType != NULL)
1143 //              {
1144 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_EMAIL_VAL_LABEL_STR, ctsStrCustomType);
1145 //                      if(errorCode != CTS_SUCCESS)
1146 //                      {
1147 //                              LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
1148 //                              contacts_svc_value_free(ctsValue);
1149 //                              continue;
1150 //                      }
1151 //              }
1152
1153                 gsList = g_slist_append(gsList, ctsValue);
1154         }
1155
1156         contacts_svc_struct_store_list(m_platformContact, CTS_CF_EMAIL_LIST, gsList);
1157
1158         for (; gsList; gsList = g_slist_next(gsList))
1159                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1160         g_slist_free(gsList);
1161 }
1162
1163 void ContactObjectA2PConverter::importGrouprelList()
1164 {
1165         int errorCode = 0;
1166
1167         GSList *gsList = NULL;
1168         GSList *gsListIter = NULL;
1169
1170         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_GROUPREL_LIST, &gsList);
1171         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1172         {
1173                 ThrowMsg(PlatformException, "getting grouprel list (err:" <<
1174                                 errorCode << ", gsList:" << gsList << ")");
1175         }
1176
1177         gsListIter = gsList;
1178         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1179         {
1180                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1181                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_GROUPREL_VAL_DELETE_BOOL, true);
1182                 if(errorCode != CTS_SUCCESS)
1183                 {
1184                         ThrowMsg(PlatformException, "clearing grouprel list (err:" << errorCode << ")");
1185                 }
1186         }
1187
1188         if(m_abstractContact->getCategoriesNum() == 0)
1189                 return;
1190
1191         CTSiter* ctsIterGroup = NULL;
1192         GSList *gsListGroups = NULL;
1193
1194         int addressBookId = ContactUtility::strToInt(m_abstractContact->getAddressBookId());
1195
1196         StringArrayPtr categories = m_abstractContact->getCategories();
1197
1198         StringArray::iterator categoriesIter = categories->begin();
1199         for(; categoriesIter != categories->end(); categoriesIter++)
1200         {
1201                 string category = *categoriesIter;
1202
1203                 errorCode = contacts_svc_get_list(CTS_LIST_ALL_GROUP, &ctsIterGroup);
1204                 if (errorCode == CTS_SUCCESS)
1205                 {
1206                         while (contacts_svc_iter_next(ctsIterGroup) == CTS_SUCCESS)
1207                         {
1208                                 CTSvalue *ctsValueFoundGroup = contacts_svc_iter_get_info(ctsIterGroup);
1209                                 if (ctsValueFoundGroup)
1210                                 {
1211                                         group_info_t* groupInfo = g_new0(group_info_t, 1);
1212
1213                                         groupInfo->group_name = g_strdup(contacts_svc_value_get_str(ctsValueFoundGroup, CTS_LIST_GROUP_NAME_STR));
1214                                         groupInfo->addressbook_id = contacts_svc_value_get_int(ctsValueFoundGroup, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT);
1215                                         groupInfo->group_id = contacts_svc_value_get_int(ctsValueFoundGroup, CTS_GROUP_VAL_ID_INT);
1216                                         gsListGroups = g_slist_append(gsListGroups, groupInfo);
1217                                 }
1218                         }
1219                 }
1220
1221                 CTSvalue *group = contacts_svc_value_new(CTS_VALUE_GROUP_RELATION);
1222                 if(group == NULL)
1223                 {
1224                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_GROUP_RELATION)");
1225                         continue;
1226                 }
1227
1228                 int groupId = -1;
1229
1230                 bool isNewGroup = true;
1231                 GSList* gsListGroupsIter = gsListGroups;
1232                 for(; gsListGroupsIter; gsListGroupsIter=g_slist_next(gsListGroupsIter))
1233                 {
1234                         group_info_t* groupInfo = (group_info_t*)gsListGroupsIter->data;
1235
1236                         if ((groupInfo->group_name != NULL) &&
1237                                         (category == groupInfo->group_name) &&
1238                                         (groupInfo->addressbook_id == addressBookId))
1239                         {
1240                                 isNewGroup = false;
1241                                 groupId = groupInfo->group_id;
1242                         }
1243
1244                         if (groupInfo->group_name)
1245                                 free(groupInfo->group_name);
1246                         free(groupInfo);
1247                 }
1248
1249                 g_slist_free(gsListGroups);
1250                 gsListGroups = NULL;
1251
1252                 if (isNewGroup)
1253                 {
1254                         CTSvalue *ctsValueNewGroup;
1255                         ctsValueNewGroup = contacts_svc_value_new(CTS_VALUE_GROUP);
1256
1257                         contacts_svc_value_set_str(ctsValueNewGroup, CTS_GROUP_VAL_NAME_STR, (const char*)(category.c_str()));
1258                         contacts_svc_value_set_int(ctsValueNewGroup, CTS_GROUP_VAL_ADDRESSBOOK_ID_INT, addressBookId);
1259                         groupId = contacts_svc_insert_group(addressBookId, ctsValueNewGroup);
1260                         if (groupId < 0)
1261                         {
1262                                 ThrowMsg(PlatformException, "contacts_svc_insert_group (groupId:" << groupId << ")");
1263                         }
1264
1265                         contacts_svc_value_free(ctsValueNewGroup);
1266                 }
1267
1268                 if (groupId == -1)
1269                 {
1270                         for (; gsList; gsList = g_slist_next(gsList))
1271                                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1272                         g_slist_free(gsList);
1273
1274                         ThrowMsg(PlatformException, "groupId is not properly set");
1275                 }
1276
1277                 errorCode = contacts_svc_value_set_int(group, CTS_GROUPREL_VAL_ID_INT, groupId);
1278                 if (errorCode != CTS_SUCCESS)
1279                 {
1280                         for (; gsList; gsList = g_slist_next(gsList))
1281                                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1282                         g_slist_free(gsList);
1283
1284                         ThrowMsg(PlatformException, "Fail to set group type value to ctsValue group (err:" << errorCode << ")");
1285                 }
1286
1287                 gsList = g_slist_append(gsList, group);
1288         }
1289
1290         contacts_svc_struct_store_list(m_platformContact, CTS_CF_GROUPREL_LIST, gsList);
1291
1292         for (; gsList; gsList = g_slist_next(gsList))
1293                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1294         g_slist_free(gsList);
1295 }
1296
1297 void ContactObjectA2PConverter::importEventList()
1298 {
1299         int errorCode = 0;
1300
1301         GSList *gsList = NULL;
1302         GSList *gsListIter = NULL;
1303
1304         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_EVENT_LIST, &gsList);
1305         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1306         {
1307                 ThrowMsg(PlatformException, "getting event list (err:" <<
1308                                 errorCode << ", gsList:" << gsList << ")");
1309         }
1310
1311         gsListIter = gsList;
1312         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1313         {
1314                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1315                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_EVENT_VAL_DELETE_BOOL, true);
1316                 if(errorCode != CTS_SUCCESS)
1317                 {
1318                         ThrowMsg(PlatformException, "clearing event list (err:" << errorCode << ")");
1319                 }
1320         }
1321
1322         if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
1323                 return;
1324
1325         gsList = importEventListBirthday(gsList);
1326
1327         gsList = importEventListAnniversary(gsList);
1328
1329         contacts_svc_struct_store_list(m_platformContact, CTS_CF_EVENT_LIST, gsList);
1330
1331         for (; gsList; gsList = g_slist_next(gsList))
1332                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1333         g_slist_free(gsList);
1334 }
1335
1336 GSList * ContactObjectA2PConverter::importEventListBirthday(GSList *gsList)
1337 {
1338         int errorCode = 0;
1339
1340         if(!m_abstractContact->getBirthdayIsSet())
1341                 return gsList;
1342
1343         tm birthdayTm = m_abstractContact->getBirthday();
1344
1345         if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
1346                 return gsList;
1347
1348         int birthday = ( ( birthdayTm.tm_year + 1900) * 10000 ) +
1349                         ( ( birthdayTm.tm_mon + 1 ) * 100 ) +
1350                         birthdayTm.tm_mday;
1351
1352         CTSvalue *ctsValue = NULL;
1353         ctsValue = contacts_svc_value_new(CTS_VALUE_EVENT);
1354         if(ctsValue == NULL)
1355         {
1356                 LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EVENT)");
1357                 return gsList;
1358         }
1359
1360         errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_BIRTH);
1361         if(errorCode != CTS_SUCCESS)
1362         {
1363                 LogWarning("Fail to set event type value to ctsValue value : birthday");
1364                 contacts_svc_value_free(ctsValue);
1365                 return gsList;
1366         }
1367
1368         errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_DATE_INT, birthday);
1369         if(errorCode != CTS_SUCCESS)
1370         {
1371                 LogWarning("Fail to set birthday value to ctsValue type : " << birthday);
1372                 contacts_svc_value_free(ctsValue);
1373                 return gsList;
1374         }
1375
1376         gsList = g_slist_append(gsList, ctsValue);
1377
1378         return gsList;
1379 }
1380
1381 GSList * ContactObjectA2PConverter::importEventListAnniversary(GSList *gsList)
1382 {
1383         int errorCode = 0;
1384
1385         if(m_abstractContact->getAnniversariesNum() == 0)
1386                 return gsList;
1387
1388         ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
1389
1390         ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
1391         for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
1392         {
1393                 ContactAnniversaryPtr anniversary = *anniversariesIter;
1394
1395                 if(!anniversary->getDateIsSet())
1396                         continue;
1397
1398                 tm dateTm = anniversary->getDate();
1399
1400                 if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
1401                         continue;
1402
1403                 int date = ( ( dateTm.tm_year + 1900) * 10000 ) +
1404                                 ( ( dateTm.tm_mon + 1 ) * 100 ) +
1405                                 dateTm.tm_mday;
1406
1407                 CTSvalue *ctsValue = NULL;
1408                 ctsValue = contacts_svc_value_new(CTS_VALUE_EVENT);
1409                 if(ctsValue == NULL)
1410                 {
1411                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_EVENT)");
1412                         continue;
1413                 }
1414
1415                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_TYPE_INT, CTS_EVENT_TYPE_ANNIVERSARY);
1416                 if(errorCode != CTS_SUCCESS)
1417                 {
1418                         LogWarning("Fail to set event type value to ctsValue value : birthday");
1419                         contacts_svc_value_free(ctsValue);
1420                         continue;
1421                 }
1422
1423                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_EVENT_VAL_DATE_INT, date);
1424                 if(errorCode != CTS_SUCCESS)
1425                 {
1426                         LogWarning("Fail to set date value to ctsValue type : " << date);
1427                         contacts_svc_value_free(ctsValue);
1428                         continue;
1429                 }
1430
1431 //              if(anniversary->getLabelIsSet())
1432 //              {
1433 //                      string label = anniversary->getLabel();
1434 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_EVENT_VAL_LABEL_STR, label.c_str());
1435 //                      if(errorCode != CTS_SUCCESS)
1436 //                      {
1437 //                              LogWarning("Fail to set label value to ctsValue type : " << label);
1438 //                              contacts_svc_value_free(ctsValue);
1439 //                              continue;
1440 //                      }
1441 //
1442 //              }
1443
1444                 gsList = g_slist_append(gsList, ctsValue);
1445         }
1446
1447         return gsList;
1448 }
1449
1450 void ContactObjectA2PConverter::importPostalList()
1451 {
1452         int errorCode = 0;
1453
1454         GSList *gsList = NULL;
1455         GSList *gsListIter = NULL;
1456
1457         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, &gsList);
1458         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1459         {
1460                 ThrowMsg(PlatformException, "getting postal list (err:" <<
1461                                 errorCode << ", gsList:" << gsList << ")");
1462         }
1463
1464         gsListIter = gsList;
1465         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1466         {
1467                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1468                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_POSTAL_VAL_DELETE_BOOL, true);
1469                 if(errorCode != CTS_SUCCESS)
1470                 {
1471                         ThrowMsg(PlatformException, "clearing postal list (err:" << errorCode << ")");
1472                 }
1473         }
1474
1475         if(m_abstractContact->getAddressesNum() == 0)
1476                 return;
1477
1478         ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
1479
1480         ContactAddressArray::iterator addressesIter = addresses->begin();
1481         for(; addressesIter != addresses->end(); addressesIter++)
1482         {
1483                 ContactAddressPtr address = *addressesIter;
1484                 ContactAddressTypeArrayPtr types = address->getTypes();
1485
1486                 if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
1487                                 ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
1488                                 ( !address->getCityIsSet() || address->getCity().empty() ) &&
1489                                 ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
1490                                 ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
1491                                 ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
1492                 {
1493                         LogDebug("No information for address was not set.");
1494                         continue;
1495                 }
1496
1497                 int ctsIntType = 0;
1498                 bool ctsBoolDefault = false;
1499                 char *ctsStrCustomType = NULL;
1500
1501                 ContactAddressTypeArray::iterator typesIter = types->begin();
1502                 for(; typesIter != types->end(); typesIter++)
1503                 {
1504                         ContactAddressType type = *typesIter;
1505                         if(type == CONTACT_ADDRESS_TYPE_HOME)
1506                                 ctsIntType = ctsIntType | CTS_ADDR_TYPE_HOME;
1507                         else if(type == CONTACT_ADDRESS_TYPE_WORK)
1508                                 ctsIntType = ctsIntType | CTS_ADDR_TYPE_WORK;
1509                         else if(type == CONTACT_ADDRESS_TYPE_PREF)
1510                                 ctsBoolDefault = true;
1511                         else
1512                         {
1513                                 // TODO Will be added after type changed to string
1514                                 // ctsIntType = ctsIntType | CTS_POSTAL_TYPE_CUSTOM;
1515                                 // ctsStrCustomType = ...;
1516                         }
1517                 }
1518
1519                 CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_POSTAL);
1520                 if(ctsValue == NULL)
1521                 {
1522                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_POSTAL)");
1523                         continue;
1524                 }
1525
1526                 if(address->getCountryIsSet())
1527                 {
1528                         string country = address->getCountry();
1529                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_COUNTRY_STR, country.c_str());
1530                         if(errorCode != CTS_SUCCESS)
1531                         {
1532                                 LogWarning("Fail to set country value to ctsValue str : " << country);
1533                                 contacts_svc_value_free(ctsValue);
1534                                 continue;
1535                         }
1536                 }
1537
1538                 if(address->getRegionIsSet())
1539                 {
1540                         string region = address->getRegion();
1541                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_REGION_STR, region.c_str());
1542                         if(errorCode != CTS_SUCCESS)
1543                         {
1544                                 LogWarning("Fail to set region value to ctsValue str : " << region);
1545                                 contacts_svc_value_free(ctsValue);
1546                                 continue;
1547                         }
1548                 }
1549
1550                 if(address->getCityIsSet())
1551                 {
1552                         string city = address->getCity();
1553                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_LOCALITY_STR, city.c_str());
1554                         if(errorCode != CTS_SUCCESS)
1555                         {
1556                                 LogWarning("Fail to set city value to ctsValue str : " << city);
1557                                 contacts_svc_value_free(ctsValue);
1558                                 continue;
1559                         }
1560                 }
1561
1562                 if(address->getStreetAddressIsSet())
1563                 {
1564                         string streetAddress = address->getStreetAddress();
1565                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_STREET_STR, streetAddress.c_str());
1566                         if(errorCode != CTS_SUCCESS)
1567                         {
1568                                 LogWarning("Fail to set street value to ctsValue str : " << streetAddress);
1569                                 contacts_svc_value_free(ctsValue);
1570                                 continue;
1571                         }
1572                 }
1573
1574                 if(address->getAdditionalInformationIsSet())
1575                 {
1576                         string additionalInformation = address->getAdditionalInformation();
1577                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_EXTENDED_STR, additionalInformation.c_str());
1578                         if(errorCode != CTS_SUCCESS)
1579                         {
1580                                 LogWarning("Fail to set extended value to ctsValue str : " << additionalInformation);
1581                                 contacts_svc_value_free(ctsValue);
1582                                 continue;
1583                         }
1584                 }
1585
1586                 if(address->getPostalCodeIsSet())
1587                 {
1588                         string postalCode = address->getPostalCode();
1589                         errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_POSTALCODE_STR, postalCode.c_str());
1590                         if(errorCode != CTS_SUCCESS)
1591                         {
1592                                 LogWarning("Fail to set postalcode value to ctsValue str : " << postalCode);
1593                                 contacts_svc_value_free(ctsValue);
1594                                 continue;
1595                         }
1596                 }
1597
1598                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_POSTAL_VAL_DEFAULT_BOOL, ctsBoolDefault);
1599                 if(errorCode != CTS_SUCCESS)
1600                 {
1601                         LogWarning("Fail to set favorite value to ctsValue default : " << ctsBoolDefault);
1602                         contacts_svc_value_free(ctsValue);
1603                         continue;
1604                 }
1605
1606                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_POSTAL_VAL_TYPE_INT, ctsIntType);
1607                 if(errorCode != CTS_SUCCESS)
1608                 {
1609                         LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
1610                         contacts_svc_value_free(ctsValue);
1611                         continue;
1612                 }
1613
1614 //              if(ctsStrCustomType != NULL)
1615 //              {
1616 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_POSTAL_VAL_LABEL_STR, ctsStrCustomType);
1617 //                      if(errorCode != CTS_SUCCESS)
1618 //                      {
1619 //                              LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
1620 //                              contacts_svc_value_free(ctsValue);
1621 //                              continue;
1622 //                      }
1623 //              }
1624
1625                 gsList = g_slist_append(gsList, ctsValue);
1626         }
1627
1628         contacts_svc_struct_store_list(m_platformContact, CTS_CF_POSTAL_ADDR_LIST, gsList);
1629
1630         for (; gsList; gsList = g_slist_next(gsList))
1631                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1632         g_slist_free(gsList);
1633 }
1634
1635 void ContactObjectA2PConverter::importWebAddrList()
1636 {
1637         int errorCode = 0;
1638
1639         GSList *gsList = NULL;
1640         GSList *gsListIter = NULL;
1641
1642         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, &gsList);
1643         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1644         {
1645                 ThrowMsg(PlatformException, "getting web addr list (err:" <<
1646                                 errorCode << ", gsList:" << gsList << ")");
1647         }
1648
1649         gsListIter = gsList;
1650         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1651         {
1652                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1653                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_WEB_VAL_DELETE_BOOL, true);
1654                 if(errorCode != CTS_SUCCESS)
1655                 {
1656                         ThrowMsg(PlatformException, "clearing web addr list (err:" << errorCode << ")");
1657                 }
1658         }
1659
1660         ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
1661         if(webSites->size() == 0)
1662                 return;
1663
1664         ContactWebSiteArray::iterator webSiteIter = webSites->begin();
1665         for(; webSiteIter != webSites->end(); webSiteIter++)
1666         {
1667                 ContactWebSitePtr webSite = *webSiteIter;
1668                 ContactWebSiteType type = webSite->getType();
1669
1670                 if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
1671                 {
1672                         LogDebug("url was not set.");
1673                         continue;
1674                 }
1675
1676                 string url = webSite->getUrl();
1677
1678                 int ctsIntType = 0;
1679                 char *ctsStrCustomType = NULL;
1680
1681                 if(type == WEBSITE_TYPE_HOMEPAGE)
1682                         ctsIntType = CTS_WEB_TYPE_HOME;
1683                 else if(type == WEBSITE_TYPE_BLOG)
1684                         ctsIntType = CTS_WEB_TYPE_WORK;
1685                 else
1686                 {
1687                         // TODO Will be added after type changed to string
1688                         // ctsIntType = CTS_WEB_TYPE_CUSTOM;
1689                         // ctsStrCustomType = ...;
1690                 }
1691
1692                 CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_WEB);
1693                 if(ctsValue == NULL)
1694                 {
1695                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_WEB)");
1696                         continue;
1697                 }
1698
1699                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_WEB_VAL_ADDR_STR, url.c_str());
1700                 if(errorCode != CTS_SUCCESS)
1701                 {
1702                         LogWarning("Fail to set url value to ctsValue str : " << url);
1703                         contacts_svc_value_free(ctsValue);
1704                         continue;
1705                 }
1706
1707                 errorCode = contacts_svc_value_set_int(ctsValue, CTS_WEB_VAL_TYPE_INT, ctsIntType);
1708                 if(errorCode != CTS_SUCCESS)
1709                 {
1710                         LogWarning("Fail to set default value to ctsValue type : " << ctsIntType);
1711                         contacts_svc_value_free(ctsValue);
1712                         continue;
1713                 }
1714
1715 //              if(ctsStrCustomType != NULL)
1716 //              {
1717 //                      errorCode = contacts_svc_value_set_str(ctsValue, CTS_WEB_VAL_LABEL_STR, ctsStrCustomType);
1718 //                      if(errorCode != CTS_SUCCESS)
1719 //                      {
1720 //                              LogWarning("Fail to set custom value to ctsValue type : " << ctsStrCustomType);
1721 //                              contacts_svc_value_free(ctsValue);
1722 //                              continue;
1723 //                      }
1724 //              }
1725
1726                 gsList = g_slist_append(gsList, ctsValue);
1727         }
1728
1729         contacts_svc_struct_store_list(m_platformContact, CTS_CF_WEB_ADDR_LIST, gsList);
1730
1731         for (; gsList; gsList = g_slist_next(gsList))
1732                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1733         g_slist_free(gsList);
1734 }
1735
1736 void ContactObjectA2PConverter::importNicknameList()
1737 {
1738         int errorCode = 0;
1739
1740         GSList *gsList = NULL;
1741         GSList *gsListIter = NULL;
1742
1743         errorCode = contacts_svc_struct_get_list(m_platformContact, CTS_CF_NICKNAME_LIST, &gsList);
1744         if(errorCode != CTS_SUCCESS && errorCode != CTS_ERR_NO_DATA)
1745         {
1746                 ThrowMsg(PlatformException, "getting nickname list (err:" <<
1747                                 errorCode << ", gsList:" << gsList << ")");
1748         }
1749
1750         gsListIter = gsList;
1751         for(; gsListIter; gsListIter = g_slist_next(gsListIter))
1752         {
1753                 CTSvalue* ctsValue = static_cast<CTSvalue*>(gsListIter->data);
1754                 errorCode = contacts_svc_value_set_bool(ctsValue, CTS_NICKNAME_VAL_DELETE_BOOL, true);
1755                 if(errorCode != CTS_SUCCESS)
1756                 {
1757                         ThrowMsg(PlatformException, "clearing nickname list (err:" << errorCode << ")");
1758                 }
1759         }
1760
1761         ContactNamePtr contactName = m_abstractContact->getName();
1762         if(contactName == NULL)
1763                 return;
1764
1765         if(contactName->getNicknamesNum() == 0)
1766                 return;
1767
1768         StringArrayPtr nicknames = contactName->getNicknames();
1769
1770         StringArray::iterator nicknamesIter = nicknames->begin();
1771         for(; nicknamesIter != nicknames->end(); nicknamesIter++)
1772         {
1773                 string nickname = *nicknamesIter;
1774
1775                 if(nickname.empty())
1776                 {
1777                         LogDebug("nickname was not set.");
1778                         continue;
1779                 }
1780
1781                 CTSvalue *ctsValue = contacts_svc_value_new(CTS_VALUE_NICKNAME);
1782                 if(ctsValue == NULL)
1783                 {
1784                         LogWarning("Fail to create CTSvalue with contacts_svc_value_new(CTS_VALUE_NICKNAME)");
1785                         continue;
1786                 }
1787
1788                 errorCode = contacts_svc_value_set_str(ctsValue, CTS_NICKNAME_VAL_NAME_STR, nickname.c_str());
1789                 if(errorCode != CTS_SUCCESS)
1790                 {
1791                         LogWarning("Fail to set nickname value to ctsValue str : " << nickname);
1792                         contacts_svc_value_free(ctsValue);
1793                         continue;
1794                 }
1795
1796                 gsList = g_slist_append(gsList, ctsValue);
1797         }
1798
1799         contacts_svc_struct_store_list(m_platformContact, CTS_CF_NICKNAME_LIST, gsList);
1800
1801         for (; gsList; gsList = g_slist_next(gsList))
1802                 contacts_svc_value_free(static_cast<CTSvalue*>(gsList->data));
1803         g_slist_free(gsList);
1804 }
1805
1806 } // Contact
1807 } // Platform
1808 } // TizenApis