Skip to content
Snippets Groups Projects
Commit 33978511 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

use the features main table name to get the right metadata when multiple datasets are available

parent 8e024666
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
......@@ -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();
......
......@@ -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'
);
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