1
22
23 package com.liferay.portal.model.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.LocaleUtil;
28 import com.liferay.portal.kernel.util.TimeZoneUtil;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.model.Company;
31 import com.liferay.portal.model.Contact;
32 import com.liferay.portal.model.Group;
33 import com.liferay.portal.model.Organization;
34 import com.liferay.portal.model.PasswordPolicy;
35 import com.liferay.portal.model.User;
36 import com.liferay.portal.service.CompanyLocalServiceUtil;
37 import com.liferay.portal.service.ContactLocalServiceUtil;
38 import com.liferay.portal.service.GroupLocalServiceUtil;
39 import com.liferay.portal.service.OrganizationLocalServiceUtil;
40 import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
41 import com.liferay.portal.service.RoleLocalServiceUtil;
42
43 import java.util.Date;
44 import java.util.List;
45 import java.util.Locale;
46 import java.util.TimeZone;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51
57 public class UserImpl extends UserModelImpl implements User {
58
59 public static String getFullName(
60 String firstName, String middleName, String lastName) {
61
62 return ContactImpl.getFullName(firstName, middleName, lastName);
63 }
64
65 public UserImpl() {
66 }
67
68 public String getCompanyMx() {
69 String companyMx = null;
70
71 try {
72 Company company = CompanyLocalServiceUtil.getCompanyById(
73 getCompanyId());
74
75 companyMx = company.getMx();
76 }
77 catch (Exception e) {
78 _log.error(e);
79 }
80
81 return companyMx;
82 }
83
84 public boolean hasCompanyMx() {
85 return hasCompanyMx(getEmailAddress());
86 }
87
88 public boolean hasCompanyMx(String emailAddress) {
89 try {
90 Company company = CompanyLocalServiceUtil.getCompanyById(
91 getCompanyId());
92
93 return company.hasCompanyMx(emailAddress);
94 }
95 catch (Exception e) {
96 _log.error(e);
97 }
98
99 return false;
100 }
101
102 public String getLogin() throws PortalException, SystemException {
103 String login = null;
104
105 Company company = CompanyLocalServiceUtil.getCompanyById(
106 getCompanyId());
107
108 if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_EA)) {
109 login = getEmailAddress();
110 }
111 else if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_SN)) {
112 login = getScreenName();
113 }
114 else if (company.getAuthType().equals(CompanyImpl.AUTH_TYPE_ID)) {
115 login = String.valueOf(getUserId());
116 }
117
118 return login;
119 }
120
121 public PasswordPolicy getPasswordPolicy()
122 throws PortalException, SystemException {
123
124 PasswordPolicy passwordPolicy =
125 PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(
126 getUserId());
127
128 return passwordPolicy;
129 }
130
131 public String getPasswordUnencrypted() {
132 return _passwordUnencrypted;
133 }
134
135 public void setPasswordUnencrypted(String passwordUnencrypted) {
136 _passwordUnencrypted = passwordUnencrypted;
137 }
138
139 public boolean getPasswordModified() {
140 return _passwordModified;
141 }
142
143 public boolean isPasswordModified() {
144 return _passwordModified;
145 }
146
147 public void setPasswordModified(boolean passwordModified) {
148 _passwordModified = passwordModified;
149 }
150
151 public Locale getLocale() {
152 return _locale;
153 }
154
155 public void setLanguageId(String languageId) {
156 _locale = LocaleUtil.fromLanguageId(languageId);
157
158 super.setLanguageId(LocaleUtil.toLanguageId(_locale));
159 }
160
161 public TimeZone getTimeZone() {
162 return _timeZone;
163 }
164
165 public void setTimeZoneId(String timeZoneId) {
166 if (Validator.isNull(timeZoneId)) {
167 timeZoneId = TimeZoneUtil.getDefault().getID();
168 }
169
170 _timeZone = TimeZone.getTimeZone(timeZoneId);
171
172 super.setTimeZoneId(timeZoneId);
173 }
174
175 public Contact getContact() {
176 Contact contact = null;
177
178 try {
179 contact = ContactLocalServiceUtil.getContact(getContactId());
180 }
181 catch (Exception e) {
182 contact = new ContactImpl();
183
184 _log.error(e);
185 }
186
187 return contact;
188 }
189
190 public String getFirstName() {
191 return getContact().getFirstName();
192 }
193
194 public String getMiddleName() {
195 return getContact().getMiddleName();
196 }
197
198 public String getLastName() {
199 return getContact().getLastName();
200 }
201
202 public String getFullName() {
203 return getContact().getFullName();
204 }
205
206 public boolean getMale() {
207 return getContact().getMale();
208 }
209
210 public boolean isMale() {
211 return getMale();
212 }
213
214 public boolean getFemale() {
215 return !getMale();
216 }
217
218 public boolean isFemale() {
219 return getFemale();
220 }
221
222 public Date getBirthday() {
223 return getContact().getBirthday();
224 }
225
226 public Group getGroup() {
227 Group group = null;
228
229 try {
230 group = GroupLocalServiceUtil.getUserGroup(
231 getCompanyId(), getUserId());
232 }
233 catch (Exception e) {
234 }
235
236 return group;
237 }
238
239 public Organization getOrganization() {
240 try {
241 List organizations =
242 OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
243
244 for (int i = 0; i < organizations.size(); i++) {
245 Organization organization = (Organization)organizations.get(i);
246
247 if (!organization.isLocation()) {
248 return organization;
249 }
250 }
251 }
252 catch (Exception e) {
253 _log.warn("User does not have belong to an organization");
254 }
255
256 return new OrganizationImpl();
257 }
258
259 public Organization getLocation() {
260 try {
261 List organizations =
262 OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
263
264 for (int i = 0; i < organizations.size(); i++) {
265 Organization organization = (Organization)organizations.get(i);
266
267 if (organization.isLocation()) {
268 return organization;
269 }
270 }
271 }
272 catch (Exception e) {
273 _log.warn("User does not have belong to a location");
274 }
275
276 return new OrganizationImpl();
277 }
278
279 public int getPrivateLayoutsPageCount() {
280 try {
281 Group group = getGroup();
282
283 if (group == null) {
284 return 0;
285 }
286 else {
287 return group.getPrivateLayoutsPageCount();
288 }
289 }
290 catch (Exception e) {
291 _log.error(e);
292 }
293
294 return 0;
295 }
296
297 public boolean hasPrivateLayouts() {
298 if (getPrivateLayoutsPageCount() > 0) {
299 return true;
300 }
301 else {
302 return false;
303 }
304 }
305
306 public int getPublicLayoutsPageCount() {
307 try {
308 Group group = getGroup();
309
310 if (group == null) {
311 return 0;
312 }
313 else {
314 return group.getPublicLayoutsPageCount();
315 }
316 }
317 catch (Exception e) {
318 _log.error(e);
319 }
320
321 return 0;
322 }
323
324 public boolean hasPublicLayouts() {
325 if (getPublicLayoutsPageCount() > 0) {
326 return true;
327 }
328 else {
329 return false;
330 }
331 }
332
333 public boolean isLayoutsRequired() {
334 try {
335 return RoleLocalServiceUtil.hasUserRole(
336 getUserId(), getCompanyId(), RoleImpl.POWER_USER, true);
337 }
338 catch (Exception e) {
339 return false;
340 }
341 }
342
343 private static Log _log = LogFactory.getLog(UserImpl.class);
344
345 private boolean _passwordModified;
346 private String _passwordUnencrypted;
347 private Locale _locale;
348 private TimeZone _timeZone;
349
350 }