ed91907747d09b9a03aba88758d01748eacfd4ea
[framework/osp/social.git] / src / FScl_AddressbookFilterImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18 * @file         FScl_AddressbookFilterImpl.cpp
19 * @brief        This is the implementation for _AddressbookFilterImpl class.
20 *
21 * This file contains definitions of @e _AddressbookFilterImpl class.
22 */
23
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FSclAddressbookFilter.h>
27 #include <FBase_StringConverter.h>
28 #include "FScl_ContactDbConnector.h"
29 #include "FScl_AddressbookFilterImpl.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33
34 namespace Tizen { namespace Social
35 {
36
37 // AB_FI_TYPE_ADDRESSBOOK
38 // The entries must be ordered same as AddressbookFilterProperty
39 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__addressbookFilterPropertyInfos[] =
40 {
41         {AB_FI_PR_ADDRESSBOOK_ID, _contacts_address_book.id, DATA_TYPE_INT},
42         {AB_FI_PR_ACCOUNT_ID, _contacts_address_book.account_id, DATA_TYPE_INT},
43         {AB_FI_PR_NAME, _contacts_address_book.name, DATA_TYPE_STRING},
44 };
45
46 // AB_FI_TYPE_PERSON
47 // The entries must be ordered same as PersonFilterProperty
48 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__personFilterPropertyInfos[] =
49 {
50         {PERSON_FI_PR_PERSON_ID, _contacts_person_grouprel.person_id, DATA_TYPE_INT},
51         {PERSON_FI_PR_DISPLAY_NAME, _contacts_person_grouprel.display_name, DATA_TYPE_STRING},
52         {PERSON_FI_PR_HAS_PHONE, _contacts_person_grouprel.has_phonenumber, DATA_TYPE_BOOL},
53         {PERSON_FI_PR_HAS_EMAIL, _contacts_person_grouprel.has_email, DATA_TYPE_BOOL},
54         {PERSON_FI_PR_IS_FAVORITE, _contacts_person_grouprel.is_favorite, DATA_TYPE_BOOL},
55         {PERSON_FI_PR_CATEGORY_ID, _contacts_person_grouprel.group_id, DATA_TYPE_INT},
56         {PERSON_FI_PR_ADDRESSBOOK_ID, _contacts_person_grouprel.address_book_id, DATA_TYPE_INT},
57 };
58
59 // AB_FI_TYPE_CONTACT
60 // The entries must be ordered same as ContactFilterProperty
61 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__contactFilterPropertyInfos[] =
62 {
63         {CONTACT_FI_PR_CONTACT_ID, _contacts_contact.id, DATA_TYPE_INT},
64         {CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact.address_book_id, DATA_TYPE_INT},
65         {CONTACT_FI_PR_PERSON_ID, _contacts_contact.person_id, DATA_TYPE_INT},
66         {CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact.display_name, DATA_TYPE_STRING},
67         {CONTACT_FI_PR_HAS_PHONE, _contacts_contact.has_phonenumber, DATA_TYPE_BOOL},
68         {CONTACT_FI_PR_HAS_EMAIL, _contacts_contact.has_email, DATA_TYPE_BOOL},
69 };
70
71 // AB_FI_TYPE_CATEGORY
72 // The entries must be ordered same as CategoryFilterProperty
73 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__categoryFilterPropertyInfos[] =
74 {
75         {CATEGORY_FI_PR_CATEGORY_ID, _contacts_group.id, DATA_TYPE_INT},
76         {CATEGORY_FI_PR_ADDRESSBOOK_ID, _contacts_group.address_book_id, DATA_TYPE_INT},
77         {CATEGORY_FI_PR_NAME, _contacts_group.name, DATA_TYPE_STRING},
78 };
79
80 // AB_FI_TYPE_PHONE_CONTACT
81 // The entries must be ordered same as PhoneContactFilterProperty
82 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__phoneContactFilterPropertyInfos[] =
83 {
84         {PHONE_CONTACT_FI_PR_CONTACT_ID, _contacts_contact_number.contact_id, DATA_TYPE_INT},
85         {PHONE_CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact_number.address_book_id, DATA_TYPE_INT},
86         {PHONE_CONTACT_FI_PR_PERSON_ID, _contacts_contact_number.person_id, DATA_TYPE_INT},
87         {PHONE_CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact_number.display_name, DATA_TYPE_STRING},
88         {PHONE_CONTACT_FI_PR_PHONE, _contacts_contact_number.number, DATA_TYPE_STRING},
89 };
90
91 // AB_FI_TYPE_EMAIL_CONTACT
92 // The entries must be ordered same as EmailContactFilterProperty
93 const _AddressbookFilterImpl::__FilterPropertyInfoEntry _AddressbookFilterImpl::__emailContactFilterPropertyInfos[] =
94 {
95         {EMAIL_CONTACT_FI_PR_CONTACT_ID, _contacts_contact_email.contact_id, DATA_TYPE_INT},
96         {EMAIL_CONTACT_FI_PR_ADDRESSBOOK_ID, _contacts_contact_email.address_book_id, DATA_TYPE_INT},
97         {EMAIL_CONTACT_FI_PR_PERSON_ID, _contacts_contact_email.person_id, DATA_TYPE_INT},
98         {EMAIL_CONTACT_FI_PR_DISPLAY_NAME, _contacts_contact_email.display_name, DATA_TYPE_STRING},
99         {EMAIL_CONTACT_FI_PR_EMAIL, _contacts_contact_email.email, DATA_TYPE_STRING},
100 };
101
102 const _AddressbookFilterImpl::__FilterInfoEntry _AddressbookFilterImpl::__filterInfos[] =
103 {
104         {AB_FI_TYPE_ADDRESSBOOK, _contacts_address_book._uri, AB_FI_PR_ADDRESSBOOK_ID, sizeof(__addressbookFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __addressbookFilterPropertyInfos},
105         {AB_FI_TYPE_PERSON, _contacts_person_grouprel._uri, PERSON_FI_PR_PERSON_ID, sizeof(__personFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __personFilterPropertyInfos},
106         {AB_FI_TYPE_CONTACT, _contacts_contact._uri, CONTACT_FI_PR_CONTACT_ID, sizeof(__contactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __contactFilterPropertyInfos},
107         {AB_FI_TYPE_CATEGORY, _contacts_group._uri, CATEGORY_FI_PR_CATEGORY_ID, sizeof(__categoryFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __categoryFilterPropertyInfos},
108         {AB_FI_TYPE_PHONE_CONTACT, _contacts_contact_number._uri, PHONE_CONTACT_FI_PR_CONTACT_ID, sizeof(__phoneContactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __phoneContactFilterPropertyInfos},
109         {AB_FI_TYPE_EMAIL_CONTACT, _contacts_contact_email._uri, EMAIL_CONTACT_FI_PR_CONTACT_ID, sizeof(__emailContactFilterPropertyInfos)/sizeof(_AddressbookFilterImpl::__FilterPropertyInfoEntry), __emailContactFilterPropertyInfos},
110 };
111
112 bool
113 _AddressbookFilterImpl::IsValidProperty(AddressbookFilterType filterType, unsigned long property)
114 {
115         int filterInfoCount = sizeof(__filterInfos)/sizeof(__FilterInfoEntry);
116
117         if (filterType < 0 || filterType > (filterInfoCount - 1))
118         {
119                 return false;
120         }
121
122         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
123         int propertyInfoCount = __filterInfos[filterType].propertyInfoCount;
124
125         if (property < baseIndex || property >= (baseIndex + propertyInfoCount))
126         {
127                 return false;
128         }
129
130         return true;
131 }
132
133 // IsValidProperty must be called before calling this. If IsValidProperty returns false
134 // this should not be called.
135 const char*
136 _AddressbookFilterImpl::GetUriFromType(AddressbookFilterType filterType)
137 {
138         return __filterInfos[filterType].pViewUri;
139 }
140
141 // IsValidProperty must be called before calling this. If IsValidProperty returns false
142 // this should not be called.
143 unsigned int
144 _AddressbookFilterImpl::GetViewPropertyId(AddressbookFilterType filterType, unsigned long property)
145 {
146         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
147         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
148
149         return propertyInfos[property - baseIndex].viewPropertyId;
150 }
151
152 // IsValidProperty must be called before calling this. If IsValidProperty returns false
153 // this should not be called.
154 __DataType
155 _AddressbookFilterImpl::GetPropertyType(AddressbookFilterType filterType, unsigned long property)
156 {
157         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
158         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
159
160         return propertyInfos[property - baseIndex].dataType;
161 }
162
163 _AddressbookFilterImpl::_AddressbookFilterImpl(AddressbookFilterType type)
164         : __filterHandle(null)
165         , __filterType(type)
166         , __isEmpty(true)
167 {
168         contacts_filter_h filterHandle = null;
169         const char* pUri = GetUriFromType(type);
170
171         SysTryReturnVoidResult(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
172
173         int ret = contacts_filter_create(pUri, &filterHandle);
174         SysTryReturnVoidResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, "[%s ] Memory allocation failed.", GetErrorMessage(GetLastResult()));
175
176         __filterHandle = filterHandle;
177 }
178
179 _AddressbookFilterImpl::~_AddressbookFilterImpl(void)
180 {
181         if (__filterHandle != null)
182         {
183                 contacts_filter_destroy(__filterHandle);
184         }
185 }
186
187 bool
188 _AddressbookFilterImpl::Equals(const Tizen::Base::Object& rhs) const
189 {
190         const _AddressbookFilterImpl* pAddressbookFilter = dynamic_cast<const _AddressbookFilterImpl*>(&rhs);
191         if (this == pAddressbookFilter)
192         {
193                 return true;
194         }
195
196         return false;
197 }
198
199 int
200 _AddressbookFilterImpl::GetHashCode(void) const
201 {
202         return (int)__filterHandle;
203 }
204
205 contacts_match_int_flag_e
206 _AddressbookFilterImpl::GetMatchIntFlag(FilterComparisonOperator comparisonOperator)
207 {
208         contacts_match_int_flag_e match = CONTACTS_MATCH_NONE;
209         switch(comparisonOperator)
210         {
211         case FI_CMP_OP_EQUAL:
212                 match = CONTACTS_MATCH_EQUAL;
213                 break;
214         case FI_CMP_OP_LESS_THAN:
215                 match = CONTACTS_MATCH_GREATER_THAN;
216                 break;
217         case FI_CMP_OP_LESS_THAN_OR_EQUAL:
218                 match = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
219                 break;
220         case FI_CMP_OP_GREATER_THAN:
221                 match = CONTACTS_MATCH_LESS_THAN;
222                 break;
223         case FI_CMP_OP_GREATER_THAN_OR_EQUAL:
224                 match = CONTACTS_MATCH_LESS_THAN_OR_EQUAL;
225                 break;
226         case FI_CMP_OP_IS_NULL:
227                 match = CONTACTS_MATCH_NONE;
228                 break;
229         default:
230                 match = CONTACTS_MATCH_NONE;
231         };
232
233         return match;
234 }
235
236 contacts_match_str_flag_e
237 _AddressbookFilterImpl::GetMatchStrFlag(FilterStringOperator stringOperstor)
238 {
239         contacts_match_str_flag_e match = CONTACTS_MATCH_EXISTS;
240         switch(stringOperstor)
241         {
242         case FI_STR_OP_EQUAL:
243                 match = CONTACTS_MATCH_EXACTLY;
244                 break;
245         case FI_STR_OP_FULL_STRING:
246                 match = CONTACTS_MATCH_FULLSTRING;
247                 break;
248         case FI_STR_OP_START_WITH:
249                 match = CONTACTS_MATCH_STARTSWITH;
250                 break;
251         case FI_STR_OP_END_WITH:
252                 match = CONTACTS_MATCH_ENDSWITH;
253                 break;
254         case FI_STR_OP_CONTAIN:
255                 match = CONTACTS_MATCH_CONTAINS;
256                 break;
257         case FI_STR_OP_IS_NOT_NULL:
258                 match = CONTACTS_MATCH_EXISTS;
259                 break;
260         default:
261                 match = CONTACTS_MATCH_EXISTS;
262         };
263
264         return match;
265 }
266
267
268 result
269 _AddressbookFilterImpl::AppendInt(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, int value)
270 {
271         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
272         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be int.", GetErrorMessage(E_INVALID_ARG), filterProperty);
273         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
274                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
275                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
276         SysTryReturn(NID_SCL, !(!__isEmpty && (conjunctiveOperator == FI_CONJ_OP_NONE)),\
277                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
278                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
279
280
281         unsigned int id = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
282         contacts_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
283
284         if (!__isEmpty)
285         {
286                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
287
288                 contacts_filter_add_operator(__filterHandle, filterOperator);
289         }
290
291         int ret = contacts_filter_add_int(__filterHandle, id, match, value);
292         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
293
294         __isEmpty = false;
295
296         return E_SUCCESS;
297 }
298
299 result
300 _AddressbookFilterImpl::AppendBool(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, bool value)
301 {
302         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
303         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be bool.", GetErrorMessage(E_INVALID_ARG), filterProperty);
304         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
305                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
306                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
307         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
308                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
309                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
310         SysTryReturn(NID_SCL, comparisonOperator == FI_CMP_OP_EQUAL, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. comparisonOperator %d must be FI_CMP_OP_EQUAL.", GetErrorMessage(E_INVALID_ARG), comparisonOperator);
311
312         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
313
314         if (!__isEmpty)
315         {
316                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
317
318                 contacts_filter_add_operator(__filterHandle, filterOperator);
319         }
320
321
322         int ret = contacts_filter_add_bool(__filterHandle, viewPropertyId, value);
323         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
324
325         __isEmpty = false;
326
327         return E_SUCCESS;
328 }
329
330 result
331 _AddressbookFilterImpl::AppendString(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterStringOperator comparisonOperator, const Tizen::Base::String& value)
332 {
333         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter property is invalid.", GetErrorMessage(E_INVALID_ARG));
334         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_STRING, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be String.", GetErrorMessage(E_INVALID_ARG), filterProperty);
335         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND  || conjunctiveOperator == FI_CONJ_OP_OR)),\
336                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
337                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
338         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
339                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
340                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
341
342
343         unsigned int viewPropertyId = _AddressbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
344         contacts_match_str_flag_e match = GetMatchStrFlag(comparisonOperator);
345         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
346         SysTryReturn(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
347
348         if (!__isEmpty)
349         {
350                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
351
352                 contacts_filter_add_operator(__filterHandle, filterOperator);
353         }
354
355         int ret = contacts_filter_add_str(__filterHandle, viewPropertyId, match, pCharArray.get());
356         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
357
358
359         __isEmpty = false;
360
361         return E_SUCCESS;
362 }
363
364 result
365 _AddressbookFilterImpl::AppendFilter(FilterConjunctiveOperator conjunctiveOperator, const _AddressbookFilterImpl& filter)
366 {
367         SysTryReturn(NID_SCL, !filter.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified filter should not be empty.", GetErrorMessage(E_INVALID_ARG));
368         SysTryReturn(NID_SCL, __filterType == filter.__filterType, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter must be same with the type of this filter.", GetErrorMessage(E_INVALID_ARG));
369         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
370                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be FI_CONJ_OP_NONE if there is no filtering expression or filter that has been appended before",\
371                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
372         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
373                         E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. conjunctiveOperator %d must be either of FI_CONJ_OP_AND or FI_CONJ_OP_OR, if there is a filtering expression or filter that has been appended before.",\
374                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
375
376         if (!__isEmpty)
377         {
378                 contacts_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CONTACTS_FILTER_OPERATOR_AND : CONTACTS_FILTER_OPERATOR_OR;
379                 contacts_filter_add_operator(__filterHandle, filterOperator);
380         }
381
382         int ret = contacts_filter_add_filter(__filterHandle, filter.__filterHandle);
383         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
384
385         __isEmpty = false;
386
387         return E_SUCCESS;
388 }
389
390 contacts_filter_h
391 _AddressbookFilterImpl::GetFilterHandle(void) const
392 {
393         if (!__isEmpty)
394         {
395                 return __filterHandle;
396         }
397
398         return null;
399 }
400
401 AddressbookFilterType
402 _AddressbookFilterImpl::GetType(void) const
403 {
404         return __filterType;
405 }
406
407 bool
408 _AddressbookFilterImpl::IsEmpty(void) const
409 {
410         return __isEmpty;
411 }
412
413 const _AddressbookFilterImpl*
414 _AddressbookFilterImpl::GetInstance(const AddressbookFilter& filter)
415 {
416         return filter.__pAddressbookFilterImpl;
417 }
418
419 _AddressbookFilterImpl*
420 _AddressbookFilterImpl::GetInstance(AddressbookFilter& filter)
421 {
422         return filter.__pAddressbookFilterImpl;
423 }
424
425 }} // Tizen::Social