Example usage for com.liferay.portal.kernel.service OrganizationLocalServiceUtil getOrganization

List of usage examples for com.liferay.portal.kernel.service OrganizationLocalServiceUtil getOrganization

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service OrganizationLocalServiceUtil getOrganization.

Prototype

public static com.liferay.portal.kernel.model.Organization getOrganization(long organizationId)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the organization with the primary key.

Usage

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

License:Open Source License

public static List<Organization> getOrganizations(ResourceRequest request) throws Exception {

    long[] organizationIds = ParamUtil.getLongValues(request, "rowIds");

    List<Organization> organizations = new ArrayList<>();

    for (long organizationId : organizationIds) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        organizations.add(organization);
    }//from  w  w  w  .  j  av a2s  .  co m

    return organizations;
}

From source file:com.liferay.site.teams.web.internal.display.context.SiteTeamsDisplayContext.java

License:Open Source License

protected void addBreadcrumbEntries() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Group group = themeDisplay.getScopeGroup();

    if (group.isOrganization()) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());

        UsersAdminUtil.addPortletBreadcrumbEntries(organization, _request, _renderResponse);
    } else {//from   w w w.  j  av a2  s . co m
        PortalUtil.addPortletBreadcrumbEntry(_request, group.getDescriptiveName(themeDisplay.getLocale()),
                null);
    }

    PortalUtil.addPortletBreadcrumbEntry(_request, LanguageUtil.get(_request, "manage-teams"),
            themeDisplay.getURLCurrent());
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularOrganizationServiceImpl.java

License:Open Source License

public long[] checkOrganizations(long userId, long[] organizationIds) throws PortalException {

    long[] oldOrganizationIds = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any mandatory organizations or organizations that the
        // administrator does not have the rights to remove and check that
        // he has the permission to add a new organization

        List<Organization> oldOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(userId);

        oldOrganizationIds = new long[oldOrganizations.size()];

        for (int i = 0; i < oldOrganizations.size(); i++) {
            Organization organization = oldOrganizations.get(i);

            if (!ArrayUtil.contains(organizationIds, organization.getOrganizationId())
                    && (!OrganizationPermissionUtil.contains(permissionChecker, organization,
                            ActionKeys.ASSIGN_MEMBERS)
                            || OrganizationMembershipPolicyUtil.isMembershipProtected(permissionChecker, userId,
                                    organization.getOrganizationId())
                            || OrganizationMembershipPolicyUtil.isMembershipRequired(userId,
                                    organization.getOrganizationId()))) {

                organizationIds = ArrayUtil.append(organizationIds, organization.getOrganizationId());
            }//from  w  ww.j  a  v  a  2 s  . c om

            oldOrganizationIds[i] = organization.getOrganizationId();
        }
    }

    // Check that the administrator has the permission to add a new
    // organization and that the organization membership is allowed

    for (long organizationId : organizationIds) {
        if ((oldOrganizationIds != null) && ArrayUtil.contains(oldOrganizationIds, organizationId)) {

            continue;
        }

        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        OrganizationPermissionUtil.check(permissionChecker, organization, ActionKeys.ASSIGN_MEMBERS);
    }

    return organizationIds;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java

License:Open Source License

public List<UserGroupRole> checkUserGroupRoles(long userId, List<UserGroupRole> userGroupRoles)
        throws PortalException {

    List<UserGroupRole> oldUserGroupRoles = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any user group roles that the administrator does not
        // have the rights to remove or that have a mandatory membership
        User user = UserLocalServiceUtil.getUser(userId);
        List<UserGroup> userGroups = user.getUserGroups();

        for (UserGroup userGroup : userGroups) {
            List<UserGroupRole> roles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId,
                    userGroup.getUserGroupId());
            oldUserGroupRoles.addAll(roles);
        }/*  w  w  w.  ja  va2  s  .c o  m*/

        for (UserGroupRole oldUserGroupRole : oldUserGroupRoles) {
            Role role = oldUserGroupRole.getRole();
            Group group = oldUserGroupRole.getGroup();

            if (userGroupRoles.contains(oldUserGroupRole)) {
                continue;
            }

            if (role.getType() == RoleConstants.TYPE_ORGANIZATION) {
                Organization organization = OrganizationLocalServiceUtil
                        .getOrganization(group.getOrganizationId());

                if (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                        || OrganizationMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                organization.getOrganizationId(), role.getRoleId())
                        || OrganizationMembershipPolicyUtil.isRoleRequired(userId,
                                organization.getOrganizationId(), role.getRoleId())) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            } else if (role.getType() == RoleConstants.TYPE_SITE) {
                if (!userGroupRoles.contains(oldUserGroupRole)
                        && (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role)
                                || SiteMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId,
                                        group.getGroupId(), role.getRoleId())
                                || SiteMembershipPolicyUtil.isRoleRequired(userId, group.getGroupId(),
                                        role.getRoleId()))) {

                    userGroupRoles.add(oldUserGroupRole);
                }
            }
        }
    }

    // Check that the administrator has the permission to add a new user
    // group role and that the user group role membership is allowed

    for (UserGroupRole userGroupRole : userGroupRoles) {
        if ((oldUserGroupRoles == null) || !oldUserGroupRoles.contains(userGroupRole)) {

            UserGroupRolePermissionUtil.check(permissionChecker, userGroupRole.getGroupId(),
                    userGroupRole.getRoleId());
        }
    }

    return userGroupRoles;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

/**
 * Removes the users from the organization.
 *
 * @param organizationId the primary key of the organization
 * @param userIds the primary keys of the users
 *//*ww w . j  a v a2 s . c  om*/
protected void unsetOrganizationUsers(long organizationId, final long[] userIds) throws PortalException {

    Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

    final Group group = organization.getGroup();

    UserGroupRoleLocalServiceUtil.deleteUserGroupRoles(userIds, group.getGroupId());
    UserLocalServiceUtil.deleteOrganizationUsers(organizationId, userIds);

    reindex(userIds);

    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Message message = new Message();

            message.put("groupId", group.getGroupId());
            message.put("userIds", userIds);

            MessageBusUtil.sendMessage(DestinationNames.SUBSCRIPTION_CLEAN_UP, message);

            return null;
        }

    };

    TransactionCommitCallbackUtil.registerCallback(callable);
}