【问题标题】:Where can I find the SocialDriverConstants class for this sample code?在哪里可以找到此示例代码的 SocialDriverConstants 类?
【发布时间】: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;
}

我在哪里可以找到该课程?

【问题讨论】:

    标签: liferay liferay-6


    【解决方案1】:

    评论James' blog article 可能更有意义(就像其他人已经做过的那样,检查那里的 cmets)而不是在不相关的地方,例如堆栈溢出。与互联网上的其他地方相比,他更有可能在自己的博客文章中阅读 cmets。

    话虽如此,根据您发布的代码使用它的假设,即生成随机名称/职位,想出该类的替代品应该很容易。只需为它们生成任何随机的东西,以便满足使用它们的 API(在本例中为:addUser

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      相关资源
      最近更新 更多