Fix code for TDIS-5396
[framework/osp/social.git] / src / FSclCalendarbook.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                FSclCalendarbook.cpp
19  * @brief               This is the implementation for Calendarbook class.
20  *
21  * This file contains definitions of @e Calendarbook class.
22  */
23
24 #include <new>
25 #include <FSclCalendarbook.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include "FScl_CalEventImpl.h"
29 #include "FScl_CalTodoImpl.h"
30 #include "FScl_CalendarbookImpl.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Security;
35
36 namespace Tizen { namespace Social
37 {
38
39 Calendarbook::Calendarbook(void)
40         : __pCalendarbookImpl(null)
41 {
42 }
43
44 Calendarbook::~Calendarbook(void)
45 {
46         delete __pCalendarbookImpl;
47 }
48
49 result
50 Calendarbook::Construct(void)
51 {
52         SysAssertf(__pCalendarbookImpl == null,
53                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54
55         result r = E_SUCCESS;
56         _CalendarbookImpl* pCalendarbookImpl = null;
57
58         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
59         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
60
61         r = pCalendarbookImpl->Construct();
62         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
63
64         __pCalendarbookImpl = pCalendarbookImpl;
65
66         return E_SUCCESS;
67
68 CATCH:
69         delete pCalendarbookImpl;
70
71         return r;
72 }
73
74 result
75 Calendarbook::Construct(IRecordEventListener* pListener)
76 {
77         SysAssertf(__pCalendarbookImpl == null,
78                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
79
80         result r = E_SUCCESS;
81         _CalendarbookImpl* pCalendarbookImpl = null;
82
83         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
84         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
85
86         r = pCalendarbookImpl->Construct(pListener);
87         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
88
89         __pCalendarbookImpl = pCalendarbookImpl;
90
91         return E_SUCCESS;
92
93 CATCH:
94         delete pCalendarbookImpl;
95
96         return r;
97 }
98
99 result
100 Calendarbook::Construct(ICalendarbookEventListener& listener)
101 {
102         SysAssertf(__pCalendarbookImpl == null,
103                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
104
105         result r = E_SUCCESS;
106         _CalendarbookImpl* pCalendarbookImpl = null;
107
108         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
109         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
110
111         r = pCalendarbookImpl->Construct(listener);
112         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
113
114         __pCalendarbookImpl = pCalendarbookImpl;
115
116         return E_SUCCESS;
117
118 CATCH:
119         delete pCalendarbookImpl;
120
121         return r;
122 }
123
124 result
125 Calendarbook::AddEvent(CalEvent& event)
126 {
127         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
128         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
129         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
130         SysAssertf(__pCalendarbookImpl != null,
131                         "Not yet constructed. Construct() should be called before use.");
132
133         r = __pCalendarbookImpl->AddEvent(event);
134         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
135
136         return E_SUCCESS;
137 }
138
139 result
140 Calendarbook::AddEvent(CalEvent& event, RecordId calendarId)
141 {
142         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
143         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
144         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
145         SysAssertf(__pCalendarbookImpl != null,
146                         "Not yet constructed. Construct() should be called before use.");
147
148         r = __pCalendarbookImpl->AddEvent(event, calendarId);
149         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         return E_SUCCESS;
152 }
153
154 result
155 Calendarbook::AddTodo(CalTodo& todo)
156 {
157         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
158         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
159         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
160         SysAssertf(__pCalendarbookImpl != null,
161                         "Not yet constructed. Construct() should be called before use.");
162
163         r = __pCalendarbookImpl->AddTodo(todo);
164         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
165
166         return E_SUCCESS;
167 }
168
169 result
170 Calendarbook::AddTodo(CalTodo& todo, RecordId calendarId)
171 {
172         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
173         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
174         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
175         SysAssertf(__pCalendarbookImpl != null,
176                         "Not yet constructed. Construct() should be called before use.");
177
178         r = __pCalendarbookImpl->AddTodo(todo, calendarId);
179         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
180
181         return E_SUCCESS;
182 }
183
184 result
185 Calendarbook::RemoveEvent(CalEvent& event)
186 {
187         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
188         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
189         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
190         SysAssertf(__pCalendarbookImpl != null,
191                         "Not yet constructed. Construct() should be called before use.");
192
193         r = __pCalendarbookImpl->RemoveEvent(event);
194         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
195
196         return E_SUCCESS;
197 }
198
199 result
200 Calendarbook::RemoveEvent(RecordId eventId)
201 {
202         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
203         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
204         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
205         SysAssertf(__pCalendarbookImpl != null,
206                         "Not yet constructed. Construct() should be called before use.");
207
208         r = __pCalendarbookImpl->RemoveEvent(eventId);
209         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
210
211         return E_SUCCESS;
212 }
213
214 result
215 Calendarbook::RemoveTodo(CalTodo& todo)
216 {
217         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
218         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
219         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
220         SysAssertf(__pCalendarbookImpl != null,
221                         "Not yet constructed. Construct() should be called before use.");
222
223         r = __pCalendarbookImpl->RemoveTodo(todo);
224         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
225
226         return E_SUCCESS;
227 }
228
229 result
230 Calendarbook::RemoveTodo(RecordId todoId)
231 {
232         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
233         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
234         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
235         SysAssertf(__pCalendarbookImpl != null,
236                         "Not yet constructed. Construct() should be called before use.");
237
238         r = __pCalendarbookImpl->RemoveTodo(todoId);
239         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
240
241         return E_SUCCESS;
242 }
243
244 result
245 Calendarbook::UpdateEvent(const CalEvent& event)
246 {
247         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
248         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
249         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
250         SysAssertf(__pCalendarbookImpl != null,
251                         "Not yet constructed. Construct() should be called before use.");
252
253         r = __pCalendarbookImpl->UpdateEvent(event);
254         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
255
256         return E_SUCCESS;
257 }
258
259 result
260 Calendarbook::UpdateTodo(const CalTodo& todo)
261 {
262         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
263         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
264         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
265         SysAssertf(__pCalendarbookImpl != null,
266                         "Not yet constructed. Construct() should be called before use.");
267
268         r = __pCalendarbookImpl->UpdateTodo(todo);
269         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270
271         return E_SUCCESS;
272 }
273
274 CalEvent*
275 Calendarbook::GetEventN(RecordId eventId) const
276 {
277         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
278         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
279         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
280         SysAssertf(__pCalendarbookImpl != null,
281                         "Not yet constructed. Construct() should be called before use.");
282
283         CalEvent* pEvent = __pCalendarbookImpl->GetEventN(eventId);
284         r = GetLastResult();
285         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
286
287         return pEvent;
288 }
289
290 CalTodo*
291 Calendarbook::GetTodoN(RecordId todoId) const
292 {
293         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
294         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
295         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
296         SysAssertf(__pCalendarbookImpl != null,
297                                 "Not yet constructed. Construct() should be called before use.");
298
299         CalTodo* pTodo = __pCalendarbookImpl->GetTodoN(todoId);
300         r = GetLastResult();
301         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
302
303         return pTodo;
304 }
305
306 IList*
307 Calendarbook::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
308                                                 unsigned long priority) const
309 {
310         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
311         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
312         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
313         SysAssertf(__pCalendarbookImpl != null,
314                         "Not yet constructed. Construct() should be called before use.");
315
316         IList* pList = __pCalendarbookImpl->GetTodosN(start, end, pageNo, countPerPage, status, priority);
317         r = GetLastResult();
318         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
319
320         return pList;
321 }
322
323 int
324 Calendarbook::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
325 {
326         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
327         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
328         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
329         SysAssertf(__pCalendarbookImpl != null,
330                         "Not yet constructed. Construct() should be called before use.");
331
332         int count = __pCalendarbookImpl->GetTodoCount(start, end, status, priority);
333         r = GetLastResult();
334         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] Propagating.", GetErrorMessage(r));
335
336         return count;
337 }
338
339 IList*
340 Calendarbook::GetEventInstancesN(const DateTime& start, const DateTime& end,
341                                                                  const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
342                                                                  unsigned long category) const
343 {
344         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
345         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
346         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
347         SysAssertf(__pCalendarbookImpl != null,
348                         "Not yet constructed. Construct() should be called before use.");
349         IList* pList = __pCalendarbookImpl->GetEventInstancesN(start, end, timeZone, pageNo, countPerPage, category);
350         r = GetLastResult();
351         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
352
353         return pList;
354 }
355
356 result
357 Calendarbook::GetEventInstances(const DateTime& start, const DateTime& end,
358                                                                 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
359                                                                 RequestId& reqId,
360                                                                 const IRecordListener& listener) const
361 {
362         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
363         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
364         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
365         SysAssertf(__pCalendarbookImpl != null,
366                         "Not yet constructed. Construct() should be called before use.");
367
368         r = __pCalendarbookImpl->GetEventInstances(start, end, timeZone, pageNo, countPerPage, category, reqId, listener);
369         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
370
371         return E_SUCCESS;
372 }
373
374 IList*
375 Calendarbook::GetAllEventsN(void) const
376 {
377         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
378         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
379         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
380         SysAssertf(__pCalendarbookImpl != null,
381                         "Not yet constructed. Construct() should be called before use.");
382
383         IList* pList = __pCalendarbookImpl->GetAllEventsN();
384         r = GetLastResult();
385         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
386
387         return pList;
388 }
389
390 IList*
391 Calendarbook::GetAllTodosN(void) const
392 {
393         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
394         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
395         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
396         SysAssertf(__pCalendarbookImpl != null,
397                         "Not yet constructed. Construct() should be called before use.");
398
399         IList* pList = __pCalendarbookImpl->GetAllTodosN();
400         r = GetLastResult();
401         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
402
403         return pList;
404 }
405
406 IList*
407 Calendarbook::GetAllCalendarsN(void) const
408 {
409         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
410         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
411         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
412         SysAssertf(__pCalendarbookImpl != null,
413                         "Not yet constructed. Construct() should be called before use.");
414
415         IList* pList = __pCalendarbookImpl->GetAllCalendarsN();
416         r = GetLastResult();
417         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
418
419         return pList;
420 }
421
422 IList*
423 Calendarbook::GetChangedEventsAfterN(int version, int& latestVersion) const
424 {
425         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
426         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
427         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
428         SysAssertf(__pCalendarbookImpl != null,
429                         "Not yet constructed. Construct() should be called before use.");
430
431         IList* pList = __pCalendarbookImpl->GetChangedEventsAfterN(version, latestVersion);
432         r = GetLastResult();
433         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
434
435         return pList;
436 }
437
438 IList*
439 Calendarbook::GetChangedTodosAfterN(int version, int& latestVersion) const
440 {
441         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
442         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
443         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
444         SysAssertf(__pCalendarbookImpl != null,
445                         "Not yet constructed. Construct() should be called before use.");
446
447         IList* pList = __pCalendarbookImpl->GetChangedTodosAfterN(version, latestVersion);
448         r = GetLastResult();
449         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
450
451         return pList;
452 }
453
454 result
455 Calendarbook::AddCalendar(Calendar& calendar)
456 {
457         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
458         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
459         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
460         SysAssertf(__pCalendarbookImpl != null,
461                         "Not yet constructed. Construct() should be called before use.");
462
463         r = __pCalendarbookImpl->AddCalendar(calendar);
464         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
465
466         return E_SUCCESS;
467 }
468
469 result
470 Calendarbook::AddCalendar(Calendar& calendar, AccountId accountId)
471 {
472         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
473         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
474         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
475         SysAssertf(__pCalendarbookImpl != null,
476                         "Not yet constructed. Construct() should be called before use.");
477
478         r = __pCalendarbookImpl->AddCalendar(calendar, accountId);
479         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
480
481         return E_SUCCESS;
482 }
483
484 result
485 Calendarbook::RemoveCalendar(RecordId calendarId)
486 {
487         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
488         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
489         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
490         SysAssertf(__pCalendarbookImpl != null,
491                         "Not yet constructed. Construct() should be called before use.");
492
493         r = __pCalendarbookImpl->RemoveCalendar(calendarId);
494         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
495
496         return E_SUCCESS;
497 }
498
499 result
500 Calendarbook::UpdateCalendar(const Calendar& calendar)
501 {
502         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
503         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
504         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
505         SysAssertf(__pCalendarbookImpl != null,
506                         "Not yet constructed. Construct() should be called before use.");
507
508         r = __pCalendarbookImpl->UpdateCalendar(calendar);
509         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
510
511         return E_SUCCESS;
512 }
513
514 Calendar*
515 Calendarbook::GetCalendarN(RecordId calendarId) const
516 {
517         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
518         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
519         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
520         SysAssertf(__pCalendarbookImpl != null,
521                         "Not yet constructed. Construct() should be called before use.");
522
523         Calendar* pCalendar = __pCalendarbookImpl->GetCalendarN(calendarId);
524         r = GetLastResult();
525         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
526
527         return pCalendar;
528 }
529
530 result
531 Calendarbook::RemoveEventInstance(const CalEventInstance& eventInstance)
532 {
533         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
534         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
535         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
536         SysAssertf(__pCalendarbookImpl != null,
537                         "Not yet constructed. Construct() should be called before use.");
538
539         r = __pCalendarbookImpl->RemoveEventInstance(eventInstance);
540         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
541
542         return E_SUCCESS;
543 }
544
545 result
546 Calendarbook::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
547 {
548         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
549         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
550         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
551         SysAssertf(__pCalendarbookImpl != null,
552                         "Not yet constructed. Construct() should be called before use.");
553
554         r = __pCalendarbookImpl->UpdateEventInstance(eventInstance, event);
555         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
556
557         return E_SUCCESS;
558 }
559
560 int
561 Calendarbook::GetLatestVersion(void) const
562 {
563         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
564         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
565         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_VERSION, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
566         SysAssertf(__pCalendarbookImpl != null,
567                         "Not yet constructed. Construct() should be called before use.");
568
569         int version = __pCalendarbookImpl->GetLatestVersion();
570         r = GetLastResult();
571         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_VERSION, r, "[%s] Propagating.", GetErrorMessage(r));
572
573         return version;
574 }
575
576 IList*
577 Calendarbook::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
578 {
579         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
580         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
581         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
582         SysAssertf(__pCalendarbookImpl != null,
583                         "Not yet constructed. Construct() should be called before use.");
584
585         IList* pList = __pCalendarbookImpl->SearchN(filter, propertySortedBy, sortOrder, offset, maxCount);
586         r = GetLastResult();
587         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
588
589         return pList;
590 }
591
592 int
593 Calendarbook::GetMatchedItemCount(const CalendarbookFilter& filter) const
594 {
595         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
596         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
597         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
598         SysAssertf(__pCalendarbookImpl != null,
599                         "Not yet constructed. Construct() should be called before use.");
600
601         int count = __pCalendarbookImpl->GetMatchedItemCount(filter);
602         r = GetLastResult();
603         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] Propagating.", GetErrorMessage(r));
604
605         return count;
606 }
607
608 IList*
609 Calendarbook::ParseEventsFromVcalendarN(const String& vCalFilePath)
610 {
611         IList* pList = _CalendarbookImpl::ParseEventsFromVcalendarN(vCalFilePath);
612         result r = GetLastResult();
613         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
614
615         return pList;
616 }
617
618 IList*
619 Calendarbook::ParseTodosFromVcalendarN(const String& vCalFilePath)
620 {
621         IList* pList = _CalendarbookImpl::ParseTodosFromVcalendarN(vCalFilePath);
622         result r = GetLastResult();
623         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
624
625         return pList;
626 }
627
628 result
629 Calendarbook::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
630 {
631         result r = _CalendarbookImpl::ExportEventsToVcalendar(eventList, vCalFilePath);
632         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
633
634         return E_SUCCESS;
635 }
636
637 result
638 Calendarbook::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
639 {
640         result r = _CalendarbookImpl::ExportTodosToVcalendar(todoList, vCalFilePath);
641         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
642
643         return E_SUCCESS;
644 }
645
646 DateTime
647 Calendarbook::GetMaxDateTime(void)
648 {
649         return _CalendarbookImpl::GetMaxDateTime();
650 }
651 DateTime
652 Calendarbook::GetMinDateTime(void)
653 {
654         return _CalendarbookImpl::GetMinDateTime();
655 }
656
657 }}      // Tizen::Social