diff --git a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java b/src/main/java/eu/hbp/mip/controllers/GroupsApi.java index bb325947c957bd53807750938fee54c83195b2e5..289624981a5e8f3c596ed5ae90a85169986fe891 100644 --- a/src/main/java/eu/hbp/mip/controllers/GroupsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/GroupsApi.java @@ -15,6 +15,7 @@ import org.apache.log4j.Logger; import org.postgresql.util.PGobject; 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; @@ -38,6 +39,9 @@ public class GroupsApi { @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") @@ -49,7 +53,7 @@ public class GroupsApi { } private String loadGroups() { - String sqlQuery = "SELECT * FROM meta_variables"; + String sqlQuery = String.format("SELECT * FROM meta_variables where target_table='%s'", featuresMainTable); SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); data.next(); String json = ((PGobject) data.getObject("hierarchy")).getValue(); diff --git a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java b/src/main/java/eu/hbp/mip/controllers/VariablesApi.java index 74acd1edbd649e894601fcf666504bc505e9057f..e08e0d19f61d093f4c9b4c198d1c06df07d728a9 100644 --- a/src/main/java/eu/hbp/mip/controllers/VariablesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/VariablesApi.java @@ -14,6 +14,7 @@ import org.apache.log4j.Logger; import org.postgresql.util.PGobject; 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; @@ -38,6 +39,9 @@ public class VariablesApi { @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") @@ -120,7 +124,7 @@ public class VariablesApi { ) { LOGGER.info("Get groups and variables hierarchy"); - String sqlQuery = "SELECT * FROM meta_variables"; + String sqlQuery = String.format("SELECT * FROM meta_variables where target_table='%s'", featuresMainTable); SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); data.next(); String json = ((PGobject) data.getObject("hierarchy")).getValue(); @@ -132,7 +136,7 @@ public class VariablesApi { private List<String> loadVariables() { - String sqlQuery = "SELECT * FROM meta_variables"; + String sqlQuery = String.format("SELECT * FROM meta_variables where target_table='%s'", featuresMainTable); SqlRowSet data = metaJdbcTemplate.queryForRowSet(sqlQuery); data.next(); String json = ((PGobject) data.getObject("hierarchy")).getValue(); diff --git a/tests/meta-db/sql/create.sql b/tests/meta-db/sql/create.sql index eb69c50a09e8d6fc4acc17f6845e5cd2cf286979..0e8a944383bf5f2b885a999d8e1e88f016acab48 100644 --- a/tests/meta-db/sql/create.sql +++ b/tests/meta-db/sql/create.sql @@ -3,9 +3,10 @@ SET datestyle to 'European'; CREATE TABLE IF NOT EXISTS meta_variables ( ID serial NOT NULL PRIMARY KEY, source varchar(256) UNIQUE NOT NULL, - hierarchy json NOT NULL + hierarchy json NOT NULL, + target_table varchar(256) UNIQUE NOT NULL ); -INSERT INTO meta_variables (source, hierarchy) VALUES ( +INSERT INTO meta_variables (source, hierarchy, target_table) VALUES ( 'features', ' { @@ -40,5 +41,6 @@ INSERT INTO meta_variables (source, hierarchy) VALUES ( }] }] } - ' + ', + 'features' );