use of com.liferay.imex.role.model.Scope 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;
}
use of com.liferay.imex.role.model.Scope in project liferay-imex by jpdacunha.
the class ExportRolePermissionsServiceImpl method getScope.
private Scope getScope(Company company, Role role, String curResource, String actionId) throws PortalException, SystemException {
boolean hasCompanyScope = false;
boolean hasGroupTemplateScope = false;
boolean hasGroupScope = false;
hasCompanyScope = (role.getType() == RoleConstants.TYPE_REGULAR) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_COMPANY, role.getRoleId(), actionId);
hasGroupTemplateScope = ((role.getType() == RoleConstants.TYPE_SITE) || (role.getType() == RoleConstants.TYPE_ORGANIZATION)) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_GROUP_TEMPLATE, role.getRoleId(), actionId);
hasGroupScope = (role.getType() == RoleConstants.TYPE_REGULAR) && resourcePermissionLocalService.hasScopeResourcePermission(company.getCompanyId(), curResource, ResourceConstants.SCOPE_GROUP, role.getRoleId(), actionId);
Scope result = null;
if (hasCompanyScope) {
result = Scope.COMPANY;
} else if (hasGroupTemplateScope) {
result = Scope.GROUP_TEMPLATE;
} else if (hasGroupScope) {
result = Scope.GROUP;
} else {
result = Scope.NONE;
}
return result;
}
Aggregations