Search in sources :

Example 31 with PluginRegistry

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

the class RowGeneratorIT method testRowGenerator.

/**
 * Test case for Row Generator step.
 */
public void testRowGenerator() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("row generatortest");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a row generator step...
    // 
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);
    // 
    // Do the following specs 3 times.
    // 
    String[] fieldName = { "string", "boolean", "integer", "timestamp" };
    String[] type = { "String", "Boolean", "Integer", "Timestamp" };
    String[] value = { "string_value", "true", "20", "1970-01-01 00:00:00.000" };
    String[] fieldFormat = { "", "", "", "" };
    String[] group = { "", "", "", "" };
    String[] decimal = { "", "", "", "" };
    String[] currency = { "", "", "", "" };
    int[] intDummies = { -1, -1, -1, -1 };
    boolean[] setEmptystring = { false, false, false, false };
    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("3");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);
    rm.setCurrency(currency);
    rm.setEmptyString(setEmptystring);
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    TransHopMeta hi = new TransHopMeta(rowGeneratorStep, dummyStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    trans.startThreads();
    trans.waitUntilFinished();
    List<RowMetaAndData> checkList = createData();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, checkList);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 32 with PluginRegistry

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

the class JavaScriptSpecialIT method testLuhnCheck.

/**
 * Test case for javascript functionality: ltrim(), rtrim(), trim().
 */
public void testLuhnCheck() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("test javascript LuhnCheck");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // Create a javascript step
    // 
    String javaScriptStepname = "javascript step";
    ScriptValuesMetaMod svm = new ScriptValuesMetaMod();
    ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var str = string;\n" + "var bool = LuhnCheck(str);") };
    svm.setJSScripts(js);
    svm.setFieldname(new String[] { "bool" });
    svm.setRename(new String[] { "" });
    svm.setType(new int[] { ValueMetaInterface.TYPE_BOOLEAN });
    svm.setLength(new int[] { -1 });
    svm.setPrecision(new int[] { -1 });
    svm.setReplace(new boolean[] { false });
    svm.setCompatible(false);
    String javaScriptStepPid = registry.getPluginId(StepPluginType.class, svm);
    StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, svm);
    transMeta.addStep(javaScriptStep);
    TransHopMeta hi1 = new TransHopMeta(injectorStep, javaScriptStep);
    transMeta.addTransHop(hi1);
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
    transMeta.addTransHop(hi2);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si;
    si = trans.getStepInterface(javaScriptStepname, 0);
    RowStepCollector javaScriptRc = new RowStepCollector();
    si.addRowListener(javaScriptRc);
    si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData1();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = javaScriptRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
    List<RowMetaAndData> resultRows2 = dummyRc.getRowsRead();
    checkRows(resultRows2, goldenImageRows);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 33 with PluginRegistry

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

the class Encr method init.

public static void init(String encoderPluginId) throws KettleException {
    if (Utils.isEmpty(encoderPluginId)) {
        throw new KettleException("Unable to initialize the two way password encoder: No encoder plugin type specified.");
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithId(TwoWayPasswordEncoderPluginType.class, encoderPluginId);
    if (plugin == null) {
        throw new KettleException("Unable to find plugin with ID '" + encoderPluginId + "'.  If this is a test, make sure" + " kettle-core tests jar is a dependency.  If this is live make sure a kettle-password-encoder-plugins.xml" + " exits in the classpath");
    }
    encoder = (TwoWayPasswordEncoderInterface) registry.loadClass(plugin);
    // 
    try {
        encoder.init();
    } catch (PasswordEncoderException e) {
        throw new KettleException(e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PasswordEncoderException(org.pentaho.support.encryption.PasswordEncoderException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 34 with PluginRegistry

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

the class ParameterSimpleTransIT method testParameterSimpleTrans2.

/**
 * Test case for parameters using a simple transformation. Here 1 parameter is not provided as value, so the default
 * will be used.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans2() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("parameter_simple_trans2");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a get variables step...
    // 
    String getVariablesStepname = "get variables step";
    GetVariableMeta gvm = new GetVariableMeta();
    // Set the information of the get variables step.
    String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
    StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
    transMeta.addStep(getVariablesStep);
    // 
    // Generate 1 row
    // 
    String[] fieldName = { "Param1", "PARAM2" };
    String[] varName = { "${Param1}", "%%PARAM2%%" };
    int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
    int[] length = { -1, -1 };
    int[] precision = { -1, -1 };
    String[] format = { "", "" };
    String[] currency = { "", "" };
    String[] decimal = { "", "" };
    String[] grouping = { "", "" };
    int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
    FieldDefinition[] fields = new FieldDefinition[fieldName.length];
    for (int i = 0; i < fields.length; i++) {
        FieldDefinition field = new FieldDefinition();
        field.setFieldName(fieldName[i]);
        field.setVariableString(varName[i]);
        field.setFieldType(fieldType[i]);
        field.setFieldLength(length[i]);
        field.setFieldPrecision(precision[i]);
        field.setFieldFormat(format[i]);
        field.setCurrency(currency[i]);
        field.setDecimal(decimal[i]);
        field.setGroup(grouping[i]);
        field.setTrimType(trimType[i]);
        fields[i] = field;
    }
    gvm.setFieldDefinitions(fields);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.addParameterDefinition("Param1", "default1", "Parameter 1");
    trans.addParameterDefinition("PARAM2", "default2", "Parameter 2");
    trans.setParameterValue("Param1", "ParamValue1");
    // PARAM2 is not set
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);
    trans.startThreads();
    trans.waitUntilFinished();
    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData2();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) GetVariableMeta(org.pentaho.di.trans.steps.getvariable.GetVariableMeta)

Example 35 with PluginRegistry

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

the class ParameterSimpleTransIT method testParameterSimpleTrans1.

/**
 * Test case for parameters using a simple transformation.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans1() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("parameter_simple_trans1");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a get variables step...
    // 
    String getVariablesStepname = "get variables step";
    GetVariableMeta gvm = new GetVariableMeta();
    // Set the information of the get variables step.
    String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
    StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
    transMeta.addStep(getVariablesStep);
    // 
    // Generate 1 row
    // 
    String[] fieldName = { "PARAM1", "PARAM2" };
    String[] varName = { "${Param1}", "%%PARAM2%%" };
    int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
    int[] length = { -1, -1 };
    int[] precision = { -1, -1 };
    String[] format = { "", "" };
    String[] currency = { "", "" };
    String[] decimal = { "", "" };
    String[] grouping = { "", "" };
    int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
    FieldDefinition[] fields = new FieldDefinition[fieldName.length];
    for (int i = 0; i < fields.length; i++) {
        FieldDefinition field = new FieldDefinition();
        field.setFieldName(fieldName[i]);
        field.setVariableString(varName[i]);
        field.setFieldType(fieldType[i]);
        field.setFieldLength(length[i]);
        field.setFieldPrecision(precision[i]);
        field.setFieldFormat(format[i]);
        field.setCurrency(currency[i]);
        field.setDecimal(decimal[i]);
        field.setGroup(grouping[i]);
        field.setTrimType(trimType[i]);
        fields[i] = field;
    }
    gvm.setFieldDefinitions(fields);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.addParameterDefinition("Param1", "", "Parameter 1");
    trans.addParameterDefinition("PARAM2", "", "Parameter 2");
    trans.setParameterValue("Param1", "ParamValue1");
    trans.setParameterValue("PARAM2", "PARAMVALUE2");
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);
    trans.startThreads();
    trans.waitUntilFinished();
    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) GetVariableMeta(org.pentaho.di.trans.steps.getvariable.GetVariableMeta)

Aggregations

PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)160 StepMeta (org.pentaho.di.trans.step.StepMeta)104 TransMeta (org.pentaho.di.trans.TransMeta)103 Trans (org.pentaho.di.trans.Trans)84 TransHopMeta (org.pentaho.di.trans.TransHopMeta)78 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)74 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)72 StepInterface (org.pentaho.di.trans.step.StepInterface)70 RowStepCollector (org.pentaho.di.trans.RowStepCollector)68 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)55 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)53 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)49 RowProducer (org.pentaho.di.trans.RowProducer)48 Test (org.junit.Test)35 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)26 KettleException (org.pentaho.di.core.exception.KettleException)26 ArrayList (java.util.ArrayList)15 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 Before (org.junit.Before)11 HashMap (java.util.HashMap)7