diff --git a/docker/config/application.tmpl b/docker/config/application.tmpl index 5f2f72a3ec2a684fb9e7907df0cd65b3b73973bb..10be575a25520beec4fe724c567f70db0dd23694 100644 --- a/docker/config/application.tmpl +++ b/docker/config/application.tmpl @@ -14,13 +14,7 @@ spring: username: {{ default .Env.META_DB_USER "postgres" }} password: {{ .Env.META_DB_PASSWORD }} driver-class-name: org.postgresql.Driver - featuresDatasource: - url: {{ default .Env.FEATURES_DB_URL "jdbc:postgresql://172.22.0.1:5433/features" }} - schema: {{ default .Env.FEATURES_DB_SCHEMA "public" }} - main-table: {{ default .Env.FEATURES_DB_MAIN_TABLE "features" }} - username: {{ default .Env.FEATURES_DB_USER "postgres" }} - password: {{ .Env.FEATURES_DB_PASSWORD }} - driver-class-name: org.postgresql.Driver + data: jpa: repositories: @@ -96,5 +90,5 @@ services: workflowAuthorization: {{ default .Env.WORKFLOW_AUTHORIZATION "undefined" }} galaxy: galaxyUsername: {{ default .Env.GALAXY_USERNAME "admin" }} - galaxyPassword: {{ default .Env.GALAXY_PASSWORD "admin" }} + galaxyPassword: {{ default .Env.GALAXY_PASSWORD "password" }} diff --git a/src/main/java/eu/hbp/mip/StartupTasks.java b/src/main/java/eu/hbp/mip/StartupTasks.java deleted file mode 100644 index d7dc3e0958bc1613ee6afa13fbb4a8d6b9ddc836..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/StartupTasks.java +++ /dev/null @@ -1,87 +0,0 @@ -package eu.hbp.mip; - -import ch.chuv.lren.woken.messages.datasets.Dataset; -import com.google.gson.Gson; -import eu.hbp.mip.controllers.DatasetsApi; -import eu.hbp.mip.controllers.MiningApi; -import eu.hbp.mip.controllers.VariablesApi; -import eu.hbp.mip.model.Variable; -import eu.hbp.mip.repositories.VariableRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.DependsOn; -import org.springframework.stereotype.Component; - - -@Component -public class StartupTasks implements ApplicationListener<ApplicationReadyEvent> { - - private static final Logger LOGGER = LoggerFactory.getLogger(StartupTasks.class); - private static final Gson gson = new Gson(); - - @Autowired - private VariableRepository variableRepository; - - @Autowired - private DatasetsApi datasetsApi; - - @Autowired - private VariablesApi variablesApi; - - @Autowired - private MiningApi miningApi; - - @Override - public void onApplicationEvent(ApplicationReadyEvent event) { - - boolean variablesRepositoryOk = false; - - // Pre-fill the local variable repository with the list of datasets, interpreted here as variables - // (a bit like a categorical variable can be split into a set of variables (a.k.a one hot encoding in Data science) ) - // Try 5 times, to be more robust in the face of cluster failures / slow startup - // LOGGER.info("Prefill variable repository with datasets..."); - // for (int i = 0; i < 5; i++) { - // try { - // StringBuilder fetchedDatasets = new StringBuilder(); - // for (Dataset dataset : datasetsApi.fetchDatasets()) { - // final String code = dataset.id().code(); - // fetchedDatasets.append(code).append(' '); - // Variable v = variableRepository.findOne(code); - // if (v == null) { - // LOGGER.info("Store additional variable {}", code); - // v = new Variable(code); - // variableRepository.save(v); - // } - // } - // LOGGER.info("Datasets fetched from Woken: " + fetchedDatasets.toString()); - // variablesRepositoryOk = true; - // break; - // } catch (Exception e) { - // variablesRepositoryOk = false; - // LOGGER.error("Cannot initialise the variable repository. Is the connection to Woken working?", e); - // } - // } - - // if (!variablesRepositoryOk) { - // System.exit(1); - // } - - /* - for (String variableJson: variablesApi.loadVariables()) { - String code = gson.fromJson(variableJson, Variable.class).getCode(); - MiningQuery histogram = new MiningQuery(); - histogram.setAlgorithm(new Algorithm("histogram", "histogram", false)); - histogram.setVariables(Collections.singletonList(new Variable(code))); - histogram.setCovariables(Collections.emptyList()); - histogram.setGrouping(Collections.emptyList()); - // TODO: need to get groupings from Woken - } - */ - - LOGGER.info("[OK] MIP Portal backend is ready!"); - } - -} diff --git a/src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java b/src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java index a1525ee96e44b2bfecc8a94ba73935ab46834ba8..20b6fb7dce662714140497d47058ef943a1a7dea 100644 --- a/src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java +++ b/src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java @@ -1,6 +1,5 @@ package eu.hbp.mip.configuration; -import eu.hbp.mip.utils.DataUtil; import org.flywaydb.core.Flyway; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -26,9 +25,6 @@ import javax.sql.DataSource; @EntityScan(basePackages = "eu.hbp.mip.model") public class PersistenceConfiguration { - @Value("#{'${spring.featuresDatasource.main-table:features}'}") - private String featuresMainTable; - @Primary @Bean(name = "portalDatasource") @ConfigurationProperties(prefix="spring.portalDatasource") @@ -42,12 +38,6 @@ public class PersistenceConfiguration { return DataSourceBuilder.create().build(); } - @Bean(name = "featuresDatasource") - @ConfigurationProperties(prefix="spring.featuresDatasource") - public DataSource featuresDataSource() { - return DataSourceBuilder.create().build(); - } - @Bean @Autowired @Qualifier("metaJdbcTemplate") @@ -55,13 +45,6 @@ public class PersistenceConfiguration { return new JdbcTemplate(metaDataSource()); } - @Bean - @Autowired - @Qualifier("featuresJdbcTemplate") - public JdbcTemplate featuresJdbcTemplate() { - return new JdbcTemplate(featuresDataSource()); - } - @Bean(name = "entityManagerFactory") @DependsOn("flyway") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { @@ -80,10 +63,4 @@ public class PersistenceConfiguration { return flyway; } - @Bean(name = "dataUtil") - @Scope("singleton") - public DataUtil dataUtil() { - return new DataUtil(featuresJdbcTemplate(), featuresMainTable); - } - } diff --git a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java b/src/main/java/eu/hbp/mip/controllers/GroupsApi.java deleted file mode 100644 index dd71e18f4d57f75588071703140ffa40a6ff2e7d..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Created by mirco on 04.12.15. - */ - -package eu.hbp.mip.controllers; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import eu.hbp.mip.model.Group; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.postgresql.util.PGobject; -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.cache.annotation.Cacheable; -import org.springframework.http.ResponseEntity; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.support.rowset.SqlRowSet; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -@RestController -@RequestMapping(value = "/groups", produces = {APPLICATION_JSON_VALUE}) -@Api(value = "/groups", description = "the groups API") -public class GroupsApi { - - private static final Logger LOGGER = LoggerFactory.getLogger(GroupsApi.class); - - private static final Gson gson = new Gson(); - - @Autowired - @Qualifier("metaJdbcTemplate") - private JdbcTemplate metaJdbcTemplate; - - @Value("#{'${spring.featuresDatasource.main-table:features}'}") - private String featuresMainTable; - - - @ApiOperation(value = "Get the root group (containing all subgroups)", response = Group.class) - @Cacheable("groups") - @RequestMapping(method = RequestMethod.GET) - public ResponseEntity<Object> getTheRootGroup() { - LOGGER.info("Get root group and its whole sub-groups tree"); - - return ResponseEntity.ok(gson.fromJson(loadGroups(), Object.class)); - } - - private String loadGroups() { - String sqlQuery = String.format( - "SELECT * FROM meta_variables where target_table='%s'", featuresMainTable.toUpperCase()); - SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); - - JsonObject root = new JsonObject(); - if (data.next()) { - String json = ((PGobject) data.getObject("hierarchy")).getValue(); - root = gson.fromJson(json, JsonObject.class); - removeVariablesRecursive(root); - } - return gson.toJson(root); - } - - private void removeVariablesRecursive(JsonObject element) { - if (element.has("groups")){ - for(JsonElement child : element.getAsJsonArray("groups")) { - removeVariablesRecursive(child.getAsJsonObject()); - } - } - else { - element.add("groups", new JsonArray()); // Only for compatibility with olf frontend - } - if(element.has("variables")) { - element.remove("variables"); - } - } - -} diff --git a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java index 3ac19450cccf0b5b709d3380a9c87443659e4f5c..f0107618159215f3f663f5bfacea9bc88532a921 100644 --- a/src/main/java/eu/hbp/mip/controllers/ModelsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/ModelsApi.java @@ -13,7 +13,6 @@ import eu.hbp.mip.model.User; import eu.hbp.mip.model.UserInfo; import eu.hbp.mip.model.Variable; import eu.hbp.mip.repositories.*; -import eu.hbp.mip.utils.DataUtil; import io.swagger.annotations.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,11 +53,6 @@ public class ModelsApi { @Autowired private VariableRepository variableRepository; - @Autowired - @Qualifier("dataUtil") - private DataUtil dataUtil; - - @ApiOperation(value = "Get models", response = Model.class, responseContainer = "List") @RequestMapping(method = RequestMethod.GET) public ResponseEntity<List> getModels( @@ -95,7 +89,7 @@ public class ModelsApi { models = models != null ? models : new LinkedList<>(); for (Model m : models) { m.setDataset(datasetRepository.findOne(m.getDataset().getCode())); - modelsList.add(getModelWithDataset(m)); + modelsList.add(m); } return ResponseEntity.ok(modelsList); @@ -224,7 +218,7 @@ public class ModelsApi { Collection<String> yAxisVarsColl = new LinkedHashSet<>(yAxisVars); model.getConfig().setyAxisVariables(new LinkedList<>(yAxisVarsColl)); - return ResponseEntity.ok(getModelWithDataset(model)); + return ResponseEntity.ok(model); } @@ -285,24 +279,4 @@ public class ModelsApi { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - private Model getModelWithDataset(Model model) - { - List<String> allVars = new LinkedList<>(); - allVars.addAll(model.getDataset().getVariable()); - allVars.addAll(model.getDataset().getHeader()); - allVars.addAll(model.getDataset().getGrouping()); - - // WokenConversions conv = new WokenConversions(); - // String filtersJson = model.getQuery().getFilters(); - // Option<FilterRule> filters = conv.toFilterRule(filtersJson); - // String filtersSQL = conv.toSqlWhere(filters); - - // Gson gson = new Gson(); - // JsonObject jsonModel = gson.fromJson(gson.toJson(model, Model.class), JsonObject.class); - // jsonModel.get("dataset").getAsJsonObject() - // .add("data", dataUtil.getDataFromVariables(allVars, filtersSQL)); - - return model; //gson.fromJson(jsonModel, Model.class); - } - } diff --git a/src/main/java/eu/hbp/mip/controllers/RequestsApi.java b/src/main/java/eu/hbp/mip/controllers/RequestsApi.java index 777eac0c51ec2ed47f68d485fdbbb48dcb2df5e9..a848ff951f77bbff853780347731a55cb71c3eb3 100644 --- a/src/main/java/eu/hbp/mip/controllers/RequestsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/RequestsApi.java @@ -11,12 +11,9 @@ import com.google.gson.JsonObject; import eu.hbp.mip.model.Dataset; import eu.hbp.mip.model.Query; import eu.hbp.mip.model.StringDtoResponse; -import eu.hbp.mip.utils.DataUtil; import io.swagger.annotations.*; 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.HttpStatus; import org.springframework.http.ResponseEntity; @@ -42,11 +39,6 @@ public class RequestsApi { private static final Pattern variableExpression = Pattern.compile("\\w+"); - @Autowired - @Qualifier("dataUtil") - private DataUtil dataUtil; - - @ApiOperation(value = "Post a request", response = Dataset.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") }) @RequestMapping(method = RequestMethod.POST) @@ -79,7 +71,6 @@ public class RequestsApi { dataset.add("variable", gson.toJsonTree(variables)); dataset.add("grouping", gson.toJsonTree(groupings)); dataset.add("header", gson.toJsonTree(covariables)); - dataset.add("data", dataUtil.getDataFromVariables(allVars, filters)); return ResponseEntity.ok(gson.fromJson(dataset, Object.class)); } diff --git a/src/main/java/eu/hbp/mip/controllers/StatsApi.java b/src/main/java/eu/hbp/mip/controllers/StatsApi.java index daf1b117fd5a4588d9d4d879eb37d02987cb7aaa..d09c032bc75659c18100a4f58ca3965c2e4b4933 100644 --- a/src/main/java/eu/hbp/mip/controllers/StatsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/StatsApi.java @@ -7,7 +7,6 @@ package eu.hbp.mip.controllers; import eu.hbp.mip.model.GeneralStats; import eu.hbp.mip.repositories.ArticleRepository; import eu.hbp.mip.repositories.UserRepository; -import eu.hbp.mip.utils.DataUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -34,10 +33,6 @@ public class StatsApi { @Autowired private ArticleRepository articleRepository; - @Autowired - @Qualifier("dataUtil") - private DataUtil dataUtil; - @ApiOperation(value = "Get general statistics", response = GeneralStats.class) @RequestMapping(method = RequestMethod.GET) @@ -48,7 +43,6 @@ public class StatsApi { stats.setUsers(userRepository.count()); stats.setArticles(articleRepository.count()); - stats.setVariables(dataUtil.countVariables()); return ResponseEntity.ok(stats); } diff --git a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java b/src/main/java/eu/hbp/mip/controllers/VariablesApi.java deleted file mode 100644 index 0eae7e7cf5bfcd84f75505f7d9dfb2f0596d6469..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Created by mirco on 04.12.15. - */ - -package eu.hbp.mip.controllers; - - -import ch.chuv.lren.woken.messages.variables.VariableMetaData; -import ch.chuv.lren.woken.messages.variables.VariablesForDatasetsQuery; -import ch.chuv.lren.woken.messages.variables.VariablesForDatasetsResponse; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import eu.hbp.mip.model.Algorithm; -import eu.hbp.mip.model.MiningQuery; -import eu.hbp.mip.model.Variable; -import io.swagger.annotations.*; -import org.postgresql.util.PGobject; -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.cache.annotation.Cacheable; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.support.rowset.SqlRowSet; -import org.springframework.web.bind.annotation.*; -import scala.collection.JavaConversions; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; - -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -@RestController -@RequestMapping(value = "/variables", produces = {APPLICATION_JSON_VALUE}) -@Api(value = "/variables", description = "the variables API") -public class VariablesApi { - - private static final Logger LOGGER = LoggerFactory.getLogger(VariablesApi.class); - - private static final Gson gson = new Gson(); - - @Autowired - @Qualifier("metaJdbcTemplate") - private JdbcTemplate metaJdbcTemplate; - - @Value("#{'${spring.featuresDatasource.main-table:features}'}") - private String featuresMainTable; - - @ApiOperation(value = "Get variables", response = List.class, responseContainer = "List") - @Cacheable("variables") - @RequestMapping(method = RequestMethod.GET) - public ResponseEntity<Iterable> getVariables( - @ApiParam(value = "List of groups formatted like : (\"val1\", \"val2\", ...)") @RequestParam(value = "group", required = false) String group, - @ApiParam(value = "List of subgroups formatted like : (\"val1\", \"val2\", ...)") @RequestParam(value = "subgroup", required = false) String subgroup, - @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isVariable", required = false) String isVariable, - @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isGrouping", required = false) String isGrouping, - @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isCovariable", required = false) String isCovariable, - @ApiParam(value = "Boolean value formatted like : (\"0\") or (\"1\") or (\"false\") or (\"true\")") @RequestParam(value = "isFilter", required = false) String isFilter - ) { - LOGGER.info("Get variables"); - - LinkedList<Object> variablesObjects = new LinkedList<>(); - - for (String var : loadVariables()) - { - variablesObjects.add(gson.fromJson(var, Object.class)); - } - - return ResponseEntity.ok(variablesObjects); - } - - - - @ApiOperation(value = "Get a variable", response = Object.class) - @Cacheable("variable") - @RequestMapping(value = "/{code}", method = RequestMethod.GET) - public ResponseEntity<Object> getAVariable( - @ApiParam(value = "code of the variable ( multiple codes are allowed, separated by \",\" )", required = true) @PathVariable("code") String code - ) { - LOGGER.info("Get a variable"); - - for (String var : loadVariables()) - { - JsonObject varObj = gson.fromJson(var, JsonElement.class).getAsJsonObject(); - if (varObj.get("code").getAsString().equals(code)) - { - return ResponseEntity.ok(gson.fromJson(varObj, Object.class)); - } - } - - LOGGER.warn("Variable " + code + " not found ! "); - - return ResponseEntity.ok(null); - } - - - @ApiOperation(value = "Get values from a variable", response = List.class, responseContainer = "List") - @Cacheable("values") - @RequestMapping(value = "/{code}/values", method = RequestMethod.GET) - public ResponseEntity<Iterable> getValuesFromAVariable( - @ApiParam(value = "code", required = true) @PathVariable("code") String code, - @ApiParam(value = "Pattern to match") @RequestParam(value = "q", required = false) String q - ) { - LOGGER.info("Get values from a variable"); - - for (String var : loadVariables()) - { - JsonObject varObj = gson.fromJson(var, JsonElement.class).getAsJsonObject(); - if (varObj.get("code").getAsString().equals(code)) - { - JsonArray values = varObj.get("enumerations").getAsJsonArray(); - LinkedList<Object> valuesObjects = new LinkedList<>(); - for (JsonElement value : values){ - valuesObjects.add(gson.fromJson(value, Object.class)); - } - return ResponseEntity.ok(valuesObjects); - } - } - - LOGGER.warn("Variable " + code + " not found ! "); - - return ResponseEntity.ok(null); - } - - @ApiOperation(value = "Get groups and variables hierarchy", response = Object.class) - @Cacheable("vars_hierarchy") - @RequestMapping(value = "/hierarchy", method = RequestMethod.GET) - public ResponseEntity<Object> getVariablesHierarchy( - ) { - LOGGER.info("Get groups and variables hierarchy"); - - String sqlQuery = String.format( - "SELECT * FROM meta_variables where upper(target_table)='%s'", featuresMainTable.toUpperCase()); - SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); - data.next(); - String json = ((PGobject) data.getObject("hierarchy")).getValue(); - - Object hierarchy = gson.fromJson(json, Object.class); - - return ResponseEntity.ok(hierarchy); - } - - @ApiOperation(value = "Get query for histograms", response = Object.class) - @Cacheable("vars_histogram_query") - @RequestMapping(value = "/{code}/histogram_query", method = RequestMethod.GET) - public ResponseEntity<MiningQuery> getHistogramQuery( - @ApiParam(value = "code", required = true) @PathVariable("code") String code - ) { - LOGGER.info("Get query for histograms"); - - String sqlQuery = String.format( - "SELECT histogram_groupings FROM meta_variables where upper(target_table)='%s'", featuresMainTable.toUpperCase()); - SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); - data.next(); - String histogramGroupings = data.getString("histogram_groupings"); - - MiningQuery query = new MiningQuery(); - query.addVariable(new Variable(code)); - List<String> newGroups = Arrays.asList(histogramGroupings.split(",")); - List<Variable> groupings = query.getGrouping(); - groupings.addAll(newGroups.stream().map(Variable::new).collect(Collectors.toList())); - query.setGrouping(groupings); - query.setAlgorithm(new Algorithm("histograms", "Histograms", false)); - - return ResponseEntity.ok(query); - } - - - public List<String> loadVariables() { - String sqlQuery = String.format( - "SELECT * FROM meta_variables where upper(target_table)='%s'", featuresMainTable.toUpperCase()); - SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); - - List<String> variables = new LinkedList<>(); - if (data.next()) { - String json = ((PGobject) data.getObject("hierarchy")).getValue(); - JsonObject root = gson.fromJson(json, JsonObject.class); - extractVariablesRecursive(root, variables); - } - - return variables; - } - - private void extractVariablesRecursive(JsonObject element, List<String> variables) { - if (element.has("groups")){ - for(JsonElement child : element.getAsJsonArray("groups")) { - extractVariablesRecursive(child.getAsJsonObject(), variables); - } - } - if (element.has("variables")){ - for (JsonElement var : element.getAsJsonArray("variables")){ - JsonObject grp = new JsonObject(); - grp.addProperty("code", element.getAsJsonPrimitive("code").getAsString()); - grp.addProperty("label", element.getAsJsonPrimitive("label").getAsString()); - var.getAsJsonObject().add("group", grp); - var.getAsJsonObject().addProperty("isVariable", true); - variables.add(gson.toJson(var)); - } - } - } - - -} diff --git a/src/main/java/eu/hbp/mip/model/GeneralStats.java b/src/main/java/eu/hbp/mip/model/GeneralStats.java index 939ca27de29f3bc9d21dcdd60eb343a953c71e2d..302cf8edd320149c560b5fb252bb8ab3e4fece26 100644 --- a/src/main/java/eu/hbp/mip/model/GeneralStats.java +++ b/src/main/java/eu/hbp/mip/model/GeneralStats.java @@ -13,7 +13,6 @@ public class GeneralStats { private Long users = null; private Long articles = null; - private Long variables = null; public GeneralStats() { @@ -39,13 +38,4 @@ public class GeneralStats { public void setArticles(Long articles) { this.articles = articles; } - - - public Long getVariables() { - return variables; - } - - public void setVariables(Long variables) { - this.variables = variables; - } } diff --git a/src/main/java/eu/hbp/mip/utils/DataUtil.java b/src/main/java/eu/hbp/mip/utils/DataUtil.java deleted file mode 100644 index 1bad9d966f8f7e86b2ed3621b5e2140fec7c429b..0000000000000000000000000000000000000000 --- a/src/main/java/eu/hbp/mip/utils/DataUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -package eu.hbp.mip.utils; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.jdbc.core.JdbcTemplate; - -import java.util.List; - -/** - * Created by mirco on 14.09.16. - */ - -public class DataUtil { - - private static final int MAX_NB_SAMPLES = 200; - - private JdbcTemplate jdbcTemplate; - private String featuresMainTable; - - public DataUtil(JdbcTemplate jdbcTemplate, String featuresMainTable) - { - this.jdbcTemplate = jdbcTemplate; - this.featuresMainTable = featuresMainTable; - } - - @Cacheable("varsdata") - public JsonObject getDataFromVariables(List<String> vars, String filterSQL) - { - JsonObject data = new JsonObject(); - String filters = ""; - - if (filterSQL != null && filterSQL.length() > 0) { - filters = String.format( - " AND %s", - filterSQL.replaceAll("\\\\'", "''")); // Quick and dirty workaround - } - - for (String var : vars) { - JsonArray currentVarData = new JsonArray(); - - long nbRows = countDatasetRows(); - - if (nbRows >= 1) { - List<Object> queryResult; - synchronized(this){ - // Dirty - jdbcTemplate.execute("SELECT SETSEED(0.42)"); - // Dirty - queryResult = jdbcTemplate.queryForList( - String.format("SELECT %s FROM %s WHERE %s IS NOT NULL %s ORDER BY Random() LIMIT %d", - var, featuresMainTable, var, filters, MAX_NB_SAMPLES), - Object.class); - } - for (Object value : queryResult) { - if (value == null) { - currentVarData.add((String) null); - } else { - if (value instanceof Double) { - currentVarData.add((Double) value); - } else if (value instanceof Float) { - currentVarData.add((Float) value); - } else if (value instanceof Integer) { - currentVarData.add((Integer) value); - } else if (value instanceof Long) { - currentVarData.add((Long) value); - } else { - String strValue = String.valueOf(value); - try { - double numValue = Double.parseDouble(strValue); - currentVarData.add(numValue); - } catch (NumberFormatException e2) { - currentVarData.add(strValue); - } - } - } - } - data.add(var, currentVarData); - } - } - - return data; - } - - public JsonObject getDataFromVariables(List<String> vars) - { - return getDataFromVariables(vars); - } - - @Cacheable("colscount") - public long countVariables() - { - // Dirty - return jdbcTemplate.queryForObject( - "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " + - "WHERE table_name = '"+featuresMainTable+"'", Long.class); - } - - @Cacheable("rowscount") - public long countDatasetRows() - { - // Dirty - return jdbcTemplate.queryForObject( - "SELECT COUNT(*) FROM "+featuresMainTable, Long.class); - } - -}