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
50 public class AdminUtil {
51
52 public static String getUpdateUserPassword(
53 HttpServletRequest request, long userId) {
54
55 String password = PortalUtil.getUserPassword(request);
56
57 if (userId != PortalUtil.getUserId(request)) {
58 password = StringPool.BLANK;
59 }
60
61 return password;
62 }
63
64 public static String getUpdateUserPassword(
65 ActionRequest actionRequest, long userId) {
66
67 HttpServletRequest request = PortalUtil.getHttpServletRequest(
68 actionRequest);
69
70 return getUpdateUserPassword(request, userId);
71 }
72
73 public static User updateUser(
74 HttpServletRequest request, long userId, String screenName,
75 String emailAddress, String openId, String languageId,
76 String timeZoneId, String greeting, String comments, String smsSn,
77 String aimSn, String facebookSn, String icqSn, String jabberSn,
78 String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
79 String ymSn)
80 throws PortalException, SystemException {
81
82 String password = getUpdateUserPassword(request, userId);
83
84 User user = UserLocalServiceUtil.getUserById(userId);
85
86 Contact contact = user.getContact();
87
88 Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
89
90 birthdayCal.setTime(contact.getBirthday());
91
92 int birthdayMonth = birthdayCal.get(Calendar.MONTH);
93 int birthdayDay = birthdayCal.get(Calendar.DATE);
94 int birthdayYear = birthdayCal.get(Calendar.YEAR);
95
96 long[] groupIds = null;
97 long[] organizationIds = null;
98 long[] roleIds = null;
99 List<UserGroupRole> userGroupRoles = null;
100 long[] userGroupIds = null;
101 ServiceContext serviceContext = new ServiceContext();
102
103 return UserServiceUtil.updateUser(
104 userId, password, StringPool.BLANK, StringPool.BLANK,
105 user.isPasswordReset(), user.getReminderQueryQuestion(),
106 user.getReminderQueryAnswer(), screenName, emailAddress, openId,
107 languageId, timeZoneId, greeting, comments, contact.getFirstName(),
108 contact.getMiddleName(), contact.getLastName(),
109 contact.getPrefixId(), contact.getSuffixId(), contact.isMale(),
110 birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn,
111 icqSn, jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn,
112 contact.getJobTitle(), groupIds, organizationIds, roleIds,
113 userGroupRoles, userGroupIds, serviceContext);
114 }
115
116 public static User updateUser(
117 ActionRequest actionRequest, long userId, String screenName,
118 String emailAddress, String openId, String languageId,
119 String timeZoneId, String greeting, String comments, String smsSn,
120 String aimSn, String facebookSn, String icqSn, String jabberSn,
121 String msnSn, String mySpaceSn, String skypeSn, String twitterSn,
122 String ymSn)
123 throws PortalException, SystemException {
124
125 HttpServletRequest request = PortalUtil.getHttpServletRequest(
126 actionRequest);
127
128 return updateUser(
129 request, userId, screenName, emailAddress, openId, languageId,
130 timeZoneId, greeting, comments, smsSn, aimSn, facebookSn, icqSn,
131 jabberSn, msnSn, mySpaceSn, skypeSn, twitterSn, ymSn);
132 }
133
134 }