001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscape;
018    import com.liferay.portal.kernel.dao.orm.QueryUtil;
019    import com.liferay.portal.kernel.dao.shard.ShardUtil;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.exception.SystemException;
022    import com.liferay.portal.kernel.log.Log;
023    import com.liferay.portal.kernel.log.LogFactoryUtil;
024    import com.liferay.portal.kernel.util.Digester;
025    import com.liferay.portal.kernel.util.DigesterUtil;
026    import com.liferay.portal.kernel.util.HtmlUtil;
027    import com.liferay.portal.kernel.util.LocaleUtil;
028    import com.liferay.portal.kernel.util.PropsKeys;
029    import com.liferay.portal.kernel.util.RemotePreference;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.TimeZoneUtil;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.kernel.workflow.WorkflowConstants;
037    import com.liferay.portal.model.Address;
038    import com.liferay.portal.model.Company;
039    import com.liferay.portal.model.CompanyConstants;
040    import com.liferay.portal.model.Contact;
041    import com.liferay.portal.model.EmailAddress;
042    import com.liferay.portal.model.Group;
043    import com.liferay.portal.model.Organization;
044    import com.liferay.portal.model.PasswordPolicy;
045    import com.liferay.portal.model.Phone;
046    import com.liferay.portal.model.Role;
047    import com.liferay.portal.model.Team;
048    import com.liferay.portal.model.UserConstants;
049    import com.liferay.portal.model.UserGroup;
050    import com.liferay.portal.model.Website;
051    import com.liferay.portal.security.auth.EmailAddressGenerator;
052    import com.liferay.portal.security.auth.EmailAddressGeneratorFactory;
053    import com.liferay.portal.security.auth.FullNameGenerator;
054    import com.liferay.portal.security.auth.FullNameGeneratorFactory;
055    import com.liferay.portal.service.AddressLocalServiceUtil;
056    import com.liferay.portal.service.CompanyLocalServiceUtil;
057    import com.liferay.portal.service.ContactLocalServiceUtil;
058    import com.liferay.portal.service.EmailAddressLocalServiceUtil;
059    import com.liferay.portal.service.GroupLocalServiceUtil;
060    import com.liferay.portal.service.GroupServiceUtil;
061    import com.liferay.portal.service.LayoutLocalServiceUtil;
062    import com.liferay.portal.service.OrganizationLocalServiceUtil;
063    import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
064    import com.liferay.portal.service.PhoneLocalServiceUtil;
065    import com.liferay.portal.service.RoleLocalServiceUtil;
066    import com.liferay.portal.service.TeamLocalServiceUtil;
067    import com.liferay.portal.service.UserGroupLocalServiceUtil;
068    import com.liferay.portal.service.UserLocalServiceUtil;
069    import com.liferay.portal.service.WebsiteLocalServiceUtil;
070    import com.liferay.portal.theme.ThemeDisplay;
071    import com.liferay.portal.util.Portal;
072    import com.liferay.portal.util.PortalUtil;
073    import com.liferay.portal.util.PrefsPropsUtil;
074    import com.liferay.portal.util.PropsUtil;
075    import com.liferay.portal.util.PropsValues;
076    
077    import java.util.Collection;
078    import java.util.Collections;
079    import java.util.Date;
080    import java.util.HashMap;
081    import java.util.List;
082    import java.util.Locale;
083    import java.util.Map;
084    import java.util.Set;
085    import java.util.TimeZone;
086    import java.util.TreeSet;
087    
088    /**
089     * Represents a portal user, providing access to the user's contact information,
090     * groups, organizations, teams, user groups, roles, locale, timezone, and more.
091     *
092     * @author Brian Wing Shun Chan
093     * @author Jorge Ferrer
094     * @author Wesley Gong
095     */
096    public class UserImpl extends UserBaseImpl {
097    
098            @Override
099            public void addRemotePreference(RemotePreference remotePreference) {
100                    _remotePreferences.put(remotePreference.getName(), remotePreference);
101            }
102    
103            /**
104             * Returns the user's addresses.
105             *
106             * @return the user's addresses
107             */
108            @Override
109            public List<Address> getAddresses() {
110                    return AddressLocalServiceUtil.getAddresses(
111                            getCompanyId(), Contact.class.getName(), getContactId());
112            }
113    
114            /**
115             * Returns the user's birth date.
116             *
117             * @return the user's birth date
118             * @throws PortalException if a portal exception occurred
119             */
120            @Override
121            public Date getBirthday() throws PortalException {
122                    return getContact().getBirthday();
123            }
124    
125            /**
126             * Returns the user's company's mail domain.
127             *
128             * @return the user's company's mail domain
129             * @throws PortalException if a portal exception occurred
130             */
131            @Override
132            public String getCompanyMx() throws PortalException {
133                    Company company = CompanyLocalServiceUtil.getCompanyById(
134                            getCompanyId());
135    
136                    return company.getMx();
137            }
138    
139            /**
140             * Returns the user's associated contact.
141             *
142             * @return the user's associated contact
143             * @throws PortalException if a portal exception occurred
144             * @see    Contact
145             */
146            @Override
147            public Contact getContact() throws PortalException {
148                    try {
149                            ShardUtil.pushCompanyService(getCompanyId());
150    
151                            return ContactLocalServiceUtil.getContact(getContactId());
152                    }
153                    finally {
154                            ShardUtil.popCompanyService();
155                    }
156            }
157    
158            /**
159             * Returns the user's digest.
160             *
161             * @return the user's digest
162             */
163            @Override
164            public String getDigest() {
165                    String digest = super.getDigest();
166    
167                    if (Validator.isNull(digest) && !isPasswordEncrypted()) {
168                            digest = getDigest(getPassword());
169                    }
170    
171                    return digest;
172            }
173    
174            /**
175             * Returns a digest for the user, incorporating the password.
176             *
177             * @param  password a password to incorporate with the digest
178             * @return a digest for the user, incorporating the password
179             */
180            @Override
181            public String getDigest(String password) {
182                    if (Validator.isNull(getScreenName())) {
183                            throw new IllegalStateException("Screen name is null");
184                    }
185                    else if (Validator.isNull(getEmailAddress())) {
186                            throw new IllegalStateException("Email address is null");
187                    }
188    
189                    StringBundler sb = new StringBundler(5);
190    
191                    String digest1 = DigesterUtil.digestHex(
192                            Digester.MD5, getEmailAddress(), Portal.PORTAL_REALM, password);
193    
194                    sb.append(digest1);
195                    sb.append(StringPool.COMMA);
196    
197                    String digest2 = DigesterUtil.digestHex(
198                            Digester.MD5, getScreenName(), Portal.PORTAL_REALM, password);
199    
200                    sb.append(digest2);
201                    sb.append(StringPool.COMMA);
202    
203                    String digest3 = DigesterUtil.digestHex(
204                            Digester.MD5, String.valueOf(getUserId()), Portal.PORTAL_REALM,
205                            password);
206    
207                    sb.append(digest3);
208    
209                    return sb.toString();
210            }
211    
212            /**
213             * Returns the user's primary email address, or a blank string if the
214             * address is fake.
215             *
216             * @return the user's primary email address, or a blank string if the
217             *         address is fake
218             */
219            @Override
220            public String getDisplayEmailAddress() {
221                    String emailAddress = super.getEmailAddress();
222    
223                    EmailAddressGenerator emailAddressGenerator =
224                            EmailAddressGeneratorFactory.getInstance();
225    
226                    if (emailAddressGenerator.isFake(emailAddress)) {
227                            emailAddress = StringPool.BLANK;
228                    }
229    
230                    return emailAddress;
231            }
232    
233            /**
234             * Returns the user's display URL, discounting the URL of the user's default
235             * intranet site home page.
236             *
237             * <p>
238             * The logic for the display URL to return is as follows:
239             * </p>
240             *
241             * <ol>
242             * <li>
243             * If the user is the guest user, return an empty string.
244             * </li>
245             * <li>
246             * Else, if a friendly URL is available for the user's profile, return that
247             * friendly URL.
248             * </li>
249             * <li>
250             * Otherwise, return the URL of the user's default extranet site home page.
251             * </li>
252             * </ol>
253             *
254             * @param      portalURL the portal's URL
255             * @param      mainPath the main path
256             * @return     the user's display URL
257             * @throws     PortalException if a portal exception occurred
258             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
259             */
260            @Deprecated
261            @Override
262            public String getDisplayURL(String portalURL, String mainPath)
263                    throws PortalException {
264    
265                    return getDisplayURL(portalURL, mainPath, false);
266            }
267    
268            /**
269             * Returns the user's display URL.
270             *
271             * <p>
272             * The logic for the display URL to return is as follows:
273             * </p>
274             *
275             * <ol>
276             * <li>
277             * If the user is the guest user, return an empty string.
278             * </li>
279             * <li>
280             * Else, if a friendly URL is available for the user's profile, return that
281             * friendly URL.
282             * </li>
283             * <li>
284             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
285             * of the user's default intranet site home page.
286             * </li>
287             * <li>
288             * Otherwise, return the URL of the user's default extranet site home page.
289             * </li>
290             * </ol>
291             *
292             * @param      portalURL the portal's URL
293             * @param      mainPath the main path
294             * @param      privateLayout whether to use the URL of the user's default
295             *             intranet(versus extranet)  site home page, if no friendly URL
296             *             is available for the user's profile
297             * @return     the user's display URL
298             * @throws     PortalException if a portal exception occurred
299             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
300             */
301            @Deprecated
302            @Override
303            public String getDisplayURL(
304                            String portalURL, String mainPath, boolean privateLayout)
305                    throws PortalException {
306    
307                    if (isDefaultUser()) {
308                            return StringPool.BLANK;
309                    }
310    
311                    String profileFriendlyURL = getProfileFriendlyURL();
312    
313                    if (Validator.isNotNull(profileFriendlyURL)) {
314                            return portalURL.concat(PortalUtil.getPathContext()).concat(
315                                    profileFriendlyURL);
316                    }
317    
318                    Group group = getGroup();
319    
320                    int publicLayoutsPageCount = group.getPublicLayoutsPageCount();
321    
322                    if (publicLayoutsPageCount > 0) {
323                            StringBundler sb = new StringBundler(5);
324    
325                            sb.append(portalURL);
326                            sb.append(mainPath);
327                            sb.append("/my_sites/view?groupId=");
328                            sb.append(group.getGroupId());
329    
330                            if (privateLayout) {
331                                    sb.append("&privateLayout=1");
332                            }
333                            else {
334                                    sb.append("&privateLayout=0");
335                            }
336    
337                            return sb.toString();
338                    }
339    
340                    return StringPool.BLANK;
341            }
342    
343            /**
344             * Returns the user's display URL based on the theme display, discounting
345             * the URL of the user's default intranet site home page.
346             *
347             * <p>
348             * The logic for the display URL to return is as follows:
349             * </p>
350             *
351             * <ol>
352             * <li>
353             * If the user is the guest user, return an empty string.
354             * </li>
355             * <li>
356             * Else, if a friendly URL is available for the user's profile, return that
357             * friendly URL.
358             * </li>
359             * <li>
360             * Otherwise, return the URL of the user's default extranet site home page.
361             * </li>
362             * </ol>
363             *
364             * @param  themeDisplay the theme display
365             * @return the user's display URL
366             * @throws PortalException if a portal exception occurred
367             */
368            @Override
369            public String getDisplayURL(ThemeDisplay themeDisplay)
370                    throws PortalException {
371    
372                    return getDisplayURL(themeDisplay, false);
373            }
374    
375            /**
376             * Returns the user's display URL based on the theme display.
377             *
378             * <p>
379             * The logic for the display URL to return is as follows:
380             * </p>
381             *
382             * <ol>
383             * <li>
384             * If the user is the guest user, return an empty string.
385             * </li>
386             * <li>
387             * Else, if a friendly URL is available for the user's profile, return that
388             * friendly URL.
389             * </li>
390             * <li>
391             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
392             * of the user's default intranet site home page.
393             * </li>
394             * <li>
395             * Otherwise, return the URL of the user's default extranet site home page.
396             * </li>
397             * </ol>
398             *
399             * @param  themeDisplay the theme display
400             * @param  privateLayout whether to use the URL of the user's default
401             *         intranet (versus extranet) site home page, if no friendly URL is
402             *         available for the user's profile
403             * @return the user's display URL
404             * @throws PortalException if a portal exception occurred
405             */
406            @Override
407            public String getDisplayURL(
408                            ThemeDisplay themeDisplay, boolean privateLayout)
409                    throws PortalException {
410    
411                    if (isDefaultUser()) {
412                            return StringPool.BLANK;
413                    }
414    
415                    String portalURL = themeDisplay.getPortalURL();
416    
417                    String profileFriendlyURL = getProfileFriendlyURL();
418    
419                    if (Validator.isNotNull(profileFriendlyURL)) {
420                            return PortalUtil.addPreservedParameters(
421                                    themeDisplay,
422                                    portalURL.concat(
423                                            PortalUtil.getPathContext()).concat(profileFriendlyURL));
424                    }
425    
426                    Group group = getGroup();
427    
428                    return group.getDisplayURL(themeDisplay, privateLayout);
429            }
430    
431            /**
432             * Returns the user's email addresses.
433             *
434             * @return the user's email addresses
435             */
436            @Override
437            public List<EmailAddress> getEmailAddresses() {
438                    return EmailAddressLocalServiceUtil.getEmailAddresses(
439                            getCompanyId(), Contact.class.getName(), getContactId());
440            }
441    
442            /**
443             * Returns <code>true</code> if the user is female.
444             *
445             * @return <code>true</code> if the user is female; <code>false</code>
446             *         otherwise
447             * @throws PortalException if a portal exception occurred
448             */
449            @Override
450            public boolean getFemale() throws PortalException {
451                    return !getMale();
452            }
453    
454            /**
455             * Returns the user's full name.
456             *
457             * @return the user's full name
458             */
459            @AutoEscape
460            @Override
461            public String getFullName() {
462                    FullNameGenerator fullNameGenerator =
463                            FullNameGeneratorFactory.getInstance();
464    
465                    return fullNameGenerator.getFullName(
466                            getFirstName(), getMiddleName(), getLastName());
467            }
468    
469            @Override
470            public Group getGroup() throws PortalException {
471                    return GroupLocalServiceUtil.fetchUserGroup(
472                            getCompanyId(), getUserId());
473            }
474    
475            @Override
476            public long getGroupId() throws PortalException {
477                    Group group = getGroup();
478    
479                    return group.getGroupId();
480            }
481    
482            @Override
483            public long[] getGroupIds() {
484                    return UserLocalServiceUtil.getGroupPrimaryKeys(getUserId());
485            }
486    
487            @Override
488            public List<Group> getGroups() {
489                    return GroupLocalServiceUtil.getUserGroups(getUserId());
490            }
491    
492            @Override
493            public Locale getLocale() {
494                    return _locale;
495            }
496    
497            @Override
498            public String getLogin() throws PortalException {
499                    String login = null;
500    
501                    Company company = CompanyLocalServiceUtil.getCompanyById(
502                            getCompanyId());
503    
504                    if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_EA)) {
505                            login = getEmailAddress();
506                    }
507                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_SN)) {
508                            login = getScreenName();
509                    }
510                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_ID)) {
511                            login = String.valueOf(getUserId());
512                    }
513    
514                    return login;
515            }
516    
517            /**
518             * Returns <code>true</code> if the user is male.
519             *
520             * @return <code>true</code> if the user is male; <code>false</code>
521             *         otherwise
522             * @throws PortalException if a portal exception occurred
523             */
524            @Override
525            public boolean getMale() throws PortalException {
526                    return getContact().getMale();
527            }
528    
529            @Override
530            public List<Group> getMySiteGroups() throws PortalException {
531                    return getMySiteGroups(null, false, QueryUtil.ALL_POS);
532            }
533    
534            @Override
535            public List<Group> getMySiteGroups(boolean includeControlPanel, int max)
536                    throws PortalException {
537    
538                    return getMySiteGroups(null, includeControlPanel, max);
539            }
540    
541            @Override
542            public List<Group> getMySiteGroups(int max) throws PortalException {
543                    return getMySiteGroups(null, false, max);
544            }
545    
546            @Override
547            public List<Group> getMySiteGroups(
548                            String[] classNames, boolean includeControlPanel, int max)
549                    throws PortalException {
550    
551                    return GroupServiceUtil.getUserSitesGroups(
552                            getUserId(), classNames, includeControlPanel, max);
553            }
554    
555            @Override
556            public List<Group> getMySiteGroups(String[] classNames, int max)
557                    throws PortalException {
558    
559                    return getMySiteGroups(classNames, false, max);
560            }
561    
562            /**
563             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups}
564             */
565            @Deprecated
566            @Override
567            public List<Group> getMySites() throws PortalException {
568                    return getMySiteGroups();
569            }
570    
571            /**
572             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(boolean,
573             *             int)}
574             */
575            @Deprecated
576            @Override
577            public List<Group> getMySites(boolean includeControlPanel, int max)
578                    throws PortalException {
579    
580                    return getMySiteGroups(includeControlPanel, max);
581            }
582    
583            /**
584             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(int)}
585             */
586            @Deprecated
587            @Override
588            public List<Group> getMySites(int max) throws PortalException {
589                    return getMySiteGroups(max);
590            }
591    
592            /**
593             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
594             *             boolean, int)}
595             */
596            @Deprecated
597            @Override
598            public List<Group> getMySites(
599                            String[] classNames, boolean includeControlPanel, int max)
600                    throws PortalException {
601    
602                    return getMySiteGroups(classNames, includeControlPanel, max);
603            }
604    
605            /**
606             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
607             *             int)}
608             */
609            @Deprecated
610            @Override
611            public List<Group> getMySites(String[] classNames, int max)
612                    throws PortalException {
613    
614                    return getMySiteGroups(classNames, max);
615            }
616    
617            @Override
618            public long[] getOrganizationIds() throws PortalException {
619                    return getOrganizationIds(false);
620            }
621    
622            @Override
623            public long[] getOrganizationIds(boolean includeAdministrative)
624                    throws PortalException {
625    
626                    return OrganizationLocalServiceUtil.getUserOrganizationIds(
627                            getUserId(), includeAdministrative);
628            }
629    
630            @Override
631            public List<Organization> getOrganizations() throws PortalException {
632                    return getOrganizations(false);
633            }
634    
635            @Override
636            public List<Organization> getOrganizations(boolean includeAdministrative)
637                    throws PortalException {
638    
639                    return OrganizationLocalServiceUtil.getUserOrganizations(
640                            getUserId(), includeAdministrative);
641            }
642    
643            @Override
644            public boolean getPasswordModified() {
645                    return _passwordModified;
646            }
647    
648            @Override
649            public PasswordPolicy getPasswordPolicy() throws PortalException {
650                    if (_passwordPolicy == null) {
651                            _passwordPolicy =
652                                    PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(
653                                            getUserId());
654                    }
655    
656                    return _passwordPolicy;
657            }
658    
659            @Override
660            public String getPasswordUnencrypted() {
661                    return _passwordUnencrypted;
662            }
663    
664            @Override
665            public List<Phone> getPhones() {
666                    return PhoneLocalServiceUtil.getPhones(
667                            getCompanyId(), Contact.class.getName(), getContactId());
668            }
669    
670            @Override
671            public String getPortraitURL(ThemeDisplay themeDisplay)
672                    throws PortalException {
673    
674                    return UserConstants.getPortraitURL(
675                            themeDisplay.getPathImage(), isMale(), getPortraitId(),
676                            getUserUuid());
677            }
678    
679            @Override
680            public int getPrivateLayoutsPageCount() throws PortalException {
681                    return LayoutLocalServiceUtil.getLayoutsCount(this, true);
682            }
683    
684            @Override
685            public int getPublicLayoutsPageCount() throws PortalException {
686                    return LayoutLocalServiceUtil.getLayoutsCount(this, false);
687            }
688    
689            @Override
690            public Set<String> getReminderQueryQuestions() throws PortalException {
691                    Set<String> questions = new TreeSet<String>();
692    
693                    List<Organization> organizations =
694                            OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
695    
696                    for (Organization organization : organizations) {
697                            Set<String> organizationQuestions =
698                                    organization.getReminderQueryQuestions(getLanguageId());
699    
700                            if (organizationQuestions.isEmpty()) {
701                                    Organization parentOrganization =
702                                            organization.getParentOrganization();
703    
704                                    while (organizationQuestions.isEmpty() &&
705                                               (parentOrganization != null)) {
706    
707                                            organizationQuestions =
708                                                    parentOrganization.getReminderQueryQuestions(
709                                                            getLanguageId());
710    
711                                            parentOrganization =
712                                                    parentOrganization.getParentOrganization();
713                                    }
714                            }
715    
716                            questions.addAll(organizationQuestions);
717                    }
718    
719                    if (questions.isEmpty()) {
720                            Set<String> defaultQuestions = SetUtil.fromArray(
721                                    PropsUtil.getArray(PropsKeys.USERS_REMINDER_QUERIES_QUESTIONS));
722    
723                            questions.addAll(defaultQuestions);
724                    }
725    
726                    return questions;
727            }
728    
729            @Override
730            public RemotePreference getRemotePreference(String name) {
731                    return _remotePreferences.get(name);
732            }
733    
734            @Override
735            public Iterable<RemotePreference> getRemotePreferences() {
736                    Collection<RemotePreference> values = _remotePreferences.values();
737    
738                    return Collections.unmodifiableCollection(values);
739            }
740    
741            @Override
742            public long[] getRoleIds() {
743                    return UserLocalServiceUtil.getRolePrimaryKeys(getUserId());
744            }
745    
746            @Override
747            public List<Role> getRoles() {
748                    return RoleLocalServiceUtil.getUserRoles(getUserId());
749            }
750    
751            @Override
752            public List<Group> getSiteGroups() throws PortalException {
753                    return getSiteGroups(false);
754            }
755    
756            @Override
757            public List<Group> getSiteGroups(boolean includeAdministrative)
758                    throws PortalException {
759    
760                    return GroupLocalServiceUtil.getUserSitesGroups(
761                            getUserId(), includeAdministrative);
762            }
763    
764            @Override
765            public long[] getTeamIds() {
766                    return UserLocalServiceUtil.getTeamPrimaryKeys(getUserId());
767            }
768    
769            @Override
770            public List<Team> getTeams() {
771                    return TeamLocalServiceUtil.getUserTeams(getUserId());
772            }
773    
774            @Override
775            public TimeZone getTimeZone() {
776                    return _timeZone;
777            }
778    
779            @Override
780            public long[] getUserGroupIds() {
781                    return UserLocalServiceUtil.getUserGroupPrimaryKeys(getUserId());
782            }
783    
784            @Override
785            public List<UserGroup> getUserGroups() {
786                    return UserGroupLocalServiceUtil.getUserUserGroups(getUserId());
787            }
788    
789            @Override
790            public List<Website> getWebsites() {
791                    return WebsiteLocalServiceUtil.getWebsites(
792                            getCompanyId(), Contact.class.getName(), getContactId());
793            }
794    
795            @Override
796            public boolean hasCompanyMx() throws PortalException {
797                    return hasCompanyMx(getEmailAddress());
798            }
799    
800            @Override
801            public boolean hasCompanyMx(String emailAddress) throws PortalException {
802                    if (Validator.isNull(emailAddress)) {
803                            return false;
804                    }
805    
806                    Company company = CompanyLocalServiceUtil.getCompanyById(
807                            getCompanyId());
808    
809                    return company.hasCompanyMx(emailAddress);
810            }
811    
812            @Override
813            public boolean hasMySites() throws PortalException {
814                    if (isDefaultUser()) {
815                            return false;
816                    }
817    
818                    int max = PropsValues.MY_SITES_MAX_ELEMENTS;
819    
820                    if (max == 1) {
821    
822                            // Increment so that we return more than just the Control Panel
823                            // group
824    
825                            max++;
826                    }
827    
828                    List<Group> groups = getMySiteGroups(true, max);
829    
830                    return !groups.isEmpty();
831            }
832    
833            @Override
834            public boolean hasOrganization() {
835                    return OrganizationLocalServiceUtil.hasUserOrganizations(getUserId());
836            }
837    
838            @Override
839            public boolean hasPrivateLayouts() throws PortalException {
840                    return LayoutLocalServiceUtil.hasLayouts(this, true);
841            }
842    
843            @Override
844            public boolean hasPublicLayouts() throws PortalException {
845                    return LayoutLocalServiceUtil.hasLayouts(this, false);
846            }
847    
848            @Override
849            public boolean hasReminderQuery() {
850                    if (Validator.isNotNull(getReminderQueryQuestion()) &&
851                            Validator.isNotNull(getReminderQueryAnswer())) {
852    
853                            return true;
854                    }
855                    else {
856                            return false;
857                    }
858            }
859    
860            @Override
861            public boolean isActive() {
862                    if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
863                            return true;
864                    }
865                    else {
866                            return false;
867                    }
868            }
869    
870            @Override
871            public boolean isEmailAddressComplete() {
872                    if (Validator.isNull(getEmailAddress()) ||
873                            (PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
874                             Validator.isNull(getDisplayEmailAddress()))) {
875    
876                            return false;
877                    }
878    
879                    return true;
880            }
881    
882            @Override
883            public boolean isEmailAddressVerificationComplete() {
884                    boolean emailAddressVerificationRequired = false;
885    
886                    try {
887                            Company company = CompanyLocalServiceUtil.getCompany(
888                                    getCompanyId());
889    
890                            emailAddressVerificationRequired = company.isStrangersVerify();
891                    }
892                    catch (Exception e) {
893                            _log.error(e, e);
894                    }
895    
896                    if (emailAddressVerificationRequired) {
897                            return super.isEmailAddressVerified();
898                    }
899    
900                    return true;
901            }
902    
903            @Override
904            public boolean isFemale() throws PortalException {
905                    return getFemale();
906            }
907    
908            @Override
909            public boolean isMale() throws PortalException {
910                    return getMale();
911            }
912    
913            @Override
914            public boolean isPasswordModified() {
915                    return _passwordModified;
916            }
917    
918            @Override
919            public boolean isReminderQueryComplete() {
920                    if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) {
921                            if (Validator.isNull(getReminderQueryQuestion()) ||
922                                    Validator.isNull(getReminderQueryAnswer())) {
923    
924                                    return false;
925                            }
926                    }
927    
928                    return true;
929            }
930    
931            @Override
932            public boolean isSetupComplete() {
933                    if (isEmailAddressComplete() && isEmailAddressVerificationComplete() &&
934                            !isPasswordReset() && isReminderQueryComplete() &&
935                            isTermsOfUseComplete()) {
936    
937                            return true;
938                    }
939    
940                    return false;
941            }
942    
943            @Override
944            public boolean isTermsOfUseComplete() {
945                    boolean termsOfUseRequired = false;
946    
947                    try {
948                            termsOfUseRequired = PrefsPropsUtil.getBoolean(
949                                    getCompanyId(), PropsKeys.TERMS_OF_USE_REQUIRED);
950                    }
951                    catch (SystemException se) {
952                            termsOfUseRequired = PropsValues.TERMS_OF_USE_REQUIRED;
953                    }
954    
955                    if (termsOfUseRequired) {
956                            return super.isAgreedToTermsOfUse();
957                    }
958    
959                    return true;
960            }
961    
962            @Override
963            public void setLanguageId(String languageId) {
964                    _locale = LocaleUtil.fromLanguageId(languageId);
965    
966                    super.setLanguageId(LocaleUtil.toLanguageId(_locale));
967            }
968    
969            @Override
970            public void setPasswordModified(boolean passwordModified) {
971                    _passwordModified = passwordModified;
972            }
973    
974            @Override
975            public void setPasswordUnencrypted(String passwordUnencrypted) {
976                    _passwordUnencrypted = passwordUnencrypted;
977            }
978    
979            @Override
980            public void setTimeZoneId(String timeZoneId) {
981                    if (Validator.isNull(timeZoneId)) {
982                            timeZoneId = TimeZoneUtil.getDefault().getID();
983                    }
984    
985                    _timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
986    
987                    super.setTimeZoneId(timeZoneId);
988            }
989    
990            protected String getProfileFriendlyURL() {
991                    if (Validator.isNull(PropsValues.USERS_PROFILE_FRIENDLY_URL)) {
992                            return null;
993                    }
994    
995                    return StringUtil.replace(
996                            PropsValues.USERS_PROFILE_FRIENDLY_URL,
997                            new String[] {"${liferay:screenName}", "${liferay:userId}"},
998                            new String[] {
999                                    HtmlUtil.escapeURL(getScreenName()), String.valueOf(getUserId())
1000                            });
1001            }
1002    
1003            private static Log _log = LogFactoryUtil.getLog(UserImpl.class);
1004    
1005            private Locale _locale;
1006            private boolean _passwordModified;
1007            private PasswordPolicy _passwordPolicy;
1008            private String _passwordUnencrypted;
1009            private transient Map<String, RemotePreference> _remotePreferences =
1010                    new HashMap<String, RemotePreference>();
1011            private TimeZone _timeZone;
1012    
1013    }