Search in sources :

Example 11 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveCustomerThatQualifyForSavings.

@Override
public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings(CustomerSearchDto customerSearchDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId());
        int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize());
        List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
        int i = 1;
        for (AccountSearchResultsDto customerBO : pagedResults) {
            CustomerSearchResultDto customer = new CustomerSearchResultDto();
            customer.setCustomerId(customerBO.getClientId());
            customer.setBranchName(customerBO.getOfficeName());
            customer.setGlobalId(customerBO.getGlobelNo());
            customer.setSearchIndex(i);
            customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
            customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
            customer.setClientName(customerBO.getClientName());
            pagedDetails.add(customer);
            i++;
        }
        return pagedDetails;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) AccountSearchResultsDto(org.mifos.accounts.util.helpers.AccountSearchResultsDto) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchResultDto(org.mifos.dto.domain.CustomerSearchResultDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class SavingsServiceFacadeWebTier method createSavingsAccount.

@Override
public Long createSavingsAccount(SavingsAccountCreationDto savingsAccountCreation, List<QuestionGroupDetail> questionGroups) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    LocalDate createdDate = new LocalDate();
    Integer createdById = user.getUserId();
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
    CustomerBO customer = this.customerDao.findCustomerById(savingsAccountCreation.getCustomerId());
    SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(savingsAccountCreation.getProductId());
    Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), savingsAccountCreation.getRecommendedOrMandatoryAmount());
    AccountState savingsAccountState = AccountState.fromShort(savingsAccountCreation.getAccountState());
    CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    SavingsAccountTypeInspector savingsAccountWrapper = new SavingsAccountTypeInspector(customer, savingsProduct.getRecommendedAmntUnit());
    try {
        SavingsBO savingsAccount = null;
        if (savingsAccountWrapper.isIndividualSavingsAccount()) {
            savingsAccount = SavingsBO.createIndividalSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy);
        } else if (savingsAccountWrapper.isJointSavingsAccountWithClientTracking()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(customer.getSearchId(), customer.getOfficeId(), CustomerLevel.CLIENT);
            savingsAccount = SavingsBO.createJointSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy, activeAndOnHoldClients);
        }
        try {
            personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
        } catch (AccountException e) {
            throw new MifosRuntimeException("Access denied!", e);
        }
        this.transactionHelper.startTransaction();
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        // save question groups
        if (!questionGroups.isEmpty()) {
            Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Savings");
            QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), savingsAccount.getAccountId(), eventSourceId, questionGroups);
            questionnaireServiceFacade.saveResponses(questionGroupDetails);
        }
        this.transactionHelper.commitTransaction();
        return savingsAccount.getAccountId().longValue();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) QuestionGroupDetails(org.mifos.platform.questionnaire.service.QuestionGroupDetails) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) AccountState(org.mifos.accounts.util.helpers.AccountState) LocalDate(org.joda.time.LocalDate) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SavingsAccountTypeInspector(org.mifos.accounts.savings.business.SavingsAccountTypeInspector) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) ArrayList(java.util.ArrayList) List(java.util.List) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 13 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class CustSearchAction method search.

/**
     * FIXME: KEITHW - When replacing search functionality for customers with spring/ftl implementation,
     * find cleaner way of implementing search that returns a non domain related class (data only object)
     */
@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (request.getParameter("perspective") != null) {
        request.setAttribute("perspective", request.getParameter("perspective"));
    }
    ActionForward actionForward = super.search(mapping, form, request, response);
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    UserContext userContext = getUserContext(request);
    String searchString = actionForm.getSearchString();
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeName = this.centerServiceFacade.retrieveOfficeName(userContext.getBranchId());
    addSeachValues(searchString, userContext.getBranchId().toString(), officeName, request);
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (StringUtils.isBlank(searchString)) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    if (actionForm.getInput() != null && actionForm.getInput().equals("loan")) {
        QueryResult groupClients = new CustomerPersistence().searchGroupClient(searchString, userContext.getId(), false);
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, groupClients, request);
    } else if (actionForm.getInput() != null && actionForm.getInput().equals("savings")) {
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(searchString, userContext.getId());
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerForSavings, request);
    }
    return actionForward;
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustSearchActionForm(org.mifos.customers.struts.actionforms.CustSearchActionForm) UserContext(org.mifos.security.util.UserContext) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) ActionForward(org.apache.struts.action.ActionForward) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 14 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class EditCustomerStatusAction method previewStatus.

@TransactionDemarcate(joinToken = true)
public ActionForward previewStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In EditCustomerStatusAction:preview()");
    CustomerBO customerBO = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    EditCustomerStatusActionForm statusActionForm = (EditCustomerStatusActionForm) form;
    statusActionForm.setCommentDate(DateUtils.getCurrentDate(getUserContext(request).getPreferredLocale()));
    if (StringUtils.isNotBlank(statusActionForm.getNewStatusId())) {
        CustomerStatusDetailDto customerStatusDetail = this.centerServiceFacade.retrieveCustomerStatusDetails(statusActionForm.getNewStatusIdValue(), statusActionForm.getFlagIdValue(), customerBO.getLevel().getValue());
        SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, customerStatusDetail.getStatusName(), request);
        SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, customerStatusDetail.getFlagName(), request);
    } else {
        SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, null, request);
        SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, null, request);
    }
    Short newStatusId = statusActionForm.getNewStatusIdValue();
    Short customerLevelId = statusActionForm.getLevelIdValue();
    List<CustomerCheckListBO> checklist = new CustomerPersistence().getStatusChecklist(newStatusId, customerLevelId);
    SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_CHECK_LIST, checklist, request);
    if (statusActionForm.getNewStatusIdValue().equals(CustomerStatus.CLIENT_CLOSED.getValue())) {
        return createClientQuestionnaire.fetchAppliedQuestions(mapping, statusActionForm, request, ActionForwards.previewStatus_success);
    }
    return mapping.findForward(ActionForwards.previewStatus_success.toString());
}
Also used : CustomerCheckListBO(org.mifos.customers.checklist.business.CustomerCheckListBO) CustomerStatusDetailDto(org.mifos.dto.screen.CustomerStatusDetailDto) EditCustomerStatusActionForm(org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 15 with CustomerPersistence

use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.

the class ApplyCustomerFeeChangesHelper method execute.

@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
    List<String> errorList = new ArrayList<String>();
    List<Short> updatedFeeIds = new ArrayList<Short>();
    try {
        updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
    } catch (Exception e) {
        errorList.add(e.getMessage());
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
    for (Short feeId : updatedFeeIds) {
        try {
            FeeBO hydratedFee = getFeeDao().findById(feeId);
            if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
                List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
                if (accounts != null && accounts.size() > 0) {
                    for (AccountBO account : accounts) {
                        updateAccountFee(account, hydratedFee);
                    }
                }
            }
            hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
            UserContext userContext = new UserContext();
            userContext.setId(PersonnelConstants.SYSTEM_USER);
            hydratedFee.setUserContext(userContext);
            hydratedFee.save();
            StaticHibernateUtil.commitTransaction();
        } catch (Exception e) {
            StaticHibernateUtil.rollbackTransaction();
            errorList.add("feeId: " + feeId);
        }
    }
    if (errorList.size() > 0) {
        throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException)

Aggregations

CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)40 PersistenceException (org.mifos.framework.exceptions.PersistenceException)15 UserContext (org.mifos.security.util.UserContext)14 ArrayList (java.util.ArrayList)13 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 Date (java.util.Date)10 Test (org.junit.Test)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)9 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)8 CustomerBO (org.mifos.customers.business.CustomerBO)8 LocalDate (org.joda.time.LocalDate)7 AccountException (org.mifos.accounts.exceptions.AccountException)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)6 CustomerException (org.mifos.customers.exceptions.CustomerException)6 BusinessRuleException (org.mifos.service.BusinessRuleException)6 AccountBO (org.mifos.accounts.business.AccountBO)5 CenterPersistence (org.mifos.customers.center.persistence.CenterPersistence)5 DateTime (org.joda.time.DateTime)4