diff --git a/docker/config/application.tmpl b/docker/config/application.tmpl index 0856eacbe4e8bbb2f9137d8df71c30c64f7bc342..5f9ea27f9885a3c518cb6fed0b418276012470ea 100644 --- a/docker/config/application.tmpl +++ b/docker/config/application.tmpl @@ -89,3 +89,4 @@ endpoints: services: exareme: miningExaremeUrl: {{ default .Env.EXAREME_URL "http://localhost:9090" }}/mining/query + algorithmsUrl: {{ default .Env.EXAREME_URL "http://localhost:9090" }}/mining/algorithms.json \ No newline at end of file diff --git a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java index b275f889d2f955a8b52cdf25dde3696789a0274c..29e69e325f5bf68517b4da6102b7a5820bcc7e87 100644 --- a/src/main/java/eu/hbp/mip/controllers/MethodsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/MethodsApi.java @@ -12,22 +12,23 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; +import eu.hbp.mip.utils.HTTPUtil; +import org.springframework.beans.factory.annotation.Value; +import java.io.IOException; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @RestController -@RequestMapping(value = "/methods", produces = {APPLICATION_JSON_VALUE}) +@RequestMapping(value = "/methods", produces = { APPLICATION_JSON_VALUE }) @Api(value = "/methods", description = "the methods API") public class MethodsApi extends WokenClientController { private static final Logger LOGGER = LoggerFactory.getLogger(MethodsApi.class); private static final Gson gson = new Gson(); - - private static final String EXAREME_ALGO_JSON_FILE="data/exareme_algorithms.json"; +d + @Value("#{'${services.exareme.algorithmsUrl:http://localhost:9090/mining/algorithms.json}'}") + private String exaremeAlgorithmsUrl; @ApiOperation(value = "List available methods and validations", response = String.class) @Cacheable(value = "methods", unless = "#result.getStatusCode().value()!=200") @@ -37,19 +38,28 @@ public class MethodsApi extends WokenClientController { return requestWoken(MethodsQuery$.MODULE$, 10, r -> { MethodsResponse result = (MethodsResponse) r; - - // >> Temporary : should return result.methods() in the future JsonObject catalog = new JsonParser().parse(result.methods().compactPrint()).getAsJsonObject(); - InputStream is = MethodsApi.class.getClassLoader().getResourceAsStream(EXAREME_ALGO_JSON_FILE); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - JsonElement element = new JsonParser().parse(br); - JsonArray exaremeAlgo = element.getAsJsonArray(); - catalog.get("algorithms").getAsJsonArray().addAll(exaremeAlgo); - // << Temporary return ResponseEntity.ok(gson.toJson(catalog)); }); } + @ApiOperation(value = "List Exareme algorithms and validations", response = String.class) + @Cacheable(value = "exareme", unless = "#result.getStatusCode().value()!=200") + @RequestMapping(value = "/exareme", method = RequestMethod.GET) + public ResponseEntity<Object> getExaremeAlgorithms() { + LOGGER.info("List Exareme algorithms and validations"); + + try { + StringBuilder response = new StringBuilder(); + HTTPUtil.sendGet(exaremeAlgorithmsUrl, response); + JsonElement element = new JsonParser().parse(response.toString()); + + return ResponseEntity.ok(gson.toJson(element)); + } catch (IOException e) { + return ResponseEntity.status(500).body(e.getMessage()); + } + + } + } diff --git a/src/main/resources/data/exareme_algorithms.json b/src/main/resources/data/exareme_algorithms.json deleted file mode 100644 index 3ea4bdf19b7f2a779ecd70ab3385ef9b96c8533d..0000000000000000000000000000000000000000 --- a/src/main/resources/data/exareme_algorithms.json +++ /dev/null @@ -1,137 +0,0 @@ -[ - { - "code": "WP_VARIABLES_HISTOGRAM", - "constraints": { - "variable": { - "binominal": true, - "integer": true, - "polynominal": true, - "real": true - } - }, - "description": "Histograms", - "environment": "Exareme", - "label": " Histogram", - "parameters": [ - { - "code": "nobuckets", - "constraints": { - "max": null, - "min": 1 - }, - "default_value": 4, - "description": "The number of clusters. Typical values range from 2 to 10.", - "label": "nobuckets", - "type": "int" - } - ], - "type": [ - "statistics" - ] - }, - { - "code": "PIPELINE_ISOUP_REGRESSION_TREE_SERIALIZER", - "constraints": { - "variable": { - "binominal": true, - "integer": true, - "polynominal": true, - "real": true - } - }, - "description": "Regression Tree Serializer", - "environment": "Exareme", - "label": " Regression Tree", - "parameters": [], - "type": [ - "statistics" - ] - }, - { - "code": "PIPELINE_ISOUP_MODEL_TREE_SERIALIZER", - "constraints": { - "variable": { - "binominal": true, - "integer": true, - "polynominal": true, - "real": true - } - }, - "description": "Model Tree Serializer", - "environment": "Exareme", - "label": "Model Tree", - "parameters": [], - "type": [ - "statistics" - ] - }, - { - "code": "WP_LINEAR_REGRESSION", - "constraints": { - "variable": { - "binominal": false, - "integer": true, - "polynominal": false, - "real": true - } - }, - "description": "Linear Regression using Exareme services", - "environment": "Exareme", - "label": "Linear regression", - "parameters": [ - { - "code": "design", - "default_value": "factorial", - "description": "The type of multi-factors design. Choose 'factorial' to enable interactions analysis or 'additive' for a model without no interaction at all.", - "label": "design", - "type": "enumeration", - "values": [ - "factorial", - "additive" - ] - } - ], - "type": [ - "statistics" - ] - }, - { - "code": "K_MEANS", - "constraints": { - "covariables": { - "max_count": null, - "min_count": "1" - }, - "groupings": { - "max_count": 0, - "min_count": 0 - }, - "mixed": false, - "variable": { - "binominal": true, - "integer": true, - "polynominal": true, - "real": true - } - }, - "description": "k-Means using Exareme services", - "environment": "Exareme", - "label": "K_MEANS", - "parameters": [ - { - "code": "k", - "constraints": { - "max": null, - "min": 1 - }, - "default_value": 5, - "description": "The number of clusters. Typical values range from 2 to 10.", - "label": "k", - "type": "int" - } - ], - "type": [ - "statistics" - ] - } -]