diff --git a/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java index 2297ae9bea9e59b4abbcf472c185d486c69e8e78..216140ba22f24332a862605404e94b84f5cf113c 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java @@ -1,13 +1,11 @@ package eu.hbp.mip.models.DTOs; -import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; +import eu.hbp.mip.utils.JsonConverters; import lombok.Getter; import lombok.Setter; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.List; +import java.util.*; @Getter @Setter @@ -74,21 +72,84 @@ public class AlgorithmDTO { private List<String> valueEnumerations; } + @Getter + @Setter + public static class Rule + { + @SerializedName("id") + private String id; + + @SerializedName("type") + private String type; + + @SerializedName("operator") + private String operator; + + @SerializedName("value") + private Object value; + + public Rule(String id, String type, String operator, Object value) { + this.id = id; + this.type = type; + this.operator = operator; + this.value = value; + } + } + + @Getter + @Setter + public static class Filters + { + @SerializedName("condition") + private String condition; + + @SerializedName("rules") + private List<Object> rules; + + @SerializedName("valid") + private boolean valid; + + public Filters(String condition, List<Object> rules, boolean valid) { + this.condition = condition; + this.rules = rules; + this.valid = valid; + } + } + + public MIPEngineBody convertToMIPEngineBody() { MIPEngineBody mipEngineBody = new MIPEngineBody(); MIPEngineBody.InputData inputData = new MIPEngineBody.InputData(); + List<Object> rules = new ArrayList<>(); this.parameters.forEach(parameter -> { - if(parameter.getName().equals("x")) - inputData.setX(Arrays.asList(parameter.getValue().split(","))); - if(parameter.getName().equals("y")) - inputData.setY(Arrays.asList(parameter.getValue().split(","))); - if(parameter.getName().equals("datasets")) - inputData.setDatasets(Arrays.asList(parameter.getValue().split(","))); + if(parameter.getName().equals("x")) { + List<String> x = Arrays.asList(parameter.getValue().split(",")); + x.forEach(column -> rules.add(new Rule(column, parameter.getColumnValuesSQLType(), "is_not_null", null))); + inputData.setX(x); + } + if(parameter.getName().equals("y")) { + List<String> y = Arrays.asList(parameter.getValue().split(",")); + y.forEach(column -> rules.add(new Rule(column, parameter.getColumnValuesSQLType(), "is_not_null", null))); + inputData.setY(y); + } + if(parameter.getName().equals("dataset")){ + List<String> datasets = Arrays.asList(parameter.getValue().split(",")); + rules.add(new Rule("dataset","string", "in", datasets)); + inputData.setDatasets(datasets); + } + String pathology; if(parameter.getName().equals("pathology")) inputData.setPathology(parameter.getValue()); + + if(parameter.getName().equals("filter")){ + if (parameter.getValue() != "") + rules.add(JsonConverters.convertJsonStringToObject(parameter.getValue(), Filters.class)); + } }); + Filters filters = new Filters("AND", rules, true); + inputData.setFilters(filters); mipEngineBody.setInputdata(inputData); return mipEngineBody; } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAlgorithmDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAlgorithmDTO.java index 386195dab6451e130ccb9ab625d585d1d7e141e9..4400ff9e7fbf6124b9667646dd33b831eb467077 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAlgorithmDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAlgorithmDTO.java @@ -97,7 +97,7 @@ public class MIPEngineAlgorithmDTO { public AlgorithmDTO convertToAlgorithmDTO() { AlgorithmDTO algorithmDTO = new AlgorithmDTO(); - algorithmDTO.setName(this.name); + algorithmDTO.setName(this.name.toUpperCase()); algorithmDTO.setLabel(this.label); algorithmDTO.setDesc(this.desc); algorithmDTO.setType("mipengine"); diff --git a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineBody.java b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineBody.java index bbae5f4a096acf7401ea5e4d1cf2164488897286..b8b2f957a166467890296f35baa5e55b89f2b184 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineBody.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/MIPEngineBody.java @@ -22,7 +22,7 @@ public class MIPEngineBody { @SerializedName("datasets") private List<String> datasets; @SerializedName("filters") - private String filters; + private AlgorithmDTO.Filters filters; @SerializedName("x") private List<String> x; @SerializedName("y") diff --git a/src/main/java/eu/hbp/mip/services/ExperimentService.java b/src/main/java/eu/hbp/mip/services/ExperimentService.java index bafa71d0128a6fa87b07adefbd59cc4abc3f76f5..bc7f4dd11343e26bb888c28e5d987ec3916632ac 100644 --- a/src/main/java/eu/hbp/mip/services/ExperimentService.java +++ b/src/main/java/eu/hbp/mip/services/ExperimentService.java @@ -544,8 +544,8 @@ public class ExperimentService { // Run with the appropriate engine if (algorithmType.equals("mipengine")) { MIPEngineBody mipEngineBody = experimentDTO.getAlgorithm().convertToMIPEngineBody(); - String body = gson.toJson(mipEngineBody); - String url = mipengineAlgorithmsUrl + "/" + algorithmName; + String body = JsonConverters.convertObjectToJsonString(mipEngineBody); + String url = mipengineAlgorithmsUrl + "/" + algorithmName.toLowerCase(); logger.LogUserAction("url: " + url + ", body: " + body); logger.LogUserAction("Algorithm runs on MIPEngine."); return runMIPEngineExperiment(url, body); @@ -601,7 +601,6 @@ public class ExperimentService { } catch (Exception e) { throw new InternalServerError("Error occurred : " + e.getMessage()); } - System.out.println(results); // Results are stored in the experiment object List<Object> resultDTOS = formattingMIPEngienResult(String.valueOf(results));