use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueMetaBase method convertStringToDate.
protected synchronized Date convertStringToDate(String string) throws KettleValueException {
// see if trimming needs
string = Const.trimToType(string, getTrimType());
if (Utils.isEmpty(string)) {
return null;
}
try {
ParsePosition pp = new ParsePosition(0);
Date result = getDateFormat(TYPE_DATE).parse(string, pp);
if (pp.getErrorIndex() >= 0) {
// error happen
throw new ParseException(string, pp.getErrorIndex());
}
// If there are only spaces after pp.getIndex() - that means full values was parsed
return result;
} catch (ParseException e) {
String dateFormat = (getDateFormat() != null) ? getDateFormat().toPattern() : "null";
throw new KettleValueException(toString() + " : couldn't convert string [" + string + "] to a date using format [" + dateFormat + "] on offset location " + e.getErrorOffset(), e);
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueMetaInternetAddress method convertIntegerToInternetAddress.
protected InetAddress convertIntegerToInternetAddress(Long l) throws KettleValueException {
if (l == null) {
return null;
}
byte[] addr;
if (l >= Math.pow(256, 4)) {
addr = new byte[16];
} else {
addr = new byte[4];
}
for (int i = 0; i < addr.length; i++) {
long mask = 0xFF << (i * 8);
addr[addr.length - 1 - i] = (byte) ((l & mask) >> (8 * i));
}
try {
return InetAddress.getByAddress(addr);
} catch (Exception e) {
throw new KettleValueException("Unable to convert an Integer to an internet address", e);
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueMetaBaseTest method testGetNativeDataTypeClass.
@Test
public void testGetNativeDataTypeClass() {
ValueMetaInterface base = new ValueMetaBase();
Class<?> clazz = null;
try {
clazz = base.getNativeDataTypeClass();
Assert.fail();
} catch (KettleValueException expected) {
// ValueMetaBase should throw an exception, as all sub-classes should override
Assert.assertNull(clazz);
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueMetaBaseTest method testConvertDataUsingConversionMetaDataForCustomMeta.
@Test
public void testConvertDataUsingConversionMetaDataForCustomMeta() {
ValueMetaBase baseMeta = new ValueMetaBase("CUSTOM_VALUEMETA_STRING", ValueMetaInterface.TYPE_STRING);
baseMeta.setConversionMetadata(new ValueMetaBase("CUSTOM", 999));
Object customData = new Object();
try {
baseMeta.convertDataUsingConversionMetaData(customData);
Assert.fail("Should have thrown a Kettle Value Exception with a proper message. Not a NPE stack trace");
} catch (KettleValueException e) {
String expectedMessage = "CUSTOM_VALUEMETA_STRING String : I can't convert the specified value to data type : 999";
assertEquals(expectedMessage, e.getMessage().trim());
}
}
use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.
the class ValueMetaFactoryTest method testGetNativeDataTypeClass.
@Test
public void testGetNativeDataTypeClass() throws KettlePluginException {
for (String valueMetaName : ValueMetaFactory.getValueMetaNames()) {
int valueMetaID = ValueMetaFactory.getIdForValueMeta(valueMetaName);
ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(valueMetaID);
try {
Class<?> clazz = valueMeta.getNativeDataTypeClass();
assertNotNull(clazz);
} catch (KettleValueException kve) {
fail(valueMetaName + " should implement getNativeDataTypeClass()");
}
}
}
Aggregations