Search in sources :

Example 81 with ServiceException

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

the class LoanBO method disburseLoan.

private void disburseLoan(final String receiptNum, final Date transactionDate, final Short paymentTypeId, final PersonnelBO loggedInUser, final Date receiptDate, final Short rcvdPaymentTypeId, final boolean persistChange, final Short paymentTypeIdForFees, Integer accountForTransferId) throws AccountException, PersistenceException {
    if ((this.getState().compareTo(AccountState.LOAN_APPROVED) != 0) && (this.getState().compareTo(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) != 0)) {
        throw new AccountException("Loan not in a State to be Disbursed: " + this.getState().toString());
    }
    if (this.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(this.getLoanOffering())) {
        throw new AccountException("errors.cannotDisburseLoan.because.otherLoansAreActive");
    }
    try {
        new ProductMixValidator().checkIfProductsOfferingCanCoexist(this);
    } catch (ServiceException e1) {
        throw new AccountException(e1.getMessage());
    }
    addLoanActivity(buildLoanActivity(this.loanAmount, loggedInUser, AccountConstants.LOAN_DISBURSAL, transactionDate));
    // regenerate the installments
    if (!isFixedRepaymentSchedule() && !DateUtils.getDateWithoutTimeStamp(disbursementDate.getTime()).equals(DateUtils.getDateWithoutTimeStamp(transactionDate.getTime()))) {
        final boolean lsimEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
        if (lsimEnabled) {
            // QUESTION: does minDays
            final int minDaysInterval = new ConfigurationPersistence().getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
            this.disbursementDate = new DateTime(transactionDate).plusDays(minDaysInterval - 1).toDate();
        } else {
            this.disbursementDate = transactionDate;
        }
        regeneratePaymentSchedule(lsimEnabled, null);
        if (this.isParentGroupLoanAccount()) {
            groupLoanAccountServiceFacade.fixMemberAndParentInstallmentDetails(this.getAccountId());
        }
    }
    this.disbursementDate = transactionDate;
    final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), newState, loggedInUser, this));
    this.setAccountState(newState);
    //
    // Client performance entry
    updateCustomerHistoryOnDisbursement(this.loanAmount);
    if (getPerformanceHistory() != null) {
        getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
    }
    //
    //
    // build up account payment related data
    AccountPaymentEntity accountPayment = null;
    if (this.isInterestDeductedAtDisbursement()) {
        // the 1st payment is made and creates an initial accountPaymentEntity.
        // This disbursal process carries on with that accountPaymentEntity by updating the 'amount' to the actual
        // disbursed amount.
        accountPayment = payInterestAtDisbursement(receiptNum, transactionDate, rcvdPaymentTypeId, loggedInUser, receiptDate);
        accountPayment.setAmount(this.loanAmount.subtract(accountPayment.getAmount()));
    } else {
        // Disbursal process has to create its own accountPayment taking into account any disbursement fees
        Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
        accountPayment = new AccountPaymentEntity(this, this.loanAmount.subtract(feeAmountAtDisbursement), receiptNum, receiptDate, getPaymentTypeEntity(paymentTypeId), transactionDate);
        accountPayment.setCreatedByUser(loggedInUser);
        if (feeAmountAtDisbursement.isGreaterThanZero()) {
            processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, paymentTypeIdForFees, accountForTransferId);
        }
    }
    // create trxn entry for disbursal
    final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, loggedInUser, transactionDate, this.loanAmount, "-", null, this.loanAmount, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPayment.addAccountTrxn(loanTrxnDetailEntity);
    this.addAccountPayment(accountPayment);
    this.buildFinancialEntries(accountPayment.getAccountTrxns());
    if (persistChange) {
        try {
            ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) ProductMixValidator(org.mifos.accounts.loan.struts.action.validate.ProductMixValidator) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 82 with ServiceException

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

the class PersonnelServiceFacadeWebTier method createPersonnelInformation.

@Override
public UserDetailDto createPersonnelInformation(CreateOrUpdatePersonnelInformation personnel) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    try {
        PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
        List<RoleBO> roles = new ArrayList<RoleBO>();
        for (ListElement element : personnel.getRoles()) {
            RoleBO role = personnelBusinessService.getRoleById(new Short(element.getId().shortValue()));
            roles.add(role);
        }
        AddressDto addressDto = personnel.getAddress();
        Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
        OfficeBO office = officeDao.findOfficeById(personnel.getOfficeId());
        Name name = new Name(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName());
        verifyFields(personnel.getUserName(), personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), name.getDisplayName());
        PersonnelBO newPersonnel = new PersonnelBO(PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue()), office, personnel.getTitle(), personnel.getPreferredLocale(), personnel.getPassword(), personnel.getUserName(), personnel.getEmailId(), roles, personnel.getCustomFields(), name, personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), personnel.getMaritalStatus(), personnel.getGender(), personnel.getDateOfJoiningMFI().toDate(), personnel.getDateOfJoiningBranch().toDate(), address, Integer.valueOf(user.getUserId()).shortValue(), personnel.getPasswordExpirationDate().toDate(), null);
        transactionHelper.startTransaction();
        this.personnelDao.save(newPersonnel);
        transactionHelper.flushSession();
        newPersonnel.generateGlobalPersonnelNum();
        this.personnelDao.save(newPersonnel);
        transactionHelper.commitTransaction();
        return newPersonnel.toDto();
    } catch (PersistenceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ValidationException e) {
        transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e.getValues(), e);
    } catch (ServiceException e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ValidationException(org.mifos.framework.exceptions.ValidationException) Address(org.mifos.framework.business.util.Address) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) Name(org.mifos.framework.business.util.Name) BusinessRuleException(org.mifos.service.BusinessRuleException) ServiceException(org.mifos.framework.exceptions.ServiceException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 83 with ServiceException

use of org.mifos.framework.exceptions.ServiceException 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 84 with ServiceException

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

the class LoanAccountServiceFacadeWebTier method getApplicablePenalties.

@Override
public List<ApplicableCharge> getApplicablePenalties(Integer accountId) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        LoanBO loan = this.loanDao.findById(accountId);
        try {
            personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
        } catch (AccountException e) {
            throw new MifosRuntimeException(e.getMessage(), e);
        }
        return loanBusinessService.getAppllicablePenalties(accountId, userContext);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 85 with ServiceException

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

the class SavingsServiceFacadeWebTier method retrieveSavingsAccountAuditLogs.

@Override
public List<AuditLogDto> retrieveSavingsAccountAuditLogs(Long savingsId) {
    List<AuditLogDto> auditLogDtos = new ArrayList<AuditLogDto>();
    AuditBusinessService auditBusinessService = new AuditBusinessService();
    try {
        List<AuditLogView> auditLogs = auditBusinessService.getAuditLogRecords(EntityType.SAVINGS.getValue(), savingsId.intValue());
        for (AuditLogView auditLogView : auditLogs) {
            auditLogDtos.add(auditLogView.toDto());
        }
        return auditLogDtos;
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AuditBusinessService(org.mifos.framework.components.audit.business.service.AuditBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ArrayList(java.util.ArrayList) AuditLogView(org.mifos.framework.components.audit.util.helpers.AuditLogView) AuditLogDto(org.mifos.dto.domain.AuditLogDto) 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