【发布时间】:2015-12-26 05:58:34
【问题描述】:
这里我有一个以编程方式添加用户的代码。在代码中,第 5 行和第 6 行中有 SocialDriverConstants,这是一个类,所以如果有人有该类的代码,请分享。此代码可在 James Falkner 的 Liferay 博客中找到。代码是:
public synchronized static User addUser(String firstName, long companyId,
String themeId, boolean profileFlag)
throws Exception {
String lastName = getRndStr(SocialDriverConstants.LAST_NAMES);
String job = getRndStr(SocialDriverConstants.JOB_TITLES);
Group guestGroup = GroupLocalServiceUtil.getGroup(
companyId, GroupConstants.GUEST);
long[] groupIds;
try {
// see if there's a demo sales group, and add the user to the
// group if so
Group salesGroup = GroupLocalServiceUtil.getGroup(
companyId, "Sales");
groupIds = new long[]{guestGroup.getGroupId(),
salesGroup.getGroupId()};
} catch (Exception ex) {
groupIds = new long[]{guestGroup.getGroupId()};
}
ServiceContext serviceContext = new ServiceContext();
long[] roleIds;
try {
// see if we're using social office, and add SO's role to the new
// user if so
roleIds = new long[]{RoleLocalServiceUtil.getRole(companyId,
"Social Office User").getRoleId()};
serviceContext.setScopeGroupId(guestGroup.getGroupId());
} catch (Exception ignored) {
roleIds = new long[]{};
}
User user = UserLocalServiceUtil.addUser(UserLocalServiceUtil
.getDefaultUserId(companyId), companyId, false,
firstName,
firstName,
false, firstName.toLowerCase(), firstName.toLowerCase() +
"@liferay.com", 0, "",
LocaleUtil.getDefault(), firstName,
"", lastName, 0, 0, true, 8, 15, 1974, job, groupIds,
new long[]{}, roleIds, new long[]{},
false, serviceContext);
assignAddressTo(user);
setFirstLogin(firstName, user);
assignRandomFriends(user);
if (profileFlag) {
setupUserProfile(companyId, themeId, guestGroup, user);
}
return user;
}
我在哪里可以找到该课程?
【问题讨论】: