use of com.liferay.imex.role.model.RolePermissions in project liferay-imex by jpdacunha.
the class RoleImporter method doRoleImport.
private void doRoleImport(long companyId, User user, Properties config, File roleDir, boolean debug) {
if (roleDir != null) {
if (roleDir.exists()) {
String roleName = roleDir.getName();
String roleList = config.get(ImExRoleImporterPropsKeys.IMPORT_ROLES_IGNORE_LIST).toString();
if (!ImexPropsUtil.contains(roleName, roleList)) {
try {
File roleFile = new File(roleDir, FileNames.ROLE_FILENAME + processor.getFileExtension());
if (roleFile.exists()) {
// Importing roles
ImexRole imexRole = (ImexRole) processor.read(ImexRole.class, roleDir, FileNames.ROLE_FILENAME + processor.getFileExtension());
importService.importRole(companyId, user, imexRole);
// Importing roles permissions
File rolePermissionFile = new File(roleDir, FileNames.ROLE_PERMISSION_FILENAME + processor.getFileExtension());
if (rolePermissionFile.exists()) {
boolean reInitPermissions = GetterUtil.getBoolean(config.get(ImExRoleImporterPropsKeys.IMPORT_ROLES_RESET_PERMISSIONS).toString());
RolePermissions rolePermissions = (RolePermissions) processor.read(RolePermissions.class, roleDir, FileNames.ROLE_PERMISSION_FILENAME + processor.getFileExtension());
importPermissionService.updateRolePermissions(companyId, imexRole, rolePermissions, reInitPermissions);
} else {
reportService.getDNE(_log, rolePermissionFile.getAbsolutePath());
}
reportService.getOK(_log, imexRole.getName());
} else {
reportService.getDNE(_log, roleFile.getAbsolutePath());
}
} catch (Exception e) {
reportService.getError(_log, roleName, e);
if (debug) {
_log.error(e, e);
}
}
} else {
reportService.getSkipped(_log, roleName);
}
} else {
reportService.getDNE(_log, roleDir.getAbsolutePath());
}
} else {
_log.error("Skipping null roleDir ...");
}
}
use of com.liferay.imex.role.model.RolePermissions in project liferay-imex by jpdacunha.
the class RoleExporter method doRoleExport.
private void doRoleExport(Properties config, Role role, File rolesDir, boolean debug) throws ImexException {
if (role != null) {
Locale locale = LocaleUtil.getDefault();
String uuid = role.getUuid();
String name = role.getName();
int type = role.getType();
String description = role.getDescription(locale);
String friendlyURL = StringPool.BLANK;
long companyId = role.getCompanyId();
long roleId = role.getRoleId();
// No null control here because this param cannot be null
String roleList = config.get(ImExRoleExporterPropsKeys.EXPORT_ROLES_IGNORE_LIST).toString();
if (!ImexPropsUtil.contains(role.getName(), roleList)) {
File roleDir = initializeSingleRoleExportDirectory(rolesDir, role);
if (roleDir != null) {
if (roleDir.exists()) {
try {
// Writing role file
processor.write(new ImexRole(uuid, name, type, description, friendlyURL), roleDir, FileNames.ROLE_FILENAME + processor.getFileExtension());
// Writing role permission file
RolePermissions source = rolePermissionServive.getRolePermissions(companyId, roleId);
processor.write(source, roleDir, FileNames.ROLE_PERMISSION_FILENAME + processor.getFileExtension());
reportService.getOK(_log, role.getName());
} catch (Exception e) {
reportService.getError(_log, role.getName(), e);
if (debug) {
_log.error(e, e);
}
}
} else {
reportService.getDNE(_log, roleDir.getAbsolutePath());
}
} else {
_log.error("roleDir is null ...");
}
} else {
reportService.getSkipped(_log, role.getName());
}
} else {
_log.error("Skipping null role ...");
}
}
use of com.liferay.imex.role.model.RolePermissions 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