Search in sources :

Example 46 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory 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 47 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.

@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    try {
        personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }
    Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
    if (errors.hasErrors()) {
        throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
    }
    List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
    for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
        LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
        Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
        List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
        for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
            feeDtos.add(convertToDto(feeEntity));
        }
        loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
    }
    return loanSchedule;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) UserContext(org.mifos.security.util.UserContext) LoanRepaymentScheduleItemDto(org.mifos.dto.domain.LoanRepaymentScheduleItemDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountFeeScheduleDto(org.mifos.dto.domain.AccountFeeScheduleDto) Errors(org.mifos.platform.validations.Errors) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 48 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveSavingsAccountDetails.

@Override
public SavingsAccountDetailDto retrieveSavingsAccountDetails(Long savingsId) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    try {
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    return savingsAccount.toDto();
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 49 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class WebTierPenaltyServiceFacade method updatePenalty.

@Override
public void updatePenalty(PenaltyFormDto dto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(dto.getId());
    penaltyBO.updateDetails(userContext);
    try {
        PenaltyFrequency penaltyFrequency = dto.getPenaltyFrequency() != null ? PenaltyFrequency.getPenaltyFrequencyType(dto.getPenaltyFrequency()) : null;
        PenaltyPeriod penaltyPeriod = dto.getPenaltyPeriod() != null ? PenaltyPeriod.getPenaltyPeriod(dto.getPenaltyPeriod()) : null;
        PenaltyFormula penaltyFormula = dto.getPenaltyFormula() != null ? PenaltyFormula.getPenaltyFormula(dto.getPenaltyFormula()) : null;
        PenaltyStatus penaltyStatus = dto.getPenaltyStatus() != null ? PenaltyStatus.getPenaltyStatus(dto.getPenaltyStatus()) : null;
        penaltyBO.setPeriodType(this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod));
        penaltyBO.setPenaltyFrequency(this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency));
        penaltyBO.setPenaltyName(dto.getPenaltyName());
        penaltyBO.setPeriodDuration(dto.getDuration());
        penaltyBO.setMinimumLimit(dto.getMin());
        penaltyBO.setMaximumLimit(dto.getMax());
        penaltyBO.setStatus(this.penaltyDao.findPenaltyStatusEntityByType(penaltyStatus));
        penaltyBO.setGlCode(this.generalLedgerDao.findGlCodeById(dto.getGlCode()));
        if (dto.isRatePenalty()) {
            RatePenaltyBO ratePenaltyBO = (RatePenaltyBO) penaltyBO;
            ratePenaltyBO.setRate(dto.getRate());
            ratePenaltyBO.setFormula(this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula));
        } else {
            AmountPenaltyBO amountPenaltyBO = (AmountPenaltyBO) penaltyBO;
            amountPenaltyBO.setAmount(new Money(getCurrency(dto.getCurrencyId()), dto.getAmount()));
        }
        try {
            StaticHibernateUtil.startTransaction();
            this.penaltyDao.save(penaltyBO);
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            throw new MifosRuntimeException(e);
        } finally {
            StaticHibernateUtil.closeSession();
        }
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) PenaltyPeriod(org.mifos.accounts.penalties.util.helpers.PenaltyPeriod) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) BusinessRuleException(org.mifos.service.BusinessRuleException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PenaltyFrequency(org.mifos.accounts.penalties.util.helpers.PenaltyFrequency) PenaltyStatus(org.mifos.accounts.penalties.util.helpers.PenaltyStatus) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) PenaltyFormula(org.mifos.accounts.penalties.util.helpers.PenaltyFormula) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 MifosUser (org.mifos.security.MifosUser)49 UserContext (org.mifos.security.util.UserContext)49 MifosRuntimeException (org.mifos.core.MifosRuntimeException)37 BusinessRuleException (org.mifos.service.BusinessRuleException)26 AccountException (org.mifos.accounts.exceptions.AccountException)18 PersistenceException (org.mifos.framework.exceptions.PersistenceException)17 ArrayList (java.util.ArrayList)13 LoanBO (org.mifos.accounts.loan.business.LoanBO)12 ServiceException (org.mifos.framework.exceptions.ServiceException)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)9 ApplicationException (org.mifos.framework.exceptions.ApplicationException)9 Money (org.mifos.framework.util.helpers.Money)8 LocalDate (org.joda.time.LocalDate)7 SystemException (org.mifos.framework.exceptions.SystemException)6 CustomerBO (org.mifos.customers.business.CustomerBO)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 Date (java.util.Date)4 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)4 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)4