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