Mercurial > lada > lada-server
changeset 636:cdcb7a141529
Added new query config for messprogramme and serve it via QueryService.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 27 Apr 2015 18:50:42 +0200 |
parents | 93076cf1af97 |
children | 4211a1e32f51 |
files | src/main/java/de/intevation/lada/query/QueryTools.java src/main/java/de/intevation/lada/rest/QueryService.java src/main/resources/messprogrammquery.json src/main/resources/probequery.json src/main/resources/queryconf.json |
diffstat | 5 files changed, 143 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/query/QueryTools.java Mon Apr 27 18:48:59 2015 +0200 +++ b/src/main/java/de/intevation/lada/query/QueryTools.java Mon Apr 27 18:50:42 2015 +0200 @@ -32,16 +32,17 @@ */ public class QueryTools { - private static String FILE = "/queryconf.json"; + private static String PROBE_CONFIG = "/probequery.json"; + private static String MESSPROGRAMM_CONFIG = "/messprogrammquery.json"; /** * Read the config file using the system property * "de.intevation.lada.sqlconfig". * * @return The file content. */ - public static String readConfigFile() { + public static String readConfigFile(String file) { try { - InputStream inputStream = QueryConfig.class.getResourceAsStream(FILE); + InputStream inputStream = QueryConfig.class.getResourceAsStream(file); int ch; StringBuilder builder = new StringBuilder(); while((ch = inputStream.read()) != -1) { @@ -62,8 +63,8 @@ * * @return List of {@link QueryConfig} objects. */ - public static List<QueryConfig> getConfig() { - String content = readConfigFile(); + private static List<QueryConfig> getConfig(String file) { + String content = readConfigFile(file); if (content == null) { return null; } @@ -111,6 +112,14 @@ return configs; } + public static List<QueryConfig> getProbeConfig() { + return getConfig(PROBE_CONFIG); + } + + public static List<QueryConfig> getMessprogrammConfig() { + return getConfig(MESSPROGRAMM_CONFIG); + } + /** * Get a query by id. * First reads the config file and returns the {@link QueryConfig} @@ -121,7 +130,7 @@ */ public static JsonObject getQueryById(String id) { try { - String content = readConfigFile(); + String content = readConfigFile(PROBE_CONFIG); if (content != null) { JsonReader reader = Json.createReader(new StringReader(content)); JsonArray queries = reader.readArray(); @@ -171,4 +180,24 @@ } return ret; } + + public static JsonObject getMpQueryById(String id) { + try { + String content = readConfigFile(MESSPROGRAMM_CONFIG); + if (content != null) { + JsonReader reader = Json.createReader(new StringReader(content)); + JsonArray queries = reader.readArray(); + for (int i = 0; i < queries.size(); i++) { + JsonObject query = queries.getJsonObject(i); + if (query.getString("id").equals(id)) { + return query; + } + } + } + return null; + } + catch (JsonException e) { + return null; + } + } }
--- a/src/main/java/de/intevation/lada/rest/QueryService.java Mon Apr 27 18:48:59 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/QueryService.java Mon Apr 27 18:50:42 2015 +0200 @@ -51,11 +51,22 @@ public class QueryService { /** - * Request all configured queries. + * Request all configured probe queries. */ @GET + @Path("/probe") @Produces("application/json") - public Response get() { - return new Response(true, 200, QueryTools.getConfig()); + public Response getProbe() { + return new Response(true, 200, QueryTools.getProbeConfig()); + } + + /** + * Request all configured messprogramm queries. + */ + @GET + @Path("/messprogramm") + @Produces("application/json") + public Response getMessprogramm() { + return new Response(true, 200, QueryTools.getMessprogrammConfig()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/messprogrammquery.json Mon Apr 27 18:50:42 2015 +0200 @@ -0,0 +1,14 @@ +[ +{ "id": "1", + "name": "Kein Filter", + "description": "Abfrage der Messprogramme ohne Filter", + "sql": "select m.id as id, m.name as name, m.mst_id as mstId, m.umw_id as umwId from land.messprogramm m", + "result": [ + {"dataIndex": "name", "header": "Name", "width": 100}, + {"dataIndex": "mstId", "header": "MST", "width": 100}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100} + ], + "filters": [ + ] +} +]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/probequery.json Mon Apr 27 18:50:42 2015 +0200 @@ -0,0 +1,80 @@ +[ +{ "id": "1", + "name": "Kein Filter", + "description": "Abfrage der Proben ohne Filter", + "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id", + "result": [ + {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, + {"dataIndex": "mstId", "header": "MST", "width": 100}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100} + ], + "filters": [ + ] +}, +{ "id": "2", + "name": "MST und UMW", + "description": "Abfrage der Proben gefiltert nach Messtellen ID und ID des Umweltbereichs", + "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)", + "result": [ + {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, + {"dataIndex": "mstId", "header": "MST", "width": 100}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100} + ], + "filters": [ + {"dataIndex": "mst_id", "type": "listmst", "label": "Messstelle"}, + {"dataIndex": "umw_id", "type": "listumw", "label": "Umweltbereich"} + ] +}, +{ "id": "3", + "name": "Proben pro Land", + "description": "Proben gefiltert nach Ländern", + "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (netzbetreiber_id = :netz OR '' = :netz)", + "result": [ + {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, + {"dataIndex": "netzbetreiberId", "header": "Land", "width": 100}, + {"dataIndex": "mstId", "header": "MST", "width": 100}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, + {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100} + ], + "filters": [ + {"dataIndex": "netz", "type": "listnetz", "label": "Land"} + ] +}, +{ "id": "4", + "name": "alle Proben mit Ort", + "description": "alle Proben mit Entnahmeort", + "sql": "select p.id as id, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where o.orts_typ = 'E' or o.orts_typ is null", + "result": [ + {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, + {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, + {"dataIndex": "mstId", "header": "MST", "width": 60}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, + {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100}, + {"dataIndex": "gemId", "header": "Gem-ID", "width": 100}, + {"dataIndex": "bezeichnung", "header": "Gemeinde", "flex": 1} + ], + "filters": [ + ] +}, +{ "id": "5", + "name": "Proben pro Land und UMW (Multiselect)", + "description": "Abfrage aller Proben gefiltert pro Land und Umweltbereich (mit Mehrfachauswahl)", + "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, to_char(p.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahmeVon, to_char(p.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahmeBis, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, o.orts_typ as ortsTyp, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where (o.orts_typ = 'E' or o.orts_typ is null) and (p.netzbetreiber_id = :netz OR '' =:netz) and (p.umw_id similar to (:umw_id) OR '' = :umw_id)", + "result": [ + {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, + {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, + {"dataIndex": "mstId", "header": "MST", "width": 50}, + {"dataIndex": "entnahmeVon", "header": "Entnahme von", "width": 120}, + {"dataIndex": "entnahmeBis", "header": "Entnahme bis", "width": 120}, + {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, + {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100}, + {"dataIndex": "ortsTyp", "header": "Ortstyp", "width": 50}, + {"dataIndex": "genId", "header": "Gemeinde-ID", "width": 100}, + {"dataIndex": "bezeichnung", "header": "Gemeinde", "flex": 1} + ], + "filters": [ + {"dataIndex": "netz", "type": "listnetz", "label": "Land"}, + {"dataIndex": "umw_id", "type": "listumw", "label": "Umweltbereich", "multiselect":true} + ] +} +]
--- a/src/main/resources/queryconf.json Mon Apr 27 18:48:59 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -[ -{ "id": "1", - "name": "Kein Filter", - "description": "Abfrage der Proben ohne Filter", - "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id", - "result": [ - {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, - {"dataIndex": "mstId", "header": "MST", "width": 100}, - {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100} - ], - "filters": [ - ] -}, -{ "id": "2", - "name": "MST und UMW", - "description": "Abfrage der Proben gefiltert nach Messtellen ID und ID des Umweltbereichs", - "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)", - "result": [ - {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, - {"dataIndex": "mstId", "header": "MST", "width": 100}, - {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100} - ], - "filters": [ - {"dataIndex": "mst_id", "type": "listmst", "label": "Messstelle"}, - {"dataIndex": "umw_id", "type": "listumw", "label": "Umweltbereich"} - ] -}, -{ "id": "3", - "name": "Proben pro Land", - "description": "Proben gefiltert nach Ländern", - "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr from land.probe p join land.probe_translation pt on p.id = pt.probe_id where (netzbetreiber_id = :netz OR '' = :netz)", - "result": [ - {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, - {"dataIndex": "netzbetreiberId", "header": "Land", "width": 100}, - {"dataIndex": "mstId", "header": "MST", "width": 100}, - {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, - {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100} - ], - "filters": [ - {"dataIndex": "netz", "type": "listnetz", "label": "Land"} - ] -}, -{ "id": "4", - "name": "alle Proben mit Ort", - "description": "alle Proben mit Entnahmeort", - "sql": "select p.id as id, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where o.orts_typ = 'E' or o.orts_typ is null", - "result": [ - {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, - {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, - {"dataIndex": "mstId", "header": "MST", "width": 60}, - {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, - {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100}, - {"dataIndex": "gemId", "header": "Gem-ID", "width": 100}, - {"dataIndex": "bezeichnung", "header": "Gemeinde", "flex": 1} - ], - "filters": [ - ] -}, -{ "id": "5", - "name": "Proben pro Land und UMW (Multiselect)", - "description": "Abfrage aller Proben gefiltert pro Land und Umweltbereich (mit Mehrfachauswahl)", - "sql": "select p.id as id, pt.probe_id_alt as probeId, p.netzbetreiber_id as netzbetreiberId, p.mst_id as mstId, to_char(p.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahmeVon, to_char(p.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahmeBis, p.umw_id as umwId, p.hauptproben_nr as hauptprobenNr, o.orts_typ as ortsTyp, so.gem_id as gemId, v.bezeichnung as bezeichnung from land.probe p join land.probe_translation pt on p.id = pt.probe_id left outer join land.ort o on (p.id = o.probe_id) left outer join stammdaten.ort so on (o.ort_id = so.id) left outer join stammdaten.verwaltungseinheit v on (so.gem_id = v.id) where (o.orts_typ = 'E' or o.orts_typ is null) and (p.netzbetreiber_id = :netz OR '' =:netz) and (p.umw_id similar to (:umw_id) OR '' = :umw_id)", - "result": [ - {"dataIndex": "probeId", "header": "ProbeId", "width": 100}, - {"dataIndex": "netzbetreiberId", "header": "Land", "width": 50}, - {"dataIndex": "mstId", "header": "MST", "width": 50}, - {"dataIndex": "entnahmeVon", "header": "Entnahme von", "width": 120}, - {"dataIndex": "entnahmeBis", "header": "Entnahme bis", "width": 120}, - {"dataIndex": "umwId", "header": "Umweltbereich", "width": 100}, - {"dataIndex": "hauptprobenNr", "header": "Proben-Nr", "width": 100}, - {"dataIndex": "ortsTyp", "header": "Ortstyp", "width": 50}, - {"dataIndex": "genId", "header": "Gemeinde-ID", "width": 100}, - {"dataIndex": "bezeichnung", "header": "Gemeinde", "flex": 1} - ], - "filters": [ - {"dataIndex": "netz", "type": "listnetz", "label": "Land"}, - {"dataIndex": "umw_id", "type": "listumw", "label": "Umweltbereich", "multiselect":true} - ] -} -]