Search in sources :

Example 11 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDaoIntegrationTest method testShouldGenerateMinActivityIdWhenCalculate.

@Test
public void testShouldGenerateMinActivityIdWhenCalculate() throws Exception {
    short minActivityId = -32767;
    ActivityEntity activity = insertActivityForTest(minActivityId);
    Assert.assertEquals(minActivityId - 1, legacyRolesPermissionsDao.calculateDynamicActivityId());
    deleteActivityForTest(activity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Test(org.junit.Test)

Example 12 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDaoIntegrationTest method insertActivityForTest.

private 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 13 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class RolesPermissionsActionStrutsTest method testDelete.

@Test
public void testDelete() throws Exception {
    Short roleId = null;
    List<ActivityEntity> activityList = legacyRolesPermissionsDao.getActivities();
    ActivityEntity activityEntity_0 = activityList.get(0);
    ActivityEntity activityEntity_1 = activityList.get(1);
    ActivityEntity activityEntity_2 = activityList.get(2);
    ActivityEntity activityEntity_3 = activityList.get(3);
    ActivityEntity activityEntity_4 = activityList.get(4);
    rolesPermissionService.createRole(RolesAndPermissionConstants.ADMIN_ROLE, "New Role", legacyRolesPermissionsDao.getActivitieIds());
    role = legacyRolesPermissionsDao.getRole("New Role");
    roleId = role.getId();
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "preview");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("id", role.getId().toString());
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.preview_success.toString());
    Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "delete");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.delete_success.toString());
    Assert.assertNull(request.getAttribute(Constants.CURRENTFLOWKEY));
    role = legacyRolesPermissionsDao.getRole("New Role");
    Assert.assertNull(role);
    UserContext userContext = TestUtils.makeUser(roleId);
    ActivityContext activityContext = new ActivityContext(activityEntity_0.getId(), (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext(activityEntity_1.getId(), (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext(activityEntity_2.getId(), (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext(activityEntity_3.getId(), (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext(activityEntity_4.getId(), (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 14 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class RoleTempleteBuilderIntegrationTest method testGetRolesTemplete.

@Test
public void testGetRolesTemplete() throws Exception {
    List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
    StringBuilder stringBuilder = new RoleTempleteBuilder().getRolesTemplete(activities);
    Assert.assertNotNull(stringBuilder);
    Assert.assertTrue(stringBuilder.toString().contains("Can create new role"));
    Assert.assertTrue(stringBuilder.toString().contains("Can modify a role"));
    Assert.assertTrue(stringBuilder.toString().contains("Can delete a role"));
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Test(org.junit.Test)

Example 15 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class RoleTempleteBuilder method getRolesTemplete.

/**
     * This is the main function which would build the table tree for ui
     *
     * @param l
     *            List if all the activities in the system
     * @return stringbuffer representatiuon of the tree
     */
public StringBuilder getRolesTemplete(List<ActivityEntity> l) {
    nameHelper = 0;
    // StringBuffer buff = new StringBuffer();
    StringBuilder buff = new StringBuilder();
    // first build the map
    for (short k = 0; k < l.size(); k++) {
        indexMap.put(l.get(k).getId(), k);
    }
    // make checkmap
    buildCheckedItems(l);
    // by this time child map has been built
    short start = 0;
    List<ActivityEntity> li = childMap.get(Short.valueOf(start));
    buff.append("<script language=\"javascript\" src=\"pages/application/rolesandpermission/js/checkBoxLogic.js\"  type=\"text/javascript\">   </script>");
    for (int i = 0; i < li.size(); i++) {
        String name = Integer.toString(i);
        Short index = getIndex(li.get(i).getId());
        buff.append("<table width=\"95%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" class=\"bluetableborder\">");
        buff.append("<tr class=\"bluetablehead05\">");
        buff.append("<td width=\"3%\"  ><input name=\"" + "activity(" + nameHelper++ + ")\"" + " id=\"" + name + "\" type=\"checkbox\" value=\"checkbox\" ");
        if (checkedLinks.contains(l.get(index).getId())) {
            buff.append("  checked=true ");
        }
        buff.append("onclick=\"doCheck(this)\" > </td>");
        buff.append("<td colspan=\"");
        buff.append(maxDepth + 2 + "\"  >");
        buff.append("<span class=\"fontnormalbold\">");
        ActivityEntity entity = l.get(index);
        String activityName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(entity.getActivityNameLookupValues());
        buff.append(activityName);
        buff.append("</span></td></tr>");
        makeTable(l, li.get(i).getId(), buff, 1, name);
        buff.append("</table><br>");
    }
    return buff;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MessageLookup(org.mifos.application.master.MessageLookup)

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