Search in sources :

Example 1 with Action

use of com.liferay.imex.role.model.Action 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 Action

use of com.liferay.imex.role.model.Action 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)

Aggregations

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