521acbda0684868e06bf2077c926e1d717f77f99
[framework/osp/social.git] / src / FScl_AddressbookUtil.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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                FScl_AddressbookUtil.cpp
18  * @brief               This is the implementation for _AddressbookUtil class.
19  *
20  * This file contains definitions of @e _AddressbookUtil class.
21  */
22
23 #include <stdlib.h>
24 #include <unique_ptr.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColArrayListT.h>
28 #include <FSclTypes.h>
29 #include <FSclContact.h>
30 #include <FSclPerson.h>
31 #include <FSclCategory.h>
32 #include <FSclUserProfile.h>
33 #include <FSclUrl.h>
34 #include <FSclAddress.h>
35 #include <FSclImAddress.h>
36 #include <FSclContactEvent.h>
37 #include <FSclRelationship.h>
38 #include <FSclOrganization.h>
39 #include <FBaseSysLog.h>
40 #include <FBase_StringConverter.h>
41 #include <FSclContactChangeInfo.h>
42 #include <FScl_ContactChangeInfoImpl.h>
43 #include <FSclCategoryChangeInfo.h>
44 #include <FScl_CategoryChangeInfoImpl.h>
45 #include "FScl_AddressbookUtil.h"
46 #include "FScl_ContactImpl.h"
47 #include "FScl_CategoryImpl.h"
48 #include "FScl_RecordImpl.h"
49 #include <FSclPhoneNumberContact.h>
50 #include "FScl_PhoneNumberContactImpl.h"
51 #include <FSclEmailContact.h>
52 #include "FScl_EmailContactImpl.h"
53 #include "FScl_PersonImpl.h"
54 #include "FSclAddressbook.h"
55 #include "FScl_AddressbookImpl.h"
56 #include "FScl_UserProfileImpl.h"
57
58 using namespace std;
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61
62 namespace Tizen { namespace Social
63 {
64
65 template<>
66 Contact*
67 __ContactsContact::ConvertResultTo<Contact>(__SearchResult<__ContactsContact>& searchResult)
68 {
69         int intValue = 0;
70         contacts_record_h newRecord = null;
71
72         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
73         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
74
75         contacts_record_get_int(currentRecord, _contacts_contact.id, &intValue);
76         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
77
78         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
79         SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
80
81         contacts_record_clone(currentRecord, &newRecord);
82         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
83
84         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
85
86         contacts_record_get_int(newRecord, _contacts_contact.id, &intValue);
87
88         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
89
90         return pContact.release();
91 }
92
93 template<>
94 Category*
95 __ContactsGroup::ConvertResultTo<Category>(__SearchResult<__ContactsGroup>& searchResult)
96 {
97         int intValue = 0;
98         contacts_record_h newRecord = null;
99
100         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
101         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
102
103         contacts_record_get_int(currentRecord, _contacts_group.id, &intValue);
104         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
105
106         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
107         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
108
109         contacts_record_clone(currentRecord, &newRecord);
110         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
111
112         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
113
114         contacts_record_get_int(newRecord, _contacts_group.id, &intValue);
115
116         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
117
118         __Filter<__ContactsGroupRelation> filter;
119         filter.Construct();
120         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
121
122         __Query<__ContactsGroupRelation> query;
123         query.Construct();
124         query.SetFilter(filter);
125
126         int count = _AddressbookUtil::GetCountWithQuery(query);
127         SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
128
129         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
130
131         return pCategory.release();
132 }
133
134 template<>
135 Category*
136 __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGroupRelation>& searchResult)
137 {
138         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
139
140         int intValue = 0;
141
142         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
143         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
144
145         contacts_record_get_int(currentRecord, _contacts_group_relation.group_id, &intValue);
146         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
147
148         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
149         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
150
151         unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
152         SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
153
154         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
155         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
156
157         __Filter<__ContactsGroupRelation> filter;
158         filter.Construct();
159         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
160
161         __Query<__ContactsGroupRelation> query;
162         query.Construct();
163         query.SetFilter(filter);
164
165         int count = _AddressbookUtil::GetCountWithQuery(query);
166         if (count < 0)
167         {
168                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
169                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
170
171                 count = 0;
172         }
173
174         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
175
176         return pCategory.release();
177 }
178
179 template<>
180 Category*
181 __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsContactGroupRel>& searchResult)
182 {
183         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
184
185         int intValue = 0;
186
187         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
188         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
189
190         contacts_record_get_int(currentRecord, _contacts_contact_grouprel.group_id, &intValue);
191         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
192
193         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
194         SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
195
196         unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
197         SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
198
199         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
200         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
201
202         __Filter<__ContactsGroupRelation> filter;
203         filter.Construct();
204         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
205
206         __Query<__ContactsGroupRelation> query;
207         query.Construct();
208         query.SetFilter(filter);
209
210         int count = _AddressbookUtil::GetCountWithQuery(query);
211         if (count < 0)
212         {
213                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
214                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
215
216                 count = 0;
217         }
218
219         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
220
221         return pCategory.release();
222 }
223
224
225 template<>
226 Contact*
227 __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsContactGroupRel>& searchResult)
228 {
229         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
230
231         int intValue = 0;
232
233         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
234         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
235
236         contacts_record_get_int(currentRecord, _contacts_contact_grouprel.contact_id, &intValue);
237         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
238
239         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
240         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
241
242         unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
243         SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
244
245         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
246         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
247
248         return pContact.release();
249 }
250
251 template<>
252 Contact*
253 __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContactEmail>& searchResult)
254 {
255
256         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
257
258         int intValue = 0;
259
260         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
261         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
262
263         contacts_record_get_int(currentRecord, _contacts_contact_email.contact_id, &intValue);
264         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
265
266         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
267         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
268
269         unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
270         SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
271
272         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
273         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
274
275         return pContact.release();
276 }
277
278 template<>
279 EmailContact*
280 __ContactsContactEmail::ConvertResultTo<EmailContact>(__SearchResult<__ContactsContactEmail>& queryResult)
281 {
282         int intValue = 0;
283         EmailType type = EMAIL_TYPE_PERSONAL;
284         char* pCharValue = null;
285         int emailRecordId = 0;
286         String label;
287         String email;
288
289         contacts_record_h recordHandle = queryResult.GetCurrentRecord();
290         SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
291
292         contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
293         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
294
295         std::unique_ptr<EmailContact> pEmailContact(new (std::nothrow) EmailContact());
296         SysTryReturn(NID_SCL, pEmailContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
297
298         contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
299         _EmailContactImpl::GetInstance(*pEmailContact)->SetContactId(intValue);
300
301         contacts_record_get_int(recordHandle, _contacts_contact_email.person_id, &intValue);
302         _EmailContactImpl::GetInstance(*pEmailContact)->SetPersonId(intValue);
303
304         contacts_record_get_int(recordHandle, _contacts_contact_email.address_book_id, &intValue);
305         _EmailContactImpl::GetInstance(*pEmailContact)->SetAddressbookId(intValue);
306
307         contacts_record_get_str_p(recordHandle, _contacts_contact_email.display_name, &pCharValue);
308         _EmailContactImpl::GetInstance(*pEmailContact)->SetDisplayName(pCharValue);
309
310         contacts_record_get_str_p(recordHandle, _contacts_contact_email.image_thumbnail_path, &pCharValue);
311         _EmailContactImpl::GetInstance(*pEmailContact)->SetThumbnailPath(pCharValue);
312
313         contacts_record_get_str_p(recordHandle, _contacts_contact_email.ringtone_path, &pCharValue);
314         _EmailContactImpl::GetInstance(*pEmailContact)->SetRingtonePath(pCharValue);
315
316         // email id
317         contacts_record_get_int(recordHandle, _contacts_contact_email.email_id, &intValue);
318         emailRecordId = intValue;
319
320         // label
321         contacts_record_get_str_p(recordHandle, _contacts_contact_email.label, &pCharValue);
322         label = pCharValue;
323
324         // type
325         contacts_record_get_int(recordHandle, _contacts_contact_email.type, &intValue);
326         switch (intValue)
327         {
328         case CONTACTS_EMAIL_TYPE_HOME:
329                 type = EMAIL_TYPE_PERSONAL;
330                 break;
331         case CONTACTS_EMAIL_TYPE_WORK:
332                 type = EMAIL_TYPE_WORK;
333                 break;
334         case CONTACTS_EMAIL_TYPE_CUSTOM:
335                 type = EMAIL_TYPE_CUSTOM;
336                 break;
337         default:
338                 type = EMAIL_TYPE_OTHER;
339                 break;
340         }
341
342         // email
343         contacts_record_get_str_p(recordHandle, _contacts_contact_email.email, &pCharValue);
344         email = pCharValue;
345
346         _EmailContactImpl::GetInstance(*pEmailContact)->SetEmailData(emailRecordId, type, label, email);
347
348         return pEmailContact.release();
349 }
350
351 template<>
352 Contact*
353 __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsContactNumber>& searchResult)
354 {
355         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
356
357         int intValue = 0;
358
359         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
360         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
361
362         contacts_record_get_int(currentRecord, _contacts_contact_number.contact_id, &intValue);
363         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
364
365         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
366         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
367
368         unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, intValue));
369         SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
370
371         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
372         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
373
374         return pContact.release();
375 }
376
377 template<>
378 PhoneNumberContact*
379 __ContactsContactNumber::ConvertResultTo<PhoneNumberContact>(__SearchResult<__ContactsContactNumber>& queryResult)
380 {
381         int intValue = 0;
382         PhoneNumberType type = PHONENUMBER_TYPE_HOME;
383         char* pCharValue = null;
384         int numberRecordId = 0;
385         String label;
386         String number;
387
388         contacts_record_h recordHandle = queryResult.GetCurrentRecord();
389         SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
390
391         contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
392         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
393
394         std::unique_ptr<PhoneNumberContact> pPhoneNumberContact(new (std::nothrow) PhoneNumberContact());
395         SysTryReturn(NID_SCL, pPhoneNumberContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
396
397         contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
398         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetContactId(intValue);
399
400         contacts_record_get_int(recordHandle, _contacts_contact_number.person_id, &intValue);
401         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPersonId(intValue);
402
403         contacts_record_get_int(recordHandle, _contacts_contact_number.address_book_id, &intValue);
404         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetAddressbookId(intValue);
405
406         contacts_record_get_str_p(recordHandle, _contacts_contact_number.display_name, &pCharValue);
407         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetDisplayName(pCharValue);
408
409         contacts_record_get_str_p(recordHandle, _contacts_contact_number.image_thumbnail_path, &pCharValue);
410         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetThumbnailPath(pCharValue);
411
412         contacts_record_get_str_p(recordHandle, _contacts_contact_number.ringtone_path, &pCharValue);
413         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetRingtonePath(pCharValue);
414
415         // number id
416         contacts_record_get_int(recordHandle, _contacts_contact_number.number_id, &intValue);
417         numberRecordId = intValue;
418
419         // label
420         contacts_record_get_str_p(recordHandle, _contacts_contact_number.label, &pCharValue);
421         label = pCharValue;
422
423         // type
424         contacts_record_get_int(recordHandle, _contacts_contact_number.type, &intValue);
425         switch (intValue)
426         {
427                 case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
428                         type = PHONENUMBER_TYPE_HOME;
429                         break;
430                 case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
431                         type = PHONENUMBER_TYPE_WORK;
432                         break;
433                 case CONTACTS_NUMBER_TYPE_CELL:
434                         type = PHONENUMBER_TYPE_MOBILE;
435                         break;
436                 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
437                         type = PHONENUMBER_TYPE_HOME_FAX;
438                         break;
439                 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
440                         type = PHONENUMBER_TYPE_WORK_FAX;
441                         break;
442                 case CONTACTS_NUMBER_TYPE_PAGER:
443                         type = PHONENUMBER_TYPE_PAGER;
444                         break;
445                 case CONTACTS_NUMBER_TYPE_CUSTOM:
446                         type = PHONENUMBER_TYPE_CUSTOM;
447                         break;
448                 default:
449                         type = PHONENUMBER_TYPE_OTHER;
450                         break;
451         }
452
453         // number
454         contacts_record_get_str_p(recordHandle, _contacts_contact_number.number, &pCharValue);
455         number = pCharValue;
456
457         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPhoneNumberData(numberRecordId, type, label, number);
458
459         return pPhoneNumberContact.release();
460 }
461
462 template<>
463 Addressbook*
464 __ContactsAddressbook::ConvertResultTo<Addressbook>(__SearchResult<__ContactsAddressbook>& queryResult)
465 {
466         int intValue = 0;
467         char* pCharValue = null;
468
469         contacts_record_h currentRecord = queryResult.GetCurrentRecord();
470         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
471
472         std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
473         SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
474
475         result r = pAddressbook->Construct();
476         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
477
478         contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
479         _AddressbookImpl::GetInstance(*pAddressbook)->SetId(intValue);
480
481         contacts_record_get_str_p(currentRecord, _contacts_address_book.name, &pCharValue);
482         _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
483
484         contacts_record_get_int(currentRecord, _contacts_address_book.account_id, &intValue);
485         _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
486
487         return pAddressbook.release();
488 }
489
490
491
492 template<>
493 Person*
494 __ContactsPerson::ConvertResultTo<Person>(__SearchResult<__ContactsPerson>& queryResult)
495 {
496         int intValue = 0;
497         char* pCharValue = null;
498         bool boolValue = false;
499
500         contacts_record_h currentRecord = queryResult.GetCurrentRecord();
501         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
502
503         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
504         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
505
506         contacts_record_get_int(currentRecord, _contacts_person.id, &intValue);
507         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
508
509         contacts_record_get_str_p(currentRecord, _contacts_person.addressbook_ids, &pCharValue);
510         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
511
512         contacts_record_get_bool(currentRecord, _contacts_person.is_favorite, &boolValue);
513         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
514
515         contacts_record_get_bool(currentRecord, _contacts_person.has_phonenumber, &boolValue);
516         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
517
518         contacts_record_get_bool(currentRecord, _contacts_person.has_email, &boolValue);
519         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
520
521         contacts_record_get_str_p(currentRecord, _contacts_person.image_thumbnail_path, &pCharValue);
522         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
523
524         contacts_record_get_str_p(currentRecord, _contacts_person.ringtone_path, &pCharValue);
525         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
526
527         contacts_record_get_str_p(currentRecord, _contacts_person.display_name, &pCharValue);
528         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
529
530         return pPerson.release();
531
532 }
533
534 Person*
535 _AddressbookUtil::CreatePersonN(void)
536 {
537         Person* pPerson = new (std::nothrow) Person();
538         return pPerson;
539 }
540
541 template<>
542 Person*
543 __ContactsPersonGroupRel::ConvertResultTo<Person>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
544 {
545         int intValue = 0;
546         char* pCharValue = null;
547         bool boolValue = false;
548
549         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
550         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
551
552         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
553         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
554
555         contacts_record_get_int(currentRecord, _contacts_person_grouprel.person_id, &intValue);
556         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
557
558         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.addressbook_ids, &pCharValue);
559         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
560
561         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.is_favorite, &boolValue);
562         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
563
564         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_phonenumber, &boolValue);
565         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
566
567         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_email, &boolValue);
568         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
569
570         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
571         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
572
573         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.ringtone_path, &pCharValue);
574         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
575
576         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.display_name, &pCharValue);
577         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
578
579         return pPerson.release();
580 }
581
582 template<>
583 Category*
584 __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
585 {
586         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
587
588         int intValue = 0;
589
590         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
591         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
592
593         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
594         SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
595
596         contacts_record_get_int(currentRecord, _contacts_person_grouprel.group_id, &intValue);
597         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
598
599
600         unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, intValue));
601         SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
602
603         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
604         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
605
606         __Filter<__ContactsGroupRelation> filter;
607         filter.Construct();
608         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
609
610         __Query<__ContactsGroupRelation> query;
611         query.Construct();
612         query.SetFilter(filter);
613
614         int count = _AddressbookUtil::GetCountWithQuery(query);
615         if (count < 0)
616         {
617                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
618                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
619
620                 count = 0;
621         }
622
623         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
624
625         return pCategory.release();
626 }
627
628 template<>
629 Person*
630 __ContactsPerson::ConvertHandleTo<Person>(contacts_record_h recordHandle)
631 {
632         int intValue = 0;
633         char* pCharValue = null;
634         bool boolValue = false;
635
636         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
637         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
638
639         contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
640         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
641
642         contacts_record_get_str_p(recordHandle, _contacts_person.addressbook_ids, &pCharValue);
643         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
644
645         contacts_record_get_bool(recordHandle, _contacts_person.is_favorite, &boolValue);
646         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
647
648         contacts_record_get_bool(recordHandle, _contacts_person.has_phonenumber, &boolValue);
649         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
650
651         contacts_record_get_bool(recordHandle, _contacts_person.has_email, &boolValue);
652         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
653
654         contacts_record_get_str_p(recordHandle, _contacts_person.image_thumbnail_path, &pCharValue);
655         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
656
657         contacts_record_get_str_p(recordHandle, _contacts_person.ringtone_path, &pCharValue);
658         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
659
660         contacts_record_get_str_p(recordHandle, _contacts_person.display_name, &pCharValue);
661         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
662
663         return pPerson.release();
664 }
665
666 template<>
667 Person*
668 __ContactsPersonGroupRel::ConvertHandleTo<Person>(contacts_record_h recordHandle)
669 {
670         int intValue = 0;
671         char* pCharValue = null;
672         bool boolValue = false;
673
674         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
675         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
676
677         contacts_record_get_int(recordHandle, _contacts_person_grouprel.person_id, &intValue);
678         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
679
680         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.addressbook_ids, &pCharValue);
681         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
682
683         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.is_favorite, &boolValue);
684         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
685
686         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_phonenumber, &boolValue);
687         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
688
689         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_email, &boolValue);
690         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
691
692         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
693         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
694
695         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.ringtone_path, &pCharValue);
696         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
697
698         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.display_name, &pCharValue);
699         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
700
701         return pPerson.release();
702 }
703
704 template<>
705 ContactChangeInfo*
706 __ContactsContactUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsContactUpdatedInfo>& searchResult)
707 {
708         int intValue = 0;
709         bool boolValue = false;
710         RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
711
712         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
713         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
714
715         std::unique_ptr<ContactChangeInfo> pContactChagneInfo(new (std::nothrow) ContactChangeInfo());
716         SysTryReturn(NID_SCL, pContactChagneInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
717
718         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.contact_id, &intValue);
719         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetContactId(intValue);
720
721         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.address_book_id, &intValue);
722         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetAddressbookId(intValue);
723
724         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.type, &intValue);
725
726         switch (intValue)
727         {
728                 case CONTACTS_CHANGE_INSERTED:
729                         changeType = RECORD_CHANGE_TYPE_ADDED;
730                         break;
731                 case CONTACTS_CHANGE_UPDATED:
732                         changeType = RECORD_CHANGE_TYPE_UPDATED;
733                         break;
734                 case CONTACTS_CHANGE_DELETED:
735                         // fall through
736                 default:
737                         changeType = RECORD_CHANGE_TYPE_REMOVED;
738                         break;
739         }
740
741         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetChangeType(changeType);
742
743         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.version, &intValue);
744         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetVersion(intValue);
745
746         contacts_record_get_bool(currentRecord, _contacts_contact_updated_info.image_changed, &boolValue);
747         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetThumbnailChangeStatus(boolValue);
748
749         return pContactChagneInfo.release();
750 }
751
752 template<>
753 CategoryChangeInfo*
754 __ContactsGroupUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupUpdatedInfo>& searchResult)
755 {
756         int intValue = 0;
757         RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
758
759         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
760         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
761
762         std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
763         SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
764
765         contacts_record_get_int(currentRecord, _contacts_group_updated_info.group_id, &intValue);
766         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
767
768         contacts_record_get_int(currentRecord, _contacts_group_updated_info.address_book_id, &intValue);
769         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
770
771         contacts_record_get_int(currentRecord, _contacts_group_updated_info.type, &intValue);
772
773         switch (intValue)
774         {
775                 case CONTACTS_CHANGE_INSERTED:
776                         changeType = RECORD_CHANGE_TYPE_ADDED;
777                         break;
778                 case CONTACTS_CHANGE_UPDATED:
779                         changeType = RECORD_CHANGE_TYPE_UPDATED;
780                         break;
781                 case CONTACTS_CHANGE_DELETED:
782                         // fall through
783                 default:
784                         changeType = RECORD_CHANGE_TYPE_REMOVED;
785                         break;
786         }
787
788         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(changeType);
789
790         contacts_record_get_int(currentRecord, _contacts_group_updated_info.version, &intValue);
791         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
792
793         return pCategoryChangeInfo.release();
794 }
795
796 template<>
797 CategoryChangeInfo*
798 __ContactsGroupRelUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupRelUpdatedInfo>& searchResult)
799 {
800         int intValue = 0;
801
802         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
803         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
804
805         std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
806         SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
807
808         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.group_id, &intValue);
809         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
810
811         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
812         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
813
814         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.address_book_id, &intValue);
815         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
816
817         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.type, &intValue);
818
819         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(RECORD_CHANGE_TYPE_UPDATED);
820
821         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
822         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
823
824         return pCategoryChangeInfo.release();
825 }
826
827 template<>
828 UserProfile*
829 __ContactsUserProfile::ConvertResultTo<UserProfile>(__SearchResult<__ContactsUserProfile>& searchResult)
830 {
831         contacts_record_h newRecord = null;
832
833         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
834         SysTryReturn(NID_SCL, currentRecord != null, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
835
836         std::unique_ptr<UserProfile> pProfile(new (std::nothrow) UserProfile());
837         SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
838
839         contacts_record_clone(currentRecord, &newRecord);
840         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
841
842         _UserProfileImpl::GetInstance(*pProfile)->SetUserProfileHandle(newRecord);
843
844         return pProfile.release();
845 }
846
847 template<>
848  __SearchResult<__ContactsPerson>*
849 _AddressbookUtil::Search(const Tizen::Base::String& keyword)
850 {
851         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
852
853         __SearchResult<__ContactsPerson>* pQueryResult = null;
854
855         contacts_list_h list = null;
856         std::unique_ptr<char[]> pKeyword(_StringConverter::CopyToCharArrayN(keyword));
857
858         int ret = contacts_db_search_records(__ContactsPerson::GetUri(), pKeyword.get(), 0, 0, &list);
859         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
860         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
861
862         pQueryResult = new (std::nothrow) __SearchResult<__ContactsPerson>(list);
863         SysTryReturn(NID_SCL, pQueryResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
864
865         return pQueryResult;
866 }
867
868 IListT<AddressbookId>*
869 _AddressbookUtil::GetRwAbIdListN(void)
870 {
871         ClearLastResult();
872
873         __Filter<__ContactsAddressbook> filter;
874         filter.Construct();
875         filter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_GREATER_THAN, 0);
876
877         __Query<__ContactsAddressbook> query;
878         query.Construct();
879         query.SetFilter(filter);
880
881         std::unique_ptr<IList, AllElementsDeleter> pAbList(SearchWithQueryN<__ContactsAddressbook, Addressbook>(query));
882         SysTryReturn(NID_SCL, pAbList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
883
884         std::unique_ptr<IEnumerator> pEnum(pAbList->GetEnumeratorN());
885         SysTryReturn(NID_SCL, pEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
886
887         std::unique_ptr< ArrayListT<AddressbookId> > pAbIdList(new (std::nothrow) ArrayListT<AddressbookId>);
888         SysTryReturn(NID_SCL, pAbIdList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
889
890         result r = pAbIdList->Construct(pAbList->GetCount());
891         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
892
893         while (pEnum->MoveNext() == E_SUCCESS)
894         {
895                 Addressbook* pAddressbook = static_cast<Addressbook*>(pEnum->GetCurrent());
896
897                 pAbIdList->Add(pAddressbook->GetId());
898         }
899
900         return pAbIdList.release();
901 }
902
903 result
904 _AddressbookUtil::GetAbListN(IListT<AddressbookId>& rwAbIdList, IListT<AddressbookId>& roAbIdList)
905 {
906         ClearLastResult();
907
908         __Query<__ContactsAddressbook> query;
909         query.Construct();
910
911         std::unique_ptr<__SearchResult<__ContactsAddressbook> > pSearchResult(_AddressbookUtil::ExecuteQuery(query, 0, 0));
912         if (pSearchResult == null)
913         {
914                 return E_SUCCESS;
915         }
916
917         while (pSearchResult->MoveNext() == E_SUCCESS)
918         {
919                 int intValue = 0;
920                 contacts_record_h currentRecord = pSearchResult->GetCurrentRecord();
921
922                 contacts_record_get_int(currentRecord, _contacts_address_book.mode, &intValue);
923                 if (intValue == CONTACTS_ADDRESS_BOOK_MODE_NONE)
924                 {
925                         contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
926
927                         rwAbIdList.Add(intValue);
928                 }
929                 else
930                 {
931                         contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
932                         roAbIdList.Add(intValue);
933                 }
934         }
935
936         return E_SUCCESS;
937 }
938
939 }}  // Tizen::Social