use of org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method updateRole.
@Override
public void updateRole(Short roleId, Short userId, String name, List<Short> ActivityIds, List<ActivityRestrictionDto> activityRestrictionDtoList) throws Exception {
RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
List<ActivityEntity> activityList = getActivityEntities(ActivityIds);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
List<RoleActivityRestrictionBO> activitiesRestrictions = getActivitiesRestrictionsForUpdate(userContext, activityRestrictionDtoList);
validateRole(name, activityList, role);
try {
StaticHibernateUtil.startTransaction();
role.updateWithActivitiesRestrictions(userId, name, activityList, activitiesRestrictions);
legacyRolesPermissionsDao.save(role);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (RolesPermissionException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method retrieveAllRoles.
@Override
public List<ListElement> retrieveAllRoles() {
try {
List<RoleBO> roles = new RolesPermissionsBusinessService().getRoles();
if (!roles.isEmpty()) {
List<ListElement> roleList = new ArrayList<ListElement>();
for (RoleBO role : roles) {
ListElement element = new ListElement(new Integer(role.getId()), role.getName());
roleList.add(element);
}
return roleList;
}
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
return null;
}
use of org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService in project head by mifos.
the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.
@Test
public void testUpgradePathNotRuined() throws Exception {
// TODO Temporary solution to avoid unsuccessful test on some machines
// Retrieve initial activities information
List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
int newActivityId = activities.get(activities.size() - 1).getId() + 1;
// Upload a report creating an activity for the report
FormFile file = new MockFormFile("testFilename.rptdesign");
BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
setRequestPathInfo("/birtReportsUploadAction.do");
addRequestParameter("method", "upload");
actionForm.setFile(file);
actionForm.setReportTitle("exsitTitle");
actionForm.setReportCategoryId("1");
actionForm.setIsActive("1");
setActionForm(actionForm);
actionPerform();
Assert.assertEquals(0, getErrorSize());
Assert.assertNotNull(request.getAttribute("report"));
// Simulate an future activities upgrade
AddActivity activity = null;
try {
activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
} catch (Exception e) {
legacyRolesPermissionsDao.delete(request.getAttribute("report"));
StaticHibernateUtil.flushSession();
throw e;
}
// Undo
ReportsBO report = (ReportsBO) request.getAttribute("report");
removeReport(report.getReportId());
}
Aggregations