Skip to content
Snippets Groups Projects
Commit af5828b2 authored by kfilippopolitis's avatar kfilippopolitis
Browse files

Implemented adaptor for get /algorithms from MIPEngine and post /algorithms/{alogrithm_name}

parent 550b34d6
No related branches found
No related tags found
1 merge request!23Dev/mip 62/mip engine integration with the mip portalbackend
package eu.hbp.mip.models.DTOs;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
@Getter
......@@ -70,4 +73,25 @@ public class AlgorithmDTO {
@SerializedName("valueEnumerations")
private List<String> valueEnumerations;
}
public MIPEngineBody convertToMIPEngineBody()
{
MIPEngineBody mipEngineBody = new MIPEngineBody();
MIPEngineBody.InputData inputData = new MIPEngineBody.InputData();
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("dataset"))
inputData.setDatasets(Arrays.asList(parameter.getValue().split(",")));
if(parameter.getName().equals("pathology"))
inputData.setPathology(parameter.getValue());
if(parameter.getName().equals("filter"))
inputData.setFilters(null);
});
mipEngineBody.setInputdata(inputData);
return mipEngineBody;
}
}
......@@ -25,7 +25,7 @@ public class MIPEngineAlgorithmDTO {
private String type;
@SerializedName("parameters")
private Object parameters;
private InputDataParamDTO parameters;
@SerializedName("crossvalidation")
private String crossvalidation;
......@@ -57,6 +57,7 @@ public class MIPEngineAlgorithmDTO {
@SerializedName("desc")
private String desc;
public AlgorithmDTO.AlgorithmParamDTO convertToAlgorithmParamDTO(String name) throws Exception {
AlgorithmDTO.AlgorithmParamDTO algorithmParamDTO = new AlgorithmDTO.AlgorithmParamDTO();
algorithmParamDTO.setName(name);
......@@ -67,10 +68,6 @@ public class MIPEngineAlgorithmDTO {
algorithmParamDTO.setValueType(this.types.get(0));
}
else{
if(stattypes == null){
System.out.println("Dsafasfads------------------------->>>>>>>>>>>>>>>");
System.out.println(name);
}
algorithmParamDTO.setType("column");
algorithmParamDTO.setColumnValuesSQLType(String.join(", ", this.types));
algorithmParamDTO.setColumnValuesIsCategorical(getColumnValuesIsCategorical(this.stattypes));
......
package eu.hbp.mip.models.DTOs;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class MIPEngineBody {
@SerializedName("inputdata")
private InputData inputdata;
@SerializedName("parameters")
private Object parameters;
@Getter
@Setter
public static class InputData {
@SerializedName("pathology")
private String pathology;
@SerializedName("datasets")
private List<String> datasets;
@SerializedName("filters")
private String filters;
@SerializedName("x")
private List<String> x;
@SerializedName("y")
private List<String> y;
}
}
......@@ -17,6 +17,7 @@ import eu.hbp.mip.models.DAOs.ExperimentDAO;
import eu.hbp.mip.models.DAOs.UserDAO;
import eu.hbp.mip.models.DTOs.AlgorithmDTO;
import eu.hbp.mip.models.DTOs.ExperimentDTO;
import eu.hbp.mip.models.DTOs.MIPEngineBody;
import eu.hbp.mip.models.galaxy.GalaxyWorkflowResult;
import eu.hbp.mip.models.galaxy.PostWorkflowToGalaxyDtoResponse;
import eu.hbp.mip.repositories.ExperimentRepository;
......@@ -506,6 +507,17 @@ public class ExperimentService {
return JsonConverters.convertObjectToJsonString(finalJsonObject);
}
private List<Object> formattingMIPEngienResult(String result) {
List<List<String>> resultJson = JsonConverters.convertJsonStringToObject(result, new ArrayList<ArrayList<String>>().getClass());
List<Object> finalObject = new ArrayList<>();
LinkedTreeMap<String,Object> data = new LinkedTreeMap<>();
data.put("data", resultJson);
data.put("type", "application/json");
finalObject.add(data);
List<Object> result_kappa = finalObject;
return result_kappa;
}
/**
* The runExperiment will run the experiment to exareme or MIPEngine.
*
......@@ -520,22 +532,18 @@ public class ExperimentService {
// Run the 1st algorithm from the list
String algorithmName = experimentDTO.getAlgorithm().getName();
// Get the parameters
List<AlgorithmDTO.AlgorithmParamDTO> algorithmParameters
= experimentDTO.getAlgorithm().getParameters();
String body = gson.toJson(algorithmParameters);
logger.LogUserAction("Completed, returning: " + experimentDTO);
// Run with the appropriate engine
if (algorithmType.equals("mipengine")) {
MIPEngineBody mipEngineBody = experimentDTO.getAlgorithm().convertToMIPEngineBody();
String body = gson.toJson(mipEngineBody);
String url = mipengineAlgorithmsUrl + "/" + algorithmName;
logger.LogUserAction("url: " + url + ", body: " + body);
logger.LogUserAction("Algorithm runs on MIPEngine.");
return runMIPEngineExperiment(url, body);
} else {
List<AlgorithmDTO.AlgorithmParamDTO> algorithmParameters
= experimentDTO.getAlgorithm().getParameters();
String body = gson.toJson(algorithmParameters);
String url = queryExaremeUrl + "/" + algorithmName;
logger.LogUserAction("url: " + url + ", body: " + body);
logger.LogUserAction("Algorithm runs on Exareme.");
......@@ -584,11 +592,8 @@ public class ExperimentService {
} catch (Exception e) {
throw new InternalServerError("Error occurred : " + e.getMessage());
}
System.out.println("----------------------------------->>>>>>>>>>>>>>>>>>>>>>");
System.out.println(results);
// Results are stored in the experiment object
ExperimentDTO experimentDTOWithOnlyResult = JsonConverters.convertJsonStringToObject(String.valueOf(results), ExperimentDTO.class);
List<Object> resultDTOS = experimentDTOWithOnlyResult.getResult();
List<Object> resultDTOS = formattingMIPEngienResult(String.valueOf(results));
return new ExperimentResult(code, resultDTOS);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment