Improved: function parseBigDecimalForEntity is in wrong location

(OFBIZ-10689)

Actually this is a firts step that simply renames 
  ObjectType::simpleTypeConvert to
  ObjectType::simpleTypeOrObjectConvert
and improves the simpleTypeOrObjectConvert Javadoc

Thanks: Pierre Smits for report, Deepak Dixit for discussion

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1850027 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2018-12-31 09:23:36 +00:00
parent 9306ba09b6
commit b7f211729f
30 changed files with 68 additions and 61 deletions
@@ -137,7 +137,7 @@ public class PcChargeApi {
String objString = null;
try {
objString = (String) ObjectType.simpleTypeConvert(value, "java.lang.String", null, null);
objString = (String) ObjectType.simpleTypeOrObjectConvert(value, "java.lang.String", null, null);
} catch (GeneralException | ClassCastException e) {
Debug.logError(e, module);
throw new IllegalArgumentException("Unable to convert value to String");
@@ -121,7 +121,7 @@ public class RitaApi {
String objString = null;
try {
objString = (String) ObjectType.simpleTypeConvert(value, "java.lang.String", null, null);
objString = (String) ObjectType.simpleTypeOrObjectConvert(value, "java.lang.String", null, null);
} catch (GeneralException | ClassCastException e) {
Debug.logError(e, module);
throw new IllegalArgumentException("Unable to convert value to String");
@@ -185,7 +185,7 @@ public class OrderManagerEvents {
if (UtilValidate.isNotEmpty(paymentMethodAmountStr)) {
BigDecimal paymentMethodAmount = BigDecimal.ZERO;
try {
paymentMethodAmount = (BigDecimal) ObjectType.simpleTypeConvert(paymentMethodAmountStr, "BigDecimal", null, locale);
paymentMethodAmount = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(paymentMethodAmountStr, "BigDecimal", null, locale);
} catch (GeneralException e) {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderProblemsPaymentParsingAmount", locale));
return "error";
@@ -225,7 +225,7 @@ public class OrderManagerEvents {
if (UtilValidate.isNotEmpty(amountStr)) {
BigDecimal paymentTypeAmount = BigDecimal.ZERO;
try {
paymentTypeAmount = (BigDecimal) ObjectType.simpleTypeConvert(amountStr, "BigDecimal", null, locale);
paymentTypeAmount = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(amountStr, "BigDecimal", null, locale);
} catch (GeneralException e) {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderProblemsPaymentParsingAmount", locale));
return "error";
@@ -225,7 +225,7 @@ public class OrderLookupServices {
paramList.add("minDate=" + minDate);
try {
Object converted = ObjectType.simpleTypeConvert(minDate, "Timestamp", null, null);
Object converted = ObjectType.simpleTypeOrObjectConvert(minDate, "Timestamp", null, null);
if (converted != null) {
conditions.add(EntityCondition.makeCondition(dateField, EntityOperator.GREATER_THAN_EQUAL_TO, converted));
}
@@ -243,7 +243,7 @@ public class OrderLookupServices {
paramList.add("maxDate=" + maxDate);
try {
Object converted = ObjectType.simpleTypeConvert(maxDate, "Timestamp", null, null);
Object converted = ObjectType.simpleTypeOrObjectConvert(maxDate, "Timestamp", null, null);
if (converted != null) {
conditions.add(EntityCondition.makeCondition("orderDate", EntityOperator.LESS_THAN_EQUAL_TO, converted));
}
@@ -3691,7 +3691,7 @@ public class OrderServices {
String quantityStr = itemQtyMap.get(key);
BigDecimal groupQty = BigDecimal.ZERO;
try {
groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
groupQty = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantityStr, "BigDecimal", null, locale);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -3755,7 +3755,7 @@ public class OrderServices {
if (UtilValidate.isNotEmpty(priceStr)) {
BigDecimal price = null;
try {
price = (BigDecimal) ObjectType.simpleTypeConvert(priceStr, "BigDecimal", null, locale);
price = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(priceStr, "BigDecimal", null, locale);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -3866,7 +3866,7 @@ public class OrderServices {
String quantityStr = itemQtyMap.get(key);
BigDecimal groupQty = BigDecimal.ZERO;
try {
groupQty = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
groupQty = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantityStr, "BigDecimal", null, locale);
} catch (GeneralException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
@@ -1472,7 +1472,7 @@ public class CheckOutHelper {
}
try {
this.cart.setShipBeforeDate(shipGroupIndex, (Timestamp) ObjectType.simpleTypeConvert(shipBeforeDate, "Timestamp", null, null));
this.cart.setShipBeforeDate(shipGroupIndex, (Timestamp) ObjectType.simpleTypeOrObjectConvert(shipBeforeDate, "Timestamp", null, null));
} catch (Exception e) {
errMsg = "Ship Before Date must be a valid date formed ";
result = ServiceUtil.returnError(errMsg);
@@ -1487,7 +1487,7 @@ public class CheckOutHelper {
}
try {
this.cart.setShipAfterDate(shipGroupIndex, (Timestamp) ObjectType.simpleTypeConvert(shipAfterDate,"Timestamp", null, null));
this.cart.setShipAfterDate(shipGroupIndex, (Timestamp) ObjectType.simpleTypeOrObjectConvert(shipAfterDate,"Timestamp", null, null));
} catch (Exception e) {
errMsg = "Ship After Date must be a valid date formed ";
result = ServiceUtil.returnError(errMsg);
@@ -414,7 +414,7 @@ public class ShoppingCartEvents {
reservLengthStr = (String) paramMap.remove("reservLength");
// parse the reservation Length
try {
reservLength = (BigDecimal) ObjectType.simpleTypeConvert(reservLengthStr, "BigDecimal", null, locale);
reservLength = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(reservLengthStr, "BigDecimal", null, locale);
} catch (Exception e) {
Debug.logWarning(e, "Problems parsing reservation length string: "
+ reservLengthStr, module);
@@ -427,7 +427,7 @@ public class ShoppingCartEvents {
reservPersonsStr = (String) paramMap.remove("reservPersons");
// parse the number of persons
try {
reservPersons = (BigDecimal) ObjectType.simpleTypeConvert(reservPersonsStr, "BigDecimal", null, locale);
reservPersons = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(reservPersonsStr, "BigDecimal", null, locale);
} catch (Exception e) {
Debug.logWarning(e, "Problems parsing reservation number of persons string: " + reservPersonsStr, module);
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error, "OrderNumberOfPersonsShouldBeOneOrLarger", locale));
@@ -461,7 +461,7 @@ public class ShoppingCartEvents {
// parse the price
try {
price = (BigDecimal) ObjectType.simpleTypeConvert(priceStr, "BigDecimal", null, locale);
price = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(priceStr, "BigDecimal", null, locale);
} catch (Exception e) {
Debug.logWarning(e, "Problems parsing price string: " + priceStr, module);
price = null;
@@ -469,7 +469,7 @@ public class ShoppingCartEvents {
// parse the quantity
try {
quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, "BigDecimal", null, locale);
quantity = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantityStr, "BigDecimal", null, locale);
//For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, cart.getProductStoreId())){
@@ -500,7 +500,7 @@ public class ShoppingCartEvents {
BigDecimal amount = null;
if (UtilValidate.isNotEmpty(selectedAmountStr)) {
try {
amount = (BigDecimal) ObjectType.simpleTypeConvert(selectedAmountStr, "BigDecimal", null, locale);
amount = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(selectedAmountStr, "BigDecimal", null, locale);
} catch (Exception e) {
Debug.logWarning(e, "Problem parsing amount string: " + selectedAmountStr, module);
amount = null;
@@ -541,7 +541,7 @@ public class ShoppingCartHelper {
if (UtilValidate.isNotEmpty(quantStr)) {
BigDecimal quantity;
try {
quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantStr, "BigDecimal", null, cart.getLocale());
quantity = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantStr, "BigDecimal", null, cart.getLocale());
} catch (GeneralException ge) {
quantity = BigDecimal.ZERO;
}
@@ -744,12 +744,12 @@ public class ShoppingCartHelper {
}
} else if (parameterName.startsWith("reservLength")) {
if (item != null) {
BigDecimal reservLength = (BigDecimal) ObjectType.simpleTypeConvert(quantString, "BigDecimal", null, locale);
BigDecimal reservLength = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantString, "BigDecimal", null, locale);
item.setReservLength(reservLength);
}
} else if (parameterName.startsWith("reservPersons")) {
if (item != null) {
BigDecimal reservPersons = (BigDecimal) ObjectType.simpleTypeConvert(quantString, "BigDecimal", null, locale);
BigDecimal reservPersons = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantString, "BigDecimal", null, locale);
item.setReservPersons(reservPersons);
}
} else if (parameterName.startsWith("shipBeforeDate")) {
@@ -784,7 +784,7 @@ public class ShoppingCartHelper {
item.setItemType(quantString);
}
} else {
quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantString, "BigDecimal", null, locale);
quantity = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(quantString, "BigDecimal", null, locale);
//For quantity we should test if we allow to add decimal quantity for this product an productStore :
// if not and if quantity is in decimal format then return error.
if (!ProductWorker.isDecimalQuantityOrderAllowed(delegator, item.getProductId(), cart.getProductStoreId()) && parameterName.startsWith("update")) {
@@ -62,7 +62,7 @@ public class TaskEvents {
Locale locale = UtilHttp.getLocale(request);
try {
fromDate = (java.sql.Timestamp) ObjectType.simpleTypeConvert(fromDateStr, "java.sql.Timestamp", null, null);
fromDate = (java.sql.Timestamp) ObjectType.simpleTypeOrObjectConvert(fromDateStr, "java.sql.Timestamp", null, null);
} catch (GeneralException e) {
request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderInvalidDateFormatForFromDate", locale));
return "error";
@@ -236,7 +236,7 @@ public class ProductEvents {
if (UtilValidate.isNotEmpty(fromDateStr)) {
try {
fromDate = (Timestamp) ObjectType.simpleTypeConvert(fromDateStr, "Timestamp", null, UtilHttp.getTimeZone(request), UtilHttp.getLocale(request), false);
fromDate = (Timestamp) ObjectType.simpleTypeOrObjectConvert(fromDateStr, "Timestamp", null, UtilHttp.getTimeZone(request), UtilHttp.getLocale(request), false);
} catch (Exception e) {
errMsgList.add("From Date not formatted correctly.");
}
@@ -307,7 +307,7 @@ public class ProductEvents {
if (UtilValidate.isNotEmpty(thruDateStr)) {
try {
thruDate = (Timestamp) ObjectType.simpleTypeConvert(thruDateStr, "Timestamp", null, UtilHttp.getTimeZone(request), UtilHttp.getLocale(request), false);
thruDate = (Timestamp) ObjectType.simpleTypeOrObjectConvert(thruDateStr, "Timestamp", null, UtilHttp.getTimeZone(request), UtilHttp.getLocale(request), false);
} catch (Exception e) {
errMsgList.add(UtilProperties.getMessage(resource,"productevents.thru_date_not_formatted_correctly", UtilHttp.getLocale(request)));
}
@@ -471,7 +471,7 @@ public class ICalConverter {
if (serviceMap.containsKey(modelParam.name)) {
Object value = serviceMap.get(modelParam.name);
if (UtilValidate.isNotEmpty(modelParam.type)) {
value = ObjectType.simpleTypeConvert(value, modelParam.type, null, null, null, true);
value = ObjectType.simpleTypeOrObjectConvert(value, modelParam.type, null, null, null, true);
}
localMap.put(modelParam.name, value);
}
@@ -485,14 +485,21 @@ public class ObjectType {
return isOrSubOf(objectClass, typeClass);
}
public static Object simpleTypeConvert(Object obj, String type, String format, Locale locale, boolean noTypeFail) throws GeneralException {
return simpleTypeConvert(obj, type, format, null, locale, noTypeFail);
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale, boolean noTypeFail) throws GeneralException {
return simpleTypeOrObjectConvert(obj, type, format, null, locale, noTypeFail);
}
/**
* Converts the passed object to the named simple type. Supported types
* include: String, Boolean, Double, Float, Long, Integer, Date (java.sql.Date),
* Time, Timestamp, TimeZone;
* Converts the passed object to the named type.
* Initially created for only simple types but actually handle more types and not all simple types.
* See ObjectTypeTests class for more, and (normally) up to date information
*
* Supported types:
* - All primitives
* - Simple types: String, Boolean, Double, Float, Long, Integer, BigDecimal.
* - Other Objects: List, Map, Set, Calendar, Date (java.sql.Date), Time, Timestamp, TimeZone, Date (util.Date and sql.Date)
* - Simple types (maybe) not handled: Short, BigInteger, Byte, Character, ObjectName and Void...
*
* @param obj Object to convert
* @param type Optional Java class name of type to convert to. A <code>null</code> or empty <code>String</code> will return the original object.
* @param format Optional (can be null) format string for Date, Time, Timestamp
@@ -504,7 +511,7 @@ public class ObjectType {
*/
@SourceMonitored
@SuppressWarnings("unchecked")
public static Object simpleTypeConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail) throws GeneralException {
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail) throws GeneralException {
if (obj == null || UtilValidate.isEmpty(type) || "Object".equals(type) || "java.lang.Object".equals(type)) {
return obj;
}
@@ -517,7 +524,7 @@ public class ObjectType {
if ("String".equals(type) || "java.lang.String".equals(type)) {
return nodeValue;
}
return simpleTypeConvert(nodeValue, type, format, timeZone, locale, noTypeFail);
return simpleTypeOrObjectConvert(nodeValue, type, format, timeZone, locale, noTypeFail);
}
int genericsStart = type.indexOf("<");
if (genericsStart != -1) {
@@ -581,8 +588,8 @@ public class ObjectType {
return obj;
}
public static Object simpleTypeConvert(Object obj, String type, String format, Locale locale) throws GeneralException {
return simpleTypeConvert(obj, type, format, locale, true);
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale) throws GeneralException {
return simpleTypeOrObjectConvert(obj, type, format, locale, true);
}
public static Boolean doRealCompare(Object value1, Object value2, String operator, String type, String format,
@@ -626,7 +633,7 @@ public class ObjectType {
value2Locale = UtilMisc.parseLocale("en");
}
try {
convertedValue2 = simpleTypeConvert(value2, type, format, value2Locale);
convertedValue2 = simpleTypeOrObjectConvert(value2, type, format, value2Locale);
} catch (GeneralException e) {
Debug.logError(e, module);
messages.add("Could not convert value2 for comparison: " + e.getMessage());
@@ -642,7 +649,7 @@ public class ObjectType {
Object convertedValue1 = null;
try {
convertedValue1 = simpleTypeConvert(value1, type, format, locale);
convertedValue1 = simpleTypeOrObjectConvert(value1, type, format, locale);
} catch (GeneralException e) {
Debug.logError(e, module);
messages.add("Could not convert value1 for comparison: " + e.getMessage());
@@ -146,7 +146,7 @@ public final class UtilProperties implements Serializable {
return defaultNumber;
}
try {
return (Number)(ObjectType.simpleTypeConvert(str, type, null, null));
return (Number)(ObjectType.simpleTypeOrObjectConvert(str, type, null, null));
} catch (GeneralException e) {
Debug.logWarning("Error converting String \"" + str + "\" to " + type + "; using defaultNumber " + defaultNumber + ".", module);
}
@@ -439,7 +439,7 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty {
if (obj instanceof String) {
buffer.append(obj);
} else {
buffer.append(ObjectType.simpleTypeConvert(obj, "String", null, timeZone, locale, true));
buffer.append(ObjectType.simpleTypeOrObjectConvert(obj, "String", null, timeZone, locale, true));
}
}
} catch (GeneralException | RuntimeException e) {
@@ -96,7 +96,7 @@ public class ObjectTypeTests extends GenericTestCaseBase {
}
public static Object simpleTypeConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail) throws GeneralException {
return ObjectType.simpleTypeConvert(obj, type, format, timeZone, locale, noTypeFail);
return ObjectType.simpleTypeOrObjectConvert(obj, type, format, timeZone, locale, noTypeFail);
}
public static void simpleTypeConvertTest(String label, Object toConvert, String type, Object wanted) throws GeneralException {
@@ -249,7 +249,7 @@ public class ObjectTypeTests extends GenericTestCaseBase {
public void testClassNotFound() {
GeneralException caught = null;
try {
ObjectType.simpleTypeConvert(this, "foobarbaz", null, null, null, false);
ObjectType.simpleTypeOrObjectConvert(this, "foobarbaz", null, null, null, false);
} catch (GeneralException e) {
caught = e;
} finally {
@@ -485,7 +485,7 @@ public class GenericEntity implements Map<String, Object>, LocalizedMap<Object>,
// make sure the type matches the field Java type
if (value instanceof TimeDuration) {
try {
value = ObjectType.simpleTypeConvert(value, type.getJavaType(), null, null);
value = ObjectType.simpleTypeOrObjectConvert(value, type.getJavaType(), null, null);
} catch (GeneralException e) {
Debug.logError(e, module);
}
@@ -1376,7 +1376,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
throw new IllegalArgumentException(errMsg);
}
try {
return ObjectType.simpleTypeConvert(value, fieldJavaType, null, null, false);
return ObjectType.simpleTypeOrObjectConvert(value, fieldJavaType, null, null, false);
} catch (GeneralException e) {
String errMsg = "Could not convert field value for the field: [" + modelField.getName() + "] on the [" + this.getEntityName() + "] entity to the [" + fieldJavaType + "] type for the value [" + value + "]: " + e.toString();
Debug.logError(e, errMsg, module);
@@ -1404,7 +1404,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
}
String fieldJavaType = modelFieldTypeReader.getModelFieldType(modelField.getType()).getJavaType();
try {
return ObjectType.simpleTypeConvert(value, fieldJavaType, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
return ObjectType.simpleTypeOrObjectConvert(value, fieldJavaType, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
} catch (GeneralException e) {
String errMsg = "Could not convert field value for the field: [" + modelField.getName() + "] on the [" + this.getEntityName() + "] entity to the [" + fieldJavaType + "] type for the value [" + value + "]: " + e.toString();
Debug.logError(e, errMsg, module);
@@ -63,7 +63,7 @@ public class Converters implements ConverterLoader {
Object fieldValue = entry.getValue();
ModelField field = value.getModelEntity().getField(fieldName);
ModelFieldType type = delegator.getEntityFieldType(value.getModelEntity(), field.getType());
value.set(fieldName, ObjectType.simpleTypeConvert(fieldValue, type.getJavaType(), null, null));
value.set(fieldName, ObjectType.simpleTypeOrObjectConvert(fieldValue, type.getJavaType(), null, null));
}
return value;
} catch (ConversionException e) {
@@ -180,7 +180,7 @@ public final class SetCalendar extends MethodOperation {
int millis = 0;
try {
if (!this.localeFse.isEmpty()) {
locale = (Locale) ObjectType.simpleTypeConvert(this.localeFse.expand(methodContext.getEnvMap()), "Locale", null, null);
locale = (Locale) ObjectType.simpleTypeOrObjectConvert(this.localeFse.expand(methodContext.getEnvMap()), "Locale", null, null);
}
if (locale == null) {
locale = methodContext.getLocale();
@@ -189,7 +189,7 @@ public final class SetCalendar extends MethodOperation {
locale = Locale.getDefault();
}
if (!this.timeZoneFse.isEmpty()) {
timeZone = (TimeZone) ObjectType.simpleTypeConvert(this.timeZoneFse.expand(methodContext.getEnvMap()), "TimeZone", null, null);
timeZone = (TimeZone) ObjectType.simpleTypeOrObjectConvert(this.timeZoneFse.expand(methodContext.getEnvMap()), "TimeZone", null, null);
}
if (timeZone == null) {
timeZone = methodContext.getTimeZone();
@@ -74,7 +74,7 @@ public class Convert extends SimpleMapOperation {
}
Object convertedObject = null;
try {
convertedObject = ObjectType.simpleTypeConvert(fieldObject, type, format, locale);
convertedObject = ObjectType.simpleTypeOrObjectConvert(fieldObject, type, format, locale);
} catch (GeneralException e) {
addMessage(messages, loader, locale);
Debug.logError(e, "Error in convert simple-map-processor operation: " + e.toString(), module);
@@ -49,7 +49,7 @@ public class InFieldOper extends MakeInStringOperation {
return null;
}
try {
return (String) ObjectType.simpleTypeConvert(obj, "String", null, locale);
return (String) ObjectType.simpleTypeOrObjectConvert(obj, "String", null, locale);
} catch (GeneralException e) {
Debug.logWarning(e, module);
messages.add("Error converting incoming field \"" + fieldName + "\" in map processor: " + e.getMessage());
@@ -56,7 +56,7 @@ public class Regexp extends SimpleMapOperation {
Object obj = inMap.get(fieldName);
String fieldValue = null;
try {
fieldValue = (String) ObjectType.simpleTypeConvert(obj, "String", null, locale);
fieldValue = (String) ObjectType.simpleTypeOrObjectConvert(obj, "String", null, locale);
} catch (GeneralException e) {
messages.add("Could not convert field value for comparison: " + e.getMessage());
return;
@@ -50,7 +50,7 @@ public class ValidateMethod extends SimpleMapOperation {
Object obj = inMap.get(fieldName);
String fieldValue = null;
try {
fieldValue = (String) ObjectType.simpleTypeConvert(obj, "String", null, locale);
fieldValue = (String) ObjectType.simpleTypeOrObjectConvert(obj, "String", null, locale);
} catch (GeneralException e) {
messages.add("Could not convert field value for comparison: " + e.getMessage());
return;
@@ -784,7 +784,7 @@ public class ModelService extends AbstractMap<String, Object> implements Seriali
// convert to string
String converted;
try {
converted = (String) ObjectType.simpleTypeConvert(testValue, "String", null, null);
converted = (String) ObjectType.simpleTypeOrObjectConvert(testValue, "String", null, null);
} catch (GeneralException e) {
throw new GeneralException("Unable to convert parameter to String");
}
@@ -941,7 +941,7 @@ public class ModelService extends AbstractMap<String, Object> implements Seriali
try {
// no need to fail on type conversion; the validator will catch this
value = ObjectType.simpleTypeConvert(value, param.type, null, timeZone, locale, false);
value = ObjectType.simpleTypeOrObjectConvert(value, param.type, null, timeZone, locale, false);
} catch (GeneralException e) {
String errMsg = "Type conversion of field [" + key + "] to type [" + param.type + "] failed for value \"" + value + "\": " + e.toString();
Debug.logWarning("[ModelService.makeValid] : " + errMsg, module);
@@ -843,7 +843,7 @@ public abstract class AbstractModelAction implements Serializable, ModelAction {
newValue = new LinkedList();
} else {
try {
newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"),
newValue = ObjectType.simpleTypeOrObjectConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"),
(Locale) context.get("locale"), true);
} catch (GeneralException e) {
String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName()
@@ -520,7 +520,7 @@ public abstract class AbstractModelCondition implements Serializable, ModelCondi
}
String fieldString = null;
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, (TimeZone) context.get("timeZone"),
fieldString = (String) ObjectType.simpleTypeOrObjectConvert(fieldVal, "String", null, (TimeZone) context.get("timeZone"),
(Locale) context.get("locale"), true);
} catch (GeneralException e) {
Debug.logError(e, "Could not convert object to String, using empty String", module);
@@ -679,7 +679,7 @@ public abstract class AbstractModelCondition implements Serializable, ModelCondi
String fieldString = null;
if (fieldVal != null) {
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null,
fieldString = (String) ObjectType.simpleTypeOrObjectConvert(fieldVal, "String", null,
(TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
} catch (GeneralException e) {
Debug.logError(e, "Could not convert object to String, using empty String", module);
@@ -1583,7 +1583,7 @@ public class ModelFormField {
}
try {
BigDecimal parsedRetVal = (BigDecimal) ObjectType.simpleTypeConvert(retVal, "BigDecimal", null, null, locale,
BigDecimal parsedRetVal = (BigDecimal) ObjectType.simpleTypeOrObjectConvert(retVal, "BigDecimal", null, null, locale,
true);
retVal = UtilFormatOut.formatCurrency(parsedRetVal, isoCode, locale, 10); // we set the max to 10 digits as an hack to not round numbers in the ui
} catch (GeneralException e) {
@@ -1642,7 +1642,7 @@ public class ModelFormField {
locale = Locale.getDefault();
}
try {
Double parsedRetVal = (Double) ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
Double parsedRetVal = (Double) ObjectType.simpleTypeOrObjectConvert(retVal, "Double", null, locale, false);
String template = UtilProperties.getPropertyValue("arithmetic", "accounting-number.format",
"#,##0.00;(#,##0.00)");
retVal = UtilFormatOut.formatDecimalNumber(parsedRetVal, template, locale);
@@ -3052,7 +3052,7 @@ public class ModelFormField {
key = (String) keyObj;
} else {
try {
key = (String) ObjectType.simpleTypeConvert(keyObj, "String", null, null);
key = (String) ObjectType.simpleTypeOrObjectConvert(keyObj, "String", null, null);
} catch (GeneralException e) {
String errMsg = "Could not convert field value for the field: [" + this.keyAcsr.toString()
+ "] to String for the value [" + keyObj + "]: " + e.toString();
@@ -152,7 +152,7 @@ public abstract class ModelMenuAction {
newValue = new LinkedList();
} else {
try {
newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
newValue = ObjectType.simpleTypeOrObjectConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
} catch (GeneralException e) {
String errMsg = "Could not convert field value for the field: [" + this.field.getOriginalName() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString();
Debug.logError(e, errMsg, module);
@@ -304,7 +304,7 @@ public class ModelTheme implements Serializable {
name.put(initThemePropertiesMap, value);
} else {
try {
name.put(initThemePropertiesMap, ObjectType.simpleTypeConvert(value, type, null, null));
name.put(initThemePropertiesMap, ObjectType.simpleTypeOrObjectConvert(value, type, null, null));
} catch (GeneralException e) {
Debug.logError("Impossible to parse the value " + value + " to type " + type + " for the property " + name + " on theme " + this.name, module);
}
@@ -417,7 +417,7 @@ public abstract class ModelWidgetCondition implements Serializable {
}
String fieldString = null;
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, (TimeZone) context.get("timeZone"),
fieldString = (String) ObjectType.simpleTypeOrObjectConvert(fieldVal, "String", null, (TimeZone) context.get("timeZone"),
(Locale) context.get("locale"), true);
} catch (GeneralException e) {
Debug.logError(e, "Could not convert object to String, using empty String", module);
@@ -542,7 +542,7 @@ public abstract class ModelWidgetCondition implements Serializable {
String fieldString = null;
if (fieldVal != null) {
try {
fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null,
fieldString = (String) ObjectType.simpleTypeOrObjectConvert(fieldVal, "String", null,
(TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true);
} catch (GeneralException e) {
Debug.logError(e, "Could not convert object to String, using empty String", module);