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);
}
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;
}
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));
}
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"));
}
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;
}
Aggregations