Search in sources :

Example 1 with ValueObjectConversionException

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

the class ConversionUtil method populateBusinessObject.

public static void populateBusinessObject(ActionForm actionForm, AbstractBusinessObject object, Locale locale) throws ValueObjectConversionException {
    try {
        if (null != object) {
            ConvertUtilsBean conBean = new ConvertUtilsBean();
            MifosSqlDateConverter converter = new MifosSqlDateConverter();
            MifosDoubleConverter mifosDoubleConverter = new MifosDoubleConverter();
            MifosStringToJavaUtilDateConverter stringToJavaDateConverter = new MifosStringToJavaUtilDateConverter();
            converter.setLocale(locale);
            conBean.register(stringToJavaDateConverter, java.util.Date.class);
            conBean.register(converter, java.sql.Date.class);
            conBean.register(mifosDoubleConverter, Double.class);
            BeanUtilsBean bean = new BeanUtilsBean(conBean, BeanUtilsBean.getInstance().getPropertyUtils());
            bean.copyProperties(object, actionForm);
        } else {
            throw new IllegalArgumentException("business object was null");
        }
    } catch (InvocationTargetException e) {
        throw new ValueObjectConversionException(e);
    } catch (IllegalAccessException e) {
        throw new ValueObjectConversionException(e);
    } catch (Exception e) {
        throw new ValueObjectConversionException(e);
    }
}
Also used : BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException) ConvertUtilsBean(org.apache.commons.beanutils.ConvertUtilsBean) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ValueObjectConversionException

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

the class BaseAction method preExecute.

protected void preExecute(ActionForm actionForm, HttpServletRequest request, TransactionDemarcate annotation) throws SystemException, ApplicationException {
    if (null != request.getParameter(Constants.CURRENTFLOWKEY)) {
        request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
    }
    preHandleTransaction(request, annotation);
    UserContext userContext = (UserContext) request.getSession().getAttribute(Constants.USER_CONTEXT_KEY);
    Locale locale = getLocale(userContext);
    if (!skipActionFormToBusinessObjectConversion(request.getParameter("method"))) {
        try {
            AbstractBusinessObject businessObject = getBusinessObjectFromSession(request);
            ConversionUtil.populateBusinessObject(actionForm, businessObject, locale);
        } catch (ValueObjectConversionException e) {
            logger.debug("Value object conversion exception while validating BusinessObject: " + new LogUtils().getStackTrace(e));
        }
    }
}
Also used : Locale(java.util.Locale) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) UserContext(org.mifos.security.util.UserContext) LogUtils(org.mifos.framework.business.LogUtils) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException)

Example 3 with ValueObjectConversionException

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

the class ConvertionUtilTest method testPopulateBusinessObjectFail.

public void testPopulateBusinessObjectFail() throws Exception {
    try {
        BaseActionForm baseActionForm = new BaseActionForm();
        ConversionUtil.populateBusinessObject(baseActionForm, null, new Locale("EN"));
        Assert.fail();
    } catch (ValueObjectConversionException e) {
        Assert.assertEquals("exception.framework.SystemException.ValueObjectConversionException", e.getKey());
    }
    try {
        ConversionUtil.populateBusinessObject(null, null, new Locale("EN"));
        Assert.fail();
    } catch (ValueObjectConversionException e) {
        Assert.assertEquals("exception.framework.SystemException.ValueObjectConversionException", e.getKey());
    }
}
Also used : Locale(java.util.Locale) BaseActionForm(org.mifos.framework.struts.actionforms.BaseActionForm) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException)

Aggregations

ValueObjectConversionException (org.mifos.framework.exceptions.ValueObjectConversionException)3 Locale (java.util.Locale)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BeanUtilsBean (org.apache.commons.beanutils.BeanUtilsBean)1 ConvertUtilsBean (org.apache.commons.beanutils.ConvertUtilsBean)1 AbstractBusinessObject (org.mifos.framework.business.AbstractBusinessObject)1 LogUtils (org.mifos.framework.business.LogUtils)1 BaseActionForm (org.mifos.framework.struts.actionforms.BaseActionForm)1 UserContext (org.mifos.security.util.UserContext)1