1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.admin.util;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.util.CalendarFactoryUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.model.Contact;
22  import com.liferay.portal.model.User;
23  import com.liferay.portal.model.UserGroupRole;
24  import com.liferay.portal.service.ServiceContext;
25  import com.liferay.portal.service.UserLocalServiceUtil;
26  import com.liferay.portal.service.UserServiceUtil;
27  import com.liferay.portal.util.PortalUtil;
28  
29  import java.util.Calendar;
30  import java.util.List;
31  
32  import javax.portlet.ActionRequest;
33  
34  import javax.servlet.http.HttpServletRequest;
35  
36  /**
37   * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class AdminUtil {
42  
43      public static String getUpdateUserPassword(
44          HttpServletRequest request, long userId) {
45  
46          String password = PortalUtil.getUserPassword(request);
47  
48          if (userId != PortalUtil.getUserId(request)) {
49              password = StringPool.BLANK;
50          }
51  
52          return password;
53      }
54  
55      public static String getUpdateUserPassword(
56          ActionRequest actionRequest, long userId) {
57  
58          HttpServletRequest request = PortalUtil.getHttpServletRequest(
59              actionRequest);
60  
61          return getUpdateUserPassword(request, userId);
62      }
63  
64      public static User updateUser(
65              HttpServletRequest request, long userId, String screenName,
66              String emailAddress, String openId, String languageId,
67              String timeZoneId, String greeting, String comments, String smsSn,
68              String aimSn, String facebookSn, String icqSn, String jabberSn,
69              String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
70              String ymSn)
71          throws PortalException, SystemException {
72  
73          String password = getUpdateUserPassword(request, userId);
74  
75          User user = UserLocalServiceUtil.getUserById(userId);
76  
77          Contact contact = user.getContact();
78  
79          Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
80  
81          birthdayCal.setTime(contact.getBirthday());
82  
83          int birthdayMonth = birthdayCal.get(Calendar.MONTH);
84          int birthdayDay = birthdayCal.get(Calendar.DATE);
85          int birthdayYear = birthdayCal.get(Calendar.YEAR);
86  
87          long[] groupIds = null;
88          long[] organizationIds = null;
89          long[] roleIds = null;
90          List<UserGroupRole> userGroupRoles = null;
91          long[] userGroupIds = null;
92          ServiceContext serviceContext = new ServiceContext();
93  
94          return UserServiceUtil.updateUser(
95              userId, password, StringPool.BLANK, StringPool.BLANK,
96              user.isPasswordReset(), user.getReminderQueryQuestion(),
97              user.getReminderQueryAnswer(), screenName, emailAddress, openId,
98              languageId, timeZoneId, greeting, comments, contact.getFirstName(),
99              contact.getMiddleName(), contact.getLastName(),
100             contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
101             birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
102             icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
103             contact.getJobTitle(), groupIds, organizationIds, roleIds,
104             userGroupRoles, userGroupIds, serviceContext);
105     }
106 
107     public static User updateUser(
108             ActionRequest actionRequest, long userId, String screenName,
109             String emailAddress, String openId, String languageId,
110             String timeZoneId, String greeting, String comments, String smsSn,
111             String aimSn, String facebookSn, String icqSn, String jabberSn,
112             String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
113             String ymSn)
114         throws PortalException, SystemException {
115 
116         HttpServletRequest request = PortalUtil.getHttpServletRequest(
117             actionRequest);
118 
119         return updateUser(
120             request, userId, screenName, emailAddress, openId, languageId,
121             timeZoneId, greeting, comments, smsSn, aimSn, facebookSn, icqSn,
122             jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
123     }
124 
125 }