1
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
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 }