Modify the spec file for secure log
[framework/osp/social.git] / src / FScl_CalendarbookFilterImpl.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_CalendarbookFilterImpl.cpp
18 * @brief        This is the implementation for _CalendarbookFilterImpl class.
19 *
20 * This file contains definitions of @e _CalendarbookFilterImpl class.
21 */
22
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseDateTime.h>
26 #include <FBase_StringConverter.h>
27 #include <FSclCalendarbookFilter.h>
28 #include "FScl_CalendarbookFilterImpl.h"
29 #include "FScl_CalendarbookUtil.h"
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Social
34 {
35
36 static const long long _CALENDAR_TODO_NO_START_DATE = -0x7fffffffffffffffLL;
37 static const long long _CALENDAR_TODO_NO_DUE_DATE = 0x7fffffffffffffffLL;
38
39 // CB_FI_TYPE_CALENDAR
40 // The entries must be ordered same as CalendarFilterProperty
41 const _CalendarbookFilterImpl::__FilterPropertyInfoEntry _CalendarbookFilterImpl::__calendarFilterPropertyInfos[] =
42 {
43         {CALENDAR_FI_PR_CALENDAR_ID, _calendar_book.id, DATA_TYPE_INT},
44         {CALENDAR_FI_PR_ACCOUNT_ID, _calendar_book.account_id, DATA_TYPE_INT},
45         {CALENDAR_FI_PR_NAME, _calendar_book.name, DATA_TYPE_STRING},
46         {CALENDAR_FI_PR_ITEM_TYPE, _calendar_book.store_type, DATA_TYPE_INT},
47 };
48
49 // CB_FI_TYPE_EVENT
50 // The entries must be ordered same as EventFilterProperty
51 const _CalendarbookFilterImpl::__FilterPropertyInfoEntry _CalendarbookFilterImpl::__eventFilterPropertyInfos[] =
52 {
53         {EVENT_FI_PR_EVENT_ID, _calendar_event.id, DATA_TYPE_INT},
54         {EVENT_FI_PR_CALENDAR_ID, _calendar_event.calendar_book_id, DATA_TYPE_INT},
55         {EVENT_FI_PR_SUBJECT, _calendar_event.summary, DATA_TYPE_STRING},
56         {EVENT_FI_PR_DESCRIPTION, _calendar_event.description, DATA_TYPE_STRING},
57         {EVENT_FI_PR_LOCATION, _calendar_event.location, DATA_TYPE_STRING},
58         {EVENT_FI_PR_BUSY_STATUS, _calendar_event.busy_status, DATA_TYPE_INT},
59         {EVENT_FI_PR_PRIORITY, _calendar_event.priority, DATA_TYPE_INT},
60         {EVENT_FI_PR_SENSITIVITY, _calendar_event.sensitivity, DATA_TYPE_INT},
61         {EVENT_FI_PR_STATUS, _calendar_event.event_status, DATA_TYPE_INT},
62         {EVENT_FI_PR_UID, _calendar_event.uid, DATA_TYPE_STRING},
63         {EVENT_FI_PR_LATITUDE, _calendar_event.latitude, DATA_TYPE_DOUBLE},
64         {EVENT_FI_PR_LONGITUDE, _calendar_event.longitude, DATA_TYPE_DOUBLE},
65         {EVENT_FI_PR_LAST_REVISED_TIME, _calendar_event.last_modified_time, DATA_TYPE_DATE_TIME},
66         {EVENT_FI_PR_HAS_REMINDER, _calendar_event.has_alarm, DATA_TYPE_BOOL},
67         {EVENT_FI_PR_HAS_ATTENDEE, _calendar_event.has_attendee, DATA_TYPE_BOOL},
68 };
69
70 // CB_FI_TYPE_TODO
71 // The entries must be ordered same as TodoFilterProperty
72 const _CalendarbookFilterImpl::__FilterPropertyInfoEntry _CalendarbookFilterImpl::__todoFilterPropertyInfos[] =
73 {
74                 {TODO_FI_PR_TODO_ID, _calendar_todo.id, DATA_TYPE_INT},
75                 {TODO_FI_PR_CALENDAR_ID, _calendar_todo.calendar_book_id, DATA_TYPE_INT},
76                 {TODO_FI_PR_START_DATE, _calendar_todo.start_time, DATA_TYPE_DATE_TIME},
77                 {TODO_FI_PR_DUE_DATE, _calendar_todo.due_time, DATA_TYPE_DATE_TIME},
78                 {TODO_FI_PR_SUBJECT, _calendar_todo.summary, DATA_TYPE_STRING},
79                 {TODO_FI_PR_DESCRIPTION, _calendar_todo.description, DATA_TYPE_STRING},
80                 {TODO_FI_PR_LOCATION, _calendar_todo.location, DATA_TYPE_STRING},
81                 {TODO_FI_PR_PRIORITY, _calendar_todo.priority, DATA_TYPE_INT},
82                 {TODO_FI_PR_SENSITIVITY, _calendar_todo.sensitivity, DATA_TYPE_INT},
83                 {TODO_FI_PR_STATUS, _calendar_todo.todo_status, DATA_TYPE_INT},
84                 {TODO_FI_PR_LATITUDE, _calendar_todo.latitude, DATA_TYPE_DOUBLE},
85                 {TODO_FI_PR_LONGITUDE, _calendar_todo.longitude, DATA_TYPE_DOUBLE},
86                 {TODO_FI_PR_LAST_REVISED_TIME, _calendar_todo.last_modified_time, DATA_TYPE_DATE_TIME},
87                 {TODO_FI_PR_HAS_REMINDER, _calendar_todo.has_alarm, DATA_TYPE_BOOL},
88 };
89
90 // CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE
91 // The entries must be ordered same as EventInstanceFilterProperty
92 const _CalendarbookFilterImpl::__FilterPropertyInfoEntry _CalendarbookFilterImpl::__allDayEventInstanceFilterPropertyInfos[] =
93 {
94                 {EVENT_INST_FI_PR_ORIGINAL_EVENT_ID, _calendar_instance_allday_calendar_book.event_id, DATA_TYPE_INT},
95                 {EVENT_INST_FI_PR_CALENDAR_ID, _calendar_instance_allday_calendar_book.calendar_book_id, DATA_TYPE_INT},
96                 {EVENT_INST_FI_PR_START_TIME, _calendar_instance_allday_calendar_book.start_time, DATA_TYPE_DATE_TIME},
97                 {EVENT_INST_FI_PR_END_TIME, _calendar_instance_allday_calendar_book.end_time, DATA_TYPE_DATE_TIME},
98                 {EVENT_INST_FI_PR_SUBJECT, _calendar_instance_allday_calendar_book.summary, DATA_TYPE_STRING},
99                 {EVENT_INST_FI_PR_DESCRIPTION, _calendar_instance_allday_calendar_book.description, DATA_TYPE_STRING},
100                 {EVENT_INST_FI_PR_LOCATION, _calendar_instance_allday_calendar_book.location, DATA_TYPE_STRING},
101                 {EVENT_INST_FI_PR_BUSY_STATUS, _calendar_instance_allday_calendar_book.busy_status, DATA_TYPE_INT},
102                 {EVENT_INST_FI_PR_PRIORITY, _calendar_instance_allday_calendar_book.priority, DATA_TYPE_INT},
103                 {EVENT_INST_FI_PR_SENSITIVITY, _calendar_instance_allday_calendar_book.sensitivity, DATA_TYPE_INT},
104                 {EVENT_INST_FI_PR_STATUS, _calendar_instance_allday_calendar_book.event_status, DATA_TYPE_INT},
105                 {EVENT_INST_FI_PR_LATITUDE, _calendar_instance_allday_calendar_book.latitude, DATA_TYPE_DOUBLE},
106                 {EVENT_INST_FI_PR_LONGITUDE, _calendar_instance_allday_calendar_book.longitude, DATA_TYPE_DOUBLE},
107                 {EVENT_INST_FI_PR_IS_RECURRING, _calendar_instance_allday_calendar_book.has_rrule, DATA_TYPE_BOOL},
108                 {EVENT_INST_FI_PR_HAS_REMINDER, _calendar_instance_allday_calendar_book.has_alarm, DATA_TYPE_BOOL},
109 };
110
111 // CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE
112 // The entries must be ordered same as EventInstanceFilterProperty
113 const _CalendarbookFilterImpl::__FilterPropertyInfoEntry _CalendarbookFilterImpl::__nonAllDayEventInstanceFilterPropertyInfos[] =
114 {
115                 {EVENT_INST_FI_PR_ORIGINAL_EVENT_ID, _calendar_instance_normal_calendar_book.event_id, DATA_TYPE_INT},
116                 {EVENT_INST_FI_PR_CALENDAR_ID, _calendar_instance_normal_calendar_book.calendar_book_id, DATA_TYPE_INT},
117                 {EVENT_INST_FI_PR_START_TIME, _calendar_instance_normal_calendar_book.start_time, DATA_TYPE_DATE_TIME},
118                 {EVENT_INST_FI_PR_END_TIME, _calendar_instance_normal_calendar_book.end_time, DATA_TYPE_DATE_TIME},
119                 {EVENT_INST_FI_PR_SUBJECT, _calendar_instance_normal_calendar_book.summary, DATA_TYPE_STRING},
120                 {EVENT_INST_FI_PR_DESCRIPTION, _calendar_instance_normal_calendar_book.description, DATA_TYPE_STRING},
121                 {EVENT_INST_FI_PR_LOCATION, _calendar_instance_normal_calendar_book.location, DATA_TYPE_STRING},
122                 {EVENT_INST_FI_PR_BUSY_STATUS, _calendar_instance_normal_calendar_book.busy_status, DATA_TYPE_INT},
123                 {EVENT_INST_FI_PR_PRIORITY, _calendar_instance_normal_calendar_book.priority, DATA_TYPE_INT},
124                 {EVENT_INST_FI_PR_SENSITIVITY, _calendar_instance_normal_calendar_book.sensitivity, DATA_TYPE_INT},
125                 {EVENT_INST_FI_PR_STATUS, _calendar_instance_normal_calendar_book.event_status, DATA_TYPE_INT},
126                 {EVENT_INST_FI_PR_LATITUDE, _calendar_instance_normal_calendar_book.latitude, DATA_TYPE_DOUBLE},
127                 {EVENT_INST_FI_PR_LONGITUDE, _calendar_instance_normal_calendar_book.longitude, DATA_TYPE_DOUBLE},
128                 {EVENT_INST_FI_PR_IS_RECURRING, _calendar_instance_normal_calendar_book.has_rrule, DATA_TYPE_BOOL},
129                 {EVENT_INST_FI_PR_HAS_REMINDER, _calendar_instance_normal_calendar_book.has_alarm, DATA_TYPE_BOOL},
130 };
131
132 const _CalendarbookFilterImpl::__FilterInfoEntry _CalendarbookFilterImpl::__filterInfos[] =
133 {
134         {CB_FI_TYPE_EVENT, _calendar_event._uri, EVENT_FI_PR_EVENT_ID, sizeof(__eventFilterPropertyInfos)/sizeof(_CalendarbookFilterImpl::__FilterPropertyInfoEntry), __eventFilterPropertyInfos},
135         {CB_FI_TYPE_TODO, _calendar_todo._uri, TODO_FI_PR_TODO_ID, sizeof(__todoFilterPropertyInfos)/sizeof(_CalendarbookFilterImpl::__FilterPropertyInfoEntry), __todoFilterPropertyInfos},
136         {CB_FI_TYPE_CALENDAR, _calendar_book._uri, CALENDAR_FI_PR_CALENDAR_ID, sizeof(__calendarFilterPropertyInfos)/sizeof(_CalendarbookFilterImpl::__FilterPropertyInfoEntry), __calendarFilterPropertyInfos},
137         {CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE, _calendar_instance_allday_calendar_book._uri, EVENT_INST_FI_PR_ORIGINAL_EVENT_ID, sizeof(__allDayEventInstanceFilterPropertyInfos)/sizeof(_CalendarbookFilterImpl::__FilterPropertyInfoEntry), __allDayEventInstanceFilterPropertyInfos},
138         {CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE, _calendar_instance_normal_calendar_book._uri, EVENT_INST_FI_PR_ORIGINAL_EVENT_ID, sizeof(__nonAllDayEventInstanceFilterPropertyInfos)/sizeof(_CalendarbookFilterImpl::__FilterPropertyInfoEntry), __nonAllDayEventInstanceFilterPropertyInfos},
139 };
140
141 bool
142 _CalendarbookFilterImpl::IsValidProperty(CalendarbookFilterType filterType, unsigned long property)
143 {
144         int filterInfoCount = sizeof(__filterInfos)/sizeof(__FilterInfoEntry);
145
146         if (filterType < 0 || filterType > (filterInfoCount - 1))
147         {
148                 return false;
149         }
150
151         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
152         int propertyInfoCount = __filterInfos[filterType].propertyInfoCount;
153
154         if (property < baseIndex || property >= (baseIndex + propertyInfoCount))
155         {
156                 return false;
157         }
158
159         return true;
160 }
161
162 // IsValidProperty must be called before calling this. If IsValidProperty returns false
163 // this should not be called.
164 const char*
165 _CalendarbookFilterImpl::GetUriFromType(CalendarbookFilterType filterType)
166 {
167         return __filterInfos[filterType].pViewUri;
168 }
169
170 // IsValidProperty must be called before calling this. If IsValidProperty returns false
171 // this should not be called.
172 unsigned int
173 _CalendarbookFilterImpl::GetViewPropertyId(CalendarbookFilterType filterType, unsigned long property)
174 {
175         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
176         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
177
178         return propertyInfos[property - baseIndex].viewPropertyId;
179 }
180
181 // IsValidProperty must be called before calling this. If IsValidProperty returns__nonAllDayEventInstanceFilterPropertyInfos false
182 // this should not be called.
183 __DataType
184 _CalendarbookFilterImpl::GetPropertyType(CalendarbookFilterType filterType, unsigned long property)
185 {
186         const __FilterPropertyInfoEntry* propertyInfos = __filterInfos[filterType].propertyInfos;
187         unsigned long baseIndex = __filterInfos[filterType].baseIndex;
188
189         return propertyInfos[property - baseIndex].dataType;
190 }
191
192 _CalendarbookFilterImpl::_CalendarbookFilterImpl(CalendarbookFilterType type)
193         : __filterHandle(null)
194         , __filterType(type)
195         , __isEmpty(true)
196 {
197         calendar_filter_h filterHandle = null;
198         const char* pUri = GetUriFromType(type);
199
200         int ret = calendar_filter_create(pUri, &filterHandle);
201         SysTryReturnVoidResult(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(GetLastResult()));
202
203         __filterHandle = filterHandle;
204 }
205
206 _CalendarbookFilterImpl::~_CalendarbookFilterImpl(void)
207 {
208         if (__filterHandle != null)
209         {
210                 calendar_filter_destroy(__filterHandle);
211         }
212 }
213
214 bool
215 _CalendarbookFilterImpl::Equals(const Object& rhs) const
216 {
217         const _CalendarbookFilterImpl* pCalendarbookFilter = dynamic_cast<const _CalendarbookFilterImpl*>(&rhs);
218         if (this == pCalendarbookFilter)
219         {
220                 return true;
221         }
222
223         return false;
224 }
225
226 int
227 _CalendarbookFilterImpl::GetHashCode(void) const
228 {
229         return (int)__filterHandle;
230 }
231
232 calendar_match_int_flag_e
233 _CalendarbookFilterImpl::GetMatchIntFlag(FilterComparisonOperator comparisonOperator)
234 {
235         calendar_match_int_flag_e match = CALENDAR_MATCH_NONE;
236         switch(comparisonOperator)
237         {
238         case FI_CMP_OP_EQUAL:
239                 match = CALENDAR_MATCH_EQUAL;
240                 break;
241
242         case FI_CMP_OP_LESS_THAN:
243                 match = CALENDAR_MATCH_LESS_THAN;
244                 break;
245
246         case FI_CMP_OP_LESS_THAN_OR_EQUAL:
247                 match = CALENDAR_MATCH_LESS_THAN_OR_EQUAL;
248                 break;
249
250         case FI_CMP_OP_GREATER_THAN:
251                 match = CALENDAR_MATCH_GREATER_THAN;
252                 break;
253
254         case FI_CMP_OP_GREATER_THAN_OR_EQUAL:
255                 match = CALENDAR_MATCH_GREATER_THAN_OR_EQUAL;
256                 break;
257
258         case FI_CMP_OP_IS_NULL:
259                 match = CALENDAR_MATCH_NONE;
260                 break;
261
262         default:
263                 match = CALENDAR_MATCH_NONE;
264                 break;
265         };
266
267         return match;
268 }
269
270 calendar_match_str_flag_e
271 _CalendarbookFilterImpl::GetMatchStrFlag(FilterStringOperator stringOperstor)
272 {
273         calendar_match_str_flag_e match = CALENDAR_MATCH_EXISTS;
274         switch(stringOperstor)
275         {
276         case FI_STR_OP_EQUAL:
277                 match = CALENDAR_MATCH_EXACTLY;
278                 break;
279
280         case FI_STR_OP_FULL_STRING:
281                 match = CALENDAR_MATCH_FULLSTRING;
282                 break;
283
284         case FI_STR_OP_START_WITH:
285                 match = CALENDAR_MATCH_STARTSWITH;
286                 break;
287
288         case FI_STR_OP_END_WITH:
289                 match = CALENDAR_MATCH_ENDSWITH;
290                 break;
291
292         case FI_STR_OP_CONTAIN:
293                 match = CALENDAR_MATCH_CONTAINS;
294                 break;
295
296         case FI_STR_OP_IS_NOT_NULL:
297                 match = CALENDAR_MATCH_EXISTS;
298                 break;
299
300         default:
301                 match = CALENDAR_MATCH_EXISTS;
302                 break;
303         };
304
305         return match;
306 }
307
308 result
309 _CalendarbookFilterImpl::AppendInt(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, int value)
310 {
311         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. filterProperty = %ld", GetErrorMessage(E_INVALID_ARG), filterProperty);
312         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);
313         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
314                         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",\
315                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
316         SysTryReturn(NID_SCL, !(!__isEmpty && (conjunctiveOperator == FI_CONJ_OP_NONE)),\
317                         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.",\
318                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
319
320         unsigned int id = _CalendarbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
321         calendar_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
322
323         int convertedValue = 0;
324         switch (filterProperty)
325         {
326         case EVENT_FI_PR_BUSY_STATUS:
327                 convertedValue = _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(value);
328                 break;
329
330         case EVENT_FI_PR_PRIORITY:
331                 convertedValue = _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(value);
332                 break;
333
334         case EVENT_FI_PR_SENSITIVITY:
335                 convertedValue = _CalendarbookUtil::ConvertSensitivityToCSSensitivity(value);
336                 break;
337
338         case EVENT_FI_PR_STATUS:
339                 convertedValue = _CalendarbookUtil::ConvertEventStatusToCSEventStatus(value);
340                 break;
341
342         case TODO_FI_PR_PRIORITY:
343                 convertedValue = _CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(value);
344                 break;
345
346         case TODO_FI_PR_SENSITIVITY:
347                 convertedValue = _CalendarbookUtil::ConvertSensitivityToCSSensitivity(value);
348                 break;
349
350         case TODO_FI_PR_STATUS:
351                 convertedValue = _CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(value);
352                 break;
353
354         case CALENDAR_FI_PR_ITEM_TYPE:
355                 convertedValue = _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(value);
356                 break;
357
358         case EVENT_INST_FI_PR_BUSY_STATUS:
359                 convertedValue = _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(value);
360                 break;
361
362         case EVENT_INST_FI_PR_PRIORITY:
363                 convertedValue = _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(value);
364                 break;
365
366         case EVENT_INST_FI_PR_SENSITIVITY:
367                 convertedValue = _CalendarbookUtil::ConvertSensitivityToCSSensitivity(value);
368                 break;
369
370         case EVENT_INST_FI_PR_STATUS:
371                 convertedValue = _CalendarbookUtil::ConvertEventStatusToCSEventStatus(value);
372                 break;
373
374         default:
375                 convertedValue = value;
376                 break;
377         }
378
379         if (!__isEmpty)
380         {
381                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
382
383                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
384                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
385         }
386
387         int ret = calendar_filter_add_int(__filterHandle, id, match, convertedValue);
388         SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
389
390         __isEmpty = false;
391
392         return E_SUCCESS;
393 }
394
395 result
396 _CalendarbookFilterImpl::AppendDouble(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, double value)
397 {
398         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. filterProperty = %ld", GetErrorMessage(E_INVALID_ARG), filterProperty);
399         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_DOUBLE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be double.", GetErrorMessage(E_INVALID_ARG), filterProperty);
400         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
401                         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",\
402                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
403         SysTryReturn(NID_SCL, !(!__isEmpty && (conjunctiveOperator == FI_CONJ_OP_NONE)),\
404                         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.",\
405                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
406
407         unsigned int id = _CalendarbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
408         calendar_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
409
410         if (!__isEmpty)
411         {
412                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
413
414                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
415                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
416         }
417
418         int ret = calendar_filter_add_double(__filterHandle, id, match, value);
419         SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
420
421         __isEmpty = false;
422
423         return E_SUCCESS;
424 }
425
426 result
427 _CalendarbookFilterImpl::AppendBool(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, bool value)
428 {
429         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. filterProperty = %ld", GetErrorMessage(E_INVALID_ARG), filterProperty);
430         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);
431         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
432                         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",\
433                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
434         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
435                         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.",\
436                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
437         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);
438
439         unsigned int viewPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
440
441         if (!__isEmpty)
442         {
443                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
444
445                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
446                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
447         }
448
449         int ret = calendar_filter_add_int(__filterHandle, viewPropertyId, CALENDAR_MATCH_EQUAL, value);
450         SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
451
452         __isEmpty = false;
453
454         return E_SUCCESS;
455 }
456
457 result
458 _CalendarbookFilterImpl::AppendDateTime(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterComparisonOperator comparisonOperator, const DateTime& value)
459 {
460         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. filterProperty = %ld", GetErrorMessage(E_INVALID_ARG), filterProperty);
461         SysTryReturn(NID_SCL, GetPropertyType(__filterType, filterProperty) == DATA_TYPE_DATE_TIME, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be DateTime.", GetErrorMessage(E_INVALID_ARG), filterProperty);
462         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
463                         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",\
464                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
465         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
466                         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.",\
467                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
468         SysTryReturn(NID_SCL, _CalendarbookUtil::CheckValidDateTime(value), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. The value is not in a valid range.");
469
470         unsigned int id = _CalendarbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
471         calendar_match_int_flag_e match = GetMatchIntFlag(comparisonOperator);
472
473         if (!__isEmpty)
474         {
475                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
476
477                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
478                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
479         }
480
481
482         if (filterProperty == EVENT_FI_PR_LAST_REVISED_TIME || filterProperty == TODO_FI_PR_LAST_REVISED_TIME)
483         {
484                 int ret = calendar_filter_add_lli(__filterHandle, id, match, _CalendarbookUtil::ConvertDateTimeToEpochTime(value));
485                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
486         }
487         else if (filterProperty == TODO_FI_PR_START_DATE)
488         {
489                 calendar_time_s convertedTime;
490
491                 if (comparisonOperator == FI_CMP_OP_IS_NULL)
492                 {
493                         convertedTime.type = CALENDAR_TIME_UTIME;
494                         convertedTime.time.utime = _CALENDAR_TODO_NO_START_DATE;
495                         match = CALENDAR_MATCH_EQUAL;
496                 }
497                 else
498                 {
499                         _CalendarbookUtil::ConvertDateTimeToCalTime(value, convertedTime);
500                 }
501
502                 int ret = calendar_filter_add_caltime(__filterHandle, id, match, convertedTime);
503                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
504         }
505         else if (filterProperty == TODO_FI_PR_DUE_DATE)
506         {
507                 calendar_time_s convertedTime;
508
509                 if (comparisonOperator == FI_CMP_OP_IS_NULL)
510                 {
511                         convertedTime.type = CALENDAR_TIME_UTIME;
512                         convertedTime.time.utime = _CALENDAR_TODO_NO_DUE_DATE;
513                         match = CALENDAR_MATCH_EQUAL;
514                 }
515                 else
516                 {
517                         _CalendarbookUtil::ConvertDateTimeToCalTime(value, convertedTime);
518                 }
519
520                 int ret = calendar_filter_add_caltime(__filterHandle, id, match, convertedTime);
521                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
522         }
523         else if ((filterProperty == EVENT_INST_FI_PR_START_TIME || filterProperty == EVENT_INST_FI_PR_END_TIME) && __filterType == CB_FI_TYPE_NON_ALL_DAY_EVENT_INSTANCE)
524         {
525                 calendar_time_s convertedTime;
526                 _CalendarbookUtil::ConvertDateTimeToCalTime(value, convertedTime);
527
528                 int ret = calendar_filter_add_caltime(__filterHandle, id, match, convertedTime);
529                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
530         }
531         else if ((filterProperty == EVENT_INST_FI_PR_START_TIME || filterProperty == EVENT_INST_FI_PR_END_TIME) && (__filterType == CB_FI_TYPE_ALL_DAY_EVENT_INSTANCE))
532         {
533                 calendar_time_s convertedTime;
534                 _CalendarbookUtil::ConvertDateToCalTime(value, convertedTime);
535
536                 int ret = calendar_filter_add_caltime(__filterHandle, id, match, convertedTime);
537                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
538         }
539         else
540         {
541                 SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the specified filter property %d must be DateTime.", GetErrorMessage(E_INVALID_ARG), filterProperty);
542                 return E_INVALID_ARG;
543         }
544
545         __isEmpty = false;
546
547         return E_SUCCESS;
548 }
549
550 result
551 _CalendarbookFilterImpl::AppendString(FilterConjunctiveOperator conjunctiveOperator, unsigned long filterProperty, FilterStringOperator comparisonOperator, const String& value)
552 {
553         SysTryReturn(NID_SCL, IsValidProperty(__filterType, filterProperty), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. filterProperty = %ld", GetErrorMessage(E_INVALID_ARG), filterProperty);
554         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);
555         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND  || conjunctiveOperator == FI_CONJ_OP_OR)),\
556                         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",\
557                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
558         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
559                         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.",\
560                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
561
562         unsigned int viewPropertyId = _CalendarbookFilterImpl::GetViewPropertyId(__filterType, filterProperty);
563
564         calendar_match_str_flag_e match = GetMatchStrFlag(comparisonOperator);
565         std::unique_ptr<char[]> pCharArray( _StringConverter::CopyToCharArrayN(value));
566         SysTryReturnResult(NID_SCL, pCharArray != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
567
568         if (!__isEmpty)
569         {
570                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
571
572                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
573                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
574         }
575
576         int ret = calendar_filter_add_str(__filterHandle, viewPropertyId, match, pCharArray.get());
577         SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
578
579         __isEmpty = false;
580
581         return E_SUCCESS;
582 }
583
584 result
585 _CalendarbookFilterImpl::AppendFilter(FilterConjunctiveOperator conjunctiveOperator, const _CalendarbookFilterImpl& filter)
586 {
587         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));
588         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));
589         SysTryReturn(NID_SCL, !(__isEmpty && (conjunctiveOperator == FI_CONJ_OP_AND || conjunctiveOperator == FI_CONJ_OP_OR)),\
590                         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",\
591                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
592         SysTryReturn(NID_SCL, !(!__isEmpty && conjunctiveOperator == FI_CONJ_OP_NONE),\
593                         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.",\
594                         GetErrorMessage(E_INVALID_ARG), conjunctiveOperator);
595
596         if (!__isEmpty)
597         {
598                 calendar_filter_operator_e filterOperator = conjunctiveOperator == FI_CONJ_OP_AND ? CALENDAR_FILTER_OPERATOR_AND : CALENDAR_FILTER_OPERATOR_OR;
599
600                 int ret = calendar_filter_add_operator(__filterHandle, filterOperator);
601                 SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
602         }
603
604         int ret = calendar_filter_add_filter(__filterHandle, filter.__filterHandle);
605         SysTryReturn(NID_SCL, ret == CALENDAR_ERROR_NONE, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
606
607         __isEmpty = false;
608
609         return E_SUCCESS;
610 }
611
612 calendar_filter_h
613 _CalendarbookFilterImpl::GetFilterHandle(void) const
614 {
615         if (!__isEmpty)
616         {
617                 return __filterHandle;
618         }
619
620         return null;
621 }
622
623 CalendarbookFilterType
624 _CalendarbookFilterImpl::GetType(void) const
625 {
626         return __filterType;
627 }
628
629 bool
630 _CalendarbookFilterImpl::IsEmpty(void) const
631 {
632         return __isEmpty;
633 }
634
635 const _CalendarbookFilterImpl*
636 _CalendarbookFilterImpl::GetInstance(const CalendarbookFilter& filter)
637 {
638         return filter.__pCalendarbookFilterImpl;
639 }
640
641 _CalendarbookFilterImpl*
642 _CalendarbookFilterImpl::GetInstance(CalendarbookFilter& filter)
643 {
644         return filter.__pCalendarbookFilterImpl;
645 }
646
647 }} // Tizen::Social