Search in sources :

Example 26 with PersistenceException

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

the class ClientBO method createDepositSchedule.

/**
     * delete when usage in constructor is removed...
     */
@Deprecated
public void createDepositSchedule(final List<Days> workingDays, final List<Holiday> holidays) throws CustomerException {
    try {
        if (getParentCustomer() != null) {
            List<SavingsBO> savingsList = getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getCustomerId());
            if (getParentCustomer().getParentCustomer() != null) {
                savingsList.addAll(getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getParentCustomer().getCustomerId()));
            }
            for (SavingsBO savings : savingsList) {
                savings.setUserContext(getUserContext());
                savings.generateAndUpdateDepositActionsForClient(this, workingDays, holidays);
            }
        }
    } catch (PersistenceException pe) {
        throw new CustomerException(pe);
    } catch (AccountException ae) {
        throw new CustomerException(ae);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Example 27 with PersistenceException

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

the class CustomerServiceImpl method changeStatus.

private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
    Short oldStatusId = oldStatus.getValue();
    Short newStatusId = newStatus.getValue();
    if (customer.isClient()) {
        ClientBO client = (ClientBO) customer;
        if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
            if (client.getParentCustomer() != null) {
                CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                client.addCustomerHierarchy(hierarchy);
            }
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
            List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
            client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
            client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
            if (client.getOfferingsAssociatedInCreate() != null) {
                for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
                    try {
                        SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
                        if (savingsOffering.isActive()) {
                            List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
                            client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
                        }
                    } catch (AccountException pe) {
                        throw new CustomerException(pe);
                    }
                }
            }
            new SavingsPersistence().persistSavingAccounts(client);
            try {
                if (client.getParentCustomer() != null) {
                    List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
                    if (client.getParentCustomer().getParentCustomer() != null) {
                        savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
                    }
                    for (SavingsBO savings : savingsList) {
                        savings.setUserContext(client.getUserContext());
                        if (client.getCustomerMeeting().getMeeting() != null) {
                            if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
                                DateTime today = new DateTime().toDateMidnight().toDateTime();
                                savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
                                savings.update();
                            }
                        }
                    }
                }
            } catch (PersistenceException pe) {
                throw new CustomerException(pe);
            } catch (AccountException ae) {
                throw new CustomerException(ae);
            }
        }
    }
}
Also used : CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CalendarEvent(org.mifos.calendar.CalendarEvent) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) DateTime(org.joda.time.DateTime) AccountException(org.mifos.accounts.exceptions.AccountException) DateMidnight(org.joda.time.DateMidnight) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 28 with PersistenceException

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

the class ConfigurationPersistence method getConfigurationKeyValueWithoutFlush.

public ConfigurationKeyValue getConfigurationKeyValueWithoutFlush(String key) {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put(KEY_QUERY_PARAMETER, key);
    try {
        return (ConfigurationKeyValue) execUniqueResultNamedQueryWithoutFlush(NamedQueryConstants.GET_CONFIGURATION_KEYVALUE_BY_KEY, queryParameters);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationKeyValue(org.mifos.config.business.ConfigurationKeyValue) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 29 with PersistenceException

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

the class ClientBO method handleAttendance.

// when this method is called from Bulk Entry preview persist will be false
public void handleAttendance(final Date meetingDate, final Short attendance, final boolean persist) throws CustomerException {
    ClientAttendanceBO clientAttendance = getClientAttendanceForMeeting(meetingDate);
    if (clientAttendance == null) {
        clientAttendance = new ClientAttendanceBO();
        clientAttendance.setMeetingDate(meetingDate);
        addClientAttendance(clientAttendance);
    }
    clientAttendance.setAttendance(attendance);
    if (persist) {
        try {
            getCustomerPersistence().createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new CustomerException(e);
        }
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 30 with PersistenceException

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

the class LegacyClientDao method saveClient.

public void saveClient(final ClientBO clientBO) throws CustomerException {
    CustomerPersistence customerPersistence = new CustomerPersistence();
    customerPersistence.saveCustomer(clientBO);
    try {
        if (clientBO.getParentCustomer() != null) {
            customerPersistence.createOrUpdate(clientBO.getParentCustomer());
        }
        // seems fishy... why do savings accounts need updating here?
        new SavingsPersistence().persistSavingAccounts(clientBO);
    } catch (PersistenceException pe) {
        throw new CustomerException(CustomerConstants.CREATE_FAILED_EXCEPTION, pe);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Aggregations

PersistenceException (org.mifos.framework.exceptions.PersistenceException)215 MifosRuntimeException (org.mifos.core.MifosRuntimeException)98 ArrayList (java.util.ArrayList)55 ServiceException (org.mifos.framework.exceptions.ServiceException)53 AccountException (org.mifos.accounts.exceptions.AccountException)40 Test (org.junit.Test)35 ExpectedException (org.springframework.test.annotation.ExpectedException)32 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)24 BusinessRuleException (org.mifos.service.BusinessRuleException)23 Money (org.mifos.framework.util.helpers.Money)22 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)20 MifosUser (org.mifos.security.MifosUser)19 UserContext (org.mifos.security.util.UserContext)19 HashMap (java.util.HashMap)18 HibernateException (org.hibernate.HibernateException)18 Query (org.hibernate.Query)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 Session (org.hibernate.Session)14 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)14 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)14