Search in sources :

Example 1 with RoleActivityRestrictionBO

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

the class RolesPermissionServiceFacadeWebTier method getRoleActivitiesRestrictions.

@Override
public List<ActivityRestrictionDto> getRoleActivitiesRestrictions(Short roleId) {
    try {
        List<ActivityRestrictionDto> activityRestrictionDtoList = new ArrayList<ActivityRestrictionDto>();
        List<RoleActivityRestrictionBO> activityRestrictionBOList = legacyRolesPermissionsDao.getRoleActivitiesRestrictions(roleId);
        for (RoleActivityRestrictionBO activityRestrictionBO : activityRestrictionBOList) {
            Integer activityRestrictionId = activityRestrictionBO.getId();
            Short activityRestrictionTypeId = activityRestrictionBO.getActivityRestrictionType().getId();
            BigDecimal restrictionAmountValue = activityRestrictionBO.getRestrictionAmountValue();
            ActivityRestrictionDto activityRestrictionDto = new ActivityRestrictionDto(roleId, activityRestrictionId, activityRestrictionTypeId, restrictionAmountValue);
            activityRestrictionDtoList.add(activityRestrictionDto);
        }
        return activityRestrictionDtoList;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) BigDecimal(java.math.BigDecimal) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with RoleActivityRestrictionBO

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

the class RolesPermissionsBusinessService method getRoleActivityRestrictionAmountValueByRestrictionTypeId.

public BigDecimal getRoleActivityRestrictionAmountValueByRestrictionTypeId(Short roleId, Short activityRestrictionTypeId) throws ServiceException {
    try {
        RoleBO roleBO = rolesPermissionsPersistence.getRole(roleId);
        Set<RoleActivityRestrictionBO> restrictions = roleBO.getRestrictions();
        for (RoleActivityRestrictionBO restrictionBO : restrictions) {
            if (restrictionBO.getActivityRestrictionType().getId().equals(ActivityRestrictionType.MAX_LOAN_AMOUNT_FOR_APPROVE.getValue())) {
                return restrictionBO.getRestrictionAmountValue();
            }
        }
        return null;
    } catch (PersistenceException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 3 with RoleActivityRestrictionBO

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

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

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

the class RolesPermissionServiceFacadeWebTier method getActivitiesRestrictionsForUpdate.

private List<RoleActivityRestrictionBO> getActivitiesRestrictionsForUpdate(UserContext userContext, List<ActivityRestrictionDto> activityRestrictionDtoList) {
    try {
        List<RoleActivityRestrictionBO> activitiesRestrictions = new ArrayList<RoleActivityRestrictionBO>();
        for (ActivityRestrictionDto activityRestrictionDto : activityRestrictionDtoList) {
            RoleActivityRestrictionBO roleActivityRestrictionBO;
            if (activityRestrictionDto.getActivityRestrictionId() != null) {
                roleActivityRestrictionBO = legacyRolesPermissionsDao.getActivityRestrictionById(activityRestrictionDto.getActivityRestrictionId());
                roleActivityRestrictionBO.update(userContext.getId(), activityRestrictionDto.getAmountValue());
            } else {
                roleActivityRestrictionBO = new RoleActivityRestrictionBO(userContext);
                ActivityRestrictionTypeEntity activityRestrictionTypeEntity = legacyRolesPermissionsDao.getActivityRestrictionTypeEntity((short) activityRestrictionDto.getActivityRestrictionTypeId());
                roleActivityRestrictionBO.setActivityRestrictionType(activityRestrictionTypeEntity);
                roleActivityRestrictionBO.setRestrictionAmountValue(activityRestrictionDto.getAmountValue());
            }
            activitiesRestrictions.add(roleActivityRestrictionBO);
        }
        return activitiesRestrictions;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : ActivityRestrictionTypeEntity(org.mifos.security.rolesandpermission.business.ActivityRestrictionTypeEntity) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ActivityRestrictionDto(org.mifos.dto.domain.ActivityRestrictionDto) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

RoleActivityRestrictionBO (org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO)6 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 ArrayList (java.util.ArrayList)3 ActivityRestrictionDto (org.mifos.dto.domain.ActivityRestrictionDto)3 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)3 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)2 ServiceException (org.mifos.framework.exceptions.ServiceException)2 MifosUser (org.mifos.security.MifosUser)2 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)2 ActivityRestrictionTypeEntity (org.mifos.security.rolesandpermission.business.ActivityRestrictionTypeEntity)2 UserContext (org.mifos.security.util.UserContext)2 BigDecimal (java.math.BigDecimal)1 HibernateException (org.hibernate.HibernateException)1 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)1 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)1 RolesPermissionException (org.mifos.security.rolesandpermission.exceptions.RolesPermissionException)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1