use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.
the class BirtReportsUploadActionStrutsTest method setupReportEditPermission.
private void setupReportEditPermission(boolean allowReportEdit) throws Exception {
UserContext userContext = TestUtils.makeUser();
request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, ac);
RoleBO role = legacyRolesPermissionsDao.getRole(userContext.getRoles().iterator().next());
List<ActivityEntity> roleActivities = new ArrayList<ActivityEntity>(role.getActivities());
List<ActivityEntity> updatedRoleActivities = new ArrayList<ActivityEntity>();
for (ActivityEntity ae : roleActivities) {
if (ae.getId() != SecurityConstants.EDIT_REPORT_INFORMATION || allowReportEdit) {
updatedRoleActivities.add(ae);
}
}
try {
StaticHibernateUtil.startTransaction();
role.update(userContext.getId(), "test", updatedRoleActivities);
legacyRolesPermissionsDao.save(role);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
setRequestPathInfo("/birtReportsUploadAction.do");
addRequestParameter("method", "edit");
addRequestParameter("reportId", "1");
}
use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.
the class ReportsCategoryActionStrutsTest method testShouldCreateFailureWhenActivityIdOutOfRange.
@Test
public void testShouldCreateFailureWhenActivityIdOutOfRange() throws Exception {
ActivityEntity activity = insertActivityForTest(Short.MIN_VALUE);
setRequestPathInfo("/reportsCategoryAction.do");
addRequestParameter("method", "addNewCategory");
addRequestParameter("categoryName", "willFailureForRangeNewCategory");
actionPerform();
verifyForward("preview_failure");
String[] errors = { ReportsConstants.ERROR_NOMOREDYNAMICACTIVITYID };
verifyActionErrors(errors);
deleteActivityForTest(activity);
}
use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.
the class ReportsCategoryActionStrutsTest method insertActivityForTest.
public ActivityEntity insertActivityForTest(short activityId) throws PersistenceException {
LookUpValueEntity anLookUp = new LookUpValueEntity();
LookUpEntity lookUpEntity = legacyMasterDao.getPersistentObject(LookUpEntity.class, Short.valueOf((short) LookUpEntity.ACTIVITY));
anLookUp.setLookUpEntity(lookUpEntity);
ActivityEntity parent = legacyMasterDao.getPersistentObject(ActivityEntity.class, (short) 13);
ActivityEntity activityEntity = new ActivityEntity(activityId, parent, anLookUp);
legacyRolesPermissionsDao.createOrUpdate(anLookUp);
legacyRolesPermissionsDao.createOrUpdate(activityEntity);
return activityEntity;
}
use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.
the class AddActivityIntegrationTest method upgradeAndCheck.
private Upgrade upgradeAndCheck() throws IOException, SQLException, ApplicationException {
// Connection connection = session.connection();
// connection.setAutoCommit(true);
short newId = 17032;
AddActivity upgrade = new AddActivity(newId, SecurityConstants.LOAN_MANAGEMENT, "Can use the executive washroom");
upgrade.upgrade(session.connection());
session = StaticHibernateUtil.getSessionTL();
ActivityEntity fetched = (ActivityEntity) session.get(ActivityEntity.class, newId);
Assert.assertEquals("Can use the executive washroom", fetched.getActivityName());
Assert.assertEquals(SecurityConstants.LOAN_MANAGEMENT, (short) fetched.getParent().getId());
ActivityContext activityContext = new ActivityContext(newId, TestObjectFactory.HEAD_OFFICE);
UserContext admin = TestUtils.makeUser(RolesAndPermissionConstants.ADMIN_ROLE);
Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(admin, activityContext));
UserContext nonAdmin = TestUtils.makeUser(TestUtils.DUMMY_ROLE);
Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(nonAdmin, activityContext));
return upgrade;
}
use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.
the class LegacyRolesPermissionsDaoIntegrationTest method testShouldSuccessWhenChangeActivityParent.
@Test
public void testShouldSuccessWhenChangeActivityParent() throws PersistenceException {
ActivityEntity activity = legacyRolesPermissionsDao.getPersistentObject(ActivityEntity.class, Short.valueOf((short) 2));
Assert.assertEquals(1, activity.getParent().getId().shortValue());
legacyRolesPermissionsDao.reparentActivityUsingHibernate((short) 2, (short) 13);
activity = legacyRolesPermissionsDao.getPersistentObject(ActivityEntity.class, Short.valueOf((short) 2));
Assert.assertEquals(13, activity.getParent().getId().shortValue());
legacyRolesPermissionsDao.reparentActivityUsingHibernate((short) 2, (short) 1);
}
Aggregations