Search in sources :

Example 26 with ActivityEntity

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

the class RolesPermissionServiceFacadeWebTier method updateRole.

@Override
public void updateRole(Short roleId, Short userId, String name, List<Short> ActivityIds) throws Exception {
    RolesPermissionsBusinessService rolesPermissionsBusinessService = new RolesPermissionsBusinessService();
    RoleBO role = rolesPermissionsBusinessService.getRole(roleId);
    List<ActivityEntity> activityList = getActivityEntities(ActivityIds);
    validateRole(name, activityList, role);
    try {
        StaticHibernateUtil.startTransaction();
        role.update(userId, name, activityList);
        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 : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) RolesPermissionException(org.mifos.security.rolesandpermission.exceptions.RolesPermissionException) 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) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 27 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity 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 28 with ActivityEntity

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

the class RolesPermissionServiceFacadeWebTier method createRole.

@Override
public void createRole(Short userId, String name, List<Short> ActivityIds, List<ActivityRestrictionDto> activityRestrictionDtoList) throws Exception {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    List<ActivityEntity> activityEntities = getActivityEntities(ActivityIds);
    List<RoleActivityRestrictionBO> activitiesRestrictions = getActivitiesRestrictionsForCreate(activityRestrictionDtoList, userContext);
    RoleBO roleBO = new RoleBO(userContext, name, activityEntities, activitiesRestrictions);
    try {
        validateRole(name, activityEntities, roleBO);
        StaticHibernateUtil.startTransaction();
        legacyRolesPermissionsDao.save(roleBO);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : activityEntities) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (PersistenceException 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) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 29 with ActivityEntity

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

the class RolesPermissionServiceFacadeWebTier method createRole.

@Override
public void createRole(Short userId, String name, List<Short> ActivityIds) throws RolesPermissionException {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    List<ActivityEntity> activityEntities = getActivityEntities(ActivityIds);
    RoleBO roleBO = new RoleBO(userContext, name, activityEntities);
    try {
        validateRole(name, activityEntities, roleBO);
        StaticHibernateUtil.startTransaction();
        legacyRolesPermissionsDao.save(roleBO);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : activityEntities) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (PersistenceException 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) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 30 with ActivityEntity

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

the class RolesPermissionServiceFacadeWebTier method getActivityEntities.

private List<ActivityEntity> getActivityEntities(List<Short> ActivityIds) {
    List<ActivityEntity> activityEntities = new ArrayList<ActivityEntity>();
    for (Short id : ActivityIds) {
        try {
            ActivityEntity activityEntity = legacyRolesPermissionsDao.getActivityById(id);
            activityEntities.add(activityEntity);
        } catch (PersistenceException e) {
            throw new MifosRuntimeException(e);
        }
    }
    return activityEntities;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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