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;
}
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 + "]");
}
}
}
}
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;
}
Aggregations