diff --git a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java index ac90699e4e9402cde3993fa4b7b2670aca084063..ea8256e9955ad1d25a4a837b55f2f45bb69f83dd 100644 --- a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java @@ -101,7 +101,7 @@ public class ExperimentApi { } } catch (MalformedURLException mue) { LOGGER.trace(mue.getMessage()); } // ignore - return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); + return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK); } @ApiOperation(value = "get an experiment", response = Experiment.class) @@ -126,7 +126,7 @@ public class ExperimentApi { return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND); } - return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); + return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK); } @ApiOperation(value = "Mark an experiment as viewed", response = Experiment.class) @@ -154,7 +154,7 @@ public class ExperimentApi { LOGGER.info("Experiment updated (marked as viewed)"); - return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); + return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK); } @ApiOperation(value = "Mark an experiment as shared", response = Experiment.class) @@ -282,7 +282,7 @@ public class ExperimentApi { LOGGER.info("Experiment updated (marked as shared)"); - return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK); + return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK); } private void sendExperiment(Experiment experiment) throws MalformedURLException { diff --git a/src/main/java/eu/hbp/mip/model/Experiment.java b/src/main/java/eu/hbp/mip/model/Experiment.java index 05124f6a272eaa8eb3444b24dbe2f330cdd0e4a5..134fc2d18e3bfadbdd6e2dbf519d32385b0e0bc6 100644 --- a/src/main/java/eu/hbp/mip/model/Experiment.java +++ b/src/main/java/eu/hbp/mip/model/Experiment.java @@ -1,15 +1,15 @@ package eu.hbp.mip.model; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import com.google.gson.*; import com.google.gson.annotations.Expose; import org.apache.log4j.Logger; import org.hibernate.annotations.Cascade; import javax.persistence.*; -import java.util.*; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; /** * Created by habfast on 21/04/16. @@ -137,6 +137,34 @@ public class Experiment { return new Gson().toJson(queryElements); } + public JsonObject jsonify() { + JsonObject exp = new Gson().toJsonTree(this).getAsJsonObject(); + JsonParser parser = new JsonParser(); + + if (this.algorithms != null) + { + exp.remove("algorithms"); + JsonArray jsonAlgorithms = parser.parse(this.algorithms).getAsJsonArray(); + exp.add("algorithms", jsonAlgorithms); + } + + if (this.validations != null) + { + exp.remove("validations"); + JsonArray jsonValidations = parser.parse(this.validations).getAsJsonArray(); + exp.add("validations", jsonValidations); + } + + if (this.result != null) + { + exp.remove("result"); + JsonArray jsonResult = parser.parse(this.result).getAsJsonArray(); + exp.add("result", jsonResult); + } + + return exp; + } + public String getValidations() { return validations; }