Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/io/hyperfoil/tools/h5m/cli/ListNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Integer call() throws Exception {
System.out.println(
ListCmd.table(80,nodeGroup.sources,List.of("name","type","fqdn","operation"),
List.of(n->n.name,
n->n.type,
n->n.type().display(),
NodeEntity::getFqdn,
n->n.operation
)
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/io/hyperfoil/tools/h5m/entity/NodeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,36 @@
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class NodeEntity extends PanacheEntity implements Comparable<NodeEntity> {

public enum Type {
FINGERPRINT("fp"),
FIXED_THRESHOLD("ft"),
JQ("jq"),
JS("js"),
JSONATA("nata"),
RELATIVE_DIFFERENCE("rd"),
ROOT("root"),
SPLIT("split"),
SQL_JSONPATH_ALL_NODE("sql-all"),
SQL_JSONPATH_NODE("sql"),
USER_INPUT("user");

private final String display;

Type(String display) {
this.display = display;
}

public String display() {
return display;
}
}

public static String FQDN_SEPARATOR = ":";
public static String NAME_SEPARATOR = "=";

public static enum MultiIterationType { Length, NxN}
public static enum ScalarVariableMethod { First, All}

@Column(insertable=false, updatable=false)
@JsonIgnore
public String type; //maybe we want access to the type?
public String name;

@Column(columnDefinition = "TEXT")
Expand Down Expand Up @@ -132,8 +153,10 @@ public String getOperationEncoding(){

protected abstract NodeEntity shallowCopy();

public abstract Type type();

public boolean hasNonRootSource(){
return sources.stream().anyMatch(s->!s.type.equals("root"));
return sources.stream().anyMatch(s-> s.type() != Type.ROOT);
}

public NodeEntity copy(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public FingerprintNode(String name, String operation, List<NodeEntity> sources)
protected NodeEntity shallowCopy() {
return new FingerprintNode(name,operation);
}

@Override
public Type type() {
return Type.FINGERPRINT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public void setFingerprintFilter(String fingerprintFilter) {
operation = config.toString();
}

@Override
public Type type() {
return Type.FIXED_THRESHOLD;
}

@Override
protected NodeEntity shallowCopy() {
return new FixedThreshold(name, operation);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/io/hyperfoil/tools/h5m/entity/node/JqNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ public static JqNode parse(String name, String input, Function<String,List<NodeE

public JqNode(){
super();
this.type="jq";//setting type because detached entities might not have this field
}
public JqNode(String name){
super(name);
this.type = "jq";
}
public JqNode(String name,String operation){
super(name,operation);
this.type = "jq";
}
public JqNode(String name,String operation,List<NodeEntity> sources){
super(name,operation,sources);
this.type = "jq";
}
public JqNode(String name,String operation, NodeEntity...sources){
super(name,operation,List.of(sources));
this.type = "jq";
}

@Override
public Type type() {
return Type.JQ;
}

public static String getCwd(){
Path currentRelativePath = Paths.get("");
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/hyperfoil/tools/h5m/entity/node/JsNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ public static List<String> getParameterNames(String input, boolean removeSpread)

public JsNode(){
super();
this.type="ecma";
}
public JsNode(String name,String operation){
super(name,operation);
this.type="ecma";
}
public JsNode(String name,String operation,List<NodeEntity> sources){
super(name,operation,sources);
this.type="ecma";
}

@Override
public Type type() {
return Type.JS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static JsonataNode parse(String name, String input, Function<String,List<
return rtrn;
}

@Override
public Type type() {
return Type.JSONATA;
}

@Override
protected NodeEntity shallowCopy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public RelativeDifference(String name, String operation) {
config = new Json();
}

@Override
public Type type() {
return Type.RELATIVE_DIFFERENCE;
}

@PostLoad
public void loadConfig(){
if(this.config == null || this.config.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ public class RootNode extends NodeEntity {

public RootNode() {
super();
this.type="root";
}

@Override
public Type type() {
return Type.ROOT;
}

//The root node does not shallow copy
@Override
protected NodeEntity shallowCopy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
public class SplitNode extends NodeEntity {

public SplitNode() {
this.type = "split";
super();
}

public SplitNode(String name){
super(name);
this.type = "split";
}
public SplitNode(String name, String operation, List<NodeEntity> sources){
super(name, operation, sources);
this.type = "split";
}

@Override
public Type type() {
return Type.SPLIT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ public static SqlJsonpathAllNode parse(String name, String input, Function<Strin

public SqlJsonpathAllNode(){
super();
this.type = "sqlall";
}
public SqlJsonpathAllNode(String name, String operation, List<NodeEntity> sources){
super(name,operation,sources);
this.type = "sqlall";
}

@Override
public Type type() {
return Type.SQL_JSONPATH_ALL_NODE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ public static SqlJsonpathNode parse(String name, String input, Function<String,

public SqlJsonpathNode(){
super();
this.type = "sql";
}
public SqlJsonpathNode(String name, String operation,List<NodeEntity> sources){
super(name,operation,sources);
this.type = "sql";
}

@Override
public Type type() {
return Type.SQL_JSONPATH_NODE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public UserInputNode(String name,String operation){
super(name,operation);
}

@Override
public Type type() {
return Type.USER_INPUT;
}

@Override
protected NodeEntity shallowCopy() {
return new UserInputNode(name,operation);
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/io/hyperfoil/tools/h5m/svc/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ public List<Map<String, ValueEntity>> calculateSourceValuePermutations(NodeEntit
public List<ValueEntity> calculateValues(NodeEntity node, List<ValueEntity> roots) throws IOException {
List<ValueEntity> rtrn = new ArrayList<>();

switch (node.type){
switch (node.type()){
//nodes that operate one root at a time
case "ecma":
case "jq":
case "nata":
case "sql":
case "sqlall":
case "split":
case "fp":
case JS:
case JQ:
case JSONATA:
case SQL_JSONPATH_ALL_NODE:
case SQL_JSONPATH_NODE:
case SPLIT:
case FINGERPRINT:
for(int vIdx=0; vIdx<roots.size(); vIdx++){
ValueEntity root = roots.get(vIdx);
try {
Expand All @@ -274,40 +274,40 @@ public List<ValueEntity> calculateValues(NodeEntity node, List<ValueEntity> root
}
}
break;
case "rd":
case RELATIVE_DIFFERENCE:
RelativeDifference relDiff = (RelativeDifference) node;
for(int rIdx=0; rIdx<roots.size(); rIdx++){
ValueEntity root = roots.get(rIdx);
List<ValueEntity> found = calculateRelativeDifferenceValues(relDiff,root,rtrn.size());
rtrn.addAll(found);
}
break;
case "ft":
case FIXED_THRESHOLD:
FixedThreshold ft = (FixedThreshold) node;
for(int rIdx=0; rIdx<roots.size(); rIdx++){
ValueEntity root = roots.get(rIdx);
rtrn.addAll(calculateFixedThresholdValues(ft,root,rtrn.size()));
}
break;
default:
System.err.println("calculateValues unknown node type: " + node.type);
System.err.println("calculateValues unknown node type: " + node.type());
}
rtrn.forEach(ValueEntity::getPath);//forcing entities to be loaded is so dirty
return rtrn;
}

@Transactional
public List<ValueEntity> calculateNodeValues(NodeEntity node,Map<String, ValueEntity> sourceValues,int startingOrdinal) throws IOException {
return switch(node.type){
case "jq" -> calculateJqValues((JqNode)node,sourceValues,startingOrdinal+1);
case "ecma" -> calculateJsValues((JsNode)node,sourceValues,startingOrdinal+1);
case "nata" -> calculateJsonataValues((JsonataNode)node,sourceValues,startingOrdinal+1);
case "sql" -> calculateSqlJsonpathValues((SqlJsonpathNode)node,sourceValues,startingOrdinal+1);
case "sqlall" -> calculateSqlAllJsonpathValues((SqlJsonpathAllNode)node, sourceValues, startingOrdinal+1);
case "split" -> calculateSplitValues((SplitNode)node,sourceValues,startingOrdinal+1);
case "fp" -> calculateFpValues((FingerprintNode)node,sourceValues,startingOrdinal+1);
return switch(node.type()){
case JQ -> calculateJqValues((JqNode)node,sourceValues,startingOrdinal+1);
case JS -> calculateJsValues((JsNode)node,sourceValues,startingOrdinal+1);
case JSONATA -> calculateJsonataValues((JsonataNode)node,sourceValues,startingOrdinal+1);
case SQL_JSONPATH_NODE -> calculateSqlJsonpathValues((SqlJsonpathNode)node,sourceValues,startingOrdinal+1);
case SQL_JSONPATH_ALL_NODE -> calculateSqlAllJsonpathValues((SqlJsonpathAllNode)node, sourceValues, startingOrdinal+1);
case SPLIT -> calculateSplitValues((SplitNode)node,sourceValues,startingOrdinal+1);
case FINGERPRINT -> calculateFpValues((FingerprintNode)node,sourceValues,startingOrdinal+1);
default -> {
System.err.println("Unknown node type: "+node.type);
System.err.println("Unknown node type: "+node.type());
yield Collections.emptyList();
}
};
Expand Down