1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.admin.util;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.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.service.UserLocalServiceUtil;
24  import com.liferay.portal.service.UserServiceUtil;
25  import com.liferay.portal.util.PortalUtil;
26  
27  import java.rmi.RemoteException;
28  
29  import java.util.Calendar;
30  
31  import javax.portlet.ActionRequest;
32  
33  import javax.servlet.http.HttpServletRequest;
34  
35  /**
36   * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class AdminUtil {
41  
42      public static String getUpdateUserPassword(
43          HttpServletRequest request, long userId) {
44  
45          String password = PortalUtil.getUserPassword(request);
46  
47          if (userId != PortalUtil.getUserId(request)) {
48              password = StringPool.BLANK;
49          }
50  
51          return password;
52      }
53  
54      public static String getUpdateUserPassword(
55          ActionRequest actionRequest, long userId) {
56  
57          HttpServletRequest request = PortalUtil.getHttpServletRequest(
58              actionRequest);
59  
60          return getUpdateUserPassword(request, userId);
61      }
62  
63      public static User updateUser(
64              HttpServletRequest request, long userId, String screenName,
65              String emailAddress, String languageId, String timeZoneId,
66              String greeting, String comments, String smsSn, String aimSn,
67              String facebookSn, String icqSn, String jabberSn, String msnSn,
68              String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
69          throws PortalException, RemoteException, SystemException {
70  
71          String password = getUpdateUserPassword(request, userId);
72  
73          User user = UserLocalServiceUtil.getUserById(userId);
74  
75          Contact contact = user.getContact();
76  
77          Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
78  
79          birthdayCal.setTime(contact.getBirthday());
80  
81          int birthdayMonth = birthdayCal.get(Calendar.MONTH);
82          int birthdayDay = birthdayCal.get(Calendar.DATE);
83          int birthdayYear = birthdayCal.get(Calendar.YEAR);
84  
85          return UserServiceUtil.updateUser(
86              userId, password, user.isPasswordReset(), screenName, emailAddress,
87              languageId, timeZoneId, greeting, comments, contact.getFirstName(),
88              contact.getMiddleName(), contact.getLastName(),
89              contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
90              birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
91              icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
92              contact.getJobTitle(), user.getOrganizationIds());
93      }
94  
95      public static User updateUser(
96              ActionRequest actionRequest, long userId, String screenName,
97              String emailAddress, String languageId, String timeZoneId,
98              String greeting, String comments, String smsSn, String aimSn,
99              String facebookSn, String icqSn, String jabberSn, String msnSn,
100             String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
101         throws PortalException, RemoteException, SystemException {
102 
103         HttpServletRequest request = PortalUtil.getHttpServletRequest(
104             actionRequest);
105 
106         return updateUser(
107             request, userId, screenName, emailAddress, languageId, timeZoneId,
108             greeting, comments, smsSn, aimSn, facebookSn, icqSn, jabberSn,
109             msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
110     }
111 
112 }