Search in sources :

Example 1 with PluginRegistry

use of org.apache.hop.core.plugins.PluginRegistry in project hop by apache.

the class DatabaseMeta method findIDatabase.

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

Example 2 with PluginRegistry

use of org.apache.hop.core.plugins.PluginRegistry in project hop by apache.

the class DatabaseMetaObjectFactory method createObject.

@Override
public Object createObject(String id, Object parentObject) throws HopException {
    PluginRegistry registry = PluginRegistry.getInstance();
    IPlugin plugin = registry.findPluginWithId(DatabasePluginType.class, id);
    IDatabase iDatabase = (IDatabase) registry.loadClass(plugin);
    return iDatabase;
}
Also used : PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 3 with PluginRegistry

use of org.apache.hop.core.plugins.PluginRegistry in project hop by apache.

the class HopSearch method main.

public static void main(String[] args) {
    HopSearch hopSearch = new HopSearch();
    try {
        HopEnvironment.init();
        // Also register the search plugin type (usually only done for the GUI)
        // We don't want to load these in HopEnvironmnent.init() because for now it would
        // only be useful in Hop GUI and Hop Search.  There is no need to slow down
        // Hop Run or Hop Server with this.
        // 
        PluginRegistry registry = PluginRegistry.getInstance();
        SearchableAnalyserPluginType searchableAnalyserPluginType = SearchableAnalyserPluginType.getInstance();
        registry.addPluginType(searchableAnalyserPluginType);
        searchableAnalyserPluginType.searchPlugins();
        CommandLine cmd = new CommandLine(hopSearch);
        List<IPlugin> configPlugins = registry.getPlugins(ConfigPluginType.class);
        for (IPlugin configPlugin : configPlugins) {
            // Load only the plugins of the "search" category
            if (ConfigPlugin.CATEGORY_SEARCH.equals(configPlugin.getCategory())) {
                IConfigOptions configOptions = registry.loadClass(configPlugin, IConfigOptions.class);
                cmd.addMixin(configPlugin.getIds()[0], configOptions);
            }
        }
        hopSearch.setCmd(cmd);
        CommandLine.ParseResult parseResult = cmd.parseArgs(args);
        if (CommandLine.printHelpIfRequested(parseResult)) {
            System.exit(1);
        } else {
            hopSearch.run();
            System.exit(0);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        hopSearch.cmd.usage(System.err);
        System.exit(9);
    } catch (ExecutionException e) {
        System.err.println("Error found during execution!");
        System.err.println(Const.getStackTracker(e));
        System.exit(1);
    } catch (Exception e) {
        System.err.println("General error found, something went horribly wrong!");
        System.err.println(Const.getStackTracker(e));
        System.exit(2);
    }
}
Also used : CommandLine(picocli.CommandLine) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 4 with PluginRegistry

use of org.apache.hop.core.plugins.PluginRegistry in project hop by apache.

the class WorkflowActionEvalTableContentTest method setUpBeforeClass.

// private static DBMockIface dbi = DBMockIface();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    HopClientEnvironment.init();
    dbMap.put(IDatabase.class, DBMockIface.class.getName());
    PluginRegistry preg = PluginRegistry.getInstance();
    mockDbPlugin = mock(IPlugin.class);
    when(mockDbPlugin.matches(anyString())).thenReturn(true);
    when(mockDbPlugin.isNativePlugin()).thenReturn(true);
    when(mockDbPlugin.getMainType()).thenAnswer((Answer<Class<?>>) invocation -> IDatabase.class);
    when(mockDbPlugin.getPluginType()).thenAnswer((Answer<Class<? extends IPluginType>>) invocation -> DatabasePluginType.class);
    when(mockDbPlugin.getIds()).thenReturn(new String[] { "Oracle", "mock-db-id" });
    when(mockDbPlugin.getName()).thenReturn("mock-db-name");
    when(mockDbPlugin.getClassMap()).thenReturn(dbMap);
    preg.registerPlugin(DatabasePluginType.class, mockDbPlugin);
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) HopClientEnvironment(org.apache.hop.core.HopClientEnvironment) IValueMeta(org.apache.hop.core.row.IValueMeta) Answer(org.mockito.stubbing.Answer) Map(java.util.Map) IPluginType(org.apache.hop.core.plugins.IPluginType) DatabasePluginType(org.apache.hop.core.database.DatabasePluginType) IWorkflowEngine(org.apache.hop.workflow.engine.IWorkflowEngine) HopDatabaseException(org.apache.hop.core.exception.HopDatabaseException) Mockito.when(org.mockito.Mockito.when) Const(org.apache.hop.core.Const) Result(org.apache.hop.core.Result) RestoreHopEngineEnvironment(org.apache.hop.junit.rules.RestoreHopEngineEnvironment) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) org.junit(org.junit) BaseDatabaseMeta(org.apache.hop.core.database.BaseDatabaseMeta) Assert(org.junit.Assert) IDatabase(org.apache.hop.core.database.IDatabase) LocalWorkflowEngine(org.apache.hop.workflow.engines.local.LocalWorkflowEngine) IPlugin(org.apache.hop.core.plugins.IPlugin) Mockito.mock(org.mockito.Mockito.mock) IPluginType(org.apache.hop.core.plugins.IPluginType) IDatabase(org.apache.hop.core.database.IDatabase) DatabasePluginType(org.apache.hop.core.database.DatabasePluginType) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 5 with PluginRegistry

use of org.apache.hop.core.plugins.PluginRegistry in project hop by apache.

the class UserDefinedJavaClassDialog method test.

private boolean test() {
    PluginRegistry registry = PluginRegistry.getInstance();
    String scriptTransformName = wTransformName.getText();
    if (!checkForTransformClass()) {
        return false;
    }
    // Create a transform with the information in this dialog
    UserDefinedJavaClassMeta udjcMeta = new UserDefinedJavaClassMeta();
    getInfo(udjcMeta);
    try {
        // First, before we get into the trial run, just see if the classes
        // all compile.
        udjcMeta.cookClasses();
        if (udjcMeta.cookErrors.size() == 1) {
            Exception e = udjcMeta.cookErrors.get(0);
            new ErrorDialog(shell, "Error during class compilation", e.toString(), e);
            return false;
        } else if (udjcMeta.cookErrors.size() > 1) {
            Exception e = udjcMeta.cookErrors.get(0);
            new ErrorDialog(shell, "Errors during class compilation", String.format("Multiple errors during class compilation. First error:\n%s", e.toString()), e);
            return false;
        }
        // What fields are coming into the transform?
        IRowMeta rowMeta = pipelineMeta.getPrevTransformFields(variables, transformName).clone();
        if (rowMeta != null) {
            // time
            if (genMeta == null) {
                genMeta = new RowGeneratorMeta();
                genMeta.setRowLimit("10");
                // CHECKSTYLE:Indentation:OFF
                for (int i = 0; i < rowMeta.size(); i++) {
                    IValueMeta valueMeta = rowMeta.getValueMeta(i);
                    if (valueMeta.isStorageBinaryString()) {
                        valueMeta.setStorageType(IValueMeta.STORAGE_TYPE_NORMAL);
                    }
                    GeneratorField field = new GeneratorField();
                    field.setName(valueMeta.getName());
                    field.setType(valueMeta.getTypeDesc());
                    field.setLength(valueMeta.getLength());
                    field.setPrecision(valueMeta.getPrecision());
                    field.setCurrency(valueMeta.getCurrencySymbol());
                    field.setDecimal(valueMeta.getDecimalSymbol());
                    field.setGroup(valueMeta.getGroupingSymbol());
                    String string = null;
                    switch(valueMeta.getType()) {
                        case IValueMeta.TYPE_DATE:
                            field.setFormat("yyyy/MM/dd HH:mm:ss");
                            valueMeta.setConversionMask(field.getFormat());
                            string = valueMeta.getString(new Date());
                            break;
                        case IValueMeta.TYPE_STRING:
                            string = "test value test value";
                            break;
                        case IValueMeta.TYPE_INTEGER:
                            field.setFormat("#");
                            valueMeta.setConversionMask(field.getFormat());
                            string = valueMeta.getString(Long.valueOf(0L));
                            break;
                        case IValueMeta.TYPE_NUMBER:
                            field.setFormat("#.#");
                            valueMeta.setConversionMask(field.getFormat());
                            string = valueMeta.getString(Double.valueOf(0.0D));
                            break;
                        case IValueMeta.TYPE_BIGNUMBER:
                            field.setFormat("#.#");
                            valueMeta.setConversionMask(field.getFormat());
                            string = valueMeta.getString(BigDecimal.ZERO);
                            break;
                        case IValueMeta.TYPE_BOOLEAN:
                            string = valueMeta.getString(Boolean.TRUE);
                            break;
                        case IValueMeta.TYPE_BINARY:
                            string = valueMeta.getString(new byte[] { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 });
                            break;
                        default:
                            break;
                    }
                    field.setValue(string);
                    genMeta.getFields().add(field);
                }
            }
            TransformMeta genTransform = new TransformMeta(registry.getPluginId(TransformPluginType.class, genMeta), "## TEST DATA ##", genMeta);
            genTransform.setLocation(50, 50);
            TransformMeta scriptTransform = new TransformMeta(registry.getPluginId(TransformPluginType.class, udjcMeta), Const.NVL(scriptTransformName, "## SCRIPT ##"), udjcMeta);
            scriptTransformName = scriptTransform.getName();
            scriptTransform.setLocation(150, 50);
            // Create a hop between both transforms...
            // 
            PipelineHopMeta hop = new PipelineHopMeta(genTransform, scriptTransform);
            // Generate a new test pipeline...
            // 
            PipelineMeta pipelineMeta = new PipelineMeta();
            pipelineMeta.setName(wTransformName.getText() + " - PREVIEW");
            pipelineMeta.addTransform(genTransform);
            pipelineMeta.addTransform(scriptTransform);
            pipelineMeta.addPipelineHop(hop);
            // OK, now we ask the user to edit this dialog...
            // 
            // Now run this pipeline and grab the results...
            // 
            PipelinePreviewProgressDialog progressDialog = new PipelinePreviewProgressDialog(shell, variables, pipelineMeta, new String[] { scriptTransformName }, new int[] { Const.toInt(genMeta.getRowLimit(), 10) });
            progressDialog.open();
            Pipeline pipeline = progressDialog.getPipeline();
            String loggingText = progressDialog.getLoggingText();
            if (!progressDialog.isCancelled()) {
                if (pipeline.getResult() != null && pipeline.getResult().getNrErrors() > 0) {
                    EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString("System.Dialog.PreviewError.Title"), BaseMessages.getString("System.Dialog.PreviewError.Message"), loggingText, true);
                    etd.setReadOnly();
                    etd.open();
                }
            }
            IRowMeta previewRowsMeta = progressDialog.getPreviewRowsMeta(wTransformName.getText());
            List<Object[]> previewRows = progressDialog.getPreviewRows(wTransformName.getText());
            if (previewRowsMeta != null && previewRows != null && previewRows.size() > 0) {
                PreviewRowsDialog prd = new PreviewRowsDialog(shell, variables, SWT.NONE, wTransformName.getText(), previewRowsMeta, previewRows, loggingText);
                prd.open();
            }
            return true;
        } else {
            throw new HopException(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.Exception.CouldNotGetFields"));
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.TestFailed.DialogMessage"), e);
        return false;
    }
}
Also used : HopException(org.apache.hop.core.exception.HopException) IRowMeta(org.apache.hop.core.row.IRowMeta) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) RowGeneratorMeta(org.apache.hop.pipeline.transforms.rowgenerator.RowGeneratorMeta) HopException(org.apache.hop.core.exception.HopException) HopXmlException(org.apache.hop.core.exception.HopXmlException) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Pipeline(org.apache.hop.pipeline.Pipeline) IValueMeta(org.apache.hop.core.row.IValueMeta) GeneratorField(org.apache.hop.pipeline.transforms.rowgenerator.GeneratorField) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) BaseTransformMeta(org.apache.hop.pipeline.transform.BaseTransformMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) TransformPluginType(org.apache.hop.core.plugins.TransformPluginType) PipelinePreviewProgressDialog(org.apache.hop.ui.pipeline.dialog.PipelinePreviewProgressDialog)

Aggregations

PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)57 IPlugin (org.apache.hop.core.plugins.IPlugin)39 HopException (org.apache.hop.core.exception.HopException)22 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)13 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)12 Pipeline (org.apache.hop.pipeline.Pipeline)11 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)9 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)9 IVariables (org.apache.hop.core.variables.IVariables)8 HopPluginException (org.apache.hop.core.exception.HopPluginException)7 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)6 Method (java.lang.reflect.Method)5 ArrayList (java.util.ArrayList)5 TransformPluginType (org.apache.hop.core.plugins.TransformPluginType)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 RowMetaAndData (org.apache.hop.core.RowMetaAndData)3 Point (org.apache.hop.core.gui.Point)3 IPluginType (org.apache.hop.core.plugins.IPluginType)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)3