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