Search in sources :

Example 11 with KettleValueException

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);
    }
}
Also used : ParseException(java.text.ParseException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 12 with KettleValueException

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);
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 13 with KettleValueException

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);
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 14 with KettleValueException

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());
    }
}
Also used : LoggingObject(org.pentaho.di.core.logging.LoggingObject) KettleValueException(org.pentaho.di.core.exception.KettleValueException) Test(org.junit.Test)

Example 15 with KettleValueException

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()");
        }
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

KettleValueException (org.pentaho.di.core.exception.KettleValueException)127 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)35 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)35 KettleException (org.pentaho.di.core.exception.KettleException)25 KettleStepException (org.pentaho.di.core.exception.KettleStepException)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)16 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)13 IOException (java.io.IOException)12 Test (org.junit.Test)11 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)11 KettleFileException (org.pentaho.di.core.exception.KettleFileException)11 ParseException (java.text.ParseException)10 Date (java.util.Date)9 EOFException (java.io.EOFException)8 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 BigDecimal (java.math.BigDecimal)6