public void joinGroup(
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);
Group group = GroupLocalServiceUtil.getGroup(
themeDisplay.getScopeGroupId());
if (group.getType() == GroupConstants.TYPE_COMMUNITY_OPEN) {
UserLocalServiceUtil.addGroupUsers(
group.getGroupId(), new long[] {themeDisplay.getUserId()});
}
else {
Role role = RoleLocalServiceUtil.getRole(
themeDisplay.getCompanyId(), "Community Administrator");
LinkedHashMap<String, Object> userParams =
new LinkedHashMap<String, Object>();
userParams.put(
"userGroupRole",
new Long[] {new Long(group.getGroupId()),
new Long(role.getRoleId())});
List<User> users = UserLocalServiceUtil.search(
themeDisplay.getCompanyId(), null, Boolean.TRUE, userParams,
QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null);
for (User user : users) {
SocialRequestLocalServiceUtil.addRequest(
themeDisplay.getUserId(), 0, Group.class.getName(),
group.getGroupId(), MembersRequestKeys.ADD_MEMBER,
StringPool.BLANK, user.getUserId());
}
}
}