Fix code for TDIS-5396
[framework/osp/social.git] / src / FSclAttendee.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                FSclAttendee.cpp
19  * @brief               This is the implementation for Attendee class.
20  *
21  * This file contains definitions of @e Attendee class.
22  */
23
24 #include <FSclAttendee.h>
25 #include <FBaseResult.h>
26 #include <FBaseSysLog.h>
27 #include <FApp_AppInfo.h>
28
29 using namespace Tizen::Base;
30 using namespace Tizen::App;
31
32 namespace Tizen { namespace Social
33 {
34
35 Attendee::Attendee(const String& email)
36         : __email(email)
37         , __attendeeRole(ATTENDEE_ROLE_ATTENDEE)
38         , __attendeeStatus(ATTENDEE_STATUS_NONE)
39         , __pAttendeeImpl(null)
40         , __personId(INVALID_RECORD_ID)
41 {
42         // empty body.
43 }
44
45 Attendee::Attendee(const Attendee& rhs)
46         : __name(rhs.__name)
47         , __email(rhs.__email)
48         , __phoneNumber(rhs.__phoneNumber)
49         , __attendeeRole(rhs.__attendeeRole)
50         , __attendeeStatus(rhs.__attendeeStatus)
51         , __pAttendeeImpl(null)
52         , __personId(rhs.__personId)
53 {
54         // empty body.
55 }
56
57 Attendee::~Attendee(void)
58 {
59         // empty body.
60 }
61
62 Attendee&
63 Attendee::operator =(const Attendee& rhs)
64 {
65         if (this == &rhs)
66         {
67                 return *this;
68         }
69
70         __name = rhs.__name;
71         __email = rhs.__email;
72         __phoneNumber = rhs.__phoneNumber;
73         __attendeeRole = rhs.__attendeeRole;
74         __attendeeStatus = rhs.__attendeeStatus;
75         __personId = rhs.__personId;
76
77         return *this;
78 }
79
80 bool
81 Attendee::operator ==(const Attendee& rhs) const
82 {
83         if ((__name == rhs.__name) &&
84                         (__email == rhs.__email) &&
85                         (__phoneNumber == rhs.__phoneNumber) &&
86                         (__attendeeRole == rhs.__attendeeRole) &&
87                         (__attendeeStatus == rhs.__attendeeStatus) &&
88                         (__personId == rhs.__personId))
89         {
90                 return true;
91         }
92
93         return false;
94 }
95
96 bool
97 Attendee::operator !=(const Attendee& rhs) const
98 {
99         return !(*this == rhs);
100 }
101
102 bool
103 Attendee::Equals(const Object& rhs) const
104 {
105         const Attendee* pAttendee = dynamic_cast<const Attendee*>(&rhs);
106
107         if (pAttendee == null)
108         {
109                 return false;
110         }
111
112         return (*this == *pAttendee);
113 }
114
115 int
116 Attendee::GetHashCode(void) const
117 {
118         int hashCode = 17;
119
120         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __name.GetHashCode();
121         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __email.GetHashCode();
122         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __phoneNumber.GetHashCode();
123         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __attendeeRole;
124         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __attendeeStatus;
125         hashCode = ( hashCode << 4 ) ^ ( hashCode >> 28 ) ^ __personId;
126
127         return hashCode;
128 }
129
130 String
131 Attendee::GetName(void) const
132 {
133         return __name;
134 }
135
136 String
137 Attendee::GetEmail(void) const
138 {
139         return __email;
140 }
141
142 AttendeeRole
143 Attendee::GetRole(void) const
144 {
145         return __attendeeRole;
146 }
147
148 AttendeeStatus
149 Attendee::GetStatus(void) const
150 {
151         return __attendeeStatus;
152 }
153
154 result
155 Attendee::SetName(const String& name)
156 {
157         SysTryReturnResult(NID_SCL, !name.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. The name is empty.");
158
159         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
160         {
161                 SysTryReturnResult(NID_SCL, name.GetLength() <= MAX_ATTENDEE_NAME_LENGTH,
162                             E_INVALID_ARG, "Invalid argument is used. The length of the name exceeds MAX_ATTENDEE_NAME_LENGTH.");
163         }
164
165         __name = name;
166
167         return E_SUCCESS;
168 }
169
170 result
171 Attendee::SetEmail(const String& email)
172 {
173         SysTryReturnResult(NID_SCL, !email.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. The email is empty.");
174
175         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
176         {
177                 SysTryReturnResult(NID_SCL, email.GetLength() <= MAX_ATTENDEE_EMAIL_LENGTH,
178                                         E_INVALID_ARG, "Invalid argument is used. The length of the email exceeds MAX_ATTENDEE_EMAIL_LENGTH.");
179         }
180
181         __email = email;
182
183         return E_SUCCESS;
184 }
185
186 void
187 Attendee::SetRole(AttendeeRole role)
188 {
189         switch (role)
190         {
191         case ATTENDEE_ROLE_ATTENDEE:
192                 //fall through
193         case ATTENDEE_ROLE_REQUIRED_ATTENDEE:
194                 //fall through
195         case ATTENDEE_ROLE_ORGANIZER:
196                 __attendeeRole = role;
197                 break;
198         default:
199                 __attendeeRole = ATTENDEE_ROLE_ATTENDEE;
200                 break;
201         }
202 }
203
204 void
205 Attendee::SetStatus(AttendeeStatus status)
206 {
207         switch (status)
208         {
209         case ATTENDEE_STATUS_NONE:
210                 //fall through
211         case ATTENDEE_STATUS_NOT_RESPONDED:
212                 //fall through
213         case ATTENDEE_STATUS_ACCEPTED:
214                 //fall through
215         case ATTENDEE_STATUS_DECLINED:
216                 //fall through
217         case ATTENDEE_STATUS_TENTATIVE:
218                 __attendeeStatus = status;
219                 break;
220         default:
221                 __attendeeStatus = ATTENDEE_STATUS_NONE;
222                 break;
223         }
224 }
225
226 void
227 Attendee::SetPhoneNumber(const String& phoneNumber)
228 {
229         __phoneNumber = phoneNumber;
230 }
231
232 String
233 Attendee::GetPhoneNumber(void) const
234 {
235         return __phoneNumber;
236 }
237
238 void
239 Attendee::SetPersonId(PersonId personId)
240 {
241         __personId = personId;
242 }
243
244 PersonId
245 Attendee::GetPersonId(void) const
246 {
247         return __personId;
248 }
249
250 }}      // Tizen::Social