Update change log and spec for wrt-plugins-tizen_0.4.20
[platform/framework/web/wrt-plugins-tizen.git] / src / Contact / JSPerson.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        JSPerson.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief       Implementation of the JSPerson class
23  */
24
25 #include <dpl/log/log.h>
26 #include <dpl/shared_ptr.h>
27 #include <CommonsJavaScript/Validator.h>
28 #include <JSTizenExceptionFactory.h>
29 #include <JSTizenException.h>
30 #include <SecurityExceptions.h>
31 #include "ContactFactory.h"
32 #include "plugin_config.h"
33 #include "ContactConverter.h"
34 #include "JSPerson.h"
35 #include <ArgumentValidator.h>
36 #include <JSWebAPIError.h>
37 #include <TimeTracer.h>
38
39 #define FILTER_CLASS_NAME               "Person"
40
41 #define CONTACT_ATTR_ID                 "id"
42 #define CONTACT_ATTR_DISPLAY_NAME       "displayName"
43 #define CONTACT_ATTR_CONTACT_COUNT      "contactCount"
44 #define CONTACT_ATTR_HAS_PHONE_NUMBER   "hasPhoneNumber"
45 #define CONTACT_ATTR_HAS_EMAIL          "hasEmail"
46 #define CONTACT_ATTR_IS_FAVORITE        "isFavorite"
47 #define CONTACT_ATTR_PHOTO_URI              "photoURI"
48 #define CONTACT_ATTR_RINGTONE_URI       "ringtoneURI"
49 #define CONTACT_ATTR_DISPLAY_CONTACT_ID "displayContactId"
50 #define CONTACT_FUNC_LINK               "link"
51 #define CONTACT_FUNC_UNLINK             "unlink"
52
53 namespace DeviceAPI {
54 namespace Contact {
55
56 using namespace DeviceAPI::Common;
57 using namespace WrtDeviceApis::Commons;
58 using namespace WrtDeviceApis::CommonsJavaScript;
59
60 JSClassDefinition JSPerson::m_classInfo =
61 {
62         0,
63         kJSClassAttributeNone,
64         FILTER_CLASS_NAME,
65         NULL,
66         m_property,
67         m_functions,
68         Initialize,
69         Finalize,
70         NULL, //hasProperty,
71         NULL, //GetProperty,
72         NULL, //SetProperty,
73         NULL, //DeleteProperty,
74         NULL, //getPropertyNames,
75         NULL, //CallAsFunction,
76         NULL, //CallAsConstructor,
77         hasInstance, //HasInstance,
78         NULL, //ConvertToType,
79 };
80
81 JSStaticValue JSPerson::m_property[] = {
82         { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
83         { CONTACT_ATTR_DISPLAY_NAME, getDisplayName, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
84         { CONTACT_ATTR_CONTACT_COUNT, getContactCount, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
85         { CONTACT_ATTR_HAS_PHONE_NUMBER, getHasPhoneNumber, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
86         { CONTACT_ATTR_HAS_EMAIL, getHasEmail, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
87         { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, setIsFavorite, kJSPropertyAttributeNone },
88         { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
89         { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
90         { CONTACT_ATTR_DISPLAY_CONTACT_ID, getDisplayContactId, setDisplayContactId, kJSPropertyAttributeNone },
91         { 0, 0, 0, 0 }
92 };
93
94 JSStaticFunction JSPerson::m_functions[] =
95 {
96         { CONTACT_FUNC_LINK, link, kJSPropertyAttributeNone },
97         { CONTACT_FUNC_UNLINK, unlink, kJSPropertyAttributeNone },
98         { 0, 0, 0 }
99 };
100
101 JSClassRef JSPerson::m_classRef = JSClassCreate(&m_classInfo);
102
103 JSClassRef JSPerson::getClassRef() {
104         if (!m_classRef) {
105                 m_classRef = JSClassCreate(&m_classInfo);
106         }
107         return m_classRef;
108 }
109
110 bool JSPerson::isObjectOfClass(JSContextRef context, JSValueRef value)
111 {
112         return JSValueIsObjectOfClass(context, value, getClassRef());
113 }
114
115 PersonPtr JSPerson::getPerson(JSContextRef context, JSValueRef value)
116 {
117         if (!isObjectOfClass(context, value)) {
118                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
119         }
120         JSObjectRef object = JSValueToObject(context, value, NULL);
121         if (!object) {
122                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
123         }
124         JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
125         if (!priv) {
126                 Throw(WrtDeviceApis::Commons::NullPointerException);
127         }
128         return priv->getObject();
129 }
130
131 void JSPerson::Initialize(JSContextRef context, JSObjectRef object)
132 {
133         if (!JSObjectGetPrivate(object))
134         {
135                 PersonPtr person = ContactFactory::getInstance().createPerson();
136                 JSPersonPriv *priv = new JSPersonPriv(context, PersonPtr(person));
137                 if (!JSObjectSetPrivate(object, priv)) {
138                         delete priv;
139                 }
140         }
141 }
142
143 void JSPerson::Finalize(JSObjectRef object)
144 {
145         JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
146
147         if (priv != NULL)
148                 delete (priv);
149 }
150
151 JSObjectRef JSPerson::createJSObject(JSContextRef context, PersonPtr person)
152 {
153         JSPersonPriv *priv = new JSPersonPriv(context, person);
154         JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
155         if (NULL == jsObjectRef) {
156                 LogError("object creation error");
157                 return NULL;
158         }
159         return jsObjectRef;
160 }
161
162 PersonPtr JSPerson::getPrivData(JSObjectRef object)
163 {
164         JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
165         if (!priv) {
166                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
167         }
168         PersonPtr result = priv->getObject();
169         if (!result) {
170                 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
171         }
172         return result;
173 }
174
175 bool JSPerson::hasInstance(JSContextRef context,
176                 JSObjectRef constructor,
177                 JSValueRef possibleInstance,
178                 JSValueRef* exception)
179 {
180         return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
181 }
182
183 JSValueRef JSPerson::getId(JSContextRef context,
184                 JSObjectRef object,
185                 JSStringRef propertyName,
186                 JSValueRef* exception)
187 {
188         Try
189         {
190                 ContactConverterFactory::ConverterType converter =
191                                 ContactConverterFactory::getConverter(context);
192                 PersonPtr person = getPrivData(object);
193                 if(!person->getIdIsSet())
194                         return JSValueMakeNull(context);
195                 else
196                         return converter->toJSValueRef(person->getId());
197         }
198         Catch(WrtDeviceApis::Commons::Exception)
199         {
200                 LogWarning("trying to get incorrect value");
201         }
202         return JSValueMakeUndefined(context);
203 }
204
205 JSValueRef JSPerson::getDisplayName(JSContextRef context,
206                 JSObjectRef object,
207                 JSStringRef propertyName,
208                 JSValueRef* exception)
209 {
210         Try
211         {
212                 ContactConverterFactory::ConverterType converter =
213                                 ContactConverterFactory::getConverter(context);
214                 PersonPtr person = getPrivData(object);
215                 if(!person->getIdIsSet())
216                         return JSValueMakeNull(context);
217                 else
218                         return converter->toJSValueRef(person->getDisplayName());
219         }
220         Catch(WrtDeviceApis::Commons::Exception)
221         {
222                 LogWarning("trying to get incorrect value");
223         }
224         return JSValueMakeUndefined(context);
225 }
226
227 JSValueRef JSPerson::getContactCount(JSContextRef context,
228                 JSObjectRef object,
229                 JSStringRef propertyName,
230                 JSValueRef* exception)
231 {
232         Try
233         {
234                 ContactConverterFactory::ConverterType converter =
235                                 ContactConverterFactory::getConverter(context);
236                 PersonPtr person = getPrivData(object);
237                 if(!person->getIdIsSet())
238                         return JSValueMakeNull(context);
239                 else
240                         return converter->toJSValueRefLong(person->getContactCount());
241         }
242         Catch(WrtDeviceApis::Commons::Exception)
243         {
244                 LogWarning("trying to get incorrect value");
245         }
246         return JSValueMakeUndefined(context);
247 }
248
249 JSValueRef JSPerson::getHasPhoneNumber(JSContextRef context,
250                 JSObjectRef object,
251                 JSStringRef propertyName,
252                 JSValueRef* exception)
253 {
254         Try
255         {
256                 ContactConverterFactory::ConverterType converter =
257                                 ContactConverterFactory::getConverter(context);
258                 PersonPtr person = getPrivData(object);
259                 if(!person->getIdIsSet())
260                         return JSValueMakeNull(context);
261                 else
262                         return converter->toJSValueRef(person->getHasPhoneNumber());
263         }
264         Catch(WrtDeviceApis::Commons::Exception)
265         {
266                 LogWarning("trying to get incorrect value");
267         }
268         return JSValueMakeUndefined(context);
269 }
270
271 JSValueRef JSPerson::getHasEmail(JSContextRef context,
272                 JSObjectRef object,
273                 JSStringRef propertyName,
274                 JSValueRef* exception)
275 {
276         Try
277         {
278                 ContactConverterFactory::ConverterType converter =
279                                 ContactConverterFactory::getConverter(context);
280                 PersonPtr person = getPrivData(object);
281                 if(!person->getIdIsSet())
282                         return JSValueMakeNull(context);
283                 else
284                         return converter->toJSValueRef(person->getHasEmail());
285         }
286         Catch(WrtDeviceApis::Commons::Exception)
287         {
288                 LogWarning("trying to get incorrect value");
289         }
290
291         return JSValueMakeUndefined(context);
292 }
293
294 JSValueRef JSPerson::getIsFavorite(JSContextRef context,
295                 JSObjectRef object,
296                 JSStringRef propertyName,
297                 JSValueRef* exception)
298 {
299         Try
300         {
301                 ContactConverterFactory::ConverterType converter =
302                                 ContactConverterFactory::getConverter(context);
303                 PersonPtr person = getPrivData(object);
304                 return converter->toJSValueRef(person->getIsFavorite());
305         }
306         Catch(WrtDeviceApis::Commons::Exception)
307         {
308                 LogWarning("trying to get incorrect value");
309         }
310
311         return JSValueMakeUndefined(context);
312 }
313
314 bool JSPerson::setIsFavorite(JSContextRef context,
315                 JSObjectRef object,
316                 JSStringRef propertyName,
317                 JSValueRef value,
318                 JSValueRef* exception)
319 {
320         Try
321         {
322                 PersonPtr person = getPrivData(object);
323                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
324                 person->setIsFavorite(converter->toBool(value));
325         }
326         Catch(WrtDeviceApis::Commons::Exception)
327         {
328                 LogWarning("trying to set incorrect value");
329                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
330         }
331
332         return true;
333 }
334
335 JSValueRef JSPerson::getPhotoURI(JSContextRef context,
336                 JSObjectRef object,
337                 JSStringRef propertyName,
338                 JSValueRef* exception)
339 {
340         Try
341         {
342                 ContactConverterFactory::ConverterType converter =
343                                 ContactConverterFactory::getConverter(context);
344                 PersonPtr person = getPrivData(object);
345                 if(!person->getPhotoURIIsSet())
346                         return JSValueMakeNull(context);
347                 else
348                         return converter->toJSValueRef(person->getPhotoURI());
349         }
350         Catch(WrtDeviceApis::Commons::Exception)
351         {
352                 LogWarning("trying to get incorrect value");
353         }
354
355         return JSValueMakeUndefined(context);
356 }
357
358 bool JSPerson::setPhotoURI(JSContextRef context,
359                 JSObjectRef object,
360                 JSStringRef propertyName,
361                 JSValueRef value,
362                 JSValueRef* exception)
363 {
364         Try
365         {
366                 PersonPtr person = getPrivData(object);
367                 ContactConverterFactory::ConverterType converter =
368                                 ContactConverterFactory::getConverter(context);
369                 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
370                 if(validator->isNullOrUndefined(value))
371                         person->unsetPhotoURI();
372                 else
373                         person->setPhotoURI(converter->toString(value));
374         }
375         Catch(WrtDeviceApis::Commons::Exception)
376         {
377                 LogWarning("trying to set incorrect value");
378                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
379         }
380
381         return true;
382 }
383
384 JSValueRef JSPerson::getRingtoneURI(JSContextRef context,
385                 JSObjectRef object,
386                 JSStringRef propertyName,
387                 JSValueRef* exception)
388 {
389         Try
390         {
391                 ContactConverterFactory::ConverterType converter =
392                                 ContactConverterFactory::getConverter(context);
393                 PersonPtr person = getPrivData(object);
394                 if(!person->getRingtoneURIIsSet())
395                         return JSValueMakeNull(context);
396                 else
397                         return converter->toJSValueRef(person->getRingtoneURI());
398         }
399         Catch(WrtDeviceApis::Commons::Exception)
400         {
401                 LogWarning("trying to get incorrect value");
402         }
403
404         return JSValueMakeUndefined(context);
405 }
406
407 bool JSPerson::setRingtoneURI(JSContextRef context,
408                 JSObjectRef object,
409                 JSStringRef propertyName,
410                 JSValueRef value,
411                 JSValueRef* exception)
412 {
413         Try
414         {
415                 PersonPtr person = getPrivData(object);
416                 ContactConverterFactory::ConverterType converter =
417                                 ContactConverterFactory::getConverter(context);
418                 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
419                 if(validator->isNullOrUndefined(value))
420                         person->unsetRingtoneURI();
421                 else
422                         person->setRingtoneURI(converter->toString(value));
423         }
424         Catch(WrtDeviceApis::Commons::Exception)
425         {
426                 LogWarning("trying to set incorrect value");
427                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
428         }
429
430         return true;
431 }
432
433 JSValueRef JSPerson::getDisplayContactId(JSContextRef context,
434                 JSObjectRef object,
435                 JSStringRef propertyName,
436                 JSValueRef* exception)
437 {
438         Try
439         {
440                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
441                 PersonPtr person = getPrivData(object);
442                 if(!person->getDisplayContactIdIsSet())
443                         return JSValueMakeNull(context);
444                 else
445                         return converter->toJSValueRef(person->getDisplayContactId());
446         }
447         Catch(WrtDeviceApis::Commons::Exception)
448         {
449                 LogWarning("trying to get incorrect value");
450         }
451
452         return JSValueMakeUndefined(context);
453 }
454
455 bool JSPerson::setDisplayContactId(JSContextRef context,
456                 JSObjectRef object,
457                 JSStringRef propertyName,
458                 JSValueRef value,
459                 JSValueRef* exception)
460 {
461         Try
462         {
463                 PersonPtr person = getPrivData(object);
464                 ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
465                 BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
466                 if(validator->isNullOrUndefined(value))
467                         person->unsetDisplayContactId();
468                 else
469                         person->setDisplayContactId(converter->toString(value));
470         }
471         Catch(WrtDeviceApis::Commons::Exception)
472         {
473                 LogWarning("trying to set incorrect value");
474                 JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
475         }
476
477         return true;
478 }
479
480 JSValueRef JSPerson::link(JSContextRef context,
481                 JSObjectRef object,
482                 JSObjectRef thisObject,
483                 size_t argumentCount,
484                 const JSValueRef arguments[],
485                 JSValueRef* exception)
486 {
487         LogDebug("entered");
488         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
489         PersonPtr person(NULL);
490
491         Try
492         {
493                 person = getPrivData(thisObject);
494                 if (person == NULL)
495                         ThrowMsg(InvalidArgumentException, "No private object.");
496         }
497         Catch(Exception)
498         {
499                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
500                 return JSTizenExceptionFactory::postException(context, exception,
501                                 JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
502         }
503
504         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_PERSON_LINK);
505         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
506
507         ArgumentValidator validator(context, argumentCount, arguments);
508         std::string personId;
509         try     {
510                 personId = validator.toString(0, false);
511         } catch (const TypeMismatchException& err ) {
512                 return JSWebAPIError::throwException(context, exception, err);
513         } catch(const BasePlatformException& err) {
514                 return JSWebAPIError::throwException(context, exception, err);
515         } catch(const ConversionException& err) {
516                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
517         } catch(const NullPointerException& err) {
518                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
519         }
520
521         EventPersonLinkPtr dplEvent(new EventPersonLink());
522
523         dplEvent->setPersonId(personId);
524     dplEvent->setForSynchronousCall();
525
526         Try
527         {
528                 person->link(dplEvent);
529         }
530         Catch(ConversionException)
531         {
532                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
533                 return JSTizenExceptionFactory::postException(context, exception,
534                                 JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'PersonId'");
535         }
536         Catch(Exception)
537         {
538                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
539                 return JSTizenExceptionFactory::postException(context, exception,
540                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
541         }
542
543         if (!dplEvent->getResult())
544         {
545                 std::stringstream oss;
546                 switch (dplEvent->getExceptionCode())
547                 {
548                 case ExceptionCodes::NotFoundException:
549                         oss << "Person id (" << personId << ") is not exists.";
550                         return JSTizenExceptionFactory::postException(context, exception,
551                                         JSTizenException::INVALID_VALUES_ERROR, oss.str());
552                         break;
553                 case ExceptionCodes::InvalidArgumentException:
554                         oss << "Person id (" << personId << ") is wrong.";
555                         return JSTizenExceptionFactory::postException(context, exception,
556                                         JSTizenException::INVALID_VALUES_ERROR, oss.str());
557                         break;
558                 case ExceptionCodes::PlatformException:
559                         return JSTizenExceptionFactory::postException(context, exception,
560                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
561                         break;
562                 default:
563                         return JSTizenExceptionFactory::postException(context, exception,
564                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
565                         break;
566                 }
567         }
568         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
569         return JSValueMakeUndefined(context);
570 }
571
572 JSValueRef JSPerson::unlink(JSContextRef context,
573                 JSObjectRef object,
574                 JSObjectRef thisObject,
575                 size_t argumentCount,
576                 const JSValueRef arguments[],
577                 JSValueRef* exception)
578 {
579         LogDebug("entered");
580         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
581         PersonPtr person(NULL);
582
583         Try
584         {
585                 person = getPrivData(thisObject);
586                 if (person == NULL)
587                         ThrowMsg(InvalidArgumentException, "No private object.");
588         }
589         Catch(Exception)
590         {
591                 LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
592                 return JSTizenExceptionFactory::postException(context, exception,
593                                 JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
594         }
595
596         AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_PERSON_UNLINK);
597         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
598
599         ArgumentValidator validator(context, argumentCount, arguments);
600         std::string contactId;
601         try     {
602                 contactId = validator.toString(0, false);
603         } catch (const TypeMismatchException& err ) {
604                 return JSWebAPIError::throwException(context, exception, err);
605         } catch(const BasePlatformException& err) {
606                 return JSWebAPIError::throwException(context, exception, err);
607         } catch(const ConversionException& err) {
608                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
609         } catch(const NullPointerException& err) {
610                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "");
611         }
612
613         EventPersonUnlinkPtr dplEvent(new EventPersonUnlink());
614
615         dplEvent->setContactId(contactId);
616     dplEvent->setForSynchronousCall();
617
618         Try
619         {
620                 person->unlink(dplEvent);
621         }
622         Catch(ConversionException)
623         {
624                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
625                 return JSTizenExceptionFactory::postException(context, exception,
626                                 JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactId'");
627         }
628         Catch(Exception)
629         {
630                 LogError("Error on platform : " << _rethrown_exception.GetMessage());
631                 return JSTizenExceptionFactory::postException(context, exception,
632                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
633         }
634
635         if (!dplEvent->getResult())
636         {
637                 std::stringstream oss;
638                 switch (dplEvent->getExceptionCode())
639                 {
640                 case ExceptionCodes::InvalidArgumentException:
641                         oss << "No Contact id is wrong : '" << contactId << "'";
642                         return JSTizenExceptionFactory::postException(context, exception,
643                                         JSTizenException::INVALID_VALUES_ERROR, oss.str());
644                         break;
645                 case ExceptionCodes::NotFoundException:
646                         oss << "No Contact id '" << contactId << "'";
647                         return JSTizenExceptionFactory::postException(context, exception,
648                                         JSTizenException::INVALID_VALUES_ERROR, oss.str());
649                         break;
650                 case ExceptionCodes::OutOfRangeException:
651                         oss << "Contact (id:'" << contactId << "') is not a member of person";
652                         return JSTizenExceptionFactory::postException(context, exception,
653                                         JSTizenException::INVALID_VALUES_ERROR, oss.str());
654                         break;
655                 case ExceptionCodes::PlatformException:
656                         return JSTizenExceptionFactory::postException(context, exception,
657                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
658                         break;
659                 default:
660                         return JSTizenExceptionFactory::postException(context, exception,
661                                         JSTizenException::UNKNOWN_ERROR, "Internal error");
662                         break;
663                 }
664         }
665
666         PersonPtr unlinkedPerson = dplEvent->getPerson();
667         ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
668
669         JSValueRef result;
670         Try
671         {
672                 result = converter->toJSValueRef(unlinkedPerson);
673         }
674         Catch(Exception)
675         {
676                 LogError("Error on conversion : " << _rethrown_exception.GetMessage());
677                 return JSTizenExceptionFactory::postException(context, exception,
678                                 JSTizenException::UNKNOWN_ERROR, "Internal error");
679         }
680         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
681         return result;
682 }
683
684 } // Contact
685 } // DeviceAPI