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