001    /**
002     * Copyright (c) 2000-2010 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.portlet.enterpriseadmin.action;
016    
017    import com.liferay.portal.AddressCityException;
018    import com.liferay.portal.AddressStreetException;
019    import com.liferay.portal.AddressZipException;
020    import com.liferay.portal.CompanyMaxUsersException;
021    import com.liferay.portal.ContactFirstNameException;
022    import com.liferay.portal.ContactFullNameException;
023    import com.liferay.portal.ContactLastNameException;
024    import com.liferay.portal.DuplicateUserEmailAddressException;
025    import com.liferay.portal.DuplicateUserScreenNameException;
026    import com.liferay.portal.EmailAddressException;
027    import com.liferay.portal.NoSuchCountryException;
028    import com.liferay.portal.NoSuchListTypeException;
029    import com.liferay.portal.NoSuchRegionException;
030    import com.liferay.portal.NoSuchUserException;
031    import com.liferay.portal.PhoneNumberException;
032    import com.liferay.portal.RequiredUserException;
033    import com.liferay.portal.ReservedUserEmailAddressException;
034    import com.liferay.portal.ReservedUserScreenNameException;
035    import com.liferay.portal.UserEmailAddressException;
036    import com.liferay.portal.UserIdException;
037    import com.liferay.portal.UserPasswordException;
038    import com.liferay.portal.UserReminderQueryException;
039    import com.liferay.portal.UserScreenNameException;
040    import com.liferay.portal.UserSmsException;
041    import com.liferay.portal.WebsiteURLException;
042    import com.liferay.portal.kernel.bean.BeanParamUtil;
043    import com.liferay.portal.kernel.servlet.SessionErrors;
044    import com.liferay.portal.kernel.util.CalendarFactoryUtil;
045    import com.liferay.portal.kernel.util.Constants;
046    import com.liferay.portal.kernel.util.GetterUtil;
047    import com.liferay.portal.kernel.util.HttpUtil;
048    import com.liferay.portal.kernel.util.LocaleUtil;
049    import com.liferay.portal.kernel.util.ParamUtil;
050    import com.liferay.portal.kernel.util.StringPool;
051    import com.liferay.portal.kernel.util.StringUtil;
052    import com.liferay.portal.kernel.util.Validator;
053    import com.liferay.portal.model.Address;
054    import com.liferay.portal.model.Contact;
055    import com.liferay.portal.model.EmailAddress;
056    import com.liferay.portal.model.Group;
057    import com.liferay.portal.model.Layout;
058    import com.liferay.portal.model.Phone;
059    import com.liferay.portal.model.User;
060    import com.liferay.portal.model.UserGroupRole;
061    import com.liferay.portal.model.Website;
062    import com.liferay.portal.security.auth.PrincipalException;
063    import com.liferay.portal.service.ServiceContext;
064    import com.liferay.portal.service.ServiceContextFactory;
065    import com.liferay.portal.service.UserServiceUtil;
066    import com.liferay.portal.struts.PortletAction;
067    import com.liferay.portal.theme.ThemeDisplay;
068    import com.liferay.portal.util.PortalUtil;
069    import com.liferay.portal.util.PropsValues;
070    import com.liferay.portal.util.WebKeys;
071    import com.liferay.portlet.InvokerPortletImpl;
072    import com.liferay.portlet.admin.util.AdminUtil;
073    import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
074    import com.liferay.portlet.announcements.model.AnnouncementsEntryConstants;
075    import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
076    import com.liferay.portlet.communities.util.CommunitiesUtil;
077    import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
078    
079    import java.util.ArrayList;
080    import java.util.Calendar;
081    import java.util.List;
082    
083    import javax.portlet.ActionRequest;
084    import javax.portlet.ActionResponse;
085    import javax.portlet.PortletConfig;
086    import javax.portlet.PortletRequest;
087    import javax.portlet.PortletSession;
088    import javax.portlet.RenderRequest;
089    import javax.portlet.RenderResponse;
090    
091    import javax.servlet.http.HttpServletRequest;
092    import javax.servlet.http.HttpSession;
093    
094    import org.apache.struts.Globals;
095    import org.apache.struts.action.ActionForm;
096    import org.apache.struts.action.ActionForward;
097    import org.apache.struts.action.ActionMapping;
098    
099    /**
100     * @author Brian Wing Shun Chan
101     * @author Jorge Ferrer
102     * @author Julio Camarero
103     * @author Wesley Gong
104     */
105    public class EditUserAction extends PortletAction {
106    
107            public void processAction(
108                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
109                            ActionRequest actionRequest, ActionResponse actionResponse)
110                    throws Exception {
111    
112                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
113    
114                    try {
115                            User user = null;
116                            String oldScreenName = StringPool.BLANK;
117                            String oldLanguageId = StringPool.BLANK;
118    
119                            if (cmd.equals(Constants.ADD)) {
120                                    user = addUser(actionRequest);
121                            }
122                            else if (cmd.equals(Constants.DEACTIVATE) ||
123                                             cmd.equals(Constants.DELETE) ||
124                                             cmd.equals(Constants.RESTORE)) {
125    
126                                    deleteUsers(actionRequest);
127                            }
128                            else if (cmd.equals("deleteRole")) {
129                                    deleteRole(actionRequest);
130                            }
131                            else if (cmd.equals(Constants.UPDATE)) {
132                                    Object[] returnValue = updateUser(actionRequest);
133    
134                                    user = (User)returnValue[0];
135                                    oldScreenName = ((String)returnValue[1]);
136                                    oldLanguageId = ((String)returnValue[2]);
137                            }
138                            else if (cmd.equals("unlock")) {
139                                    user = updateLockout(actionRequest);
140                            }
141    
142                            String redirect = ParamUtil.getString(actionRequest, "redirect");
143    
144                            if (user != null) {
145                                    ThemeDisplay themeDisplay =
146                                            (ThemeDisplay)actionRequest.getAttribute(
147                                                    WebKeys.THEME_DISPLAY);
148    
149                                    if (Validator.isNotNull(oldScreenName)) {
150    
151                                            // This will fix the redirect if the user is on his personal
152                                            // my account page and changes his screen name. A redirect
153                                            // that references the old screen name no longer points to a
154                                            // valid screen name and therefore needs to be updated.
155    
156                                            Group group = user.getGroup();
157    
158                                            if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
159                                                    Layout layout = themeDisplay.getLayout();
160    
161                                                    String friendlyURLPath = group.getPathFriendlyURL(
162                                                            layout.isPrivateLayout(), themeDisplay);
163    
164                                                    String oldPath =
165                                                            friendlyURLPath + StringPool.SLASH + oldScreenName;
166                                                    String newPath =
167                                                            friendlyURLPath + StringPool.SLASH +
168                                                                    user.getScreenName();
169    
170                                                    redirect = StringUtil.replace(
171                                                            redirect, oldPath, newPath);
172    
173                                                    redirect = StringUtil.replace(
174                                                            redirect, HttpUtil.encodeURL(oldPath),
175                                                            HttpUtil.encodeURL(newPath));
176                                            }
177                                    }
178    
179                                    if (Validator.isNotNull(oldLanguageId) &&
180                                            themeDisplay.isI18n()) {
181    
182                                            String i18nLanguageId = user.getLanguageId();
183                                            int pos = i18nLanguageId.indexOf(StringPool.UNDERLINE);
184    
185                                            if (pos != -1){
186                                                    i18nLanguageId = i18nLanguageId.substring(0, pos);
187                                            }
188    
189                                            String i18nPath = StringPool.SLASH + i18nLanguageId;
190    
191                                            redirect = StringUtil.replace(
192                                                    redirect, themeDisplay.getI18nPath(), i18nPath);
193                                    }
194    
195                                    redirect = HttpUtil.setParameter(
196                                            redirect, actionResponse.getNamespace() + "p_u_i_d",
197                                            user.getUserId());
198                            }
199    
200                            sendRedirect(actionRequest, actionResponse, redirect);
201                    }
202                    catch (Exception e) {
203                            if (e instanceof NoSuchUserException ||
204                                    e instanceof PrincipalException) {
205    
206                                    SessionErrors.add(actionRequest, e.getClass().getName());
207    
208                                    setForward(actionRequest, "portlet.enterprise_admin.error");
209                            }
210                            else if (e instanceof AddressCityException ||
211                                             e instanceof AddressStreetException ||
212                                             e instanceof AddressZipException ||
213                                             e instanceof CompanyMaxUsersException ||
214                                             e instanceof ContactFirstNameException ||
215                                             e instanceof ContactFullNameException ||
216                                             e instanceof ContactLastNameException ||
217                                             e instanceof DuplicateUserEmailAddressException ||
218                                             e instanceof DuplicateUserScreenNameException ||
219                                             e instanceof EmailAddressException ||
220                                             e instanceof NoSuchCountryException ||
221                                             e instanceof NoSuchListTypeException ||
222                                             e instanceof NoSuchRegionException ||
223                                             e instanceof PhoneNumberException ||
224                                             e instanceof RequiredUserException ||
225                                             e instanceof ReservedUserEmailAddressException ||
226                                             e instanceof ReservedUserScreenNameException ||
227                                             e instanceof UserEmailAddressException ||
228                                             e instanceof UserIdException ||
229                                             e instanceof UserPasswordException ||
230                                             e instanceof UserReminderQueryException ||
231                                             e instanceof UserScreenNameException ||
232                                             e instanceof UserSmsException ||
233                                             e instanceof WebsiteURLException) {
234    
235                                    if (e instanceof NoSuchListTypeException) {
236                                            NoSuchListTypeException nslte = (NoSuchListTypeException)e;
237    
238                                            SessionErrors.add(
239                                                    actionRequest,
240                                                    e.getClass().getName() + nslte.getType());
241                                    }
242                                    else {
243                                            SessionErrors.add(actionRequest, e.getClass().getName(), e);
244                                    }
245    
246                                    if (e instanceof RequiredUserException) {
247                                            actionResponse.sendRedirect(
248                                                    ParamUtil.getString(actionRequest, "redirect"));
249                                    }
250                            }
251                            else {
252                                    throw e;
253                            }
254                    }
255            }
256    
257            public ActionForward render(
258                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
259                            RenderRequest renderRequest, RenderResponse renderResponse)
260                    throws Exception {
261    
262                    try {
263                            PortalUtil.getSelectedUser(renderRequest);
264                    }
265                    catch (Exception e) {
266                            if (e instanceof PrincipalException) {
267                                    SessionErrors.add(renderRequest, e.getClass().getName());
268    
269                                    return mapping.findForward("portlet.enterprise_admin.error");
270                            }
271                            else {
272                                    throw e;
273                            }
274                    }
275    
276                    return mapping.findForward(
277                            getForward(renderRequest, "portlet.enterprise_admin.edit_user"));
278            }
279    
280            protected User addUser(ActionRequest actionRequest)
281                    throws Exception {
282    
283                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
284                            WebKeys.THEME_DISPLAY);
285    
286                    boolean autoPassword = ParamUtil.getBoolean(
287                            actionRequest, "autoPassword", true);
288                    String password1 = ParamUtil.getString(actionRequest, "password1");
289                    String password2 = ParamUtil.getString(actionRequest, "password2");
290    
291                    String reminderQueryQuestion = ParamUtil.getString(
292                            actionRequest, "reminderQueryQuestion");
293    
294                    if (reminderQueryQuestion.equals(EnterpriseAdminUtil.CUSTOM_QUESTION)) {
295                            reminderQueryQuestion = ParamUtil.getString(
296                                    actionRequest, "reminderQueryCustomQuestion");
297                    }
298    
299                    String reminderQueryAnswer = ParamUtil.getString(
300                            actionRequest, "reminderQueryAnswer");
301                    boolean autoScreenName = ParamUtil.getBoolean(
302                            actionRequest, "autoScreenName");
303                    String screenName = ParamUtil.getString(actionRequest, "screenName");
304                    String emailAddress = ParamUtil.getString(
305                            actionRequest, "emailAddress");
306                    long facebookId = 0;
307                    String openId = ParamUtil.getString(actionRequest, "openId");
308                    String languageId = ParamUtil.getString(actionRequest, "languageId");
309                    String timeZoneId = ParamUtil.getString(actionRequest, "timeZoneId");
310                    String greeting = ParamUtil.getString(actionRequest, "greeting");
311                    String firstName = ParamUtil.getString(actionRequest, "firstName");
312                    String middleName = ParamUtil.getString(actionRequest, "middleName");
313                    String lastName = ParamUtil.getString(actionRequest, "lastName");
314                    int prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
315                    int suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
316                    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
317                    int birthdayMonth = ParamUtil.getInteger(
318                            actionRequest, "birthdayMonth");
319                    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
320                    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
321                    String comments = ParamUtil.getString(actionRequest, "comments");
322                    String smsSn = ParamUtil.getString(actionRequest, "smsSn");
323                    String aimSn = ParamUtil.getString(actionRequest, "aimSn");
324                    String facebookSn = ParamUtil.getString(actionRequest, "facebookSn");
325                    String icqSn = ParamUtil.getString(actionRequest, "icqSn");
326                    String jabberSn = ParamUtil.getString(actionRequest, "jabberSn");
327                    String msnSn = ParamUtil.getString(actionRequest, "msnSn");
328                    String mySpaceSn = ParamUtil.getString(actionRequest, "mySpaceSn");
329                    String skypeSn = ParamUtil.getString(actionRequest, "skypeSn");
330                    String twitterSn = ParamUtil.getString(actionRequest, "twitterSn");
331                    String ymSn = ParamUtil.getString(actionRequest, "ymSn");
332                    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
333                    long[] groupIds = getLongArray(
334                            actionRequest, "groupsSearchContainerPrimaryKeys");
335                    long[] organizationIds = getLongArray(
336                            actionRequest, "organizationsSearchContainerPrimaryKeys");
337                    long[] roleIds = getLongArray(
338                            actionRequest, "rolesSearchContainerPrimaryKeys");
339                    List<UserGroupRole> userGroupRoles =
340                            EnterpriseAdminUtil.getUserGroupRoles(actionRequest);
341                    long[] userGroupIds = getLongArray(
342                            actionRequest, "userGroupsSearchContainerPrimaryKeys");
343                    boolean sendEmail = true;
344                    List<Address> addresses = EnterpriseAdminUtil.getAddresses(
345                            actionRequest);
346                    List<EmailAddress> emailAddresses =
347                            EnterpriseAdminUtil.getEmailAddresses(actionRequest);
348                    List<Phone> phones = EnterpriseAdminUtil.getPhones(actionRequest);
349                    List<Website> websites = EnterpriseAdminUtil.getWebsites(actionRequest);
350                    List<AnnouncementsDelivery> announcementsDeliveries =
351                            getAnnouncementsDeliveries(actionRequest);
352    
353                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
354                            User.class.getName(), actionRequest);
355    
356                    User user = null;
357    
358                    user = UserServiceUtil.addUser(
359                            themeDisplay.getCompanyId(), autoPassword, password1, password2,
360                            autoScreenName, screenName, emailAddress, facebookId, openId,
361                            LocaleUtil.getDefault(), firstName, middleName, lastName, prefixId,
362                            suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
363                            groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
364                            addresses, emailAddresses, phones, websites,
365                            announcementsDeliveries, serviceContext);
366    
367                    if (!userGroupRoles.isEmpty()) {
368                            for (UserGroupRole userGroupRole : userGroupRoles) {
369                                    userGroupRole.setUserId(user.getUserId());
370                            }
371    
372                            user = UserServiceUtil.updateUser(
373                                    user.getUserId(), StringPool.BLANK, StringPool.BLANK,
374                                    StringPool.BLANK, false, reminderQueryQuestion,
375                                    reminderQueryAnswer, screenName, emailAddress, facebookId,
376                                    openId, languageId, timeZoneId, greeting, comments, firstName,
377                                    middleName, lastName, prefixId, suffixId, male, birthdayMonth,
378                                    birthdayDay, birthdayYear, smsSn, aimSn, facebookSn, icqSn,
379                                    jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn, jobTitle,
380                                    groupIds, organizationIds, roleIds, userGroupRoles,
381                                    userGroupIds, addresses, emailAddresses, phones, websites,
382                                    announcementsDeliveries, serviceContext);
383                    }
384    
385                    long publicLayoutSetPrototypeId = ParamUtil.getLong(
386                            actionRequest, "publicLayoutSetPrototypeId");
387                    long privateLayoutSetPrototypeId = ParamUtil.getLong(
388                            actionRequest, "privateLayoutSetPrototypeId");
389    
390                    CommunitiesUtil.applyLayoutSetPrototypes(
391                            user.getGroup(), publicLayoutSetPrototypeId,
392                            privateLayoutSetPrototypeId);
393    
394                    return user;
395            }
396    
397            protected void deleteRole(ActionRequest actionRequest) throws Exception {
398                    User user = PortalUtil.getSelectedUser(actionRequest);
399    
400                    long roleId = ParamUtil.getLong(actionRequest, "roleId");
401    
402                    UserServiceUtil.deleteRoleUser(roleId, user.getUserId());
403            }
404    
405            protected void deleteUsers(ActionRequest actionRequest) throws Exception {
406                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
407    
408                    long[] deleteUserIds = StringUtil.split(
409                            ParamUtil.getString(actionRequest, "deleteUserIds"), 0L);
410    
411                    for (int i = 0; i < deleteUserIds.length; i++) {
412                            if (cmd.equals(Constants.DEACTIVATE) ||
413                                    cmd.equals(Constants.RESTORE)) {
414    
415                                    boolean active = !cmd.equals(Constants.DEACTIVATE);
416    
417                                    UserServiceUtil.updateActive(deleteUserIds[i], active);
418                            }
419                            else {
420                                    UserServiceUtil.deleteUser(deleteUserIds[i]);
421                            }
422                    }
423            }
424    
425            protected List<AnnouncementsDelivery> getAnnouncementsDeliveries(
426                    ActionRequest actionRequest) {
427    
428                    List<AnnouncementsDelivery> announcementsDeliveries =
429                            new ArrayList<AnnouncementsDelivery>();
430    
431                    for (String type : AnnouncementsEntryConstants.TYPES) {
432                            boolean email = ParamUtil.getBoolean(
433                                    actionRequest, "announcementsType" + type + "Email");
434                            boolean sms = ParamUtil.getBoolean(
435                                    actionRequest, "announcementsType" + type + "Sms");
436                            boolean website = ParamUtil.getBoolean(
437                                    actionRequest, "announcementsType" + type + "Website");
438    
439                            AnnouncementsDelivery announcementsDelivery =
440                                    new AnnouncementsDeliveryImpl();
441    
442                            announcementsDelivery.setType(type);
443                            announcementsDelivery.setEmail(email);
444                            announcementsDelivery.setSms(sms);
445                            announcementsDelivery.setWebsite(website);
446    
447                            announcementsDeliveries.add(announcementsDelivery);
448                    }
449    
450                    return announcementsDeliveries;
451            }
452    
453            protected long[] getLongArray(PortletRequest portletRequest, String name) {
454                    String value = portletRequest.getParameter(name);
455    
456                    if (value == null) {
457                            return null;
458                    }
459    
460                    return StringUtil.split(GetterUtil.getString(value), 0L);
461            }
462    
463            protected User updateLockout(ActionRequest actionRequest) throws Exception {
464                    User user = PortalUtil.getSelectedUser(actionRequest);
465    
466                    UserServiceUtil.updateLockout(user.getUserId(), false);
467    
468                    return user;
469            }
470    
471            protected Object[] updateUser(ActionRequest actionRequest)
472                    throws Exception {
473    
474                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
475                            WebKeys.THEME_DISPLAY);
476    
477                    User user = PortalUtil.getSelectedUser(actionRequest);
478    
479                    Contact contact = user.getContact();
480    
481                    String oldPassword = AdminUtil.getUpdateUserPassword(
482                            actionRequest, user.getUserId());
483                    String newPassword1 = ParamUtil.getString(actionRequest, "password1");
484                    String newPassword2 = ParamUtil.getString(actionRequest, "password2");
485                    boolean passwordReset = ParamUtil.getBoolean(
486                            actionRequest, "passwordReset");
487    
488                    String reminderQueryQuestion = BeanParamUtil.getString(
489                            user, actionRequest, "reminderQueryQuestion");
490    
491                    if (reminderQueryQuestion.equals(EnterpriseAdminUtil.CUSTOM_QUESTION)) {
492                            reminderQueryQuestion = BeanParamUtil.getString(
493                                    user, actionRequest, "reminderQueryCustomQuestion");
494                    }
495    
496                    String reminderQueryAnswer = BeanParamUtil.getString(
497                            user, actionRequest, "reminderQueryAnswer");
498                    String oldScreenName = user.getScreenName();
499                    String screenName = BeanParamUtil.getString(
500                            user, actionRequest, "screenName");
501                    String emailAddress = BeanParamUtil.getString(
502                            user, actionRequest, "emailAddress");
503                    long facebookId = user.getFacebookId();
504                    String openId = BeanParamUtil.getString(user, actionRequest, "openId");
505                    String oldLanguageId = user.getLanguageId();
506                    String languageId = BeanParamUtil.getString(
507                            user, actionRequest, "languageId");
508                    String timeZoneId = BeanParamUtil.getString(
509                            user, actionRequest, "timeZoneId");
510                    String greeting = BeanParamUtil.getString(
511                            user, actionRequest, "greeting");
512                    String firstName = BeanParamUtil.getString(
513                            user, actionRequest, "firstName");
514                    String middleName = BeanParamUtil.getString(
515                            user, actionRequest, "middleName");
516                    String lastName = BeanParamUtil.getString(
517                            user, actionRequest, "lastName");
518                    int prefixId = BeanParamUtil.getInteger(
519                            contact, actionRequest, "prefixId");
520                    int suffixId = BeanParamUtil.getInteger(
521                            contact, actionRequest, "suffixId");
522                    boolean male = BeanParamUtil.getBoolean(
523                            user, actionRequest, "male", true);
524    
525                    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
526    
527                    birthdayCal.setTime(contact.getBirthday());
528    
529                    int birthdayMonth = ParamUtil.getInteger(
530                            actionRequest, "birthdayMonth", birthdayCal.get(Calendar.MONTH));
531                    int birthdayDay = ParamUtil.getInteger(
532                            actionRequest, "birthdayDay", birthdayCal.get(Calendar.DATE));
533                    int birthdayYear = ParamUtil.getInteger(
534                            actionRequest, "birthdayYear", birthdayCal.get(Calendar.YEAR));
535                    String comments = BeanParamUtil.getString(
536                            user, actionRequest, "comments");
537                    String smsSn = BeanParamUtil.getString(contact, actionRequest, "smsSn");
538                    String aimSn = BeanParamUtil.getString(contact, actionRequest, "aimSn");
539                    String facebookSn = BeanParamUtil.getString(
540                            contact, actionRequest, "facebookSn");
541                    String icqSn = BeanParamUtil.getString(contact, actionRequest, "icqSn");
542                    String jabberSn = BeanParamUtil.getString(
543                            contact, actionRequest, "jabberSn");
544                    String msnSn = BeanParamUtil.getString(contact, actionRequest, "msnSn");
545                    String mySpaceSn = BeanParamUtil.getString(
546                            contact, actionRequest, "mySpaceSn");
547                    String skypeSn = BeanParamUtil.getString(
548                            contact, actionRequest, "skypeSn");
549                    String twitterSn = BeanParamUtil.getString(
550                            contact, actionRequest, "twitterSn");
551                    String ymSn = BeanParamUtil.getString(contact, actionRequest, "ymSn");
552                    String jobTitle = BeanParamUtil.getString(
553                            user, actionRequest, "jobTitle");
554                    long[] groupIds = getLongArray(
555                            actionRequest, "groupsSearchContainerPrimaryKeys");
556                    long[] organizationIds = getLongArray(
557                            actionRequest, "organizationsSearchContainerPrimaryKeys");
558                    long[] roleIds = getLongArray(
559                            actionRequest, "rolesSearchContainerPrimaryKeys");
560                    List<UserGroupRole> userGroupRoles =
561                            EnterpriseAdminUtil.getUserGroupRoles(actionRequest);
562                    long[] userGroupIds = getLongArray(
563                            actionRequest, "userGroupsSearchContainerPrimaryKeys");
564                    List<Address> addresses = EnterpriseAdminUtil.getAddresses(
565                            actionRequest);
566                    List<EmailAddress> emailAddresses =
567                            EnterpriseAdminUtil.getEmailAddresses(actionRequest);
568                    List<Phone> phones = EnterpriseAdminUtil.getPhones(actionRequest);
569                    List<Website> websites = EnterpriseAdminUtil.getWebsites(actionRequest);
570                    List<AnnouncementsDelivery> announcementsDeliveries =
571                            getAnnouncementsDeliveries(actionRequest);
572    
573                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
574                            User.class.getName(), actionRequest);
575    
576                    user = UserServiceUtil.updateUser(
577                            user.getUserId(), oldPassword, newPassword1, newPassword2,
578                            passwordReset, reminderQueryQuestion, reminderQueryAnswer,
579                            screenName, emailAddress, facebookId, openId, languageId,
580                            timeZoneId, greeting, comments, firstName, middleName, lastName,
581                            prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
582                            smsSn, aimSn, facebookSn, icqSn, jabberSn, msnSn, mySpaceSn,
583                            skypeSn, twitterSn, ymSn, jobTitle, groupIds, organizationIds,
584                            roleIds, userGroupRoles, userGroupIds, addresses, emailAddresses,
585                            phones, websites, announcementsDeliveries, serviceContext);
586    
587                    if (oldScreenName.equals(user.getScreenName())) {
588                            oldScreenName = StringPool.BLANK;
589                    }
590    
591                    boolean deletePortrait = ParamUtil.getBoolean(
592                            actionRequest, "deletePortrait");
593    
594                    if (deletePortrait) {
595                            UserServiceUtil.deletePortrait(user.getUserId());
596                    }
597    
598                    if (user.getUserId() == themeDisplay.getUserId()) {
599    
600                            // Reset the locale
601    
602                            HttpServletRequest request = PortalUtil.getHttpServletRequest(
603                                    actionRequest);
604                            HttpSession session = request.getSession();
605    
606                            session.removeAttribute(Globals.LOCALE_KEY);
607    
608                            // Clear cached portlet responses
609    
610                            PortletSession portletSession = actionRequest.getPortletSession();
611    
612                            InvokerPortletImpl.clearResponses(portletSession);
613    
614                            // Password
615    
616                            if (PropsValues.SESSION_STORE_PASSWORD &&
617                                    Validator.isNotNull(newPassword1)) {
618    
619                                    portletSession.setAttribute(
620                                            WebKeys.USER_PASSWORD, newPassword1,
621                                            PortletSession.APPLICATION_SCOPE);
622                            }
623                    }
624    
625                    long publicLayoutSetPrototypeId = ParamUtil.getLong(
626                            actionRequest, "publicLayoutSetPrototypeId");
627                    long privateLayoutSetPrototypeId = ParamUtil.getLong(
628                            actionRequest, "privateLayoutSetPrototypeId");
629    
630                    CommunitiesUtil.applyLayoutSetPrototypes(
631                            user.getGroup(), publicLayoutSetPrototypeId,
632                            privateLayoutSetPrototypeId);
633    
634                    return new Object[] {user, oldScreenName, oldLanguageId};
635            }
636    
637    }