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);
}
}
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));
}
}
}
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());
}
}
Aggregations