1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.admin.util;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.CalendarFactoryUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.model.Contact;
30  import com.liferay.portal.model.User;
31  import com.liferay.portal.model.UserGroupRole;
32  import com.liferay.portal.service.ServiceContext;
33  import com.liferay.portal.service.UserLocalServiceUtil;
34  import com.liferay.portal.service.UserServiceUtil;
35  import com.liferay.portal.util.PortalUtil;
36  
37  import java.util.Calendar;
38  import java.util.List;
39  
40  import javax.portlet.ActionRequest;
41  
42  import javax.servlet.http.HttpServletRequest;
43  
44  /**
45   * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   */
49  public class AdminUtil {
50  
51      public static String getUpdateUserPassword(
52          HttpServletRequest request, long userId) {
53  
54          String password = PortalUtil.getUserPassword(request);
55  
56          if (userId != PortalUtil.getUserId(request)) {
57              password = StringPool.BLANK;
58          }
59  
60          return password;
61      }
62  
63      public static String getUpdateUserPassword(
64          ActionRequest actionRequest, long userId) {
65  
66          HttpServletRequest request = PortalUtil.getHttpServletRequest(
67              actionRequest);
68  
69          return getUpdateUserPassword(request, userId);
70      }
71  
72      public static User updateUser(
73              HttpServletRequest request, long userId, String screenName,
74              String emailAddress, String openId, String languageId,
75              String timeZoneId, String greeting, String comments, String smsSn,
76              String aimSn, String facebookSn, String icqSn, String jabberSn,
77              String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
78              String ymSn)
79          throws PortalException, SystemException {
80  
81          String password = getUpdateUserPassword(request, userId);
82  
83          User user = UserLocalServiceUtil.getUserById(userId);
84  
85          Contact contact = user.getContact();
86  
87          Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
88  
89          birthdayCal.setTime(contact.getBirthday());
90  
91          int birthdayMonth = birthdayCal.get(Calendar.MONTH);
92          int birthdayDay = birthdayCal.get(Calendar.DATE);
93          int birthdayYear = birthdayCal.get(Calendar.YEAR);
94  
95          long[] groupIds = null;
96          long[] organizationIds = null;
97          long[] roleIds = null;
98          List<UserGroupRole> userGroupRoles = null;
99          long[] userGroupIds = null;
100         ServiceContext serviceContext = new ServiceContext();
101 
102         return UserServiceUtil.updateUser(
103             userId, password, StringPool.BLANK, StringPool.BLANK,
104             user.isPasswordReset(), user.getReminderQueryQuestion(),
105             user.getReminderQueryAnswer(), screenName, emailAddress, openId,
106             languageId, timeZoneId, greeting, comments, contact.getFirstName(),
107             contact.getMiddleName(), contact.getLastName(),
108             contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
109             birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
110             icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
111             contact.getJobTitle(), groupIds, organizationIds, roleIds,
112             userGroupRoles, userGroupIds, serviceContext);
113     }
114 
115     public static User updateUser(
116             ActionRequest actionRequest, long userId, String screenName,
117             String emailAddress, String openId, String languageId,
118             String timeZoneId, String greeting, String comments, String smsSn,
119             String aimSn, String facebookSn, String icqSn, String jabberSn,
120             String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
121             String ymSn)
122         throws PortalException, SystemException {
123 
124         HttpServletRequest request = PortalUtil.getHttpServletRequest(
125             actionRequest);
126 
127         return updateUser(
128             request, userId, screenName, emailAddress, openId, languageId,
129             timeZoneId, greeting, comments, smsSn, aimSn, facebookSn, icqSn,
130             jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
131     }
132 
133 }