Search in sources :

Example 1 with WorkflowHopMeta

use of org.apache.hop.workflow.WorkflowHopMeta in project hop by apache.

the class HopGuiWorkflowActionDelegate method deleteActions.

public void deleteActions(WorkflowMeta workflow, List<ActionMeta> actions) {
    // Hops belonging to the deleting actions are placed in a single transaction and removed.
    List<WorkflowHopMeta> workflowHops = new ArrayList<>();
    int[] hopIndexes = new int[workflow.nrWorkflowHops()];
    int hopIndex = 0;
    for (int i = workflow.nrWorkflowHops() - 1; i >= 0; i--) {
        WorkflowHopMeta hi = workflow.getWorkflowHop(i);
        for (int j = 0; j < actions.size() && hopIndex < hopIndexes.length; j++) {
            if (hi.getFromAction().equals(actions.get(j)) || hi.getToAction().equals(actions.get(j))) {
                int idx = workflow.indexOfWorkflowHop(hi);
                workflowHops.add((WorkflowHopMeta) hi.clone());
                hopIndexes[hopIndex] = idx;
                workflow.removeWorkflowHop(idx);
                hopIndex++;
                break;
            }
        }
    }
    if (!workflowHops.isEmpty()) {
        WorkflowHopMeta[] hops = workflowHops.toArray(new WorkflowHopMeta[workflowHops.size()]);
        hopGui.undoDelegate.addUndoDelete(workflow, hops, hopIndexes);
    }
    // Deleting actions are placed all in a single transaction and removed.
    int[] positions = new int[actions.size()];
    for (int i = 0; i < actions.size(); i++) {
        int pos = workflow.indexOfAction(actions.get(i));
        workflow.removeAction(pos);
        positions[i] = pos;
    }
    hopGui.undoDelegate.addUndoDelete(workflow, actions.toArray(new ActionMeta[0]), positions);
    workflowGraph.updateGui();
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) ArrayList(java.util.ArrayList) Point(org.apache.hop.core.gui.Point) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta)

Example 2 with WorkflowHopMeta

use of org.apache.hop.workflow.WorkflowHopMeta in project hop by apache.

the class HopGuiWorkflowClipboardDelegate method pasteXml.

public void pasteXml(WorkflowMeta workflowMeta, String clipboardContent, Point locaction) {
    try {
        Document doc = XmlHandler.loadXmlString(clipboardContent);
        Node workflowNode = XmlHandler.getSubNode(doc, XML_TAG_WORKFLOW_ACTIONS);
        // De-select all, re-select pasted transforms...
        workflowMeta.unselectAll();
        Node actionsNode = XmlHandler.getSubNode(workflowNode, XML_TAG_ACTIONS);
        int nr = XmlHandler.countNodes(actionsNode, ActionMeta.XML_TAG);
        ActionMeta[] actions = new ActionMeta[nr];
        ArrayList<String> actionsOldNames = new ArrayList<>(nr);
        Point min = new Point(99999999, 99999999);
        // Load the entries...
        for (int i = 0; i < nr; i++) {
            Node actionNode = XmlHandler.getSubNodeByNr(actionsNode, ActionMeta.XML_TAG, i);
            actions[i] = new ActionMeta(actionNode, hopGui.getMetadataProvider(), workflowGraph.getVariables());
            if (locaction != null) {
                Point p = actions[i].getLocation();
                if (min.x > p.x) {
                    min.x = p.x;
                }
                if (min.y > p.y) {
                    min.y = p.y;
                }
            }
        }
        // Load the hops...
        Node hopsNode = XmlHandler.getSubNode(workflowNode, "order");
        nr = XmlHandler.countNodes(hopsNode, "hop");
        WorkflowHopMeta[] hops = new WorkflowHopMeta[nr];
        for (int i = 0; i < nr; i++) {
            Node hopNode = XmlHandler.getSubNodeByNr(hopsNode, "hop", i);
            hops[i] = new WorkflowHopMeta(hopNode, Arrays.asList(actions));
        }
        // This is the offset:
        Point offset = new Point(locaction.x - min.x, locaction.y - min.y);
        // Undo/redo object positions...
        int[] position = new int[actions.length];
        for (int i = 0; i < actions.length; i++) {
            Point p = actions[i].getLocation();
            String name = actions[i].getName();
            PropsUi.setLocation(actions[i], p.x + offset.x, p.y + offset.y);
            // Check the name, find alternative...
            actionsOldNames.add(name);
            actions[i].setName(workflowMeta.getAlternativeActionName(name));
            workflowMeta.addAction(actions[i]);
            position[i] = workflowMeta.indexOfAction(actions[i]);
            actions[i].setSelected(true);
        }
        // 
        for (WorkflowHopMeta hop : hops) {
            workflowMeta.addWorkflowHop(hop);
        }
        // Load the notes...
        Node notesNode = XmlHandler.getSubNode(workflowNode, "notepads");
        nr = XmlHandler.countNodes(notesNode, "notepad");
        if (log.isDebug()) {
            // "I found "+nr+" notepads to paste."
            log.logDebug(BaseMessages.getString(PKG, "HopGui.Log.FoundNotepads", "" + nr));
        }
        NotePadMeta[] notes = new NotePadMeta[nr];
        for (int i = 0; i < notes.length; i++) {
            Node noteNode = XmlHandler.getSubNodeByNr(notesNode, "notepad", i);
            notes[i] = new NotePadMeta(noteNode);
            Point p = notes[i].getLocation();
            PropsUi.setLocation(notes[i], p.x + offset.x, p.y + offset.y);
            workflowMeta.addNote(notes[i]);
            notes[i].setSelected(true);
        }
        // Save undo information too...
        hopGui.undoDelegate.addUndoNew(workflowMeta, actions, position, false);
        int[] hopPos = new int[hops.length];
        for (int i = 0; i < hops.length; i++) {
            hopPos[i] = workflowMeta.indexOfWorkflowHop(hops[i]);
        }
        hopGui.undoDelegate.addUndoNew(workflowMeta, hops, hopPos, true);
        int[] notePos = new int[notes.length];
        for (int i = 0; i < notes.length; i++) {
            notePos[i] = workflowMeta.indexOfNote(notes[i]);
        }
        hopGui.undoDelegate.addUndoNew(workflowMeta, notes, notePos, true);
    } catch (HopException e) {
        // See if this was different (non-XML) content
        // 
        pasteNoXmlContent(workflowMeta, clipboardContent, locaction);
    }
    workflowGraph.redraw();
}
Also used : HopException(org.apache.hop.core.exception.HopException) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) Point(org.apache.hop.core.gui.Point) Document(org.w3c.dom.Document) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) Point(org.apache.hop.core.gui.Point) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta) ActionMeta(org.apache.hop.workflow.action.ActionMeta) NotePadMeta(org.apache.hop.core.NotePadMeta)

Example 3 with WorkflowHopMeta

use of org.apache.hop.workflow.WorkflowHopMeta in project hop by apache.

the class HopGuiWorkflowUndoDelegate method undoWorkflowAction.

public void undoWorkflowAction(IHopFileTypeHandler handler, WorkflowMeta workflowMeta, ChangeAction changeAction) {
    switch(changeAction.getType()) {
        // We created a new transform : undo this...
        case NewAction:
            // Delete the transform at correct location:
            for (int i = changeAction.getCurrent().length - 1; i >= 0; i--) {
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.removeAction(idx);
            }
            break;
        // We created a new note : undo this...
        case NewNote:
            // Delete the note at correct location:
            for (int i = changeAction.getCurrent().length - 1; i >= 0; i--) {
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.removeNote(idx);
            }
            break;
        // We created a new hop : undo this...
        case NewHop:
            // Delete the hop at correct location:
            for (int i = changeAction.getCurrent().length - 1; i >= 0; i--) {
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.removeWorkflowHop(idx);
            }
            break;
        // We delete a transform : undo this...
        case DeleteAction:
            // un-Delete the transform at correct location: re-insert
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                ActionMeta action = (ActionMeta) changeAction.getCurrent()[i];
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.addAction(idx, action);
            }
            break;
        // We delete new note : undo this...
        case DeleteNote:
            // re-insert the note at correct location:
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                NotePadMeta ni = (NotePadMeta) changeAction.getCurrent()[i];
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.addNote(idx, ni);
            }
            break;
        // We deleted a hop : undo this...
        case DeleteHop:
            // re-insert the hop at correct location:
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                WorkflowHopMeta hopMeta = (WorkflowHopMeta) changeAction.getCurrent()[i];
                int idx = changeAction.getCurrentIndex()[i];
                // Build a new hop:
                ActionMeta from = workflowMeta.findAction(hopMeta.getFromAction().getName());
                ActionMeta to = workflowMeta.findAction(hopMeta.getToAction().getName());
                WorkflowHopMeta newHopMeta = new WorkflowHopMeta(from, to);
                workflowMeta.addWorkflowHop(idx, newHopMeta);
            }
            break;
        // We changed a transform : undo this...
        case ChangeAction:
            // Delete the current transform, insert previous version.
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                ActionMeta prev = ((ActionMeta) changeAction.getPrevious()[i]).clone();
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.getAction(idx).replaceMeta(prev);
            }
            break;
        // We changed a note : undo this...
        case ChangeNote:
            // Delete & re-insert
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.removeNote(idx);
                NotePadMeta prev = (NotePadMeta) changeAction.getPrevious()[i];
                workflowMeta.addNote(idx, (NotePadMeta) prev.clone());
            }
            break;
        // We changed a hop : undo this...
        case ChangeHop:
            // Delete & re-insert
            for (int i = 0; i < changeAction.getCurrent().length; i++) {
                WorkflowHopMeta prev = (WorkflowHopMeta) changeAction.getPrevious()[i];
                int idx = changeAction.getCurrentIndex()[i];
                workflowMeta.removeWorkflowHop(idx);
                workflowMeta.addWorkflowHop(idx, (WorkflowHopMeta) prev.clone());
            }
            break;
        // The position of a transform has changed: undo this...
        case PositionAction:
            // Find the location of the transform:
            for (int i = 0; i < changeAction.getCurrentIndex().length; i++) {
                ActionMeta action = workflowMeta.getAction(changeAction.getCurrentIndex()[i]);
                action.setLocation(changeAction.getPreviousLocation()[i]);
            }
            break;
        // The position of a note has changed: undo this...
        case PositionNote:
            for (int i = 0; i < changeAction.getCurrentIndex().length; i++) {
                int idx = changeAction.getCurrentIndex()[i];
                NotePadMeta npi = workflowMeta.getNote(idx);
                Point prev = changeAction.getPreviousLocation()[i];
                npi.setLocation(prev);
            }
            break;
        default:
            break;
    }
    // OK, now check if we need to do this again...
    if (workflowMeta.viewNextUndo() != null) {
        if (workflowMeta.viewNextUndo().getNextAlso()) {
            undoWorkflowAction(handler, workflowMeta);
        }
    }
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) NotePadMeta(org.apache.hop.core.NotePadMeta) Point(org.apache.hop.core.gui.Point) Point(org.apache.hop.core.gui.Point) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta)

Example 4 with WorkflowHopMeta

use of org.apache.hop.workflow.WorkflowHopMeta in project hop by apache.

the class CanvasFacadeImpl method setDataWorkflow.

private void setDataWorkflow(Canvas canvas, float magnification, AbstractMeta meta) {
    final int iconSize = HopGui.getInstance().getProps().getIconSize();
    WorkflowMeta workflowMeta = (WorkflowMeta) meta;
    JsonObject jsonNodes = new JsonObject();
    workflowMeta.getActions().forEach(actionMeta -> {
        JsonObject jsonNode = new JsonObject();
        jsonNode.add("x", actionMeta.getLocation().x);
        jsonNode.add("y", actionMeta.getLocation().y);
        jsonNode.add("selected", actionMeta.isSelected());
        // Translated from org.apache.hop.ui.hopgui.shared.SwtGc.drawActionIcon(int, int,
        // ActionMeta, float)
        SwtUniversalImage swtImage = null;
        if (actionMeta.isMissing()) {
            swtImage = GuiResource.getInstance().getSwtImageMissing();
        } else {
            String pluginId = actionMeta.getAction().getPluginId();
            if (pluginId != null) {
                swtImage = GuiResource.getInstance().getImagesActions().get(pluginId);
            }
        }
        if (swtImage == null) {
            return;
        }
        int w = Math.round(iconSize * magnification);
        int h = Math.round(iconSize * magnification);
        Image image = swtImage.getAsBitmapForSize(Display.getCurrent(), w, h);
        // Translated
        jsonNode.add("img", image.internalImage.getResourceName());
        jsonNodes.add(actionMeta.getName(), jsonNode);
    });
    canvas.setData("nodes", jsonNodes);
    JsonArray jsonHops = new JsonArray();
    for (int i = 0; i < workflowMeta.nrWorkflowHops(); i++) {
        JsonObject jsonHop = new JsonObject();
        WorkflowHopMeta hop = workflowMeta.getWorkflowHop(i);
        jsonHop.add("from", hop.getFromAction().getName());
        jsonHop.add("to", hop.getToAction().getName());
        jsonHops.add(jsonHop);
    }
    canvas.setData("hops", jsonHops);
}
Also used : JsonArray(org.eclipse.rap.json.JsonArray) JsonObject(org.eclipse.rap.json.JsonObject) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) Image(org.eclipse.swt.graphics.Image) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta)

Example 5 with WorkflowHopMeta

use of org.apache.hop.workflow.WorkflowHopMeta in project hop by apache.

the class WorkflowLoggingExtensionPoint method logWorkflowMetadata.

private void logWorkflowMetadata(final ILogChannel log, final Session session, final NeoConnection connection, final IWorkflowEngine<WorkflowMeta> workflow) throws HopException {
    log.logDetailed("Logging workflow metadata to Neo4j server : " + connection.getName());
    final WorkflowMeta workflowMeta = workflow.getWorkflowMeta();
    synchronized (session) {
        session.writeTransaction((TransactionWork<Void>) transaction -> {
            try {
                Map<String, Object> workflowPars = new HashMap<>();
                workflowPars.put("workflowName", workflowMeta.getName());
                workflowPars.put("description", workflowMeta.getDescription());
                workflowPars.put("filename", workflowMeta.getFilename());
                StringBuilder workflowCypher = new StringBuilder();
                workflowCypher.append("MERGE (w:Workflow { name : $workflowName} ) ");
                workflowCypher.append("SET w.filename = $filename, w.description = $description ");
                log.logDetailed("Workflow metadata cypher : " + workflowCypher);
                transaction.run(workflowCypher.toString(), workflowPars);
                for (ActionMeta actionMeta : workflowMeta.getActions()) {
                    Map<String, Object> actionPars = new HashMap<>();
                    actionPars.put("workflowName", workflowMeta.getName());
                    actionPars.put("name", actionMeta.getName());
                    actionPars.put("description", actionMeta.getDescription());
                    actionPars.put("pluginId", actionMeta.getAction().getPluginId());
                    actionPars.put("evaluation", actionMeta.isEvaluation());
                    actionPars.put("launchingParallel", actionMeta.isLaunchingInParallel());
                    actionPars.put("start", actionMeta.isStart());
                    actionPars.put("unconditional", actionMeta.isUnconditional());
                    actionPars.put("locationX", actionMeta.getLocation().x);
                    actionPars.put("locationY", actionMeta.getLocation().y);
                    StringBuilder actionCypher = new StringBuilder();
                    actionCypher.append("MATCH (w:Workflow { name : $workflowName } ) ");
                    actionCypher.append("MERGE (a:Action { workflowName : $workflowName, name : $name }) ");
                    actionCypher.append("MERGE (a)-[rel:ACTION_OF_WORKFLOW]->(w) ");
                    actionCypher.append("SET ");
                    actionCypher.append("  a.description = $description ");
                    actionCypher.append(", a.pluginId = $pluginId ");
                    actionCypher.append(", a.evaluation = $evaluation ");
                    actionCypher.append(", a.launchingParallel = $launchingParallel ");
                    actionCypher.append(", a.start = $start ");
                    actionCypher.append(", a.unconditional = $unconditional ");
                    actionCypher.append(", a.locationX = $locationX ");
                    actionCypher.append(", a.locationY = $locationY ");
                    log.logDetailed("Action copy '" + actionMeta.getName() + "' cypher : " + actionCypher);
                    transaction.run(actionCypher.toString(), actionPars);
                }
                for (int i = 0; i < workflowMeta.nrWorkflowHops(); i++) {
                    WorkflowHopMeta hopMeta = workflowMeta.getWorkflowHop(i);
                    Map<String, Object> hopPars = new HashMap<>();
                    hopPars.put("fromAction", hopMeta.getFromAction().getName());
                    hopPars.put("toAction", hopMeta.getToAction().getName());
                    hopPars.put("workflowName", workflowMeta.getName());
                    StringBuilder hopCypher = new StringBuilder();
                    hopCypher.append("MATCH (f:Action { workflowName : $workflowName, name : $fromAction}) ");
                    hopCypher.append("MATCH (t:Action { workflowName : $workflowName, name : $toAction}) ");
                    hopCypher.append("MERGE (f)-[rel:PRECEDES]->(t) ");
                    transaction.run(hopCypher.toString(), hopPars);
                }
                transaction.commit();
            } catch (Exception e) {
                transaction.rollback();
                log.logError("Error logging workflow metadata", e);
            }
            return null;
        });
    }
}
Also used : Session(org.neo4j.driver.Session) ActionMeta(org.apache.hop.workflow.action.ActionMeta) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IVariables(org.apache.hop.core.variables.IVariables) Date(java.util.Date) Defaults(org.apache.hop.neo4j.logging.Defaults) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ActionResult(org.apache.hop.workflow.ActionResult) TransactionWork(org.neo4j.driver.TransactionWork) Transaction(org.neo4j.driver.Transaction) NeoConnection(org.apache.hop.neo4j.shared.NeoConnection) Map(java.util.Map) LoggingCore(org.apache.hop.neo4j.logging.util.LoggingCore) IWorkflowEngine(org.apache.hop.workflow.engine.IWorkflowEngine) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta) Driver(org.neo4j.driver.Driver) ILogChannel(org.apache.hop.core.logging.ILogChannel) HopLogStore(org.apache.hop.core.logging.HopLogStore) LoggingObjectType(org.apache.hop.core.logging.LoggingObjectType) LoggingHierarchy(org.apache.hop.core.logging.LoggingHierarchy) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) List(java.util.List) Result(org.apache.hop.core.Result) IExecutionFinishedListener(org.apache.hop.pipeline.IExecutionFinishedListener) ActionMeta(org.apache.hop.workflow.action.ActionMeta) HashMap(java.util.HashMap) Map(java.util.Map) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) WorkflowHopMeta(org.apache.hop.workflow.WorkflowHopMeta)

Aggregations

WorkflowHopMeta (org.apache.hop.workflow.WorkflowHopMeta)9 ActionMeta (org.apache.hop.workflow.action.ActionMeta)6 Point (org.apache.hop.core.gui.Point)5 NotePadMeta (org.apache.hop.core.NotePadMeta)4 HopException (org.apache.hop.core.exception.HopException)3 ArrayList (java.util.ArrayList)2 IVariables (org.apache.hop.core.variables.IVariables)2 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Result (org.apache.hop.core.Result)1 SwtUniversalImage (org.apache.hop.core.SwtUniversalImage)1 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)1 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)1 HopLogStore (org.apache.hop.core.logging.HopLogStore)1 ILogChannel (org.apache.hop.core.logging.ILogChannel)1 LoggingHierarchy (org.apache.hop.core.logging.LoggingHierarchy)1