1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.admin.util;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.util.CalendarFactoryUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.model.Contact;
27  import com.liferay.portal.model.User;
28  import com.liferay.portal.service.UserLocalServiceUtil;
29  import com.liferay.portal.service.UserServiceUtil;
30  import com.liferay.portal.util.PortalUtil;
31  
32  import java.rmi.RemoteException;
33  
34  import java.util.Calendar;
35  
36  import javax.portlet.ActionRequest;
37  
38  import javax.servlet.http.HttpServletRequest;
39  
40  /**
41   * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class AdminUtil {
47  
48      public static String getUpdateUserPassword(
49          HttpServletRequest request, long userId) {
50  
51          String password = PortalUtil.getUserPassword(request);
52  
53          if (userId != PortalUtil.getUserId(request)) {
54              password = StringPool.BLANK;
55          }
56  
57          return password;
58      }
59  
60      public static String getUpdateUserPassword(
61          ActionRequest actionRequest, long userId) {
62  
63          HttpServletRequest request = PortalUtil.getHttpServletRequest(
64              actionRequest);
65  
66          return getUpdateUserPassword(request, userId);
67      }
68  
69      public static User updateUser(
70              HttpServletRequest request, long userId, String screenName,
71              String emailAddress, String languageId, String timeZoneId,
72              String greeting, String comments, String smsSn, String aimSn,
73              String facebookSn, String icqSn, String jabberSn, String msnSn,
74              String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
75          throws PortalException, RemoteException, SystemException {
76  
77          String password = getUpdateUserPassword(request, userId);
78  
79          User user = UserLocalServiceUtil.getUserById(userId);
80  
81          Contact contact = user.getContact();
82  
83          Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
84  
85          birthdayCal.setTime(contact.getBirthday());
86  
87          int birthdayMonth = birthdayCal.get(Calendar.MONTH);
88          int birthdayDay = birthdayCal.get(Calendar.DATE);
89          int birthdayYear = birthdayCal.get(Calendar.YEAR);
90  
91          return UserServiceUtil.updateUser(
92              userId, password, user.isPasswordReset(), screenName, emailAddress,
93              languageId, timeZoneId, greeting, comments, contact.getFirstName(),
94              contact.getMiddleName(), contact.getLastName(),
95              contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
96              birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
97              icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
98              contact.getJobTitle(), user.getOrganizationIds());
99      }
100 
101     public static User updateUser(
102             ActionRequest actionRequest, long userId, String screenName,
103             String emailAddress, String languageId, String timeZoneId,
104             String greeting, String comments, String smsSn, String aimSn,
105             String facebookSn, String icqSn, String jabberSn, String msnSn,
106             String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
107         throws PortalException, RemoteException, SystemException {
108 
109         HttpServletRequest request = PortalUtil.getHttpServletRequest(
110             actionRequest);
111 
112         return updateUser(
113             request, userId, screenName, emailAddress, languageId, timeZoneId,
114             greeting, comments, smsSn, aimSn, facebookSn, icqSn, jabberSn,
115             msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
116     }
117 
118 }