Search in sources :

Example 91 with CheckResult

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

the class RssOutputMeta 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;
    // Now see what we can find as previous step...
    if (prev != null && prev.size() > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.FieldsReceived", "" + prev.size()), stepMeta);
        remarks.add(cr);
    // Starting from prev...
    /*
       * for (int i=0;i<prev.size();i++) { Value pv = prev.getValue(i); int idx = r.searchValueIndex(pv.getName()); if
       * (idx<0) { error_message+="\t\t"+pv.getName()+" ("+pv.getTypeDesc()+")"+Const.CR; error_found=true; } } if
       * (error_found) { error_message=BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.FieldsNotFoundInOutput",
       * error_message);
       *
       * cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepMeta); remarks.add(cr); } else { cr =
       * new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG,
       * "RssOutputMeta.CheckResult.AllFieldsFoundInOutput"), stepMeta); remarks.add(cr); }
       */
    // Starting from table fields in r...
    /*
       * for (int i=0;i<r.size();i++) { Value rv = r.getValue(i); int idx = prev.searchValueIndex(rv.getName()); if
       * (idx<0) { error_message+="\t\t"+rv.getName()+" ("+rv.getTypeDesc()+")"+Const.CR; error_found=true; } } if
       * (error_found) { error_message=BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.FieldsNotFound",
       * error_message);
       *
       * cr = new CheckResult(CheckResult.TYPE_RESULT_WARNING, error_message, stepMeta); remarks.add(cr); } else { cr =
       * new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG,
       * "RssOutputMeta.CheckResult.AllFieldsFound"), stepMeta); remarks.add(cr); }
       */
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.NoFields"), stepMeta);
        remarks.add(cr);
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.ExpectedInputOk"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "RssOutputMeta.CheckResult.ExpectedInputError"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult)

Example 92 with CheckResult

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

the class ScriptValuesMetaMod 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) {
    boolean error_found = false;
    String error_message = "";
    CheckResult cr;
    Context jscx;
    Scriptable jsscope;
    Script jsscript;
    jscx = ContextFactory.getGlobal().enterContext();
    jsscope = jscx.initStandardObjects(null, false);
    try {
        jscx.setOptimizationLevel(Integer.valueOf(transMeta.environmentSubstitute(optimizationLevel)));
    } catch (NumberFormatException nfe) {
        error_message = "Error with optimization level.  Could not convert the value of " + transMeta.environmentSubstitute(optimizationLevel) + " to an integer.";
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
        remarks.add(cr);
    } catch (IllegalArgumentException iae) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, iae.getMessage(), stepMeta);
        remarks.add(cr);
    }
    String strActiveStartScriptName = "";
    String strActiveEndScriptName = "";
    String strActiveScript = "";
    String strActiveStartScript = "";
    String strActiveEndScript = "";
    // Building the Scripts
    if (jsScripts.length > 0) {
        for (int i = 0; i < jsScripts.length; i++) {
            if (jsScripts[i].isTransformScript()) {
                // strActiveScriptName =jsScripts[i].getScriptName();
                strActiveScript = jsScripts[i].getScript();
            } else if (jsScripts[i].isStartScript()) {
                strActiveStartScriptName = jsScripts[i].getScriptName();
                strActiveStartScript = jsScripts[i].getScript();
            } else if (jsScripts[i].isEndScript()) {
                strActiveEndScriptName = jsScripts[i].getScriptName();
                strActiveEndScript = jsScripts[i].getScript();
            }
        }
    }
    if (prev != null && strActiveScript.length() > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.ConnectedStepOK", String.valueOf(prev.size())), stepMeta);
        remarks.add(cr);
        // Adding the existing Scripts to the Context
        for (int i = 0; i < getNumberOfJSScripts(); i++) {
            Scriptable jsR = Context.toObject(jsScripts[i].getScript(), jsscope);
            jsscope.put(jsScripts[i].getScriptName(), jsscope, jsR);
        }
        // Modification for Additional Script parsing
        try {
            if (getAddClasses() != null) {
                for (int i = 0; i < getAddClasses().length; i++) {
                    Object jsOut = Context.javaToJS(getAddClasses()[i].getAddObject(), jsscope);
                    ScriptableObject.putProperty(jsscope, getAddClasses()[i].getJSName(), jsOut);
                }
            }
        } catch (Exception e) {
            error_message = ("Couldn't add JavaClasses to Context! Error:");
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
        // Adding some default JavaScriptFunctions to the System
        try {
            Context.javaToJS(ScriptValuesAddedFunctions.class, jsscope);
            ((ScriptableObject) jsscope).defineFunctionProperties(ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class, ScriptableObject.DONTENUM);
        } catch (Exception ex) {
            error_message = "Couldn't add Default Functions! Error:" + Const.CR + ex.toString();
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
        // Adding some Constants to the JavaScript
        try {
            jsscope.put("SKIP_TRANSFORMATION", jsscope, Integer.valueOf(ScriptValuesMod.SKIP_TRANSFORMATION));
            jsscope.put("ABORT_TRANSFORMATION", jsscope, Integer.valueOf(ScriptValuesMod.ABORT_TRANSFORMATION));
            jsscope.put("ERROR_TRANSFORMATION", jsscope, Integer.valueOf(ScriptValuesMod.ERROR_TRANSFORMATION));
            jsscope.put("CONTINUE_TRANSFORMATION", jsscope, Integer.valueOf(ScriptValuesMod.CONTINUE_TRANSFORMATION));
        } catch (Exception ex) {
            error_message = "Couldn't add Transformation Constants! Error:" + Const.CR + ex.toString();
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
        try {
            ScriptValuesModDummy dummyStep = new ScriptValuesModDummy(prev, transMeta.getStepFields(stepMeta));
            Scriptable jsvalue = Context.toObject(dummyStep, jsscope);
            jsscope.put("_step_", jsscope, jsvalue);
            Object[] row = new Object[prev.size()];
            Scriptable jsRowMeta = Context.toObject(prev, jsscope);
            jsscope.put("rowMeta", jsscope, jsRowMeta);
            for (int i = 0; i < prev.size(); i++) {
                ValueMetaInterface valueMeta = prev.getValueMeta(i);
                Object valueData = null;
                // 
                if (valueMeta.isDate()) {
                    valueData = new Date();
                }
                if (valueMeta.isString()) {
                    valueData = "test value test value test value test value test value " + "test value test value test value test value test value";
                }
                if (valueMeta.isInteger()) {
                    valueData = Long.valueOf(0L);
                }
                if (valueMeta.isNumber()) {
                    valueData = new Double(0.0);
                }
                if (valueMeta.isBigNumber()) {
                    valueData = BigDecimal.ZERO;
                }
                if (valueMeta.isBoolean()) {
                    valueData = Boolean.TRUE;
                }
                if (valueMeta.isBinary()) {
                    valueData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                }
                row[i] = valueData;
                if (isCompatible()) {
                    Value value = valueMeta.createOriginalValue(valueData);
                    Scriptable jsarg = Context.toObject(value, jsscope);
                    jsscope.put(valueMeta.getName(), jsscope, jsarg);
                } else {
                    Scriptable jsarg = Context.toObject(valueData, jsscope);
                    jsscope.put(valueMeta.getName(), jsscope, jsarg);
                }
            }
            // Add support for Value class (new Value())
            Scriptable jsval = Context.toObject(Value.class, jsscope);
            jsscope.put("Value", jsscope, jsval);
            // 
            if (isCompatible()) {
                Row v2Row = RowMeta.createOriginalRow(prev, row);
                Scriptable jsV2Row = Context.toObject(v2Row, jsscope);
                jsscope.put("row", jsscope, jsV2Row);
            } else {
                Scriptable jsRow = Context.toObject(row, jsscope);
                jsscope.put("row", jsscope, jsRow);
            }
        } catch (Exception ev) {
            error_message = "Couldn't add Input fields to Script! Error:" + Const.CR + ev.toString();
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
        try {
            // Checking for StartScript
            if (strActiveStartScript != null && strActiveStartScript.length() > 0) {
                /* Object startScript = */
                jscx.evaluateString(jsscope, strActiveStartScript, "trans_Start", 1, null);
                error_message = "Found Start Script. " + strActiveStartScriptName + " Processing OK";
                cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepMeta);
                remarks.add(cr);
            }
        } catch (Exception e) {
            error_message = "Couldn't process Start Script! Error:" + Const.CR + e.toString();
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
        try {
            jsscript = jscx.compileString(strActiveScript, "script", 1, null);
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.ScriptCompiledOK"), stepMeta);
            remarks.add(cr);
            try {
                jsscript.exec(jscx, jsscope);
                cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.ScriptCompiledOK2"), stepMeta);
                remarks.add(cr);
                if (fieldname.length > 0) {
                    StringBuilder message = new StringBuilder(BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.FailedToGetValues", String.valueOf(fieldname.length)) + Const.CR + Const.CR);
                    if (error_found) {
                        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message.toString(), stepMeta);
                    } else {
                        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, message.toString(), stepMeta);
                    }
                    remarks.add(cr);
                }
            } catch (JavaScriptException jse) {
                Context.exit();
                error_message = BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.CouldNotExecuteScript") + Const.CR + jse.toString();
                cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
                remarks.add(cr);
            } catch (Exception e) {
                Context.exit();
                error_message = BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.CouldNotExecuteScript2") + Const.CR + e.toString();
                cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
                remarks.add(cr);
            }
            // Checking End Script
            try {
                if (strActiveEndScript != null && strActiveEndScript.length() > 0) {
                    /* Object endScript = */
                    jscx.evaluateString(jsscope, strActiveEndScript, "trans_End", 1, null);
                    error_message = "Found End Script. " + strActiveEndScriptName + " Processing OK";
                    cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepMeta);
                    remarks.add(cr);
                }
            } catch (Exception e) {
                error_message = "Couldn't process End Script! Error:" + Const.CR + e.toString();
                cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
                remarks.add(cr);
            }
        } catch (Exception e) {
            Context.exit();
            error_message = BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.CouldNotCompileScript") + Const.CR + e.toString();
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        }
    } else {
        Context.exit();
        error_message = BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.CouldNotGetFieldsFromPreviousStep");
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
        remarks.add(cr);
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.ConnectedStepOK2"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "ScriptValuesMetaMod.CheckResult.NoInputReceived"), stepMeta);
        remarks.add(cr);
    }
}
Also used : Context(org.mozilla.javascript.Context) Script(org.mozilla.javascript.Script) ScriptableObject(org.mozilla.javascript.ScriptableObject) Scriptable(org.mozilla.javascript.Scriptable) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) JavaScriptException(org.mozilla.javascript.JavaScriptException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) Date(java.util.Date) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) JavaScriptException(org.mozilla.javascript.JavaScriptException) CheckResult(org.pentaho.di.core.CheckResult) Value(org.pentaho.di.compatibility.Value) ScriptableObject(org.mozilla.javascript.ScriptableObject) Row(org.pentaho.di.compatibility.Row)

Example 93 with CheckResult

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

the class SSTableOutputMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info) {
    CheckResult cr;
    if ((prev == null) || (prev.size() == 0)) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_WARNING, "Not receiving any fields from previous steps!", stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, "Step is connected to previous one, receiving " + prev.size() + " fields", stepMeta);
        remarks.add(cr);
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, "Step is receiving info from other steps.", stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, "No input received from other steps!", stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult)

Example 94 with CheckResult

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

the class WriteToLogMeta method check.

@Override
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(CheckResult.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.NotReceivingFields"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.StepRecevingData", prev.size() + ""), stepMeta);
        remarks.add(cr);
        String error_message = "";
        boolean error_found = false;
        // Starting from selected fields in ...
        for (int i = 0; i < fieldName.length; i++) {
            int idx = prev.indexOfValue(fieldName[i]);
            if (idx < 0) {
                error_message += "\t\t" + fieldName[i] + Const.CR;
                error_found = true;
            }
        }
        if (error_found) {
            error_message = BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.FieldsFound", error_message);
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, error_message, stepMeta);
            remarks.add(cr);
        } else {
            if (fieldName.length > 0) {
                cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.AllFieldsFound"), stepMeta);
                remarks.add(cr);
            } else {
                cr = new CheckResult(CheckResult.TYPE_RESULT_WARNING, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.NoFieldsEntered"), stepMeta);
                remarks.add(cr);
            }
        }
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.StepRecevingData2"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.NoInputReceivedFromOtherSteps"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult)

Example 95 with CheckResult

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

the class YamlInputMeta method check.

@Override
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;
    // See if we get input...
    if (input.length <= 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.NoInputExpected"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.NoInput"), stepMeta);
        remarks.add(cr);
    }
    if (getInputFields().length <= 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.NoInputField"), stepMeta);
        remarks.add(cr);
    }
    if (isInFields()) {
        if (Utils.isEmpty(getYamlField())) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.NoField"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.FieldOk"), stepMeta);
            remarks.add(cr);
        }
    } else {
        FileInputList fileInputList = getFiles(transMeta);
        // String files[] = getFiles();
        if (fileInputList == null || fileInputList.getFiles().size() == 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.NoFiles"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "YamlInputMeta.CheckResult.FilesOk", "" + fileInputList.getFiles().size()), stepMeta);
            remarks.add(cr);
        }
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

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