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