Search in sources :

Example 56 with KettleValueException

use of org.pentaho.di.core.exception.KettleValueException in project pdi-dataservice-server-plugin by pentaho.

the class ValueMetaResolver method tryConversionWithMask.

private Object tryConversionWithMask(ValueMetaInterface valueMeta, int originalType, Object value, String mask) throws PushDownOptimizationException {
    ValueMeta originalTypeMeta = new ValueMeta(null, originalType);
    originalTypeMeta.setConversionMask(mask);
    try {
        return valueMeta.convertData(originalTypeMeta, value);
    } catch (KettleValueException e) {
        throw new PushDownOptimizationException("Failed to convert type", e);
    }
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMeta(org.pentaho.di.core.row.ValueMeta)

Example 57 with KettleValueException

use of org.pentaho.di.core.exception.KettleValueException in project pdi-dataservice-server-plugin by pentaho.

the class DefaultTransWiringRowAdapterTest method testRowWrittenEventSuccessErrorLogging.

@Test
public void testRowWrittenEventSuccessErrorLogging() throws KettleStepException, KettleValueException {
    when(logChannelInterface.isRowLevel()).thenReturn(true);
    when(rowMetaInterface.getString(row)).thenThrow(new KettleValueException());
    when(rowProducer.putRowWait(rowMetaInterface, row, 1, TimeUnit.SECONDS)).thenReturn(false, true);
    defaultTransWiringRowAdapter.rowWrittenEvent(rowMetaInterface, row);
    verify(rowProducer, times(2)).putRowWait(same(rowMetaInterface), eq(row), eq(1L), eq(TimeUnit.SECONDS));
    verify(logChannelInterface).logRowlevel(DataServiceConstants.ROW_BUFFER_IS_FULL_TRYING_AGAIN);
}
Also used : KettleValueException(org.pentaho.di.core.exception.KettleValueException) Test(org.junit.Test)

Example 58 with KettleValueException

use of org.pentaho.di.core.exception.KettleValueException in project pdi-dataservice-server-plugin by pentaho.

the class DefaultTransWiringRowAdapterTest method testRowWrittenEventException.

@Test(expected = KettleStepException.class)
public void testRowWrittenEventException() throws KettleValueException, KettleStepException {
    rowMetaInterface = mock(RowMetaInterface.class);
    KettleValueException kettleValueException = new KettleValueException();
    when(rowMetaInterface.cloneRow(any(Object[].class))).thenThrow(kettleValueException);
    when(rowProducer.putRowWait(rowMetaInterface, row, 1, TimeUnit.SECONDS)).thenReturn(false, true);
    try {
        defaultTransWiringRowAdapter.rowWrittenEvent(rowMetaInterface, row);
    } catch (KettleStepException e) {
        assertEquals(kettleValueException, e.getCause());
        throw e;
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleValueException(org.pentaho.di.core.exception.KettleValueException) Test(org.junit.Test)

Example 59 with KettleValueException

use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.

the class Validator method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (ValidatorMeta) smi;
    data = (ValidatorData) sdi;
    if (super.init(smi, sdi)) {
        // initialize steps by names
        List<StepMeta> steps = new ArrayList<>();
        List<StepMetaDataCombi> transSteps = getTrans().getSteps();
        if (transSteps != null) {
            for (StepMetaDataCombi s : transSteps) {
                steps.add(s.stepMeta);
            }
        }
        meta.searchInfoAndTargetSteps(steps);
        // initialize arrays of validation data
        data.constantsMeta = new ValueMetaInterface[meta.getValidations().size()];
        data.minimumValueAsString = new String[meta.getValidations().size()];
        data.maximumValueAsString = new String[meta.getValidations().size()];
        data.fieldsMinimumLengthAsInt = new int[meta.getValidations().size()];
        data.fieldsMaximumLengthAsInt = new int[meta.getValidations().size()];
        data.minimumValue = new Object[meta.getValidations().size()];
        data.maximumValue = new Object[meta.getValidations().size()];
        data.listValues = new Object[meta.getValidations().size()][];
        data.errorCode = new String[meta.getValidations().size()];
        data.errorDescription = new String[meta.getValidations().size()];
        data.conversionMask = new String[meta.getValidations().size()];
        data.decimalSymbol = new String[meta.getValidations().size()];
        data.groupingSymbol = new String[meta.getValidations().size()];
        data.maximumLength = new String[meta.getValidations().size()];
        data.minimumLength = new String[meta.getValidations().size()];
        data.startString = new String[meta.getValidations().size()];
        data.endString = new String[meta.getValidations().size()];
        data.startStringNotAllowed = new String[meta.getValidations().size()];
        data.endStringNotAllowed = new String[meta.getValidations().size()];
        data.regularExpression = new String[meta.getValidations().size()];
        data.regularExpressionNotAllowed = new String[meta.getValidations().size()];
        data.patternExpected = new Pattern[meta.getValidations().size()];
        data.patternDisallowed = new Pattern[meta.getValidations().size()];
        for (int i = 0; i < meta.getValidations().size(); i++) {
            Validation field = meta.getValidations().get(i);
            try {
                data.constantsMeta[i] = createValueMeta(field.getFieldName(), field.getDataType());
                data.constantsMeta[i].setConversionMask(field.getConversionMask());
                data.constantsMeta[i].setDecimalSymbol(field.getDecimalSymbol());
                data.constantsMeta[i].setGroupingSymbol(field.getGroupingSymbol());
                data.errorCode[i] = environmentSubstitute(Const.NVL(field.getErrorCode(), ""));
                data.errorDescription[i] = environmentSubstitute(Const.NVL(field.getErrorDescription(), ""));
                data.conversionMask[i] = environmentSubstitute(Const.NVL(field.getConversionMask(), ""));
                data.decimalSymbol[i] = environmentSubstitute(Const.NVL(field.getDecimalSymbol(), ""));
                data.groupingSymbol[i] = environmentSubstitute(Const.NVL(field.getGroupingSymbol(), ""));
                data.maximumLength[i] = environmentSubstitute(Const.NVL(field.getMaximumLength(), ""));
                data.minimumLength[i] = environmentSubstitute(Const.NVL(field.getMinimumLength(), ""));
                data.maximumValueAsString[i] = environmentSubstitute(Const.NVL(field.getMaximumValue(), ""));
                data.minimumValueAsString[i] = environmentSubstitute(Const.NVL(field.getMinimumValue(), ""));
                data.startString[i] = environmentSubstitute(Const.NVL(field.getStartString(), ""));
                data.endString[i] = environmentSubstitute(Const.NVL(field.getEndString(), ""));
                data.startStringNotAllowed[i] = environmentSubstitute(Const.NVL(field.getStartStringNotAllowed(), ""));
                data.endStringNotAllowed[i] = environmentSubstitute(Const.NVL(field.getEndStringNotAllowed(), ""));
                data.regularExpression[i] = environmentSubstitute(Const.NVL(field.getRegularExpression(), ""));
                data.regularExpressionNotAllowed[i] = environmentSubstitute(Const.NVL(field.getRegularExpressionNotAllowed(), ""));
                ValueMetaInterface stringMeta = cloneValueMeta(data.constantsMeta[i], ValueMetaInterface.TYPE_STRING);
                data.minimumValue[i] = Utils.isEmpty(data.minimumValueAsString[i]) ? null : data.constantsMeta[i].convertData(stringMeta, data.minimumValueAsString[i]);
                data.maximumValue[i] = Utils.isEmpty(data.maximumValueAsString[i]) ? null : data.constantsMeta[i].convertData(stringMeta, data.maximumValueAsString[i]);
                try {
                    data.fieldsMinimumLengthAsInt[i] = Integer.valueOf(Const.NVL(data.minimumLength[i], "-1"));
                } catch (NumberFormatException nfe) {
                    throw new KettleValueException("Caught a number format exception converting minimum length with value " + data.minimumLength[i] + " to an int.", nfe);
                }
                try {
                    data.fieldsMaximumLengthAsInt[i] = Integer.valueOf(Const.NVL(data.maximumLength[i], "-1"));
                } catch (NumberFormatException nfe) {
                    throw new KettleValueException("Caught a number format exception converting minimum length with value " + data.maximumLength[i] + " to an int.", nfe);
                }
                int listSize = field.getAllowedValues() != null ? field.getAllowedValues().length : 0;
                data.listValues[i] = new Object[listSize];
                for (int s = 0; s < listSize; s++) {
                    data.listValues[i][s] = Utils.isEmpty(field.getAllowedValues()[s]) ? null : data.constantsMeta[i].convertData(stringMeta, environmentSubstitute(field.getAllowedValues()[s]));
                }
            } catch (KettleException e) {
                if (field.getDataType() == ValueMetaInterface.TYPE_NONE) {
                    logError(BaseMessages.getString(PKG, "Validator.Exception.SpecifyDataType"), e);
                } else {
                    logError(BaseMessages.getString(PKG, "Validator.Exception.DataConversionErrorEncountered"), e);
                }
                return false;
            }
            if (!Utils.isEmpty(data.regularExpression[i])) {
                data.patternExpected[i] = Pattern.compile(data.regularExpression[i]);
            }
            if (!Utils.isEmpty(data.regularExpressionNotAllowed[i])) {
                data.patternDisallowed[i] = Pattern.compile(data.regularExpressionNotAllowed[i]);
            }
        }
        return true;
    }
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) KettleValueException(org.pentaho.di.core.exception.KettleValueException) StepMeta(org.pentaho.di.trans.step.StepMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 60 with KettleValueException

use of org.pentaho.di.core.exception.KettleValueException in project pentaho-kettle by pentaho.

the class TextFileOutput method convertStringToBinaryString.

private byte[] convertStringToBinaryString(ValueMetaInterface v, String string) throws KettleValueException {
    int length = v.getLength();
    if (string == null) {
        return new byte[] {};
    }
    if (length > -1 && length < string.length()) {
        // we need to truncate
        String tmp = string.substring(0, length);
        if (Utils.isEmpty(v.getStringEncoding())) {
            return tmp.getBytes();
        } else {
            try {
                return tmp.getBytes(v.getStringEncoding());
            } catch (UnsupportedEncodingException e) {
                throw new KettleValueException("Unable to convert String to Binary with specified string encoding [" + v.getStringEncoding() + "]", e);
            }
        }
    } else {
        byte[] text;
        if (Utils.isEmpty(meta.getEncoding())) {
            text = string.getBytes();
        } else {
            try {
                text = string.getBytes(meta.getEncoding());
            } catch (UnsupportedEncodingException e) {
                throw new KettleValueException("Unable to convert String to Binary with specified string encoding [" + v.getStringEncoding() + "]", e);
            }
        }
        if (length > string.length()) {
            // we need to pad this
            // Also for PDI-170: not all encoding use single characters, so we need to cope
            // with this.
            int size = 0;
            byte[] filler = null;
            try {
                if (!Utils.isEmpty(meta.getEncoding())) {
                    filler = " ".getBytes(meta.getEncoding());
                } else {
                    filler = " ".getBytes();
                }
                size = text.length + filler.length * (length - string.length());
            } catch (UnsupportedEncodingException uee) {
                throw new KettleValueException(uee);
            }
            byte[] bytes = new byte[size];
            System.arraycopy(text, 0, bytes, 0, text.length);
            if (filler.length == 1) {
                java.util.Arrays.fill(bytes, text.length, size, filler[0]);
            } else {
                int currIndex = text.length;
                for (int i = 0; i < (length - string.length()); i++) {
                    for (int j = 0; j < filler.length; j++) {
                        bytes[currIndex++] = filler[j];
                    }
                }
            }
            return bytes;
        } else {
            // do not need to pad or truncate
            return text;
        }
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

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