Skip to content
Snippets Groups Projects
Commit bb9d85e9 authored by Manuel Spuhler's avatar Manuel Spuhler
Browse files

Ludovic's code

parent 002d7dd8
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ To use this image, you need a running instance of PostgreSQL and to configure th
* FEATURES_DB_USER: User to use when connecting to the science database, default value is "postgres".
* FEATURES_DB_PASSWORD: Password to use when connecting to the science database.
* FEATURES_DB_MAIN_TABLE: Table that contains the scientific data to use, default value is "features".
* DATASETS (temporary hack): list of datasets available in the features table
### OAUTH2 LOGIN
......
......@@ -21,6 +21,7 @@ spring:
username: {{ default .Env.FEATURES_DB_USER "postgres" }}
password: {{ .Env.FEATURES_DB_PASSWORD }}
driver-class-name: org.postgresql.Driver
datasets: {{ .Env.DATASETS }}
jpa:
hibernate:
dialect: org.hibernate.dialect.PostgreSQL9Dialect
......
......@@ -16,6 +16,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import javax.sql.DataSource;
import java.util.List;
/**
* Created by mirco on 11.07.16.
......
......@@ -6,19 +6,23 @@ package eu.hbp.mip.controllers;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import eu.hbp.mip.model.Dataset;
import eu.hbp.mip.model.Variable;
import eu.hbp.mip.repositories.VariableRepository;
import io.swagger.annotations.*;
import eu.hbp.mip.repositories.DatasetRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
......@@ -33,25 +37,30 @@ public class DatasetsApi {
@Autowired
private DatasetRepository datasetRepository;
@Autowired
private VariableRepository variableRepository;
@Value("#{'${spring.featuresDatasource.datasets:adni,ppmi,edsd}'}")
private String datasets;
@PostConstruct
public void init() {
for (String dataset: datasets.split(",")) {
Variable v = variableRepository.findOne(dataset);
if (v == null) {
v = new Variable(dataset);
variableRepository.save(v);
}
}
}
@ApiOperation(value = "Get dataset list", response = Dataset.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity getDatasets(
) {
LOGGER.info("Get dataset list");
JsonArray datasets = new JsonArray();
JsonObject o = new JsonObject();
o.addProperty("code", "chuv");
o.addProperty("label", "CHUV");
datasets.add(o);
JsonObject p = new JsonObject();
p.addProperty("code", "brescia");
p.addProperty("label", "Brescia");
datasets.add(p);
return ResponseEntity.ok(gson.toJson(datasets));
return ResponseEntity.ok(datasets.split(","));
}
}
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