use of org.pentaho.di.compatibility.Value in project pentaho-kettle by pentaho.
the class JavaScriptUtils method jsToDate.
public static Date jsToDate(Object value, String classType) throws KettleValueException {
double dbl;
if (classType.equalsIgnoreCase("org.mozilla.javascript.Undefined")) {
return null;
} else {
if (classType.equalsIgnoreCase("org.mozilla.javascript.NativeDate")) {
dbl = Context.toNumber(value);
} else if (classType.equalsIgnoreCase("org.mozilla.javascript.NativeJavaObject") || classType.equalsIgnoreCase("java.util.Date")) {
// Is it a java Date() class ?
try {
Date dat = (Date) Context.jsToJava(value, java.util.Date.class);
dbl = dat.getTime();
} catch (Exception e) {
//
try {
Value v = (Value) Context.jsToJava(value, Value.class);
return v.getDate();
} catch (Exception e2) {
try {
String string = Context.toString(value);
return XMLHandler.stringToDate(string);
} catch (Exception e3) {
throw new KettleValueException("Can't convert a string to a date");
}
}
}
} else if (classType.equalsIgnoreCase("java.lang.Double")) {
dbl = (Double) value;
} else {
String string = (String) Context.jsToJava(value, String.class);
dbl = Double.parseDouble(string);
}
long lng = Math.round(dbl);
return new Date(lng);
}
}
use of org.pentaho.di.compatibility.Value in project pentaho-kettle by pentaho.
the class JavaScriptUtilsTest method jsToBigNumber_NativeJavaObject_BigDecimal.
@Test
public void jsToBigNumber_NativeJavaObject_BigDecimal() throws Exception {
Value value = new Value();
value.setValue(BigDecimal.ONE);
Scriptable object = Context.toObject(value, scope);
assertEquals(1.0, JavaScriptUtils.jsToBigNumber(object, JAVA_OBJECT).doubleValue(), 1e-6);
}
use of org.pentaho.di.compatibility.Value in project pentaho-kettle by pentaho.
the class JavaScriptUtilsTest method getIntValue.
private static Scriptable getIntValue() {
Value value = new Value();
value.setValue(1);
return Context.toObject(value, scope);
}
use of org.pentaho.di.compatibility.Value in project pentaho-kettle by pentaho.
the class JavaScriptUtilsTest method getDoubleValue.
private static Scriptable getDoubleValue() {
Value value = new Value();
value.setValue(1.0);
return Context.toObject(value, scope);
}
use of org.pentaho.di.compatibility.Value in project pentaho-kettle by pentaho.
the class RowMeta method createOriginalRow.
public static Row createOriginalRow(RowMetaInterface rowMeta, Object[] rowData) throws KettleValueException {
Row row = new Row();
for (int i = 0; i < rowMeta.size(); i++) {
ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
Object valueData = rowData[i];
Value value = valueMeta.createOriginalValue(valueData);
row.addValue(value);
}
return row;
}
Aggregations