Search in sources :

Example 16 with ActionMeta

use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.

the class WorkflowMeta method getAction.

/**
 * Gets the action copy.
 *
 * @param x the x
 * @param y the y
 * @param iconsize the iconsize
 * @return the action copy
 */
public ActionMeta getAction(int x, int y, int iconsize) {
    int i;
    int s;
    s = nrActions();
    for (i = s - 1; i >= 0; i--) {
        // Back to front because drawing goes from start to end
        ActionMeta action = getAction(i);
        Point p = action.getLocation();
        if (p != null) {
            if (x >= p.x && x <= p.x + iconsize && y >= p.y && y <= p.y + iconsize) {
                return action;
            }
        }
    }
    return null;
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) Point(org.apache.hop.core.gui.Point) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) Point(org.apache.hop.core.gui.Point) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 17 with ActionMeta

use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.

the class WorkflowMeta method getMaximum.

/**
 * Gets the maximum.
 *
 * @return the maximum
 */
public Point getMaximum() {
    int maxx = 0;
    int maxy = 0;
    for (int i = 0; i < nrActions(); i++) {
        ActionMeta action = getAction(i);
        Point loc = action.getLocation();
        if (loc.x > maxx) {
            maxx = loc.x;
        }
        if (loc.y > maxy) {
            maxy = loc.y;
        }
    }
    for (int i = 0; i < nrNotes(); i++) {
        NotePadMeta ni = getNote(i);
        Point loc = ni.getLocation();
        if (loc.x + ni.width > maxx) {
            maxx = loc.x + ni.width;
        }
        if (loc.y + ni.height > maxy) {
            maxy = loc.y + ni.height;
        }
    }
    return new Point(maxx + 100, maxy + 100);
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) Point(org.apache.hop.core.gui.Point) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) Point(org.apache.hop.core.gui.Point) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 18 with ActionMeta

use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.

the class WorkflowMeta method exportResources.

@Override
public String exportResources(IVariables variables, Map<String, ResourceDefinition> definitions, IResourceNaming namingInterface, IHopMetadataProvider metadataProvider) throws HopException {
    String resourceName = null;
    try {
        // Handle naming for XML bases resources...
        // 
        String baseName;
        String originalPath;
        String fullname;
        String extension = "hwf";
        if (StringUtils.isNotEmpty(getFilename())) {
            FileObject fileObject = HopVfs.getFileObject(variables.resolve(getFilename()));
            originalPath = fileObject.getParent().getName().getPath();
            baseName = fileObject.getName().getBaseName();
            fullname = fileObject.getName().getPath();
            resourceName = namingInterface.nameResource(baseName, originalPath, extension, IResourceNaming.FileNamingType.WORKFLOW);
            ResourceDefinition definition = definitions.get(resourceName);
            if (definition == null) {
                // If we do this once, it will be plenty :-)
                // 
                WorkflowMeta workflowMeta = (WorkflowMeta) this.realClone(false);
                // Set an appropriate name
                // 
                workflowMeta.setNameSynchronizedWithFilename(false);
                workflowMeta.setName(getName());
                // 
                for (ActionMeta actionMeta : workflowMeta.workflowActions) {
                    actionMeta.getAction().exportResources(variables, definitions, namingInterface, metadataProvider);
                }
                // At the end, add ourselves to the map...
                // 
                definition = new ResourceDefinition(resourceName, workflowMeta.getXml(variables));
                // 
                if (Utils.isEmpty(this.getFilename())) {
                    definition.setOrigin(fullname);
                } else {
                    definition.setOrigin(this.getFilename());
                }
                definitions.put(fullname, definition);
            }
        }
    } catch (FileSystemException e) {
        throw new HopException(BaseMessages.getString(PKG, "WorkflowMeta.Exception.AnErrorOccuredReadingWorkflow", getFilename()), e);
    } catch (HopFileException e) {
        throw new HopException(BaseMessages.getString(PKG, "WorkflowMeta.Exception.AnErrorOccuredReadingWorkflow", getFilename()), e);
    }
    return resourceName;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) HopFileException(org.apache.hop.core.exception.HopFileException) ActionMeta(org.apache.hop.workflow.action.ActionMeta) HopException(org.apache.hop.core.exception.HopException) ResourceDefinition(org.apache.hop.resource.ResourceDefinition) FileObject(org.apache.commons.vfs2.FileObject)

Example 19 with ActionMeta

use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.

the class LocalWorkflowEngine method startExecution.

@Override
public Result startExecution() {
    if (!(workflowRunConfiguration.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration)) {
        log.logError("Error starting workflow", new HopException("A local workflow execution expects a local workflow configuration, not an instance of class " + workflowRunConfiguration.getEngineRunConfiguration().getClass().getName()));
        result = new Result();
        result.setNrErrors(1L);
        return result;
    }
    LocalWorkflowRunConfiguration config = (LocalWorkflowRunConfiguration) workflowRunConfiguration.getEngineRunConfiguration();
    // See if we need to enable transactions...
    // 
    IExtensionData parentExtensionData = getParentPipeline();
    if (parentExtensionData == null) {
        parentExtensionData = getParentWorkflow();
    }
    String connectionGroup = null;
    if (parentExtensionData != null && parentExtensionData.getExtensionDataMap() != null) {
        connectionGroup = (String) parentExtensionData.getExtensionDataMap().get(Const.CONNECTION_GROUP);
    }
    // 
    if (config.isTransactional() && connectionGroup == null) {
        // Store a value in the parent...
        // 
        connectionGroup = getWorkflowMeta().getName() + " - " + UUID.randomUUID();
        // We also need to commit/rollback at the end of this workflow...
        // 
        addWorkflowFinishedListener(workflow -> {
            String group = (String) workflow.getExtensionDataMap().get(Const.CONNECTION_GROUP);
            List<Database> databases = DatabaseConnectionMap.getInstance().getDatabases(group);
            Result result = workflow.getResult();
            for (Database database : databases) {
                // 
                try {
                    if (result.getResult() && !result.isStopped() && result.getNrErrors() == 0) {
                        try {
                            database.commit(true);
                            workflow.getLogChannel().logBasic("All transactions of database connection '" + database.getDatabaseMeta().getName() + "' were committed at the end of the workflow!");
                        } catch (HopDatabaseException e) {
                            workflow.getLogChannel().logError("Error committing database connection " + database.getDatabaseMeta().getName(), e);
                            result.setNrErrors(result.getNrErrors() + 1);
                        }
                    } else {
                        // Error? Rollback!
                        try {
                            database.rollback(true);
                            workflow.getLogChannel().logBasic("All transactions of database connection '" + database.getDatabaseMeta().getName() + "' were rolled back at the end of the workflow!");
                        } catch (HopDatabaseException e) {
                            workflow.getLogChannel().logError("Error rolling back database connection " + database.getDatabaseMeta().getName(), e);
                            result.setNrErrors(result.getNrErrors() + 1);
                        }
                    }
                } finally {
                    // Always close connection!
                    try {
                        database.closeConnectionOnly();
                        workflow.getLogChannel().logDebug("Database connection '" + database.getDatabaseMeta().getName() + "' closed successfully!");
                    } catch (HopDatabaseException hde) {
                        workflow.getLogChannel().logError("Error disconnecting from database - closeConnectionOnly failed:" + Const.CR + hde.getMessage());
                        workflow.getLogChannel().logError(Const.getStackTracker(hde));
                    }
                    // Definitely remove the connection reference the connections map
                    DatabaseConnectionMap.getInstance().removeConnection(group, null, database);
                }
            }
        });
    }
    // 
    if (connectionGroup != null && getExtensionDataMap() != null) {
        // Set the connection group for this workflow
        // 
        getExtensionDataMap().put(Const.CONNECTION_GROUP, connectionGroup);
    }
    // Pass down the value of the connection group value to actions before they're executed...
    // 
    addActionListener(new IActionListener() {

        @Override
        public void beforeExecution(IWorkflowEngine workflow, ActionMeta actionMeta, IAction action) {
            String connectionGroup = (String) workflow.getExtensionDataMap().get(Const.CONNECTION_GROUP);
            if (connectionGroup != null) {
                action.getExtensionDataMap().put(Const.CONNECTION_GROUP, connectionGroup);
            }
        }

        @Override
        public void afterExecution(IWorkflowEngine workflow, ActionMeta actionMeta, IAction action, Result result) {
        // Nothing
        }
    });
    return super.startExecution();
}
Also used : IActionListener(org.apache.hop.workflow.IActionListener) IExtensionData(org.apache.hop.core.IExtensionData) IAction(org.apache.hop.workflow.action.IAction) HopException(org.apache.hop.core.exception.HopException) HopDatabaseException(org.apache.hop.core.exception.HopDatabaseException) Result(org.apache.hop.core.Result) IWorkflowEngine(org.apache.hop.workflow.engine.IWorkflowEngine) ActionMeta(org.apache.hop.workflow.action.ActionMeta) Database(org.apache.hop.core.database.Database)

Example 20 with ActionMeta

use of org.apache.hop.workflow.action.ActionMeta in project hop by apache.

the class WorkflowMetaTest method testHasLoop_simpleLoop.

@Test
public void testHasLoop_simpleLoop() throws Exception {
    // main->2->3->main
    WorkflowMeta workflowMetaSpy = spy(workflowMeta);
    ActionMeta actionCopyMain = createAction("mainTransform");
    ActionMeta actionCopy2 = createAction("transform2");
    ActionMeta actionCopy3 = createAction("transform3");
    when(workflowMetaSpy.findNrPrevActions(actionCopyMain)).thenReturn(1);
    when(workflowMetaSpy.findPrevAction(actionCopyMain, 0)).thenReturn(actionCopy2);
    when(workflowMetaSpy.findNrPrevActions(actionCopy2)).thenReturn(1);
    when(workflowMetaSpy.findPrevAction(actionCopy2, 0)).thenReturn(actionCopy3);
    when(workflowMetaSpy.findNrPrevActions(actionCopy3)).thenReturn(1);
    when(workflowMetaSpy.findPrevAction(actionCopy3, 0)).thenReturn(actionCopyMain);
    assertTrue(workflowMetaSpy.hasLoop(actionCopyMain));
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) Test(org.junit.Test)

Aggregations

ActionMeta (org.apache.hop.workflow.action.ActionMeta)92 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)34 Point (org.apache.hop.core.gui.Point)28 HopException (org.apache.hop.core.exception.HopException)23 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)21 IAction (org.apache.hop.workflow.action.IAction)12 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)11 GuiContextAction (org.apache.hop.core.action.GuiContextAction)9 NotePadMeta (org.apache.hop.core.NotePadMeta)8 Test (org.junit.Test)7 WorkflowHopMeta (org.apache.hop.workflow.WorkflowHopMeta)6 IVariables (org.apache.hop.core.variables.IVariables)5 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)5 EnterSelectionDialog (org.apache.hop.ui.core.dialog.EnterSelectionDialog)5 HopGui (org.apache.hop.ui.hopgui.HopGui)5 LocalWorkflowEngine (org.apache.hop.workflow.engines.local.LocalWorkflowEngine)5 ArrayList (java.util.ArrayList)4 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)4 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)4 HashMap (java.util.HashMap)3