Search in sources :

Example 6 with RolesPermissionsBusinessService

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

the class RolesPermissionServiceFacadeWebTier method updateRole.

@Override
public void updateRole(Short roleId, Short userId, String name, List<Short> ActivityIds, List<ActivityRestrictionDto> activityRestrictionDtoList) throws Exception {
    RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
    RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
    List<ActivityEntity> activityList = getActivityEntities(ActivityIds);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    List<RoleActivityRestrictionBO> activitiesRestrictions = getActivitiesRestrictionsForUpdate(userContext, activityRestrictionDtoList);
    validateRole(name, activityList, role);
    try {
        StaticHibernateUtil.startTransaction();
        role.updateWithActivitiesRestrictions(userId, name, activityList, activitiesRestrictions);
        legacyRolesPermissionsDao.save(role);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (RolesPermissionException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) HibernateException(org.hibernate.HibernateException) RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) BusinessRuleException(org.mifos.service.BusinessRuleException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with RolesPermissionsBusinessService

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

the class RolesPermissionServiceFacadeWebTier method retrieveAllRoles.

@Override
public List<ListElement> retrieveAllRoles() {
    try {
        List<RoleBO> roles = new RolesPermissionsBusinessService().getRoles();
        if (!roles.isEmpty()) {
            List<ListElement> roleList = new ArrayList<ListElement>();
            for (RoleBO role : roles) {
                ListElement element = new ListElement(new Integer(role.getId()), role.getName());
                roleList.add(element);
            }
            return roleList;
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
    return null;
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ArrayList(java.util.ArrayList) ListElement(org.mifos.dto.screen.ListElement) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 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