Search in sources :

Example 11 with PluginRegistry

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

the class UpdateMetaTest method setUp.

@Before
public void setUp() throws KettleException {
    KettleEnvironment.init();
    PluginRegistry.init(false);
    TransMeta transMeta = new TransMeta();
    transMeta.setName("delete1");
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("max.sz", "10");
    transMeta.injectVariables(vars);
    umi = new UpdateMeta();
    ud = new UpdateData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String deletePid = plugReg.getPluginId(StepPluginType.class, umi);
    stepMeta = new StepMeta(deletePid, "delete", umi);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(stepMeta);
    mockHelper = new StepMockHelper<>("Update", UpdateMeta.class, UpdateData.class);
    Mockito.when(mockHelper.logChannelInterfaceFactory.create(Mockito.any(), Mockito.any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
    upd = new Update(stepMeta, ud, 1, transMeta, trans);
    upd.copyVariablesFrom(transMeta);
    List<String> attributes = Arrays.asList("schemaName", "tableName", "commitSize", "errorIgnored", "ignoreFlagField", "skipLookup", "useBatchUpdate", "keyStream", "keyLookup", "keyCondition", "keyStream2", "updateLookup", "updateStream", "databaseMeta");
    Map<String, String> getterMap = new HashMap<String, String>() {

        {
            put("schemaName", "getSchemaName");
            put("tableName", "getTableName");
            put("commitSize", "getCommitSizeVar");
            put("errorIgnored", "isErrorIgnored");
            put("ignoreFlagField", "getIgnoreFlagField");
            put("skipLookup", "isSkipLookup");
            put("useBatchUpdate", "useBatchUpdate");
            put("keyStream", "getKeyStream");
            put("keyLookup", "getKeyLookup");
            put("keyCondition", "getKeyCondition");
            put("keyStream2", "getKeyStream2");
            put("updateLookup", "getUpdateLookup");
            put("updateStream", "getUpdateStream");
            put("databaseMeta", "getDatabaseMeta");
        }
    };
    Map<String, String> setterMap = new HashMap<String, String>() {

        {
            put("schemaName", "setSchemaName");
            put("tableName", "setTableName");
            put("commitSize", "setCommitSize");
            put("errorIgnored", "setErrorIgnored");
            put("ignoreFlagField", "setIgnoreFlagField");
            put("skipLookup", "setSkipLookup");
            put("useBatchUpdate", "setUseBatchUpdate");
            put("keyStream", "setKeyStream");
            put("keyLookup", "setKeyLookup");
            put("keyCondition", "setKeyCondition");
            put("keyStream2", "setKeyStream2");
            put("updateLookup", "setUpdateLookup");
            put("updateStream", "setUpdateStream");
            put("databaseMeta", "setDatabaseMeta");
        }
    };
    FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);
    Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    attrValidatorMap.put("keyStream", stringArrayLoadSaveValidator);
    attrValidatorMap.put("keyLookup", stringArrayLoadSaveValidator);
    attrValidatorMap.put("keyCondition", stringArrayLoadSaveValidator);
    attrValidatorMap.put("keyStream2", stringArrayLoadSaveValidator);
    attrValidatorMap.put("updateLookup", stringArrayLoadSaveValidator);
    attrValidatorMap.put("updateStream", stringArrayLoadSaveValidator);
    attrValidatorMap.put("databaseMeta", new DatabaseMetaLoadSaveValidator());
    Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    loadSaveTester = new LoadSaveTester(testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(), getterMap, setterMap, attrValidatorMap, typeValidatorMap, this);
}
Also used : ArrayLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator) HashMap(java.util.HashMap) LoadSaveTester(org.pentaho.di.trans.steps.loadsave.LoadSaveTester) FieldLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DatabaseMetaLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.DatabaseMetaLoadSaveValidator) StepMeta(org.pentaho.di.trans.step.StepMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Trans(org.pentaho.di.trans.Trans) StringLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.StringLoadSaveValidator) Before(org.junit.Before)

Example 12 with PluginRegistry

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

the class DatabaseMeta method findDatabaseInterface.

/**
 * Search for the right type of DatabaseInterface object and return it.
 *
 * @param databaseTypeDesc
 *          the type of DatabaseInterface to look for (id or description)
 * @return The requested DatabaseInterface
 *
 * @throws KettleDatabaseException
 *           when the type could not be found or referenced.
 */
private static final DatabaseInterface findDatabaseInterface(String databaseTypeDesc) throws KettleDatabaseException {
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.getPlugin(DatabasePluginType.class, databaseTypeDesc);
    if (plugin == null) {
        plugin = registry.findPluginWithName(DatabasePluginType.class, databaseTypeDesc);
    }
    if (plugin == null) {
        throw new KettleDatabaseException("database type with plugin id [" + databaseTypeDesc + "] couldn't be found!");
    }
    return getDatabaseInterfacesMap().get(plugin.getIds()[0]);
}
Also used : DatabasePluginType(org.pentaho.di.core.plugins.DatabasePluginType) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 13 with PluginRegistry

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

the class SwingGUIResource method getUniversalImageIcon.

private SwingUniversalImage getUniversalImageIcon(PluginInterface plugin) throws KettleException {
    try {
        PluginRegistry registry = PluginRegistry.getInstance();
        String filename = plugin.getImageFile();
        ClassLoader classLoader = registry.getClassLoader(plugin);
        SwingUniversalImage image = null;
        if (SvgSupport.isSvgEnabled() && SvgSupport.isSvgName(filename)) {
            // Try to use the plugin class loader to get access to the icon
            // 
            InputStream inputStream = classLoader.getResourceAsStream(filename);
            if (inputStream == null) {
                inputStream = classLoader.getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream(filename);
            }
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                try {
                    inputStream = new FileInputStream(filename);
                } catch (FileNotFoundException e) {
                // Ignore, throws error below
                }
            }
            if (inputStream != null) {
                try {
                    SvgImage svg = SvgSupport.loadSvgImage(inputStream);
                    image = new SwingUniversalImageSvg(svg);
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            }
        }
        if (image == null) {
            filename = SvgSupport.toPngName(filename);
            // Try to use the plugin class loader to get access to the icon
            // 
            InputStream inputStream = classLoader.getResourceAsStream(filename);
            if (inputStream == null) {
                inputStream = classLoader.getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream(filename);
            }
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                try {
                    inputStream = new FileInputStream(filename);
                } catch (FileNotFoundException e) {
                // Ignore, throws error below
                }
            }
            if (inputStream != null) {
                try {
                    BufferedImage bitmap = ImageIO.read(inputStream);
                    WaitingImageObserver wia = new WaitingImageObserver(bitmap);
                    wia.waitImageLoaded();
                    image = new SwingUniversalImageBitmap(bitmap);
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            }
        }
        if (image == null) {
            throw new KettleException("Unable to find file: " + plugin.getImageFile() + " for plugin: " + plugin);
        }
        return image;
    } catch (Throwable e) {
        throw new KettleException("Unable to load image from file : '" + plugin.getImageFile() + "' for plugin: " + plugin, e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) SvgImage(org.pentaho.di.core.svg.SvgImage) SwingUniversalImage(org.pentaho.di.core.SwingUniversalImage) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) WaitingImageObserver(org.pentaho.reporting.libraries.base.util.WaitingImageObserver) SwingUniversalImageSvg(org.pentaho.di.core.SwingUniversalImageSvg) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) SwingUniversalImageBitmap(org.pentaho.di.core.SwingUniversalImageBitmap)

Example 14 with PluginRegistry

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

the class JavaScriptStringIT method testStringsPadCase.

/**
 * Test case for javascript functionality: lpad(), rpad(), upper(), lower().
 */
public void testStringsPadCase() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("test javascript pad casing");
    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 lpadded1 = lpad(string, \"x\", 10);\n" + "var lpadded2 = lpad(string, \" \", 9);\n" + "var rpadded1 = rpad(string, \"x\", 10);\n" + "var rpadded2 = rpad(string, \" \", 9);\n" + "var upperStr = upper(string);\n" + "var lowerStr = lower(string);\n") };
    svm.setJSScripts(js);
    svm.setFieldname(new String[] { "lpadded1", "lpadded2", "rpadded1", "rpadded2", "upperStr", "lowerStr" });
    svm.setRename(new String[] { "", "", "", "", "", "", "" });
    svm.setType(new int[] { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING });
    svm.setLength(new int[] { -1, -1, -1, -1, -1, -1, -1 });
    svm.setPrecision(new int[] { -1, -1, -1, -1, -1, -1, -1 });
    svm.setReplace(new boolean[] { false, false, false, false, false, false, false });
    svm.setCompatible(true);
    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 = createData2();
    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 = createResultData2();
    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 15 with PluginRegistry

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

the class SplitFieldToRowsIT method splitFieldToRows.

/**
 * Splits the "stringToSplit" with the passed "delimiter". The "delimiter" is assumed by this method to be a Kettle
 * variable. The parameter "delimiterVariableValue" should contain the variables value.
 *
 * The "isDelimiterRegex" parameter will process the use regex for pattern matching if true.
 *
 * @param testName
 * @param stringToSplit
 * @param isDelimiterRegex
 * @param delimiter
 * @param delimiterVariableValue
 * @return
 * @throws Exception
 */
private List<RowMetaAndData> splitFieldToRows(String testName, String stringToSplit, boolean isDelimiterRegex, String delimiter, String delimiterVariableValue) {
    RowStepCollector rc = new RowStepCollector();
    try {
        KettleEnvironment.init();
        // Create a new transformation...
        TransMeta transMeta = new TransMeta();
        transMeta.setName("Split field to rows test");
        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 Split Field to Rows step
        String splitfieldToRowsName = "Split field to rows";
        SplitFieldToRowsMeta splitFieldtoRowsMeta = new SplitFieldToRowsMeta();
        splitFieldtoRowsMeta.setDelimiter(delimiter);
        splitFieldtoRowsMeta.setDelimiterRegex(isDelimiterRegex);
        splitFieldtoRowsMeta.setSplitField(FIELD_TO_SPLIT_NAME);
        splitFieldtoRowsMeta.setNewFieldname(NEW_FIELD_NAME);
        String splitFieldTotRowsPid = registry.getPluginId(StepPluginType.class, splitFieldtoRowsMeta);
        StepMeta splitFieldToRows = new StepMeta(splitFieldTotRowsPid, splitfieldToRowsName, splitFieldtoRowsMeta);
        transMeta.addStep(splitFieldToRows);
        // hop the injector to the split field to rows step
        TransHopMeta hop_injector_splitfieldToRows = new TransHopMeta(injectorStep, splitFieldToRows);
        transMeta.addTransHop(hop_injector_splitfieldToRows);
        // 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 hop_SplitFieldToRows_Dummy = new TransHopMeta(splitFieldToRows, dummyStep);
        transMeta.addTransHop(hop_SplitFieldToRows_Dummy);
        if (!Utils.isEmpty(delimiterVariableValue)) {
            String delimiterVariableName = delimiter.replace("${", "");
            delimiterVariableName = delimiterVariableName.replace("}", "");
            transMeta.setVariable(delimiterVariableName, delimiterVariableValue);
        }
        // Now execute the transformation...
        Trans trans = new Trans(transMeta);
        trans.prepareExecution(null);
        StepInterface si = trans.getStepInterface(dummyStepname, 0);
        si.addRowListener(rc);
        RowProducer rowProducer = trans.addRowProducer(injectorStepname, 0);
        trans.startThreads();
        // add rows
        List<RowMetaAndData> inputList = createData(stringToSplit);
        for (RowMetaAndData rm : inputList) {
            rowProducer.putRow(rm.getRowMeta(), rm.getData());
        }
        rowProducer.finished();
        trans.waitUntilFinished();
    } catch (KettleException e) {
        fail("KettleEnvironment exception" + e.getMessage());
    }
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    return resultRows;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) 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)

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