Skip to content
Snippets Groups Projects
Commit 4638c26d authored by Ludovic Claude's avatar Ludovic Claude
Browse files

Api change: /mining returns shape of data and other infos

parent 2e3253c8
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ public class ExperimentActor extends UntypedActor {
return;
}
experiment.setResult(queryResult.data().get());
experiment.setFinished(new Date());
experiment.setFinished(Date.from(queryResult.timestamp().toInstant()));
experimentRepository.save(experiment);
LOGGER.info("Experiment "+ uuid +" updated (finished)");
getContext().stop(getSelf());
......
......@@ -4,6 +4,7 @@ import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.pattern.Patterns;
import akka.util.Timeout;
import eu.hbp.mip.model.Mining;
import eu.hbp.mip.woken.messages.external.QueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -21,6 +22,7 @@ import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
import java.io.IOException;
import java.sql.Date;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
......@@ -64,7 +66,15 @@ public class MiningApi {
LOGGER.error(result.error().get());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"error\":\"" + result.error().get() + "\"}");
} else {
return ResponseEntity.ok(result.data().get());
Mining mining = new Mining(
result.jobId(),
result.node(),
result.function(),
result.shape(),
Date.from(result.timestamp().toInstant()),
result.data().get()
);
return ResponseEntity.ok(mining.jsonify());
}
}
......
......@@ -12,7 +12,6 @@ import eu.hbp.mip.woken.messages.external.*;
import eu.hbp.mip.utils.TypesConvert;
import org.hibernate.annotations.Cascade;
import scala.collection.JavaConverters;
import scala.collection.Seq;
import javax.persistence.*;
import java.lang.reflect.Type;
......
package eu.hbp.mip.model;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.Date;
public class Mining {
private static final Gson gson = new Gson();
private String jobId;
private String node;
private String function;
private String shape;
private Date timestamp;
private String data;
public Mining(String jobId, String node, String function, String shape, Date timestamp, String data) {
this.jobId = jobId;
this.node = node;
this.function = function;
this.shape = shape;
this.timestamp = timestamp;
this.data = data;
}
public String getJobId() {
return jobId;
}
public String getNode() {
return node;
}
public String getFunction() {
return function;
}
public String getShape() {
return shape;
}
public Date getTimestamp() {
return timestamp;
}
public String getData() {
return data;
}
public JsonObject jsonify() {
JsonObject exp = gson.toJsonTree(this).getAsJsonObject();
JsonParser parser = new JsonParser();
if (this.data != null) {
exp.remove("data");
JsonArray jsonResult = parser.parse(this.data).getAsJsonArray();
exp.add("data", jsonResult);
}
return exp;
}
}
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