[N_SE-32914, 33582] Fixed priority converting codes
[framework/osp/social.git] / src / FSclPerson.cpp
1 //
2 // Open Service Platform
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  * @file                FSclPerson.cpp
19  * @brief               This is the implementation for Profile class.
20  *
21  * This file contains definitions of @e Person class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FSclPerson.h>
26 #include <FSclPhoneNumber.h>
27 #include <FSclEmail.h>
28 #include <FSec_AccessController.h>
29 #include "FScl_PersonImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Social
36 {
37
38 Person::Person(void)
39 {
40         _PersonImpl* pPersonImpl = new (std::nothrow) _PersonImpl();
41         SysTryReturnVoidResult(NID_SCL, pPersonImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(GetLastResult()));
42
43         __pPersonImpl = pPersonImpl;
44 }
45
46 Person::~Person(void)
47 {
48         delete __pPersonImpl;
49 }
50
51 bool
52 Person::Equals(const Object& rhs) const
53 {
54         const Person* pPerson = dynamic_cast<const Person*>(&rhs);
55         if (pPerson == null)
56         {
57                 return false;
58         }
59
60         return __pPersonImpl->Equals(*pPerson->__pPersonImpl);;
61 }
62
63 int
64 Person::GetHashCode(void) const
65 {
66         return __pPersonImpl->GetHashCode();
67 }
68
69 String
70 Person::GetDisplayName(void) const
71 {
72         return __pPersonImpl->GetDisplayName();
73 }
74
75 PersonId
76 Person::GetId(void) const
77 {
78         return __pPersonImpl->GetId();
79 }
80
81 result
82 Person::SetAsFavorite(bool isFavorite)
83 {
84         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
85         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
86         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
87
88         return __pPersonImpl->SetAsFavorite(isFavorite);
89 }
90
91 bool
92 Person::IsFavorite(void) const
93 {
94         return __pPersonImpl->IsFavorite();
95 }
96
97 String
98 Person::GetThumbnailPath(void) const
99 {
100         return  __pPersonImpl->GetThumbnailPath();
101 }
102
103 String
104 Person::GetRingtonePath(void) const
105 {
106         return __pPersonImpl->GetRingtonePath();
107 }
108
109 bool
110 Person::HasPhoneNumber(void) const
111 {
112         return __pPersonImpl->HasPhoneNumber();
113 }
114
115 bool
116 Person::HasEmail(void) const
117 {
118         return __pPersonImpl->HasEmail();
119 }
120
121 IListT<AccountId>*
122 Person::GetAccountIdsN(void) const
123 {
124         return __pPersonImpl->GetAccountIdsN();
125 }
126
127 result
128 Person::SetAsPrimaryPhoneNumber(const PhoneNumber& phoneNumber)
129 {
130         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
131         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
132         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
133
134         return __pPersonImpl->SetAsPrimaryPhoneNumber(phoneNumber);     
135 }
136
137 result
138 Person::SetAsPrimaryEmail(const Email& email)
139 {
140         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
141         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
142         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
143
144         return __pPersonImpl->SetAsPrimaryEmail(email);
145 }
146
147 PhoneNumber
148 Person::GetPrimaryPhoneNumber(void) const
149 {       
150         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
151         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
152         SysTryReturn(NID_SCL, r == E_SUCCESS, PhoneNumber(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
153
154         return __pPersonImpl->GetPrimaryPhoneNumber();
155 }
156
157 Email
158 Person::GetPrimaryEmail(void) const
159 {
160         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
161         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
162         SysTryReturn(NID_SCL, r == E_SUCCESS, Email(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
163
164         return __pPersonImpl->GetPrimaryEmail();
165 }
166
167 }} // Tizen::Social