Search in sources :

Example 1 with RolesPermissionsBusinessService

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

the class RolesPermissionServiceFacadeWebTier method deleteRole.

@Override
public void deleteRole(Integer versionNo, Short roleId) throws Exception {
    RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
    RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
    role.setVersionNo(versionNo);
    validateIfRoleAssignedToPersonnel(role);
    try {
        StaticHibernateUtil.startTransaction();
        legacyRolesPermissionsDao.delete(role);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (PersistenceException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with RolesPermissionsBusinessService

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

the class LegacyRolesPermissionsDao method calculateDynamicActivityId.

public int calculateDynamicActivityId() throws ServiceException, ActivityGeneratorException {
    int activityId = 0;
    for (ActivityEntity activity : new RolesPermissionsBusinessService().getActivities()) {
        if (activity.getId().intValue() < activityId) {
            activityId = activity.getId();
        }
    }
    if (activityId <= Short.MIN_VALUE) {
        throw new ActivityGeneratorException();
    }
    int newActivityId = activityId - 1;
    return newActivityId;
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException)

Example 3 with RolesPermissionsBusinessService

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

the class RolesPermissionsAction method manage.

@TransactionDemarcate(joinToken = true)
public ActionForward manage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    RolesPermissionsActionForm rolesPermissionsActionForm = (RolesPermissionsActionForm) form;
    SessionUtils.setCollectionAttribute(RolesAndPermissionConstants.ACTIVITYLIST, ((RolesPermissionsBusinessService) getService()).getActivities(), request);
    Short roleId = Short.valueOf(rolesPermissionsActionForm.getId());
    RoleBO role = ((RolesPermissionsBusinessService) getService()).getRole(roleId);
    List<ActivityRestrictionDto> activityRestrictionDtoList = rolesPermissionServiceFacade.getRoleActivitiesRestrictions(roleId);
    Map<Short, ActivityRestrictionDto> activityRestrictionDtoMap = new HashMap<Short, ActivityRestrictionDto>();
    for (ActivityRestrictionDto activityRestrictionDto : activityRestrictionDtoList) {
        activityRestrictionDtoMap.put(activityRestrictionDto.getActivityRestrictionTypeId(), activityRestrictionDto);
    }
    rolesPermissionsActionForm.setActivityRestrictionDtoMap(activityRestrictionDtoMap);
    rolesPermissionsActionForm.setName(role.getName());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, role, request);
    return mapping.findForward(ActionForwards.manage_success.toString());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) HashMap(java.util.HashMap) RolesPermissionsActionForm(org.mifos.security.rolesandpermission.struts.actionforms.RolesPermissionsActionForm) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with RolesPermissionsBusinessService

use of org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService 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 5 with RolesPermissionsBusinessService

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

the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.

@Test
public void testUpgradePathNotRuined() throws Exception {
    // TODO Temporary solution to avoid unsuccessful test on some machines
    // Retrieve initial activities information
    List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
    int newActivityId = activities.get(activities.size() - 1).getId() + 1;
    // Upload a report creating an activity for the report
    FormFile file = new MockFormFile("testFilename.rptdesign");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("exsitTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    Assert.assertEquals(0, getErrorSize());
    Assert.assertNotNull(request.getAttribute("report"));
    // Simulate an future activities upgrade
    AddActivity activity = null;
    try {
        activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
        activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
    } catch (Exception e) {
        legacyRolesPermissionsDao.delete(request.getAttribute("report"));
        StaticHibernateUtil.flushSession();
        throw e;
    }
    // Undo
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    removeReport(report.getReportId());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) AddActivity(org.mifos.security.AddActivity) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Aggregations

RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)8 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)6 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)4 ServiceException (org.mifos.framework.exceptions.ServiceException)3 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)3 HibernateException (org.hibernate.HibernateException)2 Test (org.junit.Test)2 RolesPermissionException (org.mifos.security.rolesandpermission.exceptions.RolesPermissionException)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FormFile (org.apache.struts.upload.FormFile)1 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)1 ActivityRestrictionDto (org.mifos.dto.domain.ActivityRestrictionDto)1 ListElement (org.mifos.dto.screen.ListElement)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 MockFormFile (org.mifos.reports.business.MockFormFile)1