Update change log and spec for wrt-plugins-tizen_0.2.84
[framework/web/wrt-plugins-tizen.git] / src / standards / Tizen / Calendar / JSCalendarItemProperties.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
18 #include <ctime>
19 #include <dpl/log/log.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Tizen/Common/JSTizenException.h>
24 #include <Tizen/Common/JSTizenExceptionFactory.h>
25 #include <Tizen/Common/SecurityExceptions.h>
26 #include <Tizen/TimeUtil/TimeUtilConverter.h>
27 #include <Tizen/TimeUtil/JSTZDate.h>
28 #include <Tizen/Tizen/JSSimpleCoordinates.h>
29 #include <API/Calendar/EventAlarm.h>
30 #include <API/Calendar/EventId.h>
31 #include <API/Calendar/ICalendar.h>
32 #include <API/Calendar/CalendarFactory.h>
33 #include "API/TimeUtil/DurationProperties.h"
34 #include "JSCalendarItemProperties.h"
35 #include "CalendarConverter.h"
36 #include "JSCalendarEventId.h"
37 #include "JSCalendarAlarm.h"
38 #include "JSCalendarRecurrenceRule.h"
39 #include "JSCalendarAttendee.h"
40 #include "JSCalendarEvent.h"
41 #include "JSCalendarTask.h"
42 #include "plugin_config.h"
43
44 using namespace TizenApis::Api::Calendar;
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace TizenApis::Commons;
48
49 namespace TizenApis {
50 namespace Tizen1_0 {
51 namespace Calendar {
52
53 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
54
55 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
56     0,
57     kJSClassAttributeNone,
58     TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
59     0,
60     m_property,
61     m_function,
62     initialize,
63     finalize,
64     NULL, //hasProperty,
65     NULL, //getProperty,
66     NULL, //setProperty,
67     NULL, //DeleteProperty,
68     NULL, //GetPropertyNames,
69     NULL, //CallAsFunction,
70     NULL, //CallAsConstructor,
71     NULL, //HasInstance,
72     NULL  //ConvertToType
73 };
74
75 JSStaticValue JSCalendarItemProperties::m_property[] = {
76     // Item Properties
77     { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription,
78       setPropertyDescription, kJSPropertyAttributeNone },
79     { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
80       setPropertySummary, kJSPropertyAttributeNone },
81     { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime,
82       setPropertyStartTime, kJSPropertyAttributeNone },
83     { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
84       setPropertyLocation, kJSPropertyAttributeNone },
85     { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation,
86       setPropertyGeolocation, kJSPropertyAttributeNone },
87     { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
88       setPropertyOrganizer, kJSPropertyAttributeNone },
89     { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
90       setPropertyVisibility, kJSPropertyAttributeNone },
91     { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
92       setPropertyStatus, kJSPropertyAttributeNone },
93     { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
94       setPropertyAlarms, kJSPropertyAttributeNone },
95     { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
96       setPropertyCategories, kJSPropertyAttributeNone },
97     { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration,
98       setPropertyDuration, kJSPropertyAttributeNone },
99     { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay,
100       setPropertyIsAllDay, kJSPropertyAttributeNone },
101     { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees,
102       setPropertyAttendees, kJSPropertyAttributeNone },
103     { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
104       setPropertyRecurrenceRule, kJSPropertyAttributeNone },
105     { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
106       setPropertyAvailability, kJSPropertyAttributeNone },
107     { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate,
108       setPropertyDueDate, kJSPropertyAttributeNone },
109     { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate,
110       setPropertyCompletedDate, kJSPropertyAttributeNone },
111     { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress,
112       setPropertyProgress, kJSPropertyAttributeNone },
113     { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority,
114       setPropertyPriority, kJSPropertyAttributeNone },
115     { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate,
116       setPropertyEndDate, kJSPropertyAttributeNone },
117
118     { 0, 0, 0, 0 }
119 };
120
121 JSStaticFunction JSCalendarItemProperties::m_function[] = {
122     { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
123     { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
124
125     { 0, 0, 0 }
126 };
127
128 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
129
130 void JSCalendarItemProperties::initialize(JSContextRef context,
131         JSObjectRef object)
132 {
133     if (!JSObjectGetPrivate(object)) {
134         LogDebug("Create calendar item private object.");
135         CalendarEventPtr item( new CalendarEvent() );
136         CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
137         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
138             delete priv;
139         }
140     } else {
141         LogDebug("Private object alrerady set.");
142     }
143 }
144
145 void JSCalendarItemProperties::finalize(JSObjectRef object)
146 {
147     LogDebug("entered");
148     CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
149     if (priv) {
150         delete priv;
151         JSObjectSetPrivate(object, NULL);
152     }
153 }
154
155 const JSClassRef JSCalendarItemProperties::getClassRef()
156 {
157     if (!m_jsClassRef) {
158         m_jsClassRef = JSClassCreate(&m_classInfo);
159     }
160     return m_jsClassRef;
161 }
162
163 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
164 {
165     return &m_classInfo;
166 }
167
168 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
169 {
170     LogDebug("entered");
171     CalendarItemPropertiesPrivObject *priv =
172         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
173     if (!priv) {
174         ThrowMsg(NullPointerException, "Private object is null");
175     }
176     CalendarEventPtr result = priv->getObject();
177     if (!result) {
178         ThrowMsg(NullPointerException, "Private object is null");
179     }
180     return result;
181 }
182
183 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
184         JSContextRef ctx,
185         const JSObjectRef object)
186 {
187     LogDebug("entered");
188     Try
189     {
190         CalendarItemPropertiesPrivObject *priv =
191             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
192         delete priv;
193         priv = new CalendarItemPropertiesPrivObject(ctx, event);
194         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
195             delete priv;
196         }
197     }
198     Catch(Exception)
199     {
200         LogError("Error during replacing event object");
201     }
202 }
203
204 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
205 {
206     CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
207     return JSObjectMake(context, getClassRef(), priv);
208 }
209
210 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
211         JSObjectRef object,
212         JSObjectRef thisObject,
213         size_t argumentCount,
214         const JSValueRef arguments[],
215         JSValueRef* exception)
216 {
217     LogDebug("entered");
218
219     CalendarItemPropertiesPrivObject *privateObject =
220         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
221
222     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
223
224     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
225
226     Try
227     {
228         if (!privateObject) {
229             ThrowMsg(ConversionException, "Object is null.");
230         }
231
232         CalendarEventPtr item = privateObject->getObject();
233         if (!item) {
234             ThrowMsg(ConversionException, "Parameter conversion failed.");
235         }
236
237         CalendarConverter converter(context);
238
239         CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
240         if (argumentCount>=1) {
241             format = converter.toVObjectFormat(converter.toString(arguments[0]));
242         } else {
243             ThrowMsg(ConversionException, "Wrong parameter type.");
244         }
245
246         ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
247         calendar->setType(item->getCalendarType());
248
249         IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
250         dplEvent->setEvent(item);
251         dplEvent->setFormat(format);
252         dplEvent->setForSynchronousCall();
253         calendar->exportEventToString(dplEvent);
254
255         if (dplEvent->getResult()) {
256             return converter.toJSValueRef(dplEvent->getEventString());
257         } else {
258             ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
259         }
260     }
261     Catch(UnsupportedException)
262     {
263                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
264         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
265     }
266     Catch(InvalidArgumentException)
267     {
268                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
269         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
270     }
271     Catch(ConversionException)
272     {
273                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
274         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
275     }
276     Catch (NotFoundException)
277     {
278                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
279         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
280     }
281     Catch(Exception)
282     {
283                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
284         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
285     }
286
287     return JSValueMakeUndefined(context);
288 }
289
290 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
291         JSObjectRef object,
292         JSObjectRef thisObject,
293         size_t argumentCount,
294         const JSValueRef arguments[],
295         JSValueRef* exception)
296 {
297     LogDebug("entered");
298
299     CalendarItemPropertiesPrivObject *privateObject =
300         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
301
302     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
303
304     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
305
306     Try
307     {
308         if (!privateObject) {
309             ThrowMsg(ConversionException, "Object is null.");
310         }
311
312         CalendarEventPtr item = privateObject->getObject(); // item to copy
313         if (!item) {
314             ThrowMsg(ConversionException, "Parameter conversion failed.");
315         }
316         JSContextRef globalContext = privateObject->getContext();
317
318         // Call the copy constructor.
319         CalendarEventPtr clonedItem( new CalendarEvent(*item));
320
321         // Reset the id.
322         clonedItem->resetId();
323         clonedItem->setRecurrenceId(0);
324
325                 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
326                 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
327                 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
328             // Use global context for potential async api invocation.
329             return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
330                 } else {
331                         ThrowMsg(ConversionException, "Wrong object type.");
332                 }
333     }
334     Catch(UnsupportedException)
335     {
336                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
337         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
338     }
339     Catch(InvalidArgumentException)
340     {
341                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
342         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
343     }
344     Catch(ConversionException)
345     {
346                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
347         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
348     }
349     Catch (NotFoundException)
350     {
351                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
352         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
353     }
354     Catch(Exception)
355     {
356                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
357         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
358     }
359
360     return JSValueMakeUndefined(context);
361 }
362
363 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
364         JSObjectRef object,
365         JSStringRef propertyName,
366         JSValueRef* exception)
367 {
368     LogDebug("entered");
369     Try
370     {
371         Converter converter(context);
372         CalendarEventPtr event = getPrivateObject(object);
373         return converter.toJSValueRef(event->getDescription());
374     }
375     Catch(Exception)
376     {
377                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
378     }
379     return JSValueMakeUndefined(context);
380 }
381
382 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
383         JSObjectRef object,
384         JSStringRef propertyName,
385         JSValueRef value,
386         JSValueRef* exception)
387 {
388     LogDebug("entered");
389     Try
390     {
391         Converter converter(context);
392         CalendarEventPtr event = getPrivateObject(object);
393         std::string description = converter.toString(value);
394         event->setDescription(description);
395         return true;
396     }
397     Catch(Exception)
398     {
399                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
400         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
401     }
402
403     return false;
404 }
405
406 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
407         JSObjectRef object,
408         JSStringRef propertyName,
409         JSValueRef* exception)
410 {
411     LogDebug("entered");
412     Try
413     {
414         Converter converter(context);
415         CalendarEventPtr event = getPrivateObject(object);
416         return converter.toJSValueRef(event->getSubject());
417     }
418     Catch(Exception)
419     {
420                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
421     }
422     return JSValueMakeUndefined(context);
423 }
424
425 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
426         JSObjectRef object,
427         JSStringRef propertyName,
428         JSValueRef value,
429         JSValueRef* exception)
430 {
431     LogDebug("entered");
432     Try
433     {
434         Converter converter(context);
435         CalendarEventPtr event = getPrivateObject(object);
436         std::string subject = converter.toString(value);
437         event->setSubject(subject);
438         return true;
439     }
440     Catch(Exception)
441     {
442                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
443         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
444     }
445
446     return false;
447 }
448
449 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
450         JSObjectRef object,
451         JSStringRef propertyName,
452         JSValueRef* exception)
453 {
454     LogDebug("entered");
455     Try
456     {
457         CalendarItemPropertiesPrivObject *privateObject =
458             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
459         TimeUtilConverter timeConverter(context);
460         CalendarEventPtr event = privateObject->getObject();
461
462         LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
463         if (UNDEFINED_TIME==event->getStartTime()) {
464             return JSValueMakeUndefined(context);
465         } else {
466             return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
467         }
468     }
469     Catch(Exception)
470     {
471                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
472     }
473     return JSValueMakeUndefined(context);
474 }
475
476 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
477         JSObjectRef object,
478         JSStringRef propertyName,
479         JSValueRef value,
480         JSValueRef* exception)
481 {
482     LogDebug("entered");
483     Try
484     {
485         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
486             ThrowMsg(ConversionException, "Wrong parameter type.");
487         }
488
489         CalendarEventPtr event = getPrivateObject(object);
490         TimeUtilConverter converter(context);
491         std::time_t duration = event->getEndTime() - event->getStartTime();
492         if (duration<0) {
493             duration = 0;
494         }
495
496         long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
497         event->setStartTime(startTime);
498         event->setEndTime(startTime + duration);
499
500         std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
501         event->setTimeZone(timeZone);
502         return true;
503     }
504     Catch(Exception)
505     {
506                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
507         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
508     }
509
510     return false;
511 }
512
513 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
514         JSObjectRef object,
515         JSStringRef propertyName,
516         JSValueRef* exception)
517 {
518     LogDebug("entered");
519     Try
520     {
521         Converter converter(context);
522         CalendarEventPtr event = getPrivateObject(object);
523         return converter.toJSValueRef(event->getLocation());
524     }
525     Catch(Exception)
526     {
527                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
528     }
529     return JSValueMakeUndefined(context);
530 }
531
532 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
533         JSObjectRef object,
534         JSStringRef propertyName,
535         JSValueRef value,
536         JSValueRef* exception)
537 {
538     LogDebug("entered");
539     Try
540     {
541         Converter converter(context);
542         CalendarEventPtr event = getPrivateObject(object);
543         std::string location = converter.toString(value);
544         event->setLocation(location);
545         return true;
546     }
547     Catch(Exception)
548     {
549                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
550         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
551     }
552
553     return false;
554 }
555
556 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
557         JSObjectRef object,
558         JSStringRef propertyName,
559         JSValueRef* exception)
560 {
561     LogDebug("entered");
562     Try
563     {
564         CalendarConverter converter(context);
565         CalendarEventPtr event = getPrivateObject(object);
566         StringArrayPtr categories = event->getCategories();
567         if (categories) {
568             return converter.toJSValueRef(categories);
569         }
570     }
571     Catch(Exception)
572     {
573                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
574     }
575     return JSValueMakeUndefined(context);
576 }
577
578 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
579         JSObjectRef object,
580         JSStringRef propertyName,
581         JSValueRef value,
582         JSValueRef* exception)
583 {
584     LogDebug("entered");
585     Try
586     {
587         CalendarEventPtr event = getPrivateObject(object);
588         CalendarConverter converter(context);
589                 event->setCategories(converter.toStringArray(value));
590         return true;
591     }
592     Catch(Exception)
593     {
594                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
595         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
596     }
597
598     return false;
599 }
600
601 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
602         JSObjectRef object,
603         JSStringRef propertyName,
604         JSValueRef* exception)
605 {
606     LogDebug("entered");
607     Try
608     {
609         CalendarConverter converter(context);
610         CalendarEventPtr event = getPrivateObject(object);
611         std::string status = converter.toTizenValue(event->getStatus());
612         return converter.toJSValueRef(status);
613     }
614     Catch(Exception)
615     {
616                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
617     }
618     return JSValueMakeUndefined(context);
619 }
620
621 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
622         JSObjectRef object,
623         JSStringRef propertyName,
624         JSValueRef value,
625         JSValueRef* exception)
626 {
627     LogDebug("entered");
628     CalendarEventPtr event(NULL);
629     Try
630     {
631         event = getPrivateObject(object);
632         CalendarConverter converter(context);
633         CalendarEvent::EventStatus status =
634             converter.toEventStatus(converter.toString(value));
635         event->setStatus(status);
636         return true;
637     }
638     Catch(Exception)
639     {
640                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
641         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
642     }
643
644     return false;
645 }
646
647 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
648         JSObjectRef object,
649         JSStringRef propertyName,
650         JSValueRef* exception)
651 {
652     LogDebug("entered");
653     Try
654     {
655         CalendarEventPtr event = getPrivateObject(object);
656
657         JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
658         if (NULL == jsResult) {
659             ThrowMsg(NullPointerException, "Can not create array object.");
660         }
661         for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
662             if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
663                ThrowMsg(UnknownException, "Can not insert value into array.");
664             }
665         }
666         return jsResult;
667     }
668     Catch(Exception)
669     {
670                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
671     }
672     return JSValueMakeUndefined(context);
673 }
674
675 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
676         JSObjectRef object,
677         JSStringRef propertyName,
678         JSValueRef value,
679         JSValueRef* exception)
680 {
681     LogDebug("entered");
682     CalendarEventPtr event(NULL);
683     Try
684     {
685         event = getPrivateObject(object);
686         CalendarConverter converter(context);
687
688         EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
689
690         event->setAlarms(alarms);
691         return true;
692     }
693     Catch(Exception)
694     {
695                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
696         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
697     }
698
699     return false;
700 }
701
702 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
703         JSObjectRef object,
704         JSStringRef propertyName,
705         JSValueRef* exception)
706 {
707     LogDebug("entered");
708     Try
709     {
710         Converter converter(context);
711         CalendarEventPtr event = getPrivateObject(object);
712         return converter.toJSValueRef(event->getOrganizer());
713     }
714     Catch(Exception)
715     {
716                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
717     }
718     return JSValueMakeUndefined(context);
719 }
720
721 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
722         JSObjectRef object,
723         JSStringRef propertyName,
724         JSValueRef value,
725         JSValueRef* exception)
726 {
727     LogDebug("entered");
728     Try
729     {
730         Converter converter(context);
731         CalendarEventPtr event = getPrivateObject(object);
732         std::string organizer = converter.toString(value);
733         event->setOrganizer(organizer);
734         return true;
735     }
736     Catch(Exception)
737     {
738                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
739         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
740     }
741
742     return false;
743 }
744
745 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
746         JSObjectRef object,
747         JSStringRef propertyName,
748         JSValueRef* exception)
749 {
750     LogDebug("entered");
751     Try
752     {
753         CalendarConverter converter(context);
754         CalendarEventPtr event = getPrivateObject(object);
755         std::string visibility = converter.toTizenValue(event->getVisibility());
756         return converter.toJSValueRef(visibility);
757     }
758     Catch(Exception)
759     {
760                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
761     }
762     return JSValueMakeUndefined(context);
763 }
764
765 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
766         JSObjectRef object,
767         JSStringRef propertyName,
768         JSValueRef value,
769         JSValueRef* exception)
770 {
771     LogDebug("entered");
772     CalendarEventPtr event(NULL);
773     Try
774     {
775         event = getPrivateObject(object);
776         CalendarConverter converter(context);
777         CalendarEvent::EventVisibility visibility =
778             converter.toEventVisibility(converter.toString(value));
779         event->setVisibility(visibility);
780         return true;
781     }
782     Catch(Exception)
783     {
784                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
785         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
786     }
787
788     return false;
789 }
790
791 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
792         JSObjectRef object,
793         JSStringRef propertyName,
794         JSValueRef* exception)
795 {
796     LogDebug("entered");
797     Try
798     {
799         CalendarEventPtr event = getPrivateObject(object);
800         TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation(
801             new TizenApis::Api::Tizen::SimpleCoordinates(event->getLatitude(), event->getLongitude()) );
802
803         return TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::createJSObject(context, geoLocation);
804     }
805     Catch(Exception)
806     {
807                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
808     }
809
810     return JSValueMakeUndefined(context);
811 }
812
813 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
814         JSObjectRef object,
815         JSStringRef propertyName,
816         JSValueRef value,
817         JSValueRef* exception)
818 {
819     LogDebug("entered");
820     Try
821     {
822         CalendarEventPtr event = getPrivateObject(object);
823         TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
824             TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
825
826         event->setLatitude(geoLocation->getLatitude());
827         event->setLongitude(geoLocation->getLongitude());
828         return true;
829     }
830     Catch(Exception)
831     {
832                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
833         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
834     }
835
836     return false;
837 }
838
839 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
840         JSObjectRef object,
841         JSStringRef propertyName,
842         JSValueRef* exception)
843 {
844     LogDebug("entered");
845     Try
846     {
847         CalendarEventPtr event = getPrivateObject(object);
848
849         TimeUtilConverter converter(context);
850         long length = event->getEndTime() - event->getStartTime(); // in seconds only
851         LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
852         return converter.makeMillisecondDurationObject( length*1000 );
853     }
854     Catch(Exception)
855     {
856                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
857     }
858     return JSValueMakeUndefined(context);
859 }
860
861 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
862         JSObjectRef object,
863         JSStringRef propertyName,
864         JSValueRef value,
865         JSValueRef* exception)
866 {
867     LogDebug("entered");
868     Try
869     {
870         CalendarEventPtr event = getPrivateObject(object);
871         TimeUtilConverter converter(context);
872         long length = converter.getDurationLength(value);
873         int unit = converter.getDurationUnit(value);
874         if (length < 0) {
875             TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
876             return false;
877         }
878         if( SECONDS_UNIT==unit ) {
879             event->setEndTime(event->getStartTime() + length);
880         } else if ( MINUTES_UNIT==unit ) {
881             event->setEndTime(event->getStartTime() + length*60);
882         } else if ( HOURS_UNIT==unit ) {
883             event->setEndTime(event->getStartTime() + length*60*60);
884         } else if ( DAYS_UNIT==unit ) {
885             event->setEndTime(event->getStartTime() + length*24*60*60);
886         } else if ( MSECS_UNIT==unit ) {
887             event->setEndTime(event->getStartTime() + length/1000);
888         } else {
889             TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
890             return false;
891         }
892
893         return true;
894     }
895     Catch(Exception)
896     {
897                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
898         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
899     }
900
901     return false;
902 }
903
904 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
905         JSObjectRef object,
906         JSStringRef propertyName,
907         JSValueRef* exception)
908 {
909     LogDebug("entered");
910     Try
911     {
912         CalendarItemPropertiesPrivObject *priv =
913             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
914
915         CalendarEventPtr event = getPrivateObject(object);
916         EventRecurrenceRulePtr rrule;
917         if (event->getIsDetached()) {
918             LogDebug("This is a detached event.");
919             return JSValueMakeUndefined(context);
920         } else {
921             rrule = event->getRecurrenceRule();
922         }
923
924         if (EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
925             return JSValueMakeUndefined(context);
926         } else {
927             return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
928         }
929     }
930     Catch(Exception)
931     {
932                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
933     }
934     return JSValueMakeUndefined(context);
935 }
936
937 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
938         JSObjectRef object,
939         JSStringRef propertyName,
940         JSValueRef value,
941         JSValueRef* exception)
942 {
943     LogDebug("entered");
944     CalendarEventPtr event(NULL);
945     Try
946     {
947         event = getPrivateObject(object);
948         if (event->getIsDetached()) {
949             LogWarning("Can't set the recurrenceRule of a detached event!");
950             TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_SUPPORTED_ERROR);
951         }
952         event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
953         return true;
954     }
955     Catch(Exception)
956     {
957                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
958         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
959     }
960
961     return false;
962 }
963
964 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
965         JSObjectRef object,
966         JSStringRef propertyName,
967         JSValueRef* exception)
968 {
969     LogDebug("entered");
970     Try
971     {
972         CalendarConverter converter(context);
973         CalendarEventPtr event = getPrivateObject(object);
974         return converter.toJSValueRef(event->getIsAllDay());
975     }
976     Catch(Exception)
977     {
978                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
979     }
980     return JSValueMakeUndefined(context);
981 }
982
983 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
984         JSObjectRef object,
985         JSStringRef propertyName,
986         JSValueRef value,
987         JSValueRef* exception)
988 {
989     Try
990     {
991         CalendarEventPtr event = getPrivateObject(object);
992         Converter converter(context);
993         event->setIsAllDay(converter.toBool(value));
994         return true;
995     }
996     Catch(Exception)
997     {
998                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
999         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1000     }
1001
1002     return false;
1003 }
1004
1005 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
1006         JSObjectRef object,
1007         JSStringRef propertyName,
1008         JSValueRef* exception)
1009 {
1010     LogDebug("entered");
1011     Try
1012     {
1013         CalendarConverter converter(context);
1014         CalendarEventPtr event = getPrivateObject(object);
1015         std::string availability = converter.toTizenValue(event->getAvailability());
1016         return converter.toJSValueRef(availability);
1017     }
1018     Catch(Exception)
1019     {
1020                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1021     }
1022     return JSValueMakeUndefined(context);
1023 }
1024
1025 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
1026         JSObjectRef object,
1027         JSStringRef propertyName,
1028         JSValueRef value,
1029         JSValueRef* exception)
1030 {
1031     LogDebug("entered");
1032     CalendarEventPtr event(NULL);
1033     Try
1034     {
1035         event = getPrivateObject(object);
1036         CalendarConverter converter(context);
1037         CalendarEvent::EventAvailability availability =
1038             converter.toEventAvailability(converter.toString(value));
1039         event->setAvailability(availability);
1040         return true;
1041     }
1042     Catch(Exception)
1043     {
1044                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1045         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1046     }
1047
1048     return false;
1049 }
1050
1051 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
1052         JSObjectRef object,
1053         JSStringRef propertyName,
1054         JSValueRef* exception)
1055 {
1056     LogDebug("entered");
1057     Try
1058     {
1059         CalendarEventPtr event = getPrivateObject(object);
1060         EventAttendeeListPtr attendees = event->getAttendees();
1061         if (attendees) {
1062             JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
1063             if (NULL == jsResult) {
1064                 ThrowMsg(NullPointerException, "Can not create array object.");
1065             }
1066             for(unsigned int i=0; i<attendees->size(); i++) {
1067                 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
1068                    ThrowMsg(UnknownException, "Can not insert value into array.");
1069                 }
1070             }
1071             return jsResult;
1072         }
1073     }
1074     Catch(Exception)
1075     {
1076                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1077     }
1078     return JSValueMakeUndefined(context);
1079 }
1080
1081 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1082         JSObjectRef object,
1083         JSStringRef propertyName,
1084         JSValueRef value,
1085         JSValueRef* exception)
1086 {
1087     LogDebug("entered");
1088     Try
1089     {
1090         CalendarEventPtr event = getPrivateObject(object);
1091         CalendarConverter converter(context);
1092         event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1093         return true;
1094     }
1095     Catch(Exception)
1096     {
1097                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1098         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1099     }
1100
1101     return false;
1102 }
1103
1104 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1105         JSObjectRef object,
1106         JSStringRef propertyName,
1107         JSValueRef* exception)
1108 {
1109     LogDebug("entered");
1110     Try
1111         {
1112         CalendarItemPropertiesPrivObject *privateObject =
1113             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1114         CalendarEventPtr task = privateObject->getObject();
1115         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1116             return JSValueMakeUndefined(context);
1117         }
1118         if (!task) {
1119             ThrowMsg(NullPointerException, "Task object is NULL.");
1120         }
1121
1122         if (UNDEFINED_TIME==task->getEndTime()) {
1123             return JSValueMakeUndefined(context);
1124         } else {
1125             TimeUtilConverter timeConverter(context);
1126             return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1127         }
1128     }
1129     Catch(Exception)
1130     {
1131                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1132     }
1133     return JSValueMakeUndefined(context);
1134 }
1135
1136 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1137         JSObjectRef object,
1138         JSStringRef propertyName,
1139         JSValueRef value,
1140         JSValueRef* exception)
1141 {
1142     LogDebug("entered");
1143     Try
1144     {
1145         CalendarEventPtr task = getPrivateObject(object);
1146         if (!task) {
1147             ThrowMsg(NullPointerException, "Task object is NULL.");
1148         }
1149         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1150             ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1151         }
1152         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1153             ThrowMsg(ConversionException, "Wrong parameter type.");
1154         }
1155
1156         TimeUtilConverter converter(context);
1157         long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1158
1159         task->setEndTime(dueDate);
1160
1161         if( task->getTimeZone().empty() ) {
1162             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1163             task->setTimeZone(timeZone);
1164         }
1165         return true;
1166     }
1167     Catch(Exception)
1168     {
1169                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1170         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1171     }
1172
1173     return false;
1174 }
1175
1176 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1177         JSObjectRef object,
1178         JSStringRef propertyName,
1179         JSValueRef* exception)
1180 {
1181     LogDebug("entered");
1182     Try
1183     {
1184         CalendarItemPropertiesPrivObject *privateObject =
1185             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1186         CalendarEventPtr task = privateObject->getObject();
1187         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1188             return JSValueMakeUndefined(context);
1189         }
1190         if (!task) {
1191             ThrowMsg(NullPointerException, "Task object is NULL.");
1192         }
1193
1194         if (UNDEFINED_TIME==task->getCompletedDate()) {
1195             return JSValueMakeUndefined(context);
1196         } else {
1197             TimeUtilConverter timeConverter(context);
1198             return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1199         }
1200     }
1201     Catch(Exception)
1202     {
1203                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1204     }
1205     return JSValueMakeUndefined(context);
1206 }
1207
1208 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1209         JSObjectRef object,
1210         JSStringRef propertyName,
1211         JSValueRef value,
1212         JSValueRef* exception)
1213 {
1214     LogDebug("entered");
1215     Try
1216     {
1217         CalendarEventPtr task = getPrivateObject(object);
1218         if (!task) {
1219             ThrowMsg(NullPointerException, "Task object is NULL.");
1220         }
1221         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1222             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1223         }
1224         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1225             ThrowMsg(ConversionException, "Wrong parameter type.");
1226         }
1227
1228         TimeUtilConverter converter(context);
1229         long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1230
1231         task->setCompletedDate(completedDate);
1232
1233         if( task->getTimeZone().empty() ) {
1234             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1235             task->setTimeZone(timeZone);
1236         }
1237         return true;
1238     }
1239     Catch(Exception)
1240     {
1241                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1242         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1243     }
1244
1245     return false;
1246 }
1247
1248 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1249         JSObjectRef object,
1250         JSStringRef propertyName,
1251         JSValueRef* exception)
1252 {
1253     LogDebug("entered");
1254     Try
1255     {
1256         CalendarEventPtr task = getPrivateObject(object);
1257         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1258             return JSValueMakeUndefined(context);
1259         }
1260
1261         Converter converter(context);
1262         return converter.toJSValueRef(task->getProgress());
1263     }
1264     Catch(Exception)
1265     {
1266                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1267     }
1268     return JSValueMakeUndefined(context);
1269 }
1270
1271 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1272         JSObjectRef object,
1273         JSStringRef propertyName,
1274         JSValueRef value,
1275         JSValueRef* exception)
1276 {
1277     LogDebug("entered");
1278     Try
1279     {
1280         CalendarEventPtr task = getPrivateObject(object);
1281         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1282             return JSValueMakeUndefined(context);
1283         }
1284
1285         Converter converter(context);
1286         int progress = converter.toInt(value);
1287         task->setProgress(progress);
1288         return true;
1289     }
1290     Catch(Exception)
1291     {
1292                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1293         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1294     }
1295
1296     return false;
1297 }
1298
1299 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1300         JSObjectRef object,
1301         JSStringRef propertyName,
1302         JSValueRef* exception)
1303 {
1304     LogDebug("entered");
1305     Try
1306     {
1307         CalendarConverter converter(context);
1308         CalendarEventPtr item = getPrivateObject(object);
1309         if (!item) {
1310             ThrowMsg(NullPointerException, "Item object is NULL.");
1311         }
1312
1313         std::string priority = converter.toTizenValue(item->getPriority());
1314         return converter.toJSValueRef(priority);
1315     }
1316     Catch(Exception)
1317     {
1318                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1319     }
1320     return JSValueMakeUndefined(context);
1321 }
1322
1323 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1324         JSObjectRef object,
1325         JSStringRef propertyName,
1326         JSValueRef value,
1327         JSValueRef* exception)
1328 {
1329     LogDebug("entered");
1330     CalendarEventPtr item = getPrivateObject(object);
1331     Try
1332     {
1333         CalendarConverter converter(context);
1334         CalendarEvent::TaskPriority priority =
1335             converter.toTaskPriority(converter.toString(value));
1336         item->setPriority(priority);
1337         return true;
1338     }
1339     Catch(Exception)
1340     {
1341                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1342         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1343     }
1344
1345     return false;
1346 }
1347
1348 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1349         JSObjectRef object,
1350         JSStringRef propertyName,
1351         JSValueRef* exception)
1352 {
1353     LogDebug("entered");
1354     Try
1355     {
1356         CalendarItemPropertiesPrivObject *privateObject =
1357             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1358         CalendarEventPtr event = privateObject->getObject();
1359         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1360             return JSValueMakeUndefined(context);
1361         }
1362         if (!event) {
1363             ThrowMsg(NullPointerException, "Event object is NULL.");
1364         }
1365
1366         if (UNDEFINED_TIME==event->getEndTime()) {
1367             return JSValueMakeUndefined(context);
1368         } else {
1369             TimeUtilConverter timeConverter(context);
1370             return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1371         }
1372     }
1373     Catch(Exception)
1374     {
1375                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1376     }
1377     return JSValueMakeUndefined(context);
1378 }
1379
1380 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1381         JSObjectRef object,
1382         JSStringRef propertyName,
1383         JSValueRef value,
1384         JSValueRef* exception)
1385 {
1386     LogDebug("entered");
1387     Try
1388     {
1389         CalendarEventPtr event = getPrivateObject(object);
1390         if (!event) {
1391             ThrowMsg(NullPointerException, "Event object is NULL.");
1392         }
1393         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1394             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1395         }
1396         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1397             ThrowMsg(ConversionException, "Wrong parameter type.");
1398         }
1399
1400         TimeUtilConverter converter(context);
1401         long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1402
1403         event->setEndTime(endDate);
1404
1405         if( event->getTimeZone().empty() ) {
1406             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1407             event->setTimeZone(timeZone);
1408         }
1409         return true;
1410     }
1411     Catch(Exception)
1412     {
1413                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1414         TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1415     }
1416
1417     return false;
1418 }
1419
1420 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1421         const JSObjectRef object,
1422         JSValueRef* exception)
1423 {
1424     LogDebug("entered");
1425     CalendarItemPropertiesPrivObject *priv =
1426         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1427     if (priv == NULL) {
1428         return false;
1429     }
1430     CalendarEventPtr event = priv->getObject();
1431     if (!event) {
1432         return false;
1433     }
1434     return event->validate();
1435 }
1436
1437 }
1438 }
1439 }