Skip to content

Commit c62a9bf

Browse files
committed
Prevent the creation of invalid hops in a visual manner #6281
1 parent 87b1ce1 commit c62a9bf

File tree

10 files changed

+287
-232
lines changed

10 files changed

+287
-232
lines changed

engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ public void setTransform(int i, TransformMeta transformMeta) {
581581
* metadata at the specified index to the specified meta-data object.
582582
*
583583
* @param i The index into the hops list
584-
* @param hi The hop meta-data to set
584+
* @param hop The hop meta-data to set
585585
*/
586-
public void setPipelineHop(int i, PipelineHopMeta hi) {
587-
hops.set(i, hi);
586+
public void setPipelineHop(int i, PipelineHopMeta hop) {
587+
hops.set(i, hop);
588588
clearCaches();
589589
}
590590

@@ -649,15 +649,12 @@ public TransformMeta findTransform(String name, TransformMeta exclude) {
649649
* Searches the list of hops for a hop with a certain name.
650650
*
651651
* @param name The name of the hop to look for
652-
* @return The hop information or null if nothing was found.
652+
* @return The hop found or null if nothing was found.
653653
*/
654654
public PipelineHopMeta findPipelineHop(String name) {
655-
int i;
656-
657-
for (i = 0; i < nrPipelineHops(); i++) {
658-
PipelineHopMeta hi = getPipelineHop(i);
659-
if (hi.toString().equalsIgnoreCase(name)) {
660-
return hi;
655+
for (PipelineHopMeta hop : hops) {
656+
if (hop.toString().equalsIgnoreCase(name)) {
657+
return hop;
661658
}
662659
}
663660
return null;
@@ -667,13 +664,14 @@ public PipelineHopMeta findPipelineHop(String name) {
667664
* Search all hops for a hop where a certain transform is at the start.
668665
*
669666
* @param fromTransform The transform at the start of the hop.
670-
* @return The hop or null if no hop was found.
667+
* @return The first hop found or null if nothing was found.
671668
*/
672669
public PipelineHopMeta findPipelineHopFrom(TransformMeta fromTransform) {
673-
for (PipelineHopMeta hop : hops) {
674-
if (hop.getFromTransform() != null
675-
&& hop.getFromTransform().equals(fromTransform)) { // return the first
676-
return hop;
670+
if (fromTransform != null) {
671+
for (PipelineHopMeta hop : hops) {
672+
if (fromTransform.equals(hop.getFromTransform())) { // return the first
673+
return hop;
674+
}
677675
}
678676
}
679677
return null;
@@ -689,11 +687,11 @@ public List<PipelineHopMeta> findAllPipelineHopFrom(TransformMeta fromTransform)
689687
/**
690688
* Find a certain hop in the pipeline.
691689
*
692-
* @param hi The hop information to look for.
690+
* @param hop The hop information to look for.
693691
* @return The hop or null if no hop was found.
694692
*/
695-
public PipelineHopMeta findPipelineHop(PipelineHopMeta hi) {
696-
return findPipelineHop(hi.getFromTransform(), hi.getToTransform());
693+
public PipelineHopMeta findPipelineHop(PipelineHopMeta hop) {
694+
return findPipelineHop(hop.getFromTransform(), hop.getToTransform());
697695
}
698696

699697
/**
@@ -712,13 +710,13 @@ public PipelineHopMeta findPipelineHop(TransformMeta from, TransformMeta to) {
712710
*
713711
* @param from The transform at the start of the hop.
714712
* @param to The transform at the end of the hop.
715-
* @param disabledToo the disabled too
713+
* @param includeDisabled include disabled hop
716714
* @return The hop or null if no hop was found.
717715
*/
718716
public PipelineHopMeta findPipelineHop(
719-
TransformMeta from, TransformMeta to, boolean disabledToo) {
717+
TransformMeta from, TransformMeta to, boolean includeDisabled) {
720718
for (PipelineHopMeta hop : hops) {
721-
if ((hop.isEnabled() || disabledToo)
719+
if ((hop.isEnabled() || includeDisabled)
722720
&& hop.getFromTransform() != null
723721
&& hop.getToTransform() != null
724722
&& hop.getFromTransform().equals(from)
@@ -733,13 +731,14 @@ public PipelineHopMeta findPipelineHop(
733731
* Search all hops for a hop where a certain transform is at the end.
734732
*
735733
* @param toTransform The transform at the end of the hop.
736-
* @return The hop or null if no hop was found.
734+
* @return The hop or null if nothing was found.
737735
*/
738736
public PipelineHopMeta findPipelineHopTo(TransformMeta toTransform) {
739-
for (PipelineHopMeta hop : hops) {
740-
if (hop.getToTransform() != null
741-
&& hop.getToTransform().equals(toTransform)) { // Return the first!
742-
return hop;
737+
if (toTransform != null) {
738+
for (PipelineHopMeta hop : hops) {
739+
if (toTransform.equals(hop.getToTransform())) { // Return the first!
740+
return hop;
741+
}
743742
}
744743
}
745744
return null;

engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,23 @@ private void drawPipeline() throws HopException {
323323
drawTransformPerformanceTable(transformMeta);
324324
}
325325

326-
// Display an icon on the indicated location signaling to the user that the transform in
327-
// question does not accept input
326+
// Display a red cross on the indicated location signaling to the user that the transform in
327+
// question does not accept input or is not a good candidate for a hop (duplicate hop or loop)
328328
//
329329
if (noInputTransform != null) {
330330
gc.setLineWidth(2);
331331
gc.setForeground(EColor.RED);
332332
Point n = noInputTransform.getLocation();
333-
gc.drawLine(n.x - 5, n.y - 5, n.x + iconSize + 10, n.y + iconSize + 10);
334-
gc.drawLine(n.x - 5, n.y + iconSize + 5, n.x + iconSize + 5, n.y - 5);
333+
gc.drawLine(
334+
round(offset.x + n.x - 1),
335+
round(offset.y + n.y - 1),
336+
round(offset.x + n.x + iconSize + 1),
337+
round(offset.y + n.y + iconSize + 1));
338+
gc.drawLine(
339+
round(offset.x + n.x - 1),
340+
round(offset.y + n.y + iconSize + 1),
341+
round(offset.x + n.x + iconSize + 1),
342+
round(offset.y + n.y - 1));
335343
}
336344

337345
try {

engine/src/main/java/org/apache/hop/workflow/WorkflowMeta.java

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ public ActionMeta getAction(int i) {
662662
/**
663663
* Adds the action.
664664
*
665-
* @param action the je
665+
* @param action the action meta to add
666666
*/
667667
public void addAction(ActionMeta action) {
668668
workflowActions.add(action);
@@ -673,7 +673,7 @@ public void addAction(ActionMeta action) {
673673
/**
674674
* Adds the workflow hop.
675675
*
676-
* @param hop the hi
676+
* @param hop the workflow hop meta to add
677677
*/
678678
public void addWorkflowHop(WorkflowHopMeta hop) {
679679
workflowHops.add(hop);
@@ -683,23 +683,23 @@ public void addWorkflowHop(WorkflowHopMeta hop) {
683683
/**
684684
* Adds the action.
685685
*
686-
* @param p the p
687-
* @param action the si
686+
* @param index index at which the specified action is to be inserted
687+
* @param action the action meta to add
688688
*/
689-
public void addAction(int p, ActionMeta action) {
690-
workflowActions.add(p, action);
689+
public void addAction(int index, ActionMeta action) {
690+
workflowActions.add(index, action);
691691
changedActions = true;
692692
}
693693

694694
/**
695695
* Adds the workflow hop.
696696
*
697-
* @param p the p
698-
* @param hop the hi
697+
* @param index index at which the specified hop is to be inserted
698+
* @param hop the workflow hop meta to add
699699
*/
700-
public void addWorkflowHop(int p, WorkflowHopMeta hop) {
700+
public void addWorkflowHop(int index, WorkflowHopMeta hop) {
701701
try {
702-
workflowHops.add(p, hop);
702+
workflowHops.add(index, hop);
703703
} catch (IndexOutOfBoundsException e) {
704704
workflowHops.add(hop);
705705
}
@@ -709,10 +709,10 @@ public void addWorkflowHop(int p, WorkflowHopMeta hop) {
709709
/**
710710
* Removes the action.
711711
*
712-
* @param i the i
712+
* @param index the index of the action to be removed
713713
*/
714-
public void removeAction(int i) {
715-
ActionMeta deleted = workflowActions.remove(i);
714+
public void removeAction(int index) {
715+
ActionMeta deleted = workflowActions.remove(index);
716716
if (deleted != null) {
717717
// give transform a chance to cleanup
718718
deleted.setParentWorkflowMeta(null);
@@ -791,8 +791,8 @@ public ActionMeta findAction(String name) {
791791
/**
792792
* Find workflow hop.
793793
*
794-
* @param name the name
795-
* @return the workflow hop meta
794+
* @param name the name of the hop to look for
795+
* @return the workflow hop meta or null if nothing was found.
796796
*/
797797
public WorkflowHopMeta findWorkflowHop(String name) {
798798
for (WorkflowHopMeta hop : workflowHops) {
@@ -806,18 +806,15 @@ public WorkflowHopMeta findWorkflowHop(String name) {
806806
}
807807

808808
/**
809-
* Find workflow hop from.
809+
* Find the first workflow hop from.
810810
*
811-
* @param action the action meta
812-
* @return the workflow hop meta
811+
* @param action the action meta at the start of the hop.
812+
* @return the first hop found or null if nothing was found.
813813
*/
814814
public WorkflowHopMeta findWorkflowHopFrom(ActionMeta action) {
815815
if (action != null) {
816816
for (WorkflowHopMeta hop : workflowHops) {
817-
818-
// Return the first we find!
819-
//
820-
if (hop != null && (hop.getFromAction() != null) && hop.getFromAction().equals(action)) {
817+
if (action.equals(hop.getFromAction())) {
821818
return hop;
822819
}
823820
}
@@ -828,9 +825,9 @@ public WorkflowHopMeta findWorkflowHopFrom(ActionMeta action) {
828825
/**
829826
* Find workflow hop.
830827
*
831-
* @param from the from
832-
* @param to the to
833-
* @return the workflow hop meta
828+
* @param from the action meta at the start of the hop
829+
* @param to the to action meta at the end of the hop.
830+
* @return the workflow hop meta or null if nothing was found.
834831
*/
835832
public WorkflowHopMeta findWorkflowHop(ActionMeta from, ActionMeta to) {
836833
return findWorkflowHop(from, to, false);
@@ -839,15 +836,14 @@ public WorkflowHopMeta findWorkflowHop(ActionMeta from, ActionMeta to) {
839836
/**
840837
* Find workflow hop.
841838
*
842-
* @param from the from
843-
* @param to the to
844-
* @param includeDisabled the include disabled
845-
* @return the workflow hop meta
839+
* @param from the action meta at the start of the hop
840+
* @param to the to action meta at the end of the hop.
841+
* @param includeDisabled include disabled hop
842+
* @return the workflow hop meta or null if nothing was found.
846843
*/
847844
public WorkflowHopMeta findWorkflowHop(ActionMeta from, ActionMeta to, boolean includeDisabled) {
848845
for (WorkflowHopMeta hop : workflowHops) {
849846
if ((hop.isEnabled() || includeDisabled)
850-
&& hop != null
851847
&& hop.getFromAction() != null
852848
&& hop.getToAction() != null
853849
&& hop.getFromAction().equals(from)
@@ -859,16 +855,17 @@ public WorkflowHopMeta findWorkflowHop(ActionMeta from, ActionMeta to, boolean i
859855
}
860856

861857
/**
862-
* Find workflow hop to.
858+
* Find the first workflow hop to.
863859
*
864-
* @param actionMeta the action meta
865-
* @return the workflow hop meta
860+
* @param action the to action meta at the end of the hop.
861+
* @return the first workflow hop meta or null if nothing was found.
866862
*/
867-
public WorkflowHopMeta findWorkflowHopTo(ActionMeta actionMeta) {
868-
for (WorkflowHopMeta hop : workflowHops) {
869-
if (hop != null && hop.getToAction() != null && hop.getToAction().equals(actionMeta)) {
870-
// Return the first!
871-
return hop;
863+
public WorkflowHopMeta findWorkflowHopTo(ActionMeta action) {
864+
if (action != null) {
865+
for (WorkflowHopMeta hop : workflowHops) {
866+
if (action.equals(hop.getToAction())) {
867+
return hop;
868+
}
872869
}
873870
}
874871
return null;

engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,24 @@ private void drawActions() throws HopException {
194194
drawAction(actionMeta);
195195
}
196196

197-
// Display an icon on the indicated location signaling to the user that the action in
198-
// question does not accept input
197+
// Display a red cross on the indicated location signaling to the user that the action in
198+
// question does not accept input or is not a good candidate for a hop (duplicate hop or
199+
// workflow loop)
199200
//
200201
if (noInputAction != null) {
201202
gc.setLineWidth(2);
202203
gc.setForeground(EColor.RED);
203204
Point n = noInputAction.getLocation();
204205
gc.drawLine(
205-
round(offset.x + n.x - 5),
206-
round(offset.y + n.y - 5),
207-
round(offset.x + n.x + iconSize + 5),
208-
round(offset.y + n.y + iconSize + 5));
206+
round(offset.x + n.x - 1),
207+
round(offset.y + n.y - 1),
208+
round(offset.x + n.x + iconSize + 1),
209+
round(offset.y + n.y + iconSize + 1));
209210
gc.drawLine(
210-
round(offset.x + n.x - 5),
211-
round(offset.y + n.y + iconSize + 5),
212-
round(offset.x + n.x + iconSize + 5),
213-
round(offset.y + n.y - 5));
211+
round(offset.x + n.x - 1),
212+
round(offset.y + n.y + iconSize + 1),
213+
round(offset.x + n.x + iconSize + 1),
214+
round(offset.y + n.y - 1));
214215
}
215216

216217
try {

0 commit comments

Comments
 (0)