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();
}
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();
}
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);
}
}
}
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);
}
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;
});
}
}
Aggregations