Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#117 labels for nodes implemented #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions task/factory/default/docs/asciidoc/dataobjects.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Sets a node factory name to <code>ActionNodeFactory.NAME</code> and configures t
|[[actions]]`@actions`|`Array of link:dataobjects.html#GraphNodeOptions[GraphNodeOptions]`|+++
Sets a node factory name to <code>SubtasksNodeFactory.NAME</code> and configures subgraphs.
+++
|[[label]]`@label`|`String`|+++
Sets human readable graph node label
+++
|[[node]]`@node`|`link:dataobjects.html#NodeOptions[NodeOptions]`|+++
Node options define a node factory and its configuration.
+++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.knotx.fragments.task.factory.generic;

import com.google.common.base.Objects;
import io.knotx.fragments.task.factory.generic.node.NodeOptions;
import io.knotx.fragments.task.factory.generic.node.action.ActionNodeConfig;
import io.knotx.fragments.task.factory.generic.node.action.ActionNodeFactory;
Expand All @@ -25,7 +26,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -35,6 +35,7 @@
public class GraphNodeOptions {

private NodeOptions node;
private String label;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this label should be used in GraphNodeExecutionLog. Can you please verify if it is passed correctly?

private Map<String, GraphNodeOptions> onTransitions;

public GraphNodeOptions(NodeOptions nodeOptions, Map<String, GraphNodeOptions> transitions) {
Expand Down Expand Up @@ -88,6 +89,24 @@ public GraphNodeOptions setNode(NodeOptions node) {
return this;
}

/**
* @return graph node label
*/
public String getLabel() {
return label;
}

/**
* Sets human readable graph node label
*
* @param label graph node label
* @return reference to this, so the API can be used fluently
*/
public GraphNodeOptions setLabel(String label) {
this.label = label;
return this;
}

/**
* It specifies the next graph node for the given transition. If no graph edge is defined, then an
* empty value is returned.
Expand Down Expand Up @@ -164,19 +183,21 @@ public boolean equals(Object o) {
return false;
}
GraphNodeOptions that = (GraphNodeOptions) o;
return Objects.equals(node, that.node) &&
Objects.equals(onTransitions, that.onTransitions);
return Objects.equal(node, that.node) &&
Objects.equal(label, that.label) &&
Objects.equal(onTransitions, that.onTransitions);
}

@Override
public int hashCode() {
return Objects.hash(node, onTransitions);
return Objects.hashCode(node, label, onTransitions);
}

@Override
public String toString() {
return "GraphNodeOptions{" +
"node=" + node +
", label='" + label + '\'' +
", onTransitions=" + onTransitions +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ void expectTransitionSuccessWithNodeBThenNodeC(Vertx vertx) throws Throwable {
}, vertx);
}

@Test
@DisplayName("Expect nodes with properly configured labels")
void expectTaskWithProperlyConfiguredLabels(Vertx vertx) throws Throwable {
verify("conf/taskWithLabels.conf", config -> {
GraphNodeOptions graphNodeOptions = new GraphNodeOptions(config);
assertEquals("a-label", graphNodeOptions.getLabel());
Optional<GraphNodeOptions> nodeB = graphNodeOptions.get(SUCCESS_TRANSITION);
assertTrue(nodeB.isPresent());
assertEquals("b-label", nodeB.get().getLabel());
Optional<GraphNodeOptions> nodec = nodeB.get().get(SUCCESS_TRANSITION);
assertTrue(nodec.isPresent());
assertEquals("c-label", nodec.get().getLabel());
}, vertx);
}

private Consumer<JsonObject> validateActionNode() {
return config -> {
Expand Down
15 changes: 15 additions & 0 deletions task/factory/default/src/test/resources/conf/taskWithLabels.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# node & transitions
action = a
label = a-label
onTransitions {
_success {
action = b
label = b-label
onTransitions {
_success {
action = c
label = c-label
}
}
}
}