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