Example usage for com.liferay.portal.liveusers LiveUsers joinGroup

List of usage examples for com.liferay.portal.liveusers LiveUsers joinGroup

Introduction

In this page you can find the example usage for com.liferay.portal.liveusers LiveUsers joinGroup.

Prototype

public static void joinGroup(long companyId, long groupId, long[] userIds) 

Source Link

Usage

From source file:com.liferay.portlet.sites.action.EditGroupAction.java

License:Open Source License

protected Object[] updateGroup(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long userId = PortalUtil.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");
    int type = ParamUtil.getInteger(actionRequest, "type");
    String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
    boolean active = ParamUtil.getBoolean(actionRequest, "active");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    Group liveGroup = null;/*from   www . ja  va 2 s .  co  m*/
    String oldFriendlyURL = null;
    String oldStagingFriendlyURL = null;

    if (liveGroupId <= 0) {

        // Add group

        liveGroup = GroupServiceUtil.addGroup(name, description, type, friendlyURL, true, active,
                serviceContext);

        LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

        // Update group

        liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);

        oldFriendlyURL = liveGroup.getFriendlyURL();

        liveGroup = GroupServiceUtil.updateGroup(liveGroupId, name, description, type, friendlyURL, active,
                serviceContext);

        if (type == GroupConstants.TYPE_SITE_OPEN) {
            List<MembershipRequest> membershipRequests = MembershipRequestLocalServiceUtil.search(liveGroupId,
                    MembershipRequestConstants.STATUS_PENDING, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

            for (MembershipRequest membershipRequest : membershipRequests) {
                MembershipRequestServiceUtil.updateStatus(membershipRequest.getMembershipRequestId(),
                        themeDisplay.translate("your-membership-has-been-approved"),
                        MembershipRequestConstants.STATUS_APPROVED, serviceContext);

                LiveUsers.joinGroup(themeDisplay.getCompanyId(), membershipRequest.getGroupId(),
                        new long[] { membershipRequest.getUserId() });
            }
        }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName = ParamUtil.getString(actionRequest, "customJspServletContextName");

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    String googleAnalyticsId = ParamUtil.getString(actionRequest, "googleAnalyticsId");

    typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);

    String publicRobots = ParamUtil.getString(actionRequest, "publicRobots");
    String privateRobots = ParamUtil.getString(actionRequest, "privateRobots");

    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);

    String publicVirtualHost = ParamUtil.getString(actionRequest, "publicVirtualHost");
    String privateVirtualHost = ParamUtil.getString(actionRequest, "privateVirtualHost");

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    if (liveGroup.hasStagingGroup()) {
        Group stagingGroup = liveGroup.getStagingGroup();

        oldStagingFriendlyURL = stagingGroup.getFriendlyURL();

        publicVirtualHost = ParamUtil.getString(actionRequest, "stagingPublicVirtualHost");
        privateVirtualHost = ParamUtil.getString(actionRequest, "stagingPrivateVirtualHost");
        friendlyURL = ParamUtil.getString(actionRequest, "stagingFriendlyURL");

        LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

        LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);

        GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);
    }

    liveGroup = GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();
    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    if (!liveGroup.isStaged()) {
        long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
        long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

        if ((privateLayoutSetPrototypeId == 0) && (publicLayoutSetPrototypeId == 0)) {

            long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
            int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");

            if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
                privateLayoutSetPrototypeId = layoutSetPrototypeId;
            } else {
                publicLayoutSetPrototypeId = layoutSetPrototypeId;
            }
        }

        if ((publicLayoutSetPrototypeId > 0) || (privateLayoutSetPrototypeId > 0)) {

            SitesUtil.applyLayoutSetPrototypes(liveGroup, publicLayoutSetPrototypeId,
                    privateLayoutSetPrototypeId, serviceContext);
        } else {
            boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(serviceContext,
                    "privateLayoutSetPrototypeLinkEnabled");

            if (privateLayoutSetPrototypeLinkEnabled != privateLayoutSet.isLayoutSetPrototypeLinkEnabled()) {

                LayoutSetServiceUtil.updateLayoutSetPrototypeLinkEnabled(liveGroupId, true,
                        privateLayoutSetPrototypeLinkEnabled);
            }

            boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(serviceContext,
                    "publicLayoutSetPrototypeLinkEnabled");

            if (publicLayoutSetPrototypeLinkEnabled != publicLayoutSet.isLayoutSetPrototypeLinkEnabled()) {

                LayoutSetServiceUtil.updateLayoutSetPrototypeLinkEnabled(liveGroupId, false,
                        publicLayoutSetPrototypeLinkEnabled);
            }
        }
    }

    // Staging

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false));

    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive()
            && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {

        if ((refererPlid > 0) && liveGroup.hasStagingGroup()
                && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {

            Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(liveGroup.getGroupId(), false,
                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

            if (firstLayout == null) {
                firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(liveGroup.getGroupId(), true,
                        LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
            }

            if (firstLayout != null) {
                refererPlid = firstLayout.getPlid();
            } else {
                refererPlid = 0;
            }
        }

        StagingUtil.updateStaging(actionRequest, liveGroup);
    }

    return new Object[] { liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid };
}

From source file:com.liferay.portlet.sites.action.EditGroupAssignmentsAction.java

License:Open Source License

protected void updateGroupUsers(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    long[] addUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "addUserIds"), 0L);
    long[] removeUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "removeUserIds"), 0L);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    UserServiceUtil.addGroupUsers(groupId, addUserIds, serviceContext);
    UserServiceUtil.unsetGroupUsers(groupId, removeUserIds, serviceContext);

    LiveUsers.joinGroup(themeDisplay.getCompanyId(), groupId, addUserIds);
    LiveUsers.leaveGroup(themeDisplay.getCompanyId(), groupId, removeUserIds);
}

From source file:com.liferay.portlet.sites.action.ReplyMembershipRequestAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    try {/*w ww  . j  a  v  a 2s .co m*/
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        long membershipRequestId = ParamUtil.getLong(actionRequest, "membershipRequestId");

        int statusId = ParamUtil.getInteger(actionRequest, "statusId");
        String replyComments = ParamUtil.getString(actionRequest, "replyComments");

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        MembershipRequestServiceUtil.updateStatus(membershipRequestId, replyComments, statusId, serviceContext);

        if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
            MembershipRequest membershipRequest = MembershipRequestServiceUtil
                    .getMembershipRequest(membershipRequestId);

            LiveUsers.joinGroup(themeDisplay.getCompanyId(), membershipRequest.getGroupId(),
                    new long[] { membershipRequest.getUserId() });
        }

        SessionMessages.add(actionRequest, "membership_reply_sent");

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.sites_admin.error");
        } else if (e instanceof MembershipRequestCommentsException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.sites_admin.reply_membership_request");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.site.admin.web.internal.portlet.SiteAdminPortlet.java

License:Open Source License

protected Group updateGroup(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long userId = portal.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    long parentGroupId = ParamUtil.getLong(actionRequest, "parentGroupSearchContainerPrimaryKeys",
            GroupConstants.DEFAULT_PARENT_GROUP_ID);
    Map<Locale, String> nameMap = null;
    Map<Locale, String> descriptionMap = null;
    int type = 0;
    String friendlyURL = null;/*  ww w.  jav  a2s.c  o  m*/
    boolean inheritContent = false;
    boolean active = false;
    boolean manualMembership = true;

    int membershipRestriction = GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION;

    boolean actionRequestMembershipRestriction = ParamUtil.getBoolean(actionRequest, "membershipRestriction");

    if (actionRequestMembershipRestriction && (parentGroupId != GroupConstants.DEFAULT_PARENT_GROUP_ID)) {

        membershipRestriction = GroupConstants.MEMBERSHIP_RESTRICTION_TO_PARENT_SITE_MEMBERS;
    }

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    ServiceContextThreadLocal.pushServiceContext(serviceContext);

    Group liveGroup = null;

    if (liveGroupId <= 0) {

        // Add group

        nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
        descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
        type = ParamUtil.getInteger(actionRequest, "type");
        friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
        manualMembership = ParamUtil.getBoolean(actionRequest, "manualMembership");
        inheritContent = ParamUtil.getBoolean(actionRequest, "inheritContent");
        active = ParamUtil.getBoolean(actionRequest, "active");

        liveGroup = groupService.addGroup(parentGroupId, GroupConstants.DEFAULT_LIVE_GROUP_ID, nameMap,
                descriptionMap, type, manualMembership, membershipRestriction, friendlyURL, true,
                inheritContent, active, serviceContext);

        LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

        // Update group

        liveGroup = groupLocalService.getGroup(liveGroupId);

        nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name", liveGroup.getNameMap());
        descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description",
                liveGroup.getDescriptionMap());
        type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType());
        manualMembership = ParamUtil.getBoolean(actionRequest, "manualMembership",
                liveGroup.isManualMembership());
        friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
        inheritContent = ParamUtil.getBoolean(actionRequest, "inheritContent", liveGroup.getInheritContent());
        active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive());

        liveGroup = groupService.updateGroup(liveGroupId, parentGroupId, nameMap, descriptionMap, type,
                manualMembership, membershipRestriction, friendlyURL, inheritContent, active, serviceContext);

        if (type == GroupConstants.TYPE_SITE_OPEN) {
            List<MembershipRequest> membershipRequests = membershipRequestLocalService.search(liveGroupId,
                    MembershipRequestConstants.STATUS_PENDING, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

            for (MembershipRequest membershipRequest : membershipRequests) {
                membershipRequestService.updateStatus(membershipRequest.getMembershipRequestId(),
                        themeDisplay.translate("your-membership-has-been-approved"),
                        MembershipRequestConstants.STATUS_APPROVED, serviceContext);

                LiveUsers.joinGroup(themeDisplay.getCompanyId(), membershipRequest.getGroupId(),
                        new long[] { membershipRequest.getUserId() });
            }
        }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName = ParamUtil.getString(actionRequest, "customJspServletContextName",
            typeSettingsProperties.getProperty("customJspServletContextName"));

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    typeSettingsProperties.setProperty("defaultSiteRoleIds",
            ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA));
    typeSettingsProperties.setProperty("defaultTeamIds",
            ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

    String[] analyticsTypes = PrefsPropsUtil.getStringArray(themeDisplay.getCompanyId(),
            PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE);

    for (String analyticsType : analyticsTypes) {
        if (StringUtil.equalsIgnoreCase(analyticsType, "google")) {
            String googleAnalyticsId = ParamUtil.getString(actionRequest, "googleAnalyticsId",
                    typeSettingsProperties.getProperty("googleAnalyticsId"));

            typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);
        } else {
            String analyticsScript = ParamUtil.getString(actionRequest, Sites.ANALYTICS_PREFIX + analyticsType,
                    typeSettingsProperties.getProperty(analyticsType));

            typeSettingsProperties.setProperty(Sites.ANALYTICS_PREFIX + analyticsType, analyticsScript);
        }
    }

    boolean trashEnabled = ParamUtil.getBoolean(actionRequest, "trashEnabled",
            GetterUtil.getBoolean(typeSettingsProperties.getProperty("trashEnabled"), true));

    typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled));

    int trashEntriesMaxAgeCompany = PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(),
            PropsKeys.TRASH_ENTRIES_MAX_AGE);

    int trashEntriesMaxAgeGroup = ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge");

    if (trashEntriesMaxAgeGroup <= 0) {
        trashEntriesMaxAgeGroup = GetterUtil.getInteger(
                typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany);
    }

    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
        typeSettingsProperties.setProperty("trashEntriesMaxAge",
                String.valueOf(GetterUtil.getInteger(trashEntriesMaxAgeGroup)));
    } else {
        typeSettingsProperties.remove("trashEntriesMaxAge");
    }

    int contentSharingWithChildrenEnabled = ParamUtil.getInteger(actionRequest,
            "contentSharingWithChildrenEnabled",
            GetterUtil.getInteger(typeSettingsProperties.getProperty("contentSharingWithChildrenEnabled"),
                    Sites.CONTENT_SHARING_WITH_CHILDREN_DEFAULT_VALUE));

    typeSettingsProperties.setProperty("contentSharingWithChildrenEnabled",
            String.valueOf(contentSharingWithChildrenEnabled));

    UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    typeSettingsProperties.putAll(formTypeSettingsProperties);

    // Virtual hosts

    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    String publicVirtualHost = ParamUtil.getString(actionRequest, "publicVirtualHost",
            publicLayoutSet.getVirtualHostname());

    layoutSetService.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();

    String privateVirtualHost = ParamUtil.getString(actionRequest, "privateVirtualHost",
            privateLayoutSet.getVirtualHostname());

    layoutSetService.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    // Staging

    if (liveGroup.hasStagingGroup()) {
        Group stagingGroup = liveGroup.getStagingGroup();

        friendlyURL = ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL());

        groupService.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);

        LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet();

        publicVirtualHost = ParamUtil.getString(actionRequest, "stagingPublicVirtualHost",
                stagingPublicLayoutSet.getVirtualHostname());

        layoutSetService.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

        LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet();

        privateVirtualHost = ParamUtil.getString(actionRequest, "stagingPrivateVirtualHost",
                stagingPrivateLayoutSet.getVirtualHostname());

        layoutSetService.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);

        UnicodeProperties stagedGroupTypeSettingsProperties = stagingGroup.getTypeSettingsProperties();

        stagedGroupTypeSettingsProperties.putAll(formTypeSettingsProperties);

        groupService.updateGroup(stagingGroup.getGroupId(), stagedGroupTypeSettingsProperties.toString());
    }

    liveGroup = groupService.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
    long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

    boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest,
            "privateLayoutSetPrototypeLinkEnabled", privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
    boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest,
            "publicLayoutSetPrototypeLinkEnabled", publicLayoutSet.isLayoutSetPrototypeLinkEnabled());

    if ((privateLayoutSetPrototypeId == 0) && (publicLayoutSetPrototypeId == 0)
            && !privateLayoutSetPrototypeLinkEnabled && !publicLayoutSetPrototypeLinkEnabled) {

        long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
        int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");
        boolean layoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest,
                "layoutSetPrototypeLinkEnabled", layoutSetPrototypeId > 0);

        if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
            privateLayoutSetPrototypeId = layoutSetPrototypeId;

            privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        } else {
            publicLayoutSetPrototypeId = layoutSetPrototypeId;

            publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        }
    }

    if (!liveGroup.isStaged() || liveGroup.isStagedRemotely()) {
        SitesUtil.updateLayoutSetPrototypesLinks(liveGroup, publicLayoutSetPrototypeId,
                privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled,
                privateLayoutSetPrototypeLinkEnabled);
    } else {
        SitesUtil.updateLayoutSetPrototypesLinks(liveGroup.getStagingGroup(), publicLayoutSetPrototypeId,
                privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled,
                privateLayoutSetPrototypeLinkEnabled);
    }

    themeDisplay.setSiteGroupId(liveGroup.getGroupId());

    return liveGroup;
}

From source file:com.liferay.site.memberships.web.internal.portlet.SiteMembershipsPortlet.java

License:Open Source License

public void addGroupUsers(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    Group group = _getGroup(actionRequest, actionResponse);

    long groupId = group.getGroupId();

    long[] addUserIds = ParamUtil.getLongValues(actionRequest, "rowIds");

    addUserIds = filterAddUserIds(groupId, addUserIds);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _userService.addGroupUsers(groupId, addUserIds, serviceContext);

    LiveUsers.joinGroup(group.getCompanyId(), groupId, addUserIds);
}

From source file:com.liferay.site.memberships.web.internal.portlet.SiteMembershipsPortlet.java

License:Open Source License

public void replyMembershipRequest(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    Group group = _getGroup(actionRequest, actionResponse);

    long membershipRequestId = ParamUtil.getLong(actionRequest, "membershipRequestId");

    long statusId = ParamUtil.getLong(actionRequest, "statusId");
    String replyComments = ParamUtil.getString(actionRequest, "replyComments");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _membershipRequestService.updateStatus(membershipRequestId, replyComments, statusId, serviceContext);

    if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
        MembershipRequest membershipRequest = _membershipRequestService
                .getMembershipRequest(membershipRequestId);

        LiveUsers.joinGroup(group.getCompanyId(), membershipRequest.getGroupId(),
                new long[] { membershipRequest.getUserId() });
    }/*  w  w w.j a va2s.  com*/

    SessionMessages.add(actionRequest, "membershipReplySent");

    sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.site.my.sites.web.internal.portlet.MySitesPortlet.java

License:Open Source License

public void updateGroupUsers(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    long[] addUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "addUserIds"), 0L);

    addUserIds = filterAddUserIds(groupId, addUserIds);

    long[] removeUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "removeUserIds"), 0L);

    removeUserIds = filterRemoveUserIds(groupId, removeUserIds);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _userService.addGroupUsers(groupId, addUserIds, serviceContext);
    _userService.unsetGroupUsers(groupId, removeUserIds, serviceContext);

    LiveUsers.joinGroup(themeDisplay.getCompanyId(), groupId, addUserIds);
    LiveUsers.leaveGroup(themeDisplay.getCompanyId(), groupId, removeUserIds);
}