Search in sources :

Example 11 with ServiceException

use of org.mifos.framework.exceptions.ServiceException in project head by mifos.

the class AccountApplyPaymentActionForm method validateModeOfPaymentSecurity.

private void validateModeOfPaymentSecurity(HttpServletRequest request, ActionErrors errors) {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    AccountBO account = null;
    Short personnelId = userContext.getId();
    try {
        if (accountId != null) {
            account = new AccountBusinessService().getAccount(Integer.valueOf(accountId));
            if (account.getPersonnel() != null) {
                personnelId = account.getPersonnel().getPersonnelId();
            }
        }
    } catch (NumberFormatException e) {
        throw new MifosRuntimeException(e);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
    if (getPaymentTypeId().equals("4") && !ActivityMapper.getInstance().isModeOfPaymentSecurity(userContext, personnelId)) {
        errors.add(AccountConstants.LOAN_TRANSFER_PERMISSION, new ActionMessage(AccountConstants.LOAN_TRANSFER_PERMISSION, getLocalizedMessage("accounts.mode_of_payment_permission")));
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with ServiceException

use of org.mifos.framework.exceptions.ServiceException in project head by mifos.

the class BranchReportHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    Date runDate = new Date(timeInMillis);
    try {
        removeExistingBranchReportsForGivenRunDate(runDate);
        populateBranchReportBatch(session, runDate);
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BatchJobException(e);
    } catch (ServiceException e) {
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateException(org.hibernate.HibernateException) Date(java.util.Date) Session(org.hibernate.Session)

Example 13 with ServiceException

use of org.mifos.framework.exceptions.ServiceException in project head by mifos.

the class AccountBusinessService method getAppllicableFees.

public List<ApplicableCharge> getAppllicableFees(Integer accountId, UserContext userContext) throws ServiceException {
    List<ApplicableCharge> applicableChargeList = null;
    try {
        AccountBO account = getlegacyAccountDao().getAccount(accountId);
        FeeCategory categoryType = getCategoryType(account.getCustomer());
        if (account.getType() == AccountTypes.LOAN_ACCOUNT || account.getType() == AccountTypes.GROUP_LOAN_ACCOUNT) {
            applicableChargeList = getLoanApplicableCharges(getlegacyAccountDao().getAllApplicableFees(accountId, FeeCategory.LOAN), userContext, (LoanBO) account);
        } else if (account.getType() == AccountTypes.CUSTOMER_ACCOUNT) {
            if (account.getCustomer().getCustomerMeeting() == null) {
                throw new ServiceException(AccountExceptionConstants.APPLY_CAHRGE_NO_CUSTOMER_MEETING_EXCEPTION);
            }
            applicableChargeList = getCustomerApplicableCharges(getlegacyAccountDao().getAllApplicableFees(accountId, categoryType), userContext, ((CustomerAccountBO) account).getCustomer().getCustomerMeeting().getMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceId());
        }
        addMiscFeeAndPenalty(applicableChargeList);
    } catch (PersistenceException pe) {
        throw new ServiceException(pe);
    }
    return applicableChargeList;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ServiceException(org.mifos.framework.exceptions.ServiceException) LoanBO(org.mifos.accounts.loan.business.LoanBO) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeCategory(org.mifos.accounts.fees.util.helpers.FeeCategory)

Example 14 with ServiceException

use of org.mifos.framework.exceptions.ServiceException in project head by mifos.

the class WebTierAccountServiceFacade method applyMemberAccountHistoricalAdjustment.

/**
     * adjustment for member account payment has to be handled along with parent account payments and other members payments.
     * This method prepares data and run applyHistoricalAdjustment so adjustment will be made for parent payment context.
     */
@Override
@PreAuthorize("isFullyAuthenticated()")
public void applyMemberAccountHistoricalAdjustment(String memberGlobalAccountNum, Integer memberPaymentId, String adjustmentNote, Short personnelId, AdjustedPaymentDto adjustedPaymentDto) {
    try {
        LoanBO memberAccount = (LoanBO) accountBusinessService.findBySystemId(memberGlobalAccountNum);
        LoanBO parentAccount = memberAccount.getParentAccount();
        if (parentAccount == null) {
            throw new AccountException(LoanExceptionConstants.NO_PARENT_ACCOUNT_EXCEPTION);
        }
        AccountPaymentEntity parentPaymentEntity = memberAccount.findParentPaymentByMemberPaymentId(memberPaymentId);
        List<AdjustedPaymentDto> membersAdjustedPaymentDtoList = new ArrayList<AdjustedPaymentDto>();
        for (AccountPaymentEntity memberPayment : parentPaymentEntity.getMemberPayments()) {
            if (memberPayment.getAccount().getAccountId().equals(memberAccount.getAccountId())) {
                membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(adjustedPaymentDto.getAmount(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberAccount.getAccountId()));
            } else {
                membersAdjustedPaymentDtoList.add(new AdjustedPaymentDto(memberPayment.getAmount().getAmount().toString(), adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), memberPayment.getAccount().getAccountId()));
            }
        }
        BigDecimal parentAmountSubstraction = memberAccount.findPaymentById(memberPaymentId).getAmount().getAmount().subtract((new BigDecimal(adjustedPaymentDto.getAmount())));
        String newParentAmount = parentPaymentEntity.getAmount().getAmount().subtract(parentAmountSubstraction).toString();
        AdjustedPaymentDto parentAdjustedPaymentDto = new AdjustedPaymentDto(newParentAmount, adjustedPaymentDto.getPaymentDate(), adjustedPaymentDto.getPaymentType(), parentAccount.getAccountId(), membersAdjustedPaymentDtoList);
        this.applyHistoricalAdjustment(parentAccount.getGlobalAccountNum(), parentPaymentEntity.getPaymentId(), adjustmentNote, personnelId, parentAdjustedPaymentDto);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) AdjustedPaymentDto(org.mifos.dto.domain.AdjustedPaymentDto) ServiceException(org.mifos.framework.exceptions.ServiceException) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with ServiceException

use of org.mifos.framework.exceptions.ServiceException in project head by mifos.

the class WebTierAccountServiceFacade method getActiveSavingsAccountsForClientByLoanId.

@Override
public List<SavingsDetailDto> getActiveSavingsAccountsForClientByLoanId(Integer loanAccountId) {
    try {
        AccountBO account = accountBusinessService.getAccount(loanAccountId);
        CustomerDto customer = account.getCustomer().toCustomerDto();
        List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(customer.getCustomerId());
        List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
        if (savingsInUse != null) {
            for (SavingsDetailDto savingsAccount : savingsInUse) {
                if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
                    accountsForTransfer.add(savingsAccount);
                }
            }
        }
        return accountsForTransfer;
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ServiceException(org.mifos.framework.exceptions.ServiceException) CustomerDto(org.mifos.dto.domain.CustomerDto) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

ServiceException (org.mifos.framework.exceptions.ServiceException)93 PersistenceException (org.mifos.framework.exceptions.PersistenceException)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)39 Test (org.junit.Test)34 ExpectedException (org.springframework.test.annotation.ExpectedException)29 ArrayList (java.util.ArrayList)24 UserContext (org.mifos.security.util.UserContext)19 AccountBO (org.mifos.accounts.business.AccountBO)17 MifosUser (org.mifos.security.MifosUser)16 LoanBO (org.mifos.accounts.loan.business.LoanBO)15 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)14 AccountException (org.mifos.accounts.exceptions.AccountException)13 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)13 BusinessRuleException (org.mifos.service.BusinessRuleException)11 Date (java.util.Date)8 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)7 BigDecimal (java.math.BigDecimal)6 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)6 DateTimeService (org.mifos.framework.util.DateTimeService)6 LocalDate (org.joda.time.LocalDate)5