Search in sources :

Example 21 with ActivityEntity

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");
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 22 with ActivityEntity

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);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Test(org.junit.Test)

Example 23 with ActivityEntity

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;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) LookUpEntity(org.mifos.application.master.business.LookUpEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 24 with 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;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext)

Example 25 with ActivityEntity

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);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Test(org.junit.Test)

Aggregations

ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)42 PersistenceException (org.mifos.framework.exceptions.PersistenceException)13 MifosRuntimeException (org.mifos.core.MifosRuntimeException)12 Test (org.junit.Test)10 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)9 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)9 ArrayList (java.util.ArrayList)8 UserContext (org.mifos.security.util.UserContext)8 HibernateException (org.hibernate.HibernateException)7 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)7 ApplicationException (org.mifos.framework.exceptions.ApplicationException)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)6 HibernateProcessException (org.mifos.framework.exceptions.HibernateProcessException)5 SystemException (org.mifos.framework.exceptions.SystemException)5 IOException (java.io.IOException)4 MessageLookup (org.mifos.application.master.MessageLookup)4 SecurityException (org.mifos.framework.exceptions.SecurityException)4 List (java.util.List)3 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)3