Example usage for com.liferay.portal.kernel.model RoleConstants SITE_ADMINISTRATOR

List of usage examples for com.liferay.portal.kernel.model RoleConstants SITE_ADMINISTRATOR

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model RoleConstants SITE_ADMINISTRATOR.

Prototype

String SITE_ADMINISTRATOR

To view the source code for com.liferay.portal.kernel.model RoleConstants SITE_ADMINISTRATOR.

Click Source Link

Usage

From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java

License:Open Source License

protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse)
        throws Exception {

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

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

    String filterBy = ParamUtil.getString(portletRequest, "filterBy");
    String keywords = ParamUtil.getString(portletRequest, "keywords");
    int start = ParamUtil.getInteger(portletRequest, "start");
    int end = ParamUtil.getInteger(portletRequest, "end");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject();

    optionsJSONObject.put("end", end);
    optionsJSONObject.put("filterBy", filterBy);
    optionsJSONObject.put("keywords", keywords);
    optionsJSONObject.put("start", start);

    jsonObject.put("options", optionsJSONObject);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<BaseModel<?>> contacts = entryLocalService.searchUsersAndContacts(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords, start, end);

        int contactsCount = entryLocalService.searchUsersAndContactsCount(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords);

        jsonObject.put("count", contactsCount);

        for (BaseModel<?> contact : contacts) {
            JSONObject contactJSONObject = null;

            if (contact instanceof User) {
                contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact);
            } else {
                contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact,
                        redirect);//from   w w  w .  j a va 2  s .c  o  m
            }

            jsonArray.put(contactJSONObject);
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<SocialRelation> socialRelations = socialRelationLocalService.getInverseRelations(
                themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);

        for (SocialRelation socialRelation : socialRelations) {
            jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1()));
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<Entry> entries = entryLocalService.search(themeDisplay.getUserId(), keywords, start, end);

        int entriesCount = entryLocalService.searchCount(themeDisplay.getUserId(), keywords);

        jsonObject.put("count", entriesCount);

        for (Entry entry : entries) {
            JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect);

            jsonArray.put(contactJSONObject);
        }
    } else {
        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("inherit", Boolean.TRUE);

        Group group = themeDisplay.getScopeGroup();
        Layout layout = themeDisplay.getLayout();

        if (group.isUser() && layout.isPublicLayout()) {
            params.put("socialRelationType",
                    new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION });
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) {
            params.put("socialRelationType",
                    new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) });
        }

        if (portletId.equals(ContactsPortletKeys.MEMBERS)) {
            params.put("usersGroups", group.getGroupId());
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) {
            params.put("usersGroups", ContactsUtil.getGroupId(filterBy));
        }

        List<User> usersList = null;

        if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) {
            Role siteAdministratorRole = roleLocalService.getRole(group.getCompanyId(),
                    RoleConstants.SITE_ADMINISTRATOR);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteAdministratorRole.getRoleId() });

            Set<User> users = new HashSet<>();

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            Role siteOwnerRole = roleLocalService.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteOwnerRole.getRoleId() });

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            usersList = new ArrayList<>(users);

            ListUtil.sort(usersList, new UserLastNameComparator(true));
        } else {
            int usersCount = userLocalService.searchCount(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params);

            jsonObject.put("count", usersCount);

            usersList = userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true));
        }

        for (User user : usersList) {
            JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user);

            jsonArray.put(userJSONObject);
        }
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
}

From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java

License:Open Source License

protected Set<User> getRecipients(long companyId, long groupId) throws PortalException {

    Set<User> recipients = new LinkedHashSet<>();

    List<String> roleNames = new ArrayList<>();

    Group group = _groupLocalService.getGroup(groupId);

    if (group.isSite()) {
        roleNames.add(RoleConstants.SITE_ADMINISTRATOR);
        roleNames.add(RoleConstants.SITE_OWNER);
    }/*from  w  w  w  .j  a va  2  s. com*/

    if (group.isCompany()) {
        roleNames.add(RoleConstants.ADMINISTRATOR);
    } else if (group.isOrganization()) {
        roleNames.add(RoleConstants.ORGANIZATION_ADMINISTRATOR);
        roleNames.add(RoleConstants.ORGANIZATION_OWNER);
    }

    for (String roleName : roleNames) {
        Role role = _roleLocalService.getRole(companyId, roleName);

        List<UserGroupRole> userGroupRoles = _userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(groupId,
                role.getRoleId());

        for (UserGroupRole userGroupRole : userGroupRoles) {
            recipients.add(userGroupRole.getUser());
        }
    }

    if (recipients.isEmpty()) {
        Role role = _roleLocalService.getRole(companyId, RoleConstants.ADMINISTRATOR);

        recipients.addAll(_userLocalService.getRoleUsers(role.getRoleId()));
    }

    return recipients;
}

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

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

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

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    String name = ParamUtil.getString(actionRequest, "name");
    int scope = ParamUtil.getInteger(actionRequest, "scope");
    String primKey = ParamUtil.getString(actionRequest, "primKey");
    String actionId = ParamUtil.getString(actionRequest, "actionId");

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }/*from w  w w .  j  a  v  a  2  s .c  om*/

    _resourcePermissionService.removeResourcePermission(themeDisplay.getScopeGroupId(),
            themeDisplay.getCompanyId(), name, scope, primKey, roleId, actionId);

    // Send redirect

    SessionMessages.add(actionRequest, "permissionDeleted");

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

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

public Role editRole(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    String name = ParamUtil.getString(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    int type = ParamUtil.getInteger(actionRequest, "type", RoleConstants.TYPE_REGULAR);
    String subtype = ParamUtil.getString(actionRequest, "subtype");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Role.class.getName(), actionRequest);

    if (roleId <= 0) {

        // Add role

        Role role = _roleService.addRole(null, 0, name, titleMap, descriptionMap, type, subtype,
                serviceContext);//from ww  w  .  ja v a2s .c  o m

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

        redirect = _http.setParameter(redirect, actionResponse.getNamespace() + "roleId", role.getRoleId());

        actionRequest.setAttribute(WebKeys.REDIRECT, redirect);

        SessionMessages.add(actionRequest, "roleCreated");

        actionResponse.sendRedirect(redirect);

        return role;
    } else {

        // Update role

        if (name.equals(RoleConstants.SITE_ADMINISTRATOR)) {
            Role role = _roleLocalService.getRole(roleId);
            ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
            boolean manageSubgroups = ParamUtil.getBoolean(actionRequest, "manageSubgroups");

            updateAction(role, themeDisplay.getScopeGroupId(), Group.class.getName(),
                    ActionKeys.MANAGE_SUBGROUPS, manageSubgroups, ResourceConstants.SCOPE_GROUP_TEMPLATE,
                    new String[0]);
        }

        return _roleService.updateRole(roleId, name, titleMap, descriptionMap, subtype, serviceContext);
    }
}

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

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

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

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

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }/*from  ww  w . j  av a2s  . c o  m*/

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources = StringUtil
            .split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources = StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
        resourceActionsMap.put(portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
        resourceActionsMap.put(relatedPortletResource,
                ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
        resourceActionsMap.put(modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

        String selResource = entry.getKey();
        List<String> actions = entry.getValue();

        actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

        for (String actionId : actions) {
            String target = selResource + actionId;

            boolean selected = ArrayUtil.contains(selectedTargets, target);

            if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

                continue;
            }

            String[] groupIds = StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

            groupIds = ArrayUtil.distinct(groupIds);

            int scope = ResourceConstants.SCOPE_COMPANY;

            if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
                    || (role.getType() == RoleConstants.TYPE_PROVIDER)
                    || (role.getType() == RoleConstants.TYPE_SITE)) {

                scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
            } else {
                if (groupIds.length > 0) {
                    scope = ResourceConstants.SCOPE_GROUP;
                }
            }

            updateAction(role, themeDisplay.getScopeGroupId(), selResource, actionId, selected, scope,
                    groupIds);

            if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

                updateViewControlPanelPermission(role, themeDisplay.getScopeGroupId(), selResource, scope,
                        groupIds);

                rootResourceScope = scope;
                rootResourceGroupIds = groupIds;
            }
        }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
        updateViewRootResourcePermission(role, themeDisplay.getScopeGroupId(), portletResource,
                rootResourceScope, rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}

From source file:com.liferay.site.service.persistence.test.GroupServicePermissionTest.java

License:Open Source License

protected void giveSiteAdminRole(Group group) throws Exception {
    Role role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.SITE_ADMINISTRATOR);

    long[] roleIds = { role.getRoleId() };

    UserGroupRoleLocalServiceUtil.addUserGroupRoles(_user.getUserId(), group.getGroupId(), roleIds);
}

From source file:com.liferay.users.admin.demo.data.creator.internal.SiteAdminUserDemoDataCreatorImpl.java

License:Open Source License

@Override
public User create(long groupId, String emailAddress) throws PortalException {

    Group group = _groupLocalService.getGroup(groupId);

    User user = createUser(group.getCompanyId(), emailAddress);

    userLocalService.addGroupUser(groupId, user.getUserId());

    Role role = _roleLocalService.getRole(group.getCompanyId(), RoleConstants.SITE_ADMINISTRATOR);

    _userGroupRoleLocalService.addUserGroupRoles(user.getUserId(), groupId, new long[] { role.getRoleId() });

    return userLocalService.getUser(user.getUserId());
}