This commit is contained in:
Michele Artini 2023-03-22 13:13:02 +01:00
parent 27aaab75b7
commit 4079bee3f4
2 changed files with 142 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package eu.dnetlib.manager.wf.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -15,8 +16,8 @@ public class WorkflowTemplate implements Serializable {
private static final long serialVersionUID = 5919290887480115842L;
public List<WfParam> parameters;
public List<Node> graph;
private List<WfParam> parameters = new ArrayList<>();
private List<Node> graph = new ArrayList<>();
public List<Node> getGraph() {
return graph;
@ -34,15 +35,43 @@ public class WorkflowTemplate implements Serializable {
this.parameters = parameters;
}
class WfParam implements Serializable {
public static enum WfParamType {
STRING,
NUMBER,
DATE,
BOOLEAN
}
public static class WfParam implements Serializable {
private static final long serialVersionUID = 5885589803738655166L;
private String name;
private String description;
private String type;
private WfParamType type = WfParamType.STRING;
private String defaultValue;
private boolean required;
private boolean required = true;
public WfParam() {}
public WfParam(final String name) {
this.name = name;
this.description = name;
}
public WfParam(final String name, final WfParamType type) {
this.name = name;
this.description = name;
this.type = type;
}
public WfParam(final String name, final String description, final WfParamType type, final String defaultValue, final boolean required) {
this.name = name;
this.description = description;
this.type = type;
this.defaultValue = defaultValue;
this.required = required;
}
public String getName() {
return name;
@ -60,11 +89,11 @@ public class WorkflowTemplate implements Serializable {
this.description = description;
}
public String getType() {
public WfParamType getType() {
return type;
}
public void setType(final String type) {
public void setType(final WfParamType type) {
this.type = type;
}
@ -86,7 +115,7 @@ public class WorkflowTemplate implements Serializable {
}
public class Node implements Serializable {
public static class Node implements Serializable {
private static final long serialVersionUID = -3695762832959801906L;
@ -96,8 +125,24 @@ public class WorkflowTemplate implements Serializable {
private String type;
private boolean isStart = false;
private boolean isJoin = false;
private List<Arc> arcs;
private List<NodeParam> input;
private List<Arc> arcs = new ArrayList<>();
private List<NodeParam> input = new ArrayList<>();
public Node() {}
public Node(final String name, final boolean isStart) {
this.name = name;
this.isStart = isStart;
}
public Node(final String name) {
this.name = name;
}
public Node(final String name, final String type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
@ -185,18 +230,27 @@ public class WorkflowTemplate implements Serializable {
} else {
return null;
}
}
}
public class Arc implements Serializable {
public static class Arc implements Serializable {
private static final long serialVersionUID = 7866138976929522262L;
private String to;
private String condition;
public Arc() {}
public Arc(final String to) {
this.to = to;
}
public Arc(final String to, final String condition) {
this.to = to;
this.condition = condition;
}
public String getTo() {
return to;
}
@ -214,7 +268,7 @@ public class WorkflowTemplate implements Serializable {
}
}
class NodeParam implements Serializable {
public static class NodeParam implements Serializable {
private static final long serialVersionUID = 7815785723401725707L;

View File

@ -0,0 +1,74 @@
package eu.dnetlib.manager.wf.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.manager.wf.model.WorkflowTemplate.Arc;
import eu.dnetlib.manager.wf.model.WorkflowTemplate.Node;
import eu.dnetlib.manager.wf.model.WorkflowTemplate.WfParam;
import eu.dnetlib.manager.wf.model.WorkflowTemplate.WfParamType;
class WorkflowTemplateTest {
private final ObjectMapper mapper = new ObjectMapper();
private WorkflowTemplate tmpl;
private WfParam p1;
private WfParam p2;
private WfParam p3;
private Node n1;
private Node n2;
private Node n3;
private Arc a12;
private Arc a13;
private Arc a23;
private Arc a3succ;
private @BeforeEach void setUp() throws Exception {
a12 = new Arc("N2");
a13 = new Arc("N3");
a23 = new Arc("N3");
a3succ = new Arc("success");
p1 = new WfParam("Name");
p2 = new WfParam("Age", WfParamType.NUMBER);
p3 = new WfParam("Birthday", "Your Birthday", WfParamType.DATE, "1900-01-01", false);
n1 = new Node("N1", true);
n1.setArcs(Arrays.asList(a12, a13));
n2 = new Node("N2", "T2");
n2.setArcs(Arrays.asList(a23));
n3 = new Node("N3");
n2.setArcs(Arrays.asList(a3succ));
tmpl = new WorkflowTemplate();
tmpl.setParameters(Arrays.asList(p1, p2, p3));
tmpl.setGraph(Arrays.asList(n1, n2, n3));
}
@Test
final void test() throws JsonProcessingException {
final String json = mapper.writeValueAsString(tmpl);
System.out.println(json);
final WorkflowTemplate tmpl2 = mapper.readValue(json, WorkflowTemplate.class);
assertEquals(tmpl.getGraph().size(), tmpl2.getGraph().size());
assertEquals(tmpl.getParameters().size(), tmpl2.getParameters().size());
}
}