001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.admin.util;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.CalendarFactoryUtil;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.model.Contact;
028: import com.liferay.portal.model.User;
029: import com.liferay.portal.service.UserLocalServiceUtil;
030: import com.liferay.portal.service.UserServiceUtil;
031: import com.liferay.portal.util.PortalUtil;
032:
033: import java.rmi.RemoteException;
034:
035: import java.util.Calendar;
036:
037: import javax.portlet.ActionRequest;
038:
039: import javax.servlet.http.HttpServletRequest;
040:
041: /**
042: * <a href="AdminUtil.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Brian Wing Shun Chan
045: *
046: */
047: public class AdminUtil {
048:
049: public static String getUpdateUserPassword(HttpServletRequest req,
050: long userId) {
051:
052: String password = PortalUtil.getUserPassword(req);
053:
054: if (userId != PortalUtil.getUserId(req)) {
055: password = StringPool.BLANK;
056: }
057:
058: return password;
059: }
060:
061: public static String getUpdateUserPassword(ActionRequest req,
062: long userId) {
063: HttpServletRequest httpReq = PortalUtil
064: .getHttpServletRequest(req);
065:
066: return getUpdateUserPassword(httpReq, userId);
067: }
068:
069: public static User updateUser(HttpServletRequest req, long userId,
070: String screenName, String emailAddress, String languageId,
071: String timeZoneId, String greeting, String comments,
072: String smsSn, String aimSn, String icqSn, String jabberSn,
073: String msnSn, String skypeSn, String ymSn)
074: throws PortalException, RemoteException, SystemException {
075:
076: String password = getUpdateUserPassword(req, userId);
077:
078: User user = UserLocalServiceUtil.getUserById(userId);
079:
080: Contact contact = user.getContact();
081:
082: Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
083:
084: birthdayCal.setTime(contact.getBirthday());
085:
086: int birthdayMonth = birthdayCal.get(Calendar.MONTH);
087: int birthdayDay = birthdayCal.get(Calendar.DATE);
088: int birthdayYear = birthdayCal.get(Calendar.YEAR);
089:
090: return UserServiceUtil.updateUser(userId, password, user
091: .isPasswordReset(), screenName, emailAddress,
092: languageId, timeZoneId, greeting, comments, contact
093: .getFirstName(), contact.getMiddleName(),
094: contact.getLastName(), contact.getPrefixId(), contact
095: .getSuffixId(), contact.isMale(),
096: birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn,
097: icqSn, jabberSn, msnSn, skypeSn, ymSn, contact
098: .getJobTitle(), user.getOrganizationIds());
099: }
100:
101: public static User updateUser(ActionRequest req, long userId,
102: String screenName, String emailAddress, String languageId,
103: String timeZoneId, String greeting, String comments,
104: String smsSn, String aimSn, String icqSn, String jabberSn,
105: String msnSn, String skypeSn, String ymSn)
106: throws PortalException, RemoteException, SystemException {
107:
108: HttpServletRequest httpReq = PortalUtil
109: .getHttpServletRequest(req);
110:
111: return updateUser(httpReq, userId, screenName, emailAddress,
112: languageId, timeZoneId, greeting, comments, smsSn,
113: aimSn, icqSn, jabberSn, msnSn, skypeSn, ymSn);
114: }
115:
116: }
|