diff --git a/src/main/java/eu/hbp/mip/akka/ListenerActor.java b/src/main/java/eu/hbp/mip/akka/ListenerActor.java index 69659cd262424a9bf8f6941a262a1b6968b63f2b..b6249445722831c28010cfb87debbd7d16fa4334 100644 --- a/src/main/java/eu/hbp/mip/akka/ListenerActor.java +++ b/src/main/java/eu/hbp/mip/akka/ListenerActor.java @@ -1,6 +1,7 @@ package eu.hbp.mip.akka; import akka.actor.UntypedActor; +import eu.hbp.mip.messages.external.QueryResult; import org.springframework.context.annotation.Scope; import javax.inject.Inject; @@ -14,24 +15,6 @@ import javax.inject.Named; @Scope("prototype") public class ListenerActor extends UntypedActor { - public static class AlgoQuery { - private final String query; - public AlgoQuery(String query) { - this.query = query; - } - public String getQuery() { - return query; - } - } - public static class AlgoResult { - private final String result; - public AlgoResult(String result) { - this.result = result; - } - public String getResult() { - return result; - } - } final ListeningService listeningService; @Inject public ListenerActor(@Named("ListeningService") ListeningService listeningService) { @@ -40,9 +23,9 @@ public class ListenerActor extends UntypedActor { @Override public void onReceive(Object message) throws Exception { - if (message instanceof AlgoResult) { - AlgoResult algoResult = (AlgoResult) message; - listeningService.listen(algoResult.getResult()); + if (message instanceof QueryResult) { + QueryResult queryResult = (QueryResult) message; + listeningService.listen(queryResult.data().get()); } else { unhandled(message); diff --git a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java index b3da14b1a484d93f988770cf845f04365f661f21..ec2c93d36082a5639d88ba4979d76bf7d52dc1e1 100644 --- a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java +++ b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java @@ -7,7 +7,6 @@ import eu.hbp.mip.model.User; import eu.hbp.mip.repositories.UserRepository; import eu.hbp.mip.utils.CORSFilter; import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint; -import eu.hbp.mip.utils.HTTPUtil; import io.swagger.annotations.ApiParam; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -301,22 +300,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { query.append("\"").append(idToken).append("\""); query.append("}"); - - try { - int responseCode = HTTPUtil.sendPost(revokeTokenURI, query.toString(), new StringBuilder()); - if (responseCode != 200) - { - LOGGER.warn("Cannot send request to OIDC server for revocation ! "); - } - else{ - LOGGER.info("Should be logged out"); - } - - } catch (IOException e) { - LOGGER.warn("Cannot notify logout to OIDC server !"); - LOGGER.trace(e); - - } + // TODO send request } } } \ No newline at end of file diff --git a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java index ad772c9d65b14a3a8cd8dc77b57f2300f208d97c..e9eaf6567f9d386174eefb858dabc8c87df70344 100644 --- a/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ExperimentApi.java @@ -1,6 +1,6 @@ package eu.hbp.mip.controllers; -import akka.actor.ActorRef; +import akka.actor.ActorSelection; import akka.actor.ActorSystem; import com.google.common.collect.Lists; import com.google.gson.Gson; @@ -13,7 +13,6 @@ import eu.hbp.mip.model.ExperimentQuery; import eu.hbp.mip.model.User; import eu.hbp.mip.repositories.ExperimentRepository; import eu.hbp.mip.repositories.ModelRepository; -import eu.hbp.mip.utils.HTTPUtil; import eu.hbp.mip.utils.JSONUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -216,10 +215,8 @@ public class ExperimentApi { StringBuilder response = new StringBuilder(); - int code = HTTPUtil.sendGet(listMethodsUrl, response); - if (code < 200 || code > 299) { - return new ResponseEntity<>(response.toString(), HttpStatus.valueOf(code)); - } + // TODO: Use akka + int code = 500; JsonObject catalog = new JsonParser().parse(response.toString()).getAsJsonObject(); @@ -293,16 +290,10 @@ public class ExperimentApi { private void sendExperiment(Experiment experiment) throws MalformedURLException { // this runs in the background. For future optimization: use a thread pool final String url = experimentUrl; - final String query = experiment.computeQuery(); - - ActorRef wokenActor = actorSystem.actorFor(wokenPath); - - // Should maybe use this instead ??? - // ActorRef wokenActor = actorSystem.actorOf( - // SpringExtension.SpringExtProvider.get(actorSystem).props("Woken"), "woken"); - - wokenActor.tell(query, null); + final eu.hbp.mip.messages.external.ExperimentQuery experimentQuery = experiment.computeQuery(); + ActorSelection wokenActor = actorSystem.actorSelection(wokenPath); + wokenActor.tell(experimentQuery, null); } private void sendExaremeExperiment(Experiment experiment) { @@ -341,7 +332,8 @@ public class ExperimentApi { private static void executeExperiment(String url, String query, Experiment experiment) throws IOException { StringBuilder results = new StringBuilder(); - int code = HTTPUtil.sendPost(url, query, results); + // TODO: use akka + int code = 500; experiment.setResult(results.toString()); experiment.setHasError(code >= 400); experiment.setHasServerError(code >= 500); diff --git a/src/main/java/eu/hbp/mip/model/Experiment.java b/src/main/java/eu/hbp/mip/model/Experiment.java index f809373282ae46a9490aaba9112e74605a153517..cc4f997ca68cf959740f47829d49af58aacea36e 100644 --- a/src/main/java/eu/hbp/mip/model/Experiment.java +++ b/src/main/java/eu/hbp/mip/model/Experiment.java @@ -2,8 +2,13 @@ package eu.hbp.mip.model; import com.google.gson.*; import com.google.gson.annotations.Expose; +import eu.hbp.mip.messages.external.*; +import eu.hbp.mip.messages.external.Algorithm; +import eu.hbp.mip.messages.external.ExperimentQuery; import org.apache.log4j.Logger; import org.hibernate.annotations.Cascade; +import scala.collection.JavaConverters; +import scala.collection.Seq; import javax.persistence.*; import java.util.Date; @@ -11,6 +16,7 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; + /** * Created by habfast on 21/04/16. */ @@ -85,16 +91,39 @@ public class Experiment { */ } - public String computeQuery() { - JsonObject outgoingQuery = new JsonObject(); - outgoingQuery.add("algorithms", gsonOnlyExposed.fromJson(algorithms, JsonArray.class)); - outgoingQuery.add("validations", gsonOnlyExposed.fromJson(validations, JsonArray.class)); + public ExperimentQuery computeQuery() { + List<VariableId> variables = new LinkedList<>(); + List<VariableId> covariables = new LinkedList<>(); + List<VariableId> grouping = new LinkedList<>(); + List<Filter> filters = new LinkedList<>(); + List<eu.hbp.mip.messages.external.Algorithm> algorithms = new LinkedList<>(); + List<Validation> validations = new LinkedList<>(); + + for (Variable v: model.getQuery().getVariables() + ) { + variables.add(new VariableId(v.getCode())); + } + + for (Variable v: model.getQuery().getCovariables() + ) { + covariables.add(new VariableId(v.getCode())); + } + + for (Variable v: model.getQuery().getGrouping() + ) { + grouping.add(new VariableId(v.getCode())); + } + + // TODO: convert algorithms and so on + + Seq<VariableId> variablesSeq = JavaConverters.asScalaIteratorConverter(variables.iterator()).asScala().toSeq(); + Seq<VariableId> covariablesSeq = JavaConverters.asScalaIteratorConverter(covariables.iterator()).asScala().toSeq(); + Seq<VariableId> groupingSeq = JavaConverters.asScalaIteratorConverter(grouping.iterator()).asScala().toSeq(); + Seq<Filter> filtersSeq = JavaConverters.asScalaIteratorConverter(filters.iterator()).asScala().toSeq(); + Seq<Algorithm> algorithmsSeq = JavaConverters.asScalaIteratorConverter(algorithms.iterator()).asScala().toSeq(); + Seq<Validation> validationsSeq = JavaConverters.asScalaIteratorConverter(validations.iterator()).asScala().toSeq(); - outgoingQuery.add("covariables", gsonOnlyExposed.toJsonTree(model.getQuery().getCovariables())); - outgoingQuery.add("variables", gsonOnlyExposed.toJsonTree(model.getQuery().getVariables())); - outgoingQuery.add("filters", gsonOnlyExposed.toJsonTree(model.getQuery().getFilters())); - outgoingQuery.add("grouping", gsonOnlyExposed.toJsonTree(model.getQuery().getGrouping())); - return outgoingQuery.toString(); + return new ExperimentQuery(variablesSeq, covariablesSeq, groupingSeq, filtersSeq, algorithmsSeq, validationsSeq); } public String computeExaremeQuery() { diff --git a/src/main/java/eu/hbp/mip/utils/HTTPUtil.java b/src/main/java/eu/hbp/mip/utils/HTTPUtil.java deleted file mode 100644 index c641826e8e2e8bddb7e544cc60fcebdd8fd1c600..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/utils/HTTPUtil.java +++ /dev/null @@ -1,70 +0,0 @@ -package eu.hbp.mip.utils; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; - -/** - * Created by mirco on 20.06.16. - */ -public class HTTPUtil { - - private HTTPUtil() - { - /* Hide implicit public constructor */ - throw new IllegalAccessError("HTTPUtil class"); - } - - public static int sendGet(String url, StringBuilder resp) throws IOException { - return sendHTTP(url, "", resp, "GET"); - } - - public static int sendPost(String url, String query, StringBuilder resp) throws IOException { - return sendHTTP(url, query, resp, "POST"); - } - - public static int sendHTTP(String url, String query, StringBuilder resp, String httpVerb) throws IOException { - - URL obj = new URL(url); - HttpURLConnection con = (HttpURLConnection) obj.openConnection(); - - if(!"GET".equals(httpVerb)) { - con.setRequestMethod(httpVerb); - if(query != null && query.length() > 0) - { - con.addRequestProperty("Content-Type", "application/json"); - con.setRequestProperty("Content-Length", Integer.toString(query.length())); - - con.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(con.getOutputStream()); - wr.write(query.getBytes("UTF8")); - wr.flush(); - wr.close(); - } - } - - int respCode = con.getResponseCode(); - - BufferedReader in; - if(respCode == 200) { - in = new BufferedReader(new InputStreamReader(con.getInputStream())); - } - else - { - in = new BufferedReader(new InputStreamReader(con.getErrorStream())); - } - String inputLine; - StringBuilder response = new StringBuilder(); - - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - in.close(); - resp.append(response.toString()); - - return respCode; - } -}