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.service.UserLocalServiceUtil;
32  import com.liferay.portal.service.UserServiceUtil;
33  import com.liferay.portal.util.PortalUtil;
34  
35  import java.rmi.RemoteException;
36  
37  import java.util.Calendar;
38  
39  import javax.portlet.ActionRequest;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  /**
44   * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   */
48  public class AdminUtil {
49  
50      public static String getUpdateUserPassword(
51          HttpServletRequest request, long userId) {
52  
53          String password = PortalUtil.getUserPassword(request);
54  
55          if (userId != PortalUtil.getUserId(request)) {
56              password = StringPool.BLANK;
57          }
58  
59          return password;
60      }
61  
62      public static String getUpdateUserPassword(
63          ActionRequest actionRequest, long userId) {
64  
65          HttpServletRequest request = PortalUtil.getHttpServletRequest(
66              actionRequest);
67  
68          return getUpdateUserPassword(request, userId);
69      }
70  
71      public static User updateUser(
72              HttpServletRequest request, long userId, String screenName,
73              String emailAddress, String languageId, String timeZoneId,
74              String greeting, String comments, String smsSn, String aimSn,
75              String facebookSn, String icqSn, String jabberSn, String msnSn,
76              String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
77          throws PortalException, RemoteException, SystemException {
78  
79          String password = getUpdateUserPassword(request, userId);
80  
81          User user = UserLocalServiceUtil.getUserById(userId);
82  
83          Contact contact = user.getContact();
84  
85          Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
86  
87          birthdayCal.setTime(contact.getBirthday());
88  
89          int birthdayMonth = birthdayCal.get(Calendar.MONTH);
90          int birthdayDay = birthdayCal.get(Calendar.DATE);
91          int birthdayYear = birthdayCal.get(Calendar.YEAR);
92  
93          return UserServiceUtil.updateUser(
94              userId, password, user.isPasswordReset(), screenName, emailAddress,
95              languageId, timeZoneId, greeting, comments, contact.getFirstName(),
96              contact.getMiddleName(), contact.getLastName(),
97              contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
98              birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
99              icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
100             contact.getJobTitle(), user.getOrganizationIds());
101     }
102 
103     public static User updateUser(
104             ActionRequest actionRequest, long userId, String screenName,
105             String emailAddress, String languageId, String timeZoneId,
106             String greeting, String comments, String smsSn, String aimSn,
107             String facebookSn, String icqSn, String jabberSn, String msnSn,
108             String mySpaceSn, String skypeSn, String twitterSn, String ymSn)
109         throws PortalException, RemoteException, SystemException {
110 
111         HttpServletRequest request = PortalUtil.getHttpServletRequest(
112             actionRequest);
113 
114         return updateUser(
115             request, userId, screenName, emailAddress, languageId, timeZoneId,
116             greeting, comments, smsSn, aimSn, facebookSn, icqSn, jabberSn,
117             msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
118     }
119 
120 }