Search in sources :

Example 1 with RoleTempleteBuilder

use of org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder 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 2 with RoleTempleteBuilder

use of org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder in project head by mifos.

the class RoleTempleteBuilderIntegrationTest method testSetCurrentActivites.

@Test
public void testSetCurrentActivites() {
    Set<Short> activities = new HashSet<Short>();
    activities.add(Short.valueOf("1"));
    RoleTempleteBuilder roleTempleteBuilder = new RoleTempleteBuilder();
    roleTempleteBuilder.setCurrentActivites(activities);
    activities = roleTempleteBuilder.getCurrentActivites();
    Assert.assertEquals(1, activities.size());
}
Also used : RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with RoleTempleteBuilder

use of org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder in project head by mifos.

the class RoleTempleteBuilderIntegrationTest method testLocaleId.

@Test
public void testLocaleId() {
    RoleTempleteBuilder roleTempleteBuilder = new RoleTempleteBuilder();
    roleTempleteBuilder.setLocaleId(Short.valueOf("1"));
    Assert.assertEquals(Short.valueOf("1"), roleTempleteBuilder.getLocaleId());
}
Also used : RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) Test(org.junit.Test)

Example 4 with RoleTempleteBuilder

use of org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder in project head by mifos.

the class ActivityTag method doEndTag.

@SuppressWarnings("unchecked")
@Override
public int doEndTag() throws JspException {
    RoleTempleteBuilder builder = new RoleTempleteBuilder();
    List<ActivityEntity> activities;
    try {
        activities = (List<ActivityEntity>) SessionUtils.getAttribute(RolesAndPermissionConstants.ACTIVITYLIST, (HttpServletRequest) pageContext.getRequest());
        activities = filterActivities(activities);
        RoleBO role = (RoleBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) pageContext.getSession().getAttribute("rolesPermissionsActionForm");
        if (rolesPermissionsActionForm != null && rolesPermissionsActionForm.getActivities().size() > 0) {
            List<ActivityEntity> flitered = filterActivities(getActivities(activities, rolesPermissionsActionForm.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        } else if (role != null) {
            List<ActivityEntity> flitered = filterActivities(new ArrayList<ActivityEntity>(role.getActivities()));
            Set<Short> activitySet = convertToIdSet(flitered);
            builder.setCurrentActivites(activitySet);
        }
        Map<Short, ActivityRestrictionDto> activityRestrictionDtoMap = rolesPermissionsActionForm.getActivityRestrictionDtoMap();
        if (activityRestrictionDtoMap == null) {
            activityRestrictionDtoMap = new HashMap<Short, ActivityRestrictionDto>();
        }
        builder.setActivityRestrictionDtoMap(activityRestrictionDtoMap);
        SessionUtils.getAttribute(Constants.BUSINESS_KEY, (HttpServletRequest) pageContext.getRequest());
        StringBuilder sb = builder.getRolesTemplete(activities);
        pageContext.getOut().print(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    } catch (PageExpiredException e1) {
        throw new JspException(e1);
    }
    return EVAL_PAGE;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Set(java.util.Set) HashSet(java.util.HashSet) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) RoleTempleteBuilder(org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder) JspException(javax.servlet.jsp.JspException) ArrayList(java.util.ArrayList) List(java.util.List) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Aggregations

RoleTempleteBuilder (org.mifos.security.rolesandpermission.util.helpers.RoleTempleteBuilder)4 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JspException (javax.servlet.jsp.JspException)1 ActivityRestrictionDto (org.mifos.dto.domain.ActivityRestrictionDto)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)1 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)1 RolesPermissionsActionForm (org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm)1