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