Search in sources :

Example 46 with ApplicationException

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

the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.

@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
    customerBO.updateDetails(userContext);
    try {
        CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
        if (customerBO.getPersonnel() != null) {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
        }
        // Integer oldLoanCycleNo = 0;
        if (customerHistoricalDataEntity == null) {
            customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
            customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
            customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
        } else {
            // oldLoanCycleNo =
            // customerHistoricalDataEntity.getLoanCycleNumber();
            customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
            customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
        }
        customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
        customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
        customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
        customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
        customerHistoricalDataEntity.setNotes(historicalData.getNotes());
        customerHistoricalDataEntity.setProductName(historicalData.getProductName());
        customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
        customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
        customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(customerBO);
        customerBO.updateHistoricalData(customerHistoricalDataEntity);
        this.customerDao.save(customerBO);
        this.transactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 47 with ApplicationException

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

the class CenterCustAction method update.

// NOTE - manage->preview->update
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CenterBO centerFromSession = (CenterBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    CenterCustActionForm actionForm = (CenterCustActionForm) form;
    AddressDto dto = null;
    if (actionForm.getAddress() != null) {
        dto = Address.toDto(actionForm.getAddress());
    }
    CenterUpdate centerUpdate = new CenterUpdate(centerFromSession.getCustomerId(), actionForm.getDisplayName(), centerFromSession.getVersionNo(), actionForm.getLoanOfficerIdValue(), actionForm.getExternalId(), actionForm.getMfiJoiningDate(), dto, actionForm.getCustomFields(), actionForm.getCustomerPositions());
    try {
        this.centerServiceFacade.updateCenter(centerUpdate);
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterCustActionForm(org.mifos.customers.center.struts.actionforms.CenterCustActionForm) CenterUpdate(org.mifos.dto.domain.CenterUpdate) CenterBO(org.mifos.customers.center.business.CenterBO) AddressDto(org.mifos.dto.domain.AddressDto) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 48 with ApplicationException

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

the class CenterCustAction method get.

@TransactionDemarcate(saveToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    CenterInformationDto centerInformationDto;
    try {
        centerInformationDto = this.centerServiceFacade.getCenterInformationDto(((CenterCustActionForm) form).getGlobalCustNum());
    } catch (MifosRuntimeException e) {
        if (e.getCause() instanceof ApplicationException) {
            throw (ApplicationException) e.getCause();
        }
        throw e;
    }
    SessionUtils.removeThenSetAttribute("centerInformationDto", centerInformationDto, request);
    // John W - 'BusinessKey' attribute used by breadcrumb but is not in associated jsp
    CenterBO centerBO = (CenterBO) this.customerDao.findCustomerById(centerInformationDto.getCenterDisplay().getCustomerId());
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, centerBO, request);
    setCurrentPageUrl(request, centerBO);
    setQuestionGroupInstances(request, centerBO);
    return mapping.findForward(ActionForwards.get_success.toString());
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) CenterCustActionForm(org.mifos.customers.center.struts.actionforms.CenterCustActionForm) CenterBO(org.mifos.customers.center.business.CenterBO) CenterInformationDto(org.mifos.dto.domain.CenterInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 49 with ApplicationException

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

the class BulkEntryTag method doStartTag.

@SuppressWarnings("unchecked")
@Override
public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    JspWriter out = pageContext.getOut();
    StringBuilder builder = new StringBuilder();
    CollectionSheetEntryGridDto bulkEntry = null;
    try {
        bulkEntry = (CollectionSheetEntryGridDto) SessionUtils.getAttribute(CollectionSheetEntryConstants.BULKENTRY, request);
    } catch (PageExpiredException e) {
        logger.error("Page expired getting BulkEntryBO.");
    }
    if (null != bulkEntry) {
        List<ProductDto> loanProducts = bulkEntry.getLoanProducts();
        List<ProductDto> savingsProducts = bulkEntry.getSavingProducts();
        try {
            final List<CustomValueListElementDto> custAttTypes = (List<CustomValueListElementDto>) SessionUtils.getAttribute(CollectionSheetEntryConstants.CUSTOMERATTENDANCETYPES, request);
            String method = request.getParameter(CollectionSheetEntryConstants.METHOD);
            generateTagData(bulkEntry, loanProducts, savingsProducts, custAttTypes, method, builder);
        } catch (ApplicationException ae) {
            throw new JspException(ae);
        } catch (SystemException se) {
            throw new JspException(se);
        }
    }
    try {
        out.write(builder.toString());
    } catch (IOException ioe) {
        throw new JspException(ioe);
    }
    return SKIP_BODY;
}
Also used : CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) SystemException(org.mifos.framework.exceptions.SystemException) List(java.util.List) ProductDto(org.mifos.application.servicefacade.ProductDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)

Example 50 with ApplicationException

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

the class MeetingActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    String method = request.getParameter("method");
    request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    ActionErrors errors = new ActionErrors();
    try {
        errors = validateFields(request, method);
    } catch (ApplicationException ae) {
        errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
    }
    if (null != errors && !errors.isEmpty()) {
        request.setAttribute(Globals.ERROR_KEY, errors);
        request.setAttribute("methodCalled", method);
    }
    return errors;
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

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