Search in sources :

Example 51 with ApplicationException

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

the class WebTierAccountServiceFacade method applyCharge.

@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                        PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                        individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
                    } else {
                        FeeBO fee = this.feeDao.findById(chargeId);
                        if (fee instanceof RateFeeBO) {
                            individual.applyCharge(chargeId, chargeAmount);
                        } else {
                            Double radio = individual.getLoanAmount().getAmount().doubleValue() / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();
                            individual.applyCharge(chargeId, chargeAmount * radio);
                        }
                    }
                }
            }
        }
        account.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (account.isCustomerAccount()) {
            customerLevel = account.getCustomer().getLevel();
        }
        if (account.getPersonnel() != null) {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && account instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
        } else {
            account.applyCharge(chargeId, chargeAmount);
        }
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) CustomerLevel(org.mifos.customers.api.CustomerLevel) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 52 with ApplicationException

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

the class CustomerServiceImpl method transferClientTo.

@Override
public void transferClientTo(ClientBO client, OfficeBO receivingBranch) {
    try {
        this.hibernateTransactionHelper.startTransaction();
        this.hibernateTransactionHelper.beginAuditLoggingFor(client);
        client.transferToBranch(receivingBranch);
        if (client.getParentCustomer() != null) {
            CustomerBO parent = client.getParentCustomer();
            parent.incrementChildCount();
        }
        this.hibernateTransactionHelper.flushSession();
        client.generateSearchId();
        this.customerDao.save(client);
        if (client.getParentCustomer() != null) {
            this.customerDao.save(client.getParentCustomer());
        }
        this.hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerBO(org.mifos.customers.business.CustomerBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 53 with ApplicationException

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

the class CustomerServiceImpl method updateGroup.

@Override
public final void updateGroup(UserContext userContext, GroupUpdate groupUpdate) throws ApplicationException {
    GroupBO group = customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum());
    group.validateVersion(groupUpdate.getVersionNo());
    group.setUserContext(userContext);
    assembleCustomerPostionsFromDto(groupUpdate.getCustomerPositions(), group);
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(group);
        group.updateTrainedDetails(groupUpdate);
        group.setExternalId(groupUpdate.getExternalId());
        Address address = null;
        if (groupUpdate.getAddress() != null) {
            address = new Address(groupUpdate.getAddress().getLine1(), groupUpdate.getAddress().getLine2(), groupUpdate.getAddress().getLine3(), groupUpdate.getAddress().getCity(), groupUpdate.getAddress().getState(), groupUpdate.getAddress().getCountry(), groupUpdate.getAddress().getZip(), groupUpdate.getAddress().getPhoneNumber());
        }
        group.updateAddress(address);
        if (group.isNameDifferent(groupUpdate.getDisplayName())) {
            customerDao.validateGroupNameIsNotTakenForOffice(groupUpdate.getDisplayName(), group.getOffice().getOfficeId());
            group.setDisplayName(groupUpdate.getDisplayName());
        }
        updateLoanOfficerAndValidate(groupUpdate.getLoanOfficerId(), group);
        customerDao.save(group);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw e;
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) Address(org.mifos.framework.business.util.Address) GroupBO(org.mifos.customers.group.business.GroupBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 54 with ApplicationException

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

the class CustomerServiceImpl method transferClientTo.

@Override
public ClientBO transferClientTo(UserContext userContext, Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) throws CustomerException {
    ClientBO client = customerDao.findClientBySystemId(clientGlobalCustNum);
    client.validateVersion(previousClientVersionNo);
    client.validateIsSameGroup(groupId);
    client.updateDetails(userContext);
    GroupBO receivingGroup = (GroupBO) customerDao.findCustomerById(groupId);
    client.validateReceivingGroup(receivingGroup);
    client.validateForActiveAccounts();
    client.validateForPeriodicFees();
    if (client.getOfficeId() != receivingGroup.getOfficeId()) {
        customerDao.checkPermissionforEditingClientOfficeMembership(client.getUserContext(), client);
    }
    CustomerBO oldParent = client.getParentCustomer();
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        boolean regenerateSchedules = client.transferTo(receivingGroup);
        if (oldParent != null) {
            client.resetPositions(oldParent);
            oldParent.updateDetails(client.getUserContext());
            if (oldParent.getParentCustomer() != null) {
                CustomerBO center = oldParent.getParentCustomer();
                client.resetPositions(center);
                center.setUserContext(client.getUserContext());
            }
            customerDao.save(oldParent);
        }
        receivingGroup.updateDetails(client.getUserContext());
        customerDao.save(receivingGroup);
        client.updateDetails(userContext);
        customerDao.save(client);
        hibernateTransactionHelper.flushAndClearSession();
        if (regenerateSchedules) {
            client = customerDao.findClientBySystemId(clientGlobalCustNum);
            CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
            handleChangeInMeetingSchedule(client, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        }
        hibernateTransactionHelper.commitTransaction();
        return client;
    } catch (ApplicationException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ClientBO(org.mifos.customers.client.business.ClientBO) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerBO(org.mifos.customers.business.CustomerBO) CalendarEvent(org.mifos.calendar.CalendarEvent) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 55 with ApplicationException

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

the class CustomerServiceImpl method updateClientPersonalInfo.

@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
    ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
    client.validateVersion(personalInfo.getOriginalClientVersionNumber());
    client.updateDetails(userContext);
    LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
    LocalDate newDOB = currentDOB;
    try {
        // updating Date of birth
        // doesn''t sound normal but it can be required in certain cases
        // see http://mifosforge.jira.com/browse/MIFOS-4368
        newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
    } catch (InvalidDateException e) {
        throw new MifosRuntimeException(e);
    }
    if (!currentDOB.isEqual(newDOB)) {
        customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        client.updatePersonalInfo(personalInfo);
        clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
        customerDao.save(client);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new CustomerException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.commitTransaction();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientBO(org.mifos.customers.client.business.ClientBO) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

ApplicationException (org.mifos.framework.exceptions.ApplicationException)76 BusinessRuleException (org.mifos.service.BusinessRuleException)34 MifosRuntimeException (org.mifos.core.MifosRuntimeException)29 UserContext (org.mifos.security.util.UserContext)25 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 ArrayList (java.util.ArrayList)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)16 MifosUser (org.mifos.security.MifosUser)16 SystemException (org.mifos.framework.exceptions.SystemException)14 CustomerBO (org.mifos.customers.business.CustomerBO)10 ServiceException (org.mifos.framework.exceptions.ServiceException)10 Test (org.junit.Test)9 AccountException (org.mifos.accounts.exceptions.AccountException)9 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)9 CustomerException (org.mifos.customers.exceptions.CustomerException)9 HibernateException (org.hibernate.HibernateException)8 Session (org.hibernate.Session)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)7 CenterBO (org.mifos.customers.center.business.CenterBO)7