Search in sources :

Example 86 with CheckResult

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

the class RandomCCNumberGeneratorMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    // See if we have input streams leading to this step!
    int nrRemarks = remarks.size();
    for (int i = 0; i < fieldCCType.length; i++) {
        int len = Const.toInt(transMeta.environmentSubstitute(getFieldCCLength()[i]), -1);
        if (len < 0) {
            CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.WrongLen", String.valueOf(i)), stepMeta);
            remarks.add(cr);
        }
        int size = Const.toInt(transMeta.environmentSubstitute(getFieldCCSize()[i]), -1);
        if (size < 0) {
            CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.WrongSize", String.valueOf(i)), stepMeta);
            remarks.add(cr);
        }
    }
    if (remarks.size() == nrRemarks) {
        CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.AllTypesSpecified"), stepMeta);
        remarks.add(cr);
    }
    if (Utils.isEmpty(getCardNumberFieldName())) {
        CheckResult cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RandomCCNumberGeneratorMeta.CheckResult.CardNumberFieldMissing"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult)

Example 87 with CheckResult

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

the class ReplaceStringMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepinfo, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    String error_message = "";
    boolean first = true;
    boolean error_found = false;
    if (prev == null) {
        error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.NoInputReceived") + Const.CR;
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
        remarks.add(cr);
    } else {
        for (int i = 0; i < fieldInStream.length; i++) {
            String field = fieldInStream[i];
            ValueMetaInterface v = prev.searchValueMeta(field);
            if (v == null) {
                if (first) {
                    first = false;
                    error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.MissingInStreamFields") + Const.CR;
                }
                error_found = true;
                error_message += "\t\t" + field + Const.CR;
            }
        }
        if (error_found) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.FoundInStreamFields"), stepinfo);
        }
        remarks.add(cr);
        // Check whether all are strings
        first = true;
        error_found = false;
        for (int i = 0; i < fieldInStream.length; i++) {
            String field = fieldInStream[i];
            ValueMetaInterface v = prev.searchValueMeta(field);
            if (v != null) {
                if (v.getType() != ValueMetaInterface.TYPE_STRING) {
                    if (first) {
                        first = false;
                        error_message += BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.OperationOnNonStringFields") + Const.CR;
                    }
                    error_found = true;
                    error_message += "\t\t" + field + Const.CR;
                }
            }
        }
        if (error_found) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.AllOperationsOnStringFields"), stepinfo);
        }
        remarks.add(cr);
        if (fieldInStream.length > 0) {
            for (int idx = 0; idx < fieldInStream.length; idx++) {
                if (Utils.isEmpty(fieldInStream[idx])) {
                    cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.InStreamFieldMissing", new Integer(idx + 1).toString()), stepinfo);
                    remarks.add(cr);
                }
            }
        }
        // Check if all input fields are distinct.
        for (int idx = 0; idx < fieldInStream.length; idx++) {
            for (int jdx = 0; jdx < fieldInStream.length; jdx++) {
                if (fieldInStream[idx].equals(fieldInStream[jdx]) && idx != jdx && idx < jdx) {
                    error_message = BaseMessages.getString(PKG, "ReplaceStringMeta.CheckResult.FieldInputError", fieldInStream[idx]);
                    cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepinfo);
                    remarks.add(cr);
                }
            }
        }
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 88 with CheckResult

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

the class RowGenerator method buildRow.

public static final RowMetaAndData buildRow(RowGeneratorMeta meta, List<CheckResultInterface> remarks, String origin) throws KettlePluginException {
    RowMetaInterface rowMeta = new RowMeta();
    Object[] rowData = RowDataUtil.allocateRowData(meta.getFieldName().length + 2);
    int index = 0;
    if (meta.isNeverEnding()) {
        if (!Utils.isEmpty(meta.getRowTimeField())) {
            rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField()));
            rowData[index++] = null;
        }
        if (!Utils.isEmpty(meta.getLastTimeField())) {
            rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField()));
            rowData[index++] = null;
        }
    }
    for (int i = 0; i < meta.getFieldName().length; i++) {
        int valtype = ValueMetaFactory.getIdForValueMeta(meta.getFieldType()[i]);
        if (meta.getFieldName()[i] != null) {
            // build a
            ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(meta.getFieldName()[i], valtype);
            // value!
            valueMeta.setLength(meta.getFieldLength()[i]);
            valueMeta.setPrecision(meta.getFieldPrecision()[i]);
            valueMeta.setConversionMask(meta.getFieldFormat()[i]);
            valueMeta.setCurrencySymbol(meta.getCurrency()[i]);
            valueMeta.setGroupingSymbol(meta.getGroup()[i]);
            valueMeta.setDecimalSymbol(meta.getDecimal()[i]);
            valueMeta.setOrigin(origin);
            ValueMetaInterface stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING);
            if (meta.isSetEmptyString() != null && meta.isSetEmptyString()[i]) {
                // Set empty string
                rowData[index] = StringUtil.EMPTY_STRING;
            } else {
                String stringValue = meta.getValue()[i];
                // If the value is empty: consider it to be NULL.
                if (Utils.isEmpty(stringValue)) {
                    rowData[index] = null;
                    if (valueMeta.getType() == ValueMetaInterface.TYPE_NONE) {
                        String message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
                        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                    }
                } else {
                    // 
                    try {
                        rowData[index] = valueMeta.convertData(stringMeta, stringValue);
                    } catch (KettleValueException e) {
                        switch(valueMeta.getType()) {
                            case ValueMetaInterface.TYPE_NUMBER:
                                String message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Number", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_DATE:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Date", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_INTEGER:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Integer", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_BIGNUMBER:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.BigNumber", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_TIMESTAMP:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Timestamp", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            default:
                                // Boolean and binary don't throw errors normally, so it's probably an unspecified error problem...
                                message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                        }
                    }
                }
            }
            // Now add value to the row!
            // This is in fact a copy from the fields row, but now with data.
            rowMeta.addValueMeta(valueMeta);
            index++;
        }
    }
    return new RowMetaAndData(rowMeta, rowData);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) CheckResult(org.pentaho.di.core.CheckResult) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 89 with CheckResult

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

the class RowGenerator method init.

@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    try {
        meta = (RowGeneratorMeta) smi;
        data = (RowGeneratorData) sdi;
        if (super.init(smi, sdi)) {
            // Determine the number of rows to generate...
            data.rowLimit = Const.toLong(environmentSubstitute(meta.getRowLimit()), -1L);
            data.rowsWritten = 0L;
            data.delay = Const.toLong(environmentSubstitute(meta.getIntervalInMs()), -1L);
            if (data.rowLimit < 0L) {
                // Unable to parse
                logError(BaseMessages.getString(PKG, "RowGenerator.Wrong.RowLimit.Number"));
                // fail
                return false;
            }
            // Create a row (constants) with all the values in it...
            // stores the errors...
            List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
            RowMetaAndData outputRow = buildRow(meta, remarks, getStepname());
            if (!remarks.isEmpty()) {
                for (int i = 0; i < remarks.size(); i++) {
                    CheckResult cr = (CheckResult) remarks.get(i);
                    logError(cr.getText());
                }
                return false;
            }
            data.outputRowData = outputRow.getData();
            data.outputRowMeta = outputRow.getRowMeta();
            return true;
        }
        return false;
    } catch (Exception e) {
        setErrors(1L);
        logError("Error initializing step", e);
        return false;
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) CheckResult(org.pentaho.di.core.CheckResult) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 90 with CheckResult

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

the class RowGeneratorMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    if (prev != null && prev.size() > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputStreamsError"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputStreamOk"), stepMeta);
        remarks.add(cr);
        String strLimit = transMeta.environmentSubstitute(rowLimit);
        if (Const.toLong(strLimit, -1L) <= 0) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.WarnNoRows"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.WillReturnRows", strLimit), stepMeta);
            remarks.add(cr);
        }
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputError"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RowGeneratorMeta.CheckResult.NoInputOk"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult)

Aggregations

CheckResult (org.pentaho.di.core.CheckResult)204 KettleException (org.pentaho.di.core.exception.KettleException)35 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)35 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)26 Database (org.pentaho.di.core.database.Database)25 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)19 FileInputList (org.pentaho.di.core.fileinput.FileInputList)14 StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)7 KettleStepException (org.pentaho.di.core.exception.KettleStepException)6 File (java.io.File)4 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)4 PaloHelper (org.pentaho.di.palo.core.PaloHelper)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 Date (java.util.Date)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 KettleRowException (org.pentaho.di.core.exception.KettleRowException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 DimensionField (org.pentaho.di.palo.core.DimensionField)2