Search in sources :

Example 11 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException 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 12 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException 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 13 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class CollectionSheetServiceFacadeWebTier method getCollectionSheet.

@Override
public CollectionSheetDto getCollectionSheet(Integer customerId, LocalDate meetingDate) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    return collectionSheetService.retrieveCollectionSheet(customerId, meetingDate);
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException 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 15 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException 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

MifosRuntimeException (org.mifos.core.MifosRuntimeException)305 PersistenceException (org.mifos.framework.exceptions.PersistenceException)136 ArrayList (java.util.ArrayList)102 BusinessRuleException (org.mifos.service.BusinessRuleException)95 UserContext (org.mifos.security.util.UserContext)94 MifosUser (org.mifos.security.MifosUser)87 AccountException (org.mifos.accounts.exceptions.AccountException)79 ServiceException (org.mifos.framework.exceptions.ServiceException)69 ApplicationException (org.mifos.framework.exceptions.ApplicationException)48 LoanBO (org.mifos.accounts.loan.business.LoanBO)41 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)39 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)37 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)36 LocalDate (org.joda.time.LocalDate)35 CustomerBO (org.mifos.customers.business.CustomerBO)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)28 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)27 CustomerException (org.mifos.customers.exceptions.CustomerException)27 Money (org.mifos.framework.util.helpers.Money)27 AccountBO (org.mifos.accounts.business.AccountBO)25