Search in sources :

Example 1 with Resource

use of com.liferay.imex.role.model.Resource in project liferay-imex by jpdacunha.

the class ExportRolePermissionsServiceImpl method getResource.

private Resource getResource(long companyId, long roleId, String resource, List<String> actions, boolean allActions) throws PortalException, SystemException {
    Resource r = new Resource();
    r.setResourceName(resource);
    Company company = companyLocalService.getCompany(companyId);
    Role role = roleLocalService.getRole(roleId);
    for (String actionId : actions) {
        Action action = new Action();
        action.setActionId(actionId);
        Scope scope = getScope(company, role, resource, actionId);
        action.setScope(scope);
        if (allActions || !scope.equals(Scope.NONE)) {
            r.getActionList().add(action);
            if (scope.equals(Scope.GROUP)) {
                LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>();
                @SuppressWarnings("rawtypes") List<Comparable> rolePermissions = new ArrayList<Comparable>();
                rolePermissions.add(resource);
                rolePermissions.add(new Integer(ResourceConstants.SCOPE_GROUP));
                rolePermissions.add(actionId);
                rolePermissions.add(new Long(role.getRoleId()));
                groupParams.put("rolePermissions", rolePermissions);
                List<Group> groups = groupLocalService.search(company.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
                for (Group group : groups) {
                    if (group.isSite()) {
                        action.getSitesNames().add(group.getName());
                    }
                /*else {
								_log.error("Group identified by [" + group.getFriendlyURL() + "] is not a site");
								throw new IllegalStateException();
							}*/
                }
            }
        }
    }
    return r;
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) Action(com.liferay.imex.role.model.Action) Resource(com.liferay.imex.role.model.Resource) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Role(com.liferay.portal.kernel.model.Role) Scope(com.liferay.imex.role.model.Scope)

Example 2 with Resource

use of com.liferay.imex.role.model.Resource in project liferay-imex by jpdacunha.

the class ImportRolePermissionsServiceImpl method updateActions.

private void updateActions(long companyId, Role role, PortletPermissions portletPermissions) throws Exception {
    List<Resource> resourceList = new LinkedList<Resource>();
    resourceList.add(portletPermissions.getPortletResource());
    resourceList.addAll(portletPermissions.getModelResourceList());
    for (Resource resource : resourceList) {
        List<String> actions = ResourceActionsUtil.getResourceActions(resource.getResourceName());
        actions = ListUtil.sort(actions);
        String selResource = resource.getResourceName();
        for (Action action : resource.getActionList()) {
            String actionId = action.getActionId();
            int scope = action.getScope().getIntValue();
            Set<String> groupNames = action.getSitesNames();
            String[] groupIds = new String[groupNames.size()];
            int i = 0;
            for (String groupName : groupNames) {
                Group group = groupLocalService.getGroup(companyId, groupName);
                groupIds[i] = Long.toString(group.getGroupId());
                i++;
            }
            updateAction(role, selResource, actionId, scope, groupIds);
            if (_log.isDebugEnabled()) {
                _log.debug("Updating role=[" + role.getName() + "], resource=[" + selResource + "], actionId=[" + actionId + "], scope=[" + scope + "], groupIds=[" + groupIds + "][" + groupIds.length + "]");
            }
        }
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) Action(com.liferay.imex.role.model.Action) Resource(com.liferay.imex.role.model.Resource) LinkedList(java.util.LinkedList)

Example 3 with Resource

use of com.liferay.imex.role.model.Resource in project liferay-imex by jpdacunha.

the class ExportRolePermissionsServiceImpl method getRolePermissions.

private RolePermissions getRolePermissions(long companyId, long roleId, boolean allActions) throws Exception {
    RolePermissions result = new RolePermissions();
    List<Portlet> portlets = portletLocalService.getPortlets(companyId, true, false);
    List<String> portletNames = new ArrayList<String>(portlets.size() + 1);
    for (Portlet portlet : portlets) {
        String portletName = portlet.getPortletId();
        portletNames.add(portletName);
    }
    portletNames.add(PortletKeys.PORTAL);
    for (String portletName : portletNames) {
        PortletPermissions portletPermissions = new PortletPermissions();
        List<String> modelResources = ResourceActionsUtil.getPortletModelResources(portletName);
        for (String modelResource : modelResources) {
            Resource r = getModelResource(companyId, roleId, modelResource, allActions);
            if (allActions || r.getActionList().size() > 0) {
                portletPermissions.getModelResourceList().add(r);
            }
        }
        Resource pr = getPortletResource(companyId, roleId, portletName, allActions);
        portletPermissions.setPortletResource(pr);
        if (allActions || portletPermissions.getModelResourceList().size() > 0 || pr.getActionList().size() > 0) {
            result.getPortletPermissionsList().add(portletPermissions);
        }
    }
    return result;
}
Also used : RolePermissions(com.liferay.imex.role.model.RolePermissions) Portlet(com.liferay.portal.kernel.model.Portlet) PortletPermissions(com.liferay.imex.role.model.PortletPermissions) ArrayList(java.util.ArrayList) Resource(com.liferay.imex.role.model.Resource)

Aggregations

Resource (com.liferay.imex.role.model.Resource)3 Action (com.liferay.imex.role.model.Action)2 Group (com.liferay.portal.kernel.model.Group)2 ArrayList (java.util.ArrayList)2 PortletPermissions (com.liferay.imex.role.model.PortletPermissions)1 RolePermissions (com.liferay.imex.role.model.RolePermissions)1 Scope (com.liferay.imex.role.model.Scope)1 Company (com.liferay.portal.kernel.model.Company)1 Portlet (com.liferay.portal.kernel.model.Portlet)1 Role (com.liferay.portal.kernel.model.Role)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1