Search in sources :

Example 16 with PersistenceException

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

the class CheckListServiceFacadeWebTier method retrieveChecklistMasterData.

@Override
public List<CheckListMasterDto> retrieveChecklistMasterData() {
    try {
        Short localeIdNotUsed = null;
        List<CheckListMasterDto> masterData = new CheckListPersistence().getCheckListMasterData(localeIdNotUsed);
        for (CheckListMasterDto checkListMasterDto : masterData) {
            if (checkListMasterDto.isCustomer()) {
                checkListMasterDto.setMasterTypeName(ApplicationContextProvider.getBean(MessageLookup.class).lookupLabel(checkListMasterDto.getLookupKey()));
            } else {
                checkListMasterDto.setMasterTypeName(ApplicationContextProvider.getBean(MessageLookup.class).lookup(checkListMasterDto.getLookupKey()));
            }
        }
        return masterData;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : CheckListPersistence(org.mifos.customers.checklist.persistence.CheckListPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CheckListMasterDto(org.mifos.dto.domain.CheckListMasterDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 17 with PersistenceException

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

the class ClientServiceFacadeWebTier method getClientInformationDto.

@Override
public ClientInformationDto getClientInformationDto(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = customerDao.findClientBySystemId(globalCustNum);
    if (client == null) {
        throw new MifosRuntimeException("Client not found for globalCustNum, levelId: " + globalCustNum);
    }
    try {
        personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    ClientDisplayDto clientDisplay = this.customerDao.getClientDisplayDto(client.getCustomerId(), userContext);
    Integer clientId = client.getCustomerId();
    CustomerAccountSummaryDto customerAccountSummary = this.customerDao.getCustomerAccountSummaryDto(clientId);
    ClientPerformanceHistoryDto clientPerformanceHistory = assembleClientPerformanceHistoryDto(client.getClientPerformanceHistory(), clientId);
    CustomerAddressDto clientAddress = this.customerDao.getCustomerAddressDto(client);
    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(clientId);
    List<CustomerFlagDto> customerFlags = customerDao.getCustomerFlagDto(client.getCustomerFlags());
    List<LoanDetailDto> loanDetail = customerDao.getLoanDetailDto(client.getOpenLoanAccounts());
    List<LoanDetailDto> groupLoanDetail = customerDao.getLoanDetailDto(client.getOpenGroupLoanAccounts());
    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(clientId, userContext);
    CustomerMeetingDto customerMeeting = customerDao.getCustomerMeetingDto(client.getCustomerMeeting(), userContext);
    List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(clientId);
    List<LoanDetailDto> closedLoanAccounts = new ArrayList<LoanDetailDto>();
    List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
    for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
        if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.LOAN_ACCOUNT.getValue().intValue()) {
            closedLoanAccounts.add(new LoanDetailDto(closedAccount.getGlobalAccountNum(), ((LoanBO) closedAccount).getLoanOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((LoanBO) closedAccount).getLoanSummary().getOutstandingBalance().toString(), closedAccount.getTotalAmountDue().toString(), closedAccount.getTotalAmountInArrears().toString()));
        } else {
            closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
        }
    }
    Boolean activeSurveys = Boolean.FALSE;
    //        Boolean activeSurveys = new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CLIENT);
    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
    List<LoanDetailDto> guarantedLoanAccounts = new ArrayList<LoanDetailDto>();
    try {
        List<GuarantyEntity> guaranties = legacyAccountDao.getGuarantyByGurantorId(clientId);
        if (guaranties != null && guaranties.size() > 0) {
            for (GuarantyEntity guaranty : guaranties) {
                if (guaranty != null && guaranty.getState() != null && guaranty.getState()) {
                    LoanBO loan = loanDao.findById(guaranty.getLoanId());
                    guarantedLoanAccounts.add(new LoanDetailDto(loan.getGlobalAccountNum(), loan.getLoanOffering().getPrdOfferingName(), loan.getAccountState().getId(), loan.getAccountState().getName(), loan.getLoanSummary().getOutstandingBalance().toString(), loan.getTotalAmountDue().toString(), loan.getAccountType().getAccountTypeId(), loan.getTotalAmountInArrears().toString()));
                }
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException("Can not get guaranted loan accounts", e);
    }
    return new ClientInformationDto(clientDisplay, customerAccountSummary, clientPerformanceHistory, clientAddress, recentCustomerNotes, customerFlags, loanDetail, groupLoanDetail, savingsDetail, customerMeeting, activeSurveys, customerSurveys, closedLoanAccounts, closedSavingsAccounts, guarantedLoanAccounts);
}
Also used : CustomerAccountSummaryDto(org.mifos.dto.domain.CustomerAccountSummaryDto) SurveyDto(org.mifos.dto.domain.SurveyDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) GuarantyEntity(org.mifos.accounts.loan.business.GuarantyEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerMeetingDto(org.mifos.dto.domain.CustomerMeetingDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ClientDisplayDto(org.mifos.dto.screen.ClientDisplayDto) UserContext(org.mifos.security.util.UserContext) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) CustomerFlagDto(org.mifos.dto.domain.CustomerFlagDto) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ClientInformationDto(org.mifos.dto.screen.ClientInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 18 with PersistenceException

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

the class CoaServiceFacadeWebTier method delete.

@Override
public void delete(Short id) {
    try {
        COABO coaBo = legacyAccountDao.getPersistentObject(COABO.class, id);
        if (coaBo == null || !isModifiable(coaBo)) {
            throw new BusinessRuleException(CANNOT_MODIFY);
        }
        legacyAccountDao.deleteLedgerAccount(coaBo.getAccountId());
        reloadCache();
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) COABO(org.mifos.accounts.financial.business.COABO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 19 with PersistenceException

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

the class CollectionSheetServiceFacadeWebTier method loadMeetingDateForCustomer.

@Override
public CollectionSheetEntryFormDto loadMeetingDateForCustomer(final Integer customerId, final CollectionSheetEntryFormDto formDto) {
    Short backDatedTransactionAllowed = Constants.NO;
    java.util.Date meetingDate = null;
    try {
        meetingDate = customerPersistence.getLastMeetingDateForCustomer(customerId);
        final boolean isBackDatedTrxnAllowed = AccountingRules.isBackDatedTxnAllowed();
        if (meetingDate == null) {
            meetingDate = DateUtils.getCurrentDateWithoutTimeStamp();
        }
        backDatedTransactionAllowed = isBackDatedTrxnAllowed ? Constants.YES : Constants.NO;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    return new CollectionSheetEntryFormDto(formDto.getActiveBranchesList(), formDto.getPaymentTypesList(), formDto.getLoanOfficerList(), formDto.getCustomerList(), formDto.getReloadFormAutomatically(), formDto.getCenterHierarchyExists(), backDatedTransactionAllowed, meetingDate);
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 20 with PersistenceException

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

the class AdminServiceFacadeWebTier method createProductCategory.

@Override
public void createProductCategory(CreateOrUpdateProductCategory productCategoryDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    this.loanProductDao.validateNameIsAvailableForCategory(productCategoryDto.getProductCategoryName(), productCategoryDto.getProductTypeEntityId());
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        // FIXME - delegate to globalNumberGenerationStrategy
        StringBuilder globalPrdOfferingNum = new StringBuilder();
        globalPrdOfferingNum.append(userContext.getBranchId());
        globalPrdOfferingNum.append("-");
        Short maxPrdID = legacyProductCategoryDao.getMaxPrdCategoryId();
        globalPrdOfferingNum.append(StringUtils.leftPad(String.valueOf(maxPrdID != null ? maxPrdID + 1 : ProductDefinitionConstants.DEFAULTMAX), 3, '0'));
        String globalNumber = globalPrdOfferingNum.toString();
        ProductTypeEntity productType = new ProductTypeEntity(productCategoryDto.getProductTypeEntityId());
        ProductCategoryBO productCategoryBO = new ProductCategoryBO(productType, productCategoryDto.getProductCategoryName(), productCategoryDto.getProductCategoryDesc(), globalNumber);
        transactionHelper.startTransaction();
        this.loanProductDao.save(productCategoryBO);
        transactionHelper.commitTransaction();
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : HibernateTransactionHelper(org.mifos.framework.hibernate.helper.HibernateTransactionHelper) HibernateTransactionHelperForStaticHibernateUtil(org.mifos.framework.hibernate.helper.HibernateTransactionHelperForStaticHibernateUtil) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ProductTypeEntity(org.mifos.accounts.productdefinition.business.ProductTypeEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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