[Lada-commits] [PATCH 02 of 13] Moved config file for queries and read the file via stream from resources
Wald Commits
scm-commit at wald.intevation.org
Fri Feb 6 17:57:36 CET 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1423221692 -3600
# Node ID 83b92b475d9d1a225a39e16087808d32d8f8c9a6
# Parent 5fe37b00ed4178b6046edf89e7789e5365ddd407
Moved config file for queries and read the file via stream from resources.
diff -r 5fe37b00ed41 -r 83b92b475d9d src/main/java/de/intevation/lada/query/QueryTools.java
--- a/src/main/java/de/intevation/lada/query/QueryTools.java Fri Feb 06 12:20:10 2015 +0100
+++ b/src/main/java/de/intevation/lada/query/QueryTools.java Fri Feb 06 12:21:32 2015 +0100
@@ -8,12 +8,8 @@
package de.intevation.lada.query;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringReader;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@@ -31,7 +27,7 @@
*/
public class QueryTools
{
- private static String FILE = "/META-INF/queryconf.json";
+ private static String FILE = "/queryconf.json";
/**
* Read the config file using the system property
* "de.intevation.lada.sqlconfig".
@@ -40,10 +36,13 @@
*/
public static String readConfigFile() {
try {
- URL path = QueryConfig.class.getResource(FILE);
- byte[] encoded = Files.readAllBytes(Paths.get(path.getPath()));
- Charset encoding = Charset.defaultCharset();
- return encoding.decode(ByteBuffer.wrap(encoded)).toString();
+ InputStream inputStream = QueryConfig.class.getResourceAsStream(FILE);
+ int ch;
+ StringBuilder builder = new StringBuilder();
+ while((ch = inputStream.read()) != -1) {
+ builder.append((char)ch);
+ }
+ return builder.toString();
}
catch (IOException ioe) {
ioe.printStackTrace();
diff -r 5fe37b00ed41 -r 83b92b475d9d src/main/resources/META-INF/queryconf.json
--- a/src/main/resources/META-INF/queryconf.json Fri Feb 06 12:20:10 2015 +0100
+++ /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 probe_id, mst_id, umw_id from l_probe",
- "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 probe_id, mst_id, umw_id from l_probe where (mst_id = :mst_id OR '' = :mst_id) and (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": "Detailiertere Beschreibung der Abfrage",
- "sql": "select probe_id, netzbetreiber_id, mst_id, umw_id, hauptproben_nr from l_probe 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 lp.probe_id, lp.netzbetreiber_id, lp.mst_id, lp.umw_id, lp.hauptproben_nr, ort.gem_id, s_verwaltungseinheit.bezeichnung from l_probe left outer join l_ort on (lp.probe_id = l_ort.probe_id) left outer join ort on (l_ort.ort_id = ort.ort_id) left outer join s_verwaltungseinheit on (ort.gem_id = s_verwaltungseinheit.gem_id) where l_ort.orts_typ = 'E' or l_ort.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 lp.probe_id, lp.netzbetreiber_id, lp.mst_id, to_char(lp.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahme_von, to_char(lp.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahme_bis, lp.umw_id, lp.hauptproben_nr, l_ort.orts_typ, ort.gem_id, s_verwaltungseinheit.bezeichnung from l_probe left outer join l_ort on (lp.probe_id = l_ort.probe_id) left outer join ort on (l_ort.ort_id = ort.ort_id) left outer join s_verwaltungseinheit on (ort.gem_id = s_verwaltungseinheit.gem_id) where (l_ort.orts_typ = 'E' or l_ort.orts_typ is null) and lp.netzbetreiber_id = :netz and (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}
- ]
-}
-]
diff -r 5fe37b00ed41 -r 83b92b475d9d src/main/resources/queryconf.json
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/queryconf.json Fri Feb 06 12:21:32 2015 +0100
@@ -0,0 +1,80 @@
+[
+{ "id": 1,
+ "name": "Kein Filter",
+ "description": "Abfrage der Proben ohne Filter",
+ "sql": "select probe_id, mst_id, umw_id from l_probe",
+ "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 probe_id, mst_id, umw_id from l_probe where (mst_id = :mst_id OR '' = :mst_id) and (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": "Detailiertere Beschreibung der Abfrage",
+ "sql": "select probe_id, netzbetreiber_id, mst_id, umw_id, hauptproben_nr from l_probe 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 lp.probe_id, lp.netzbetreiber_id, lp.mst_id, lp.umw_id, lp.hauptproben_nr, ort.gem_id, s_verwaltungseinheit.bezeichnung from l_probe left outer join l_ort on (lp.probe_id = l_ort.probe_id) left outer join ort on (l_ort.ort_id = ort.ort_id) left outer join s_verwaltungseinheit on (ort.gem_id = s_verwaltungseinheit.gem_id) where l_ort.orts_typ = 'E' or l_ort.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 lp.probe_id, lp.netzbetreiber_id, lp.mst_id, to_char(lp.probeentnahme_beginn,'YYYY-mm-dd HH24:MI') entnahme_von, to_char(lp.probeentnahme_ende,'YYYY-mm-dd HH24:MI') entnahme_bis, lp.umw_id, lp.hauptproben_nr, l_ort.orts_typ, ort.gem_id, s_verwaltungseinheit.bezeichnung from l_probe left outer join l_ort on (lp.probe_id = l_ort.probe_id) left outer join ort on (l_ort.ort_id = ort.ort_id) left outer join s_verwaltungseinheit on (ort.gem_id = s_verwaltungseinheit.gem_id) where (l_ort.orts_typ = 'E' or l_ort.orts_typ is null) and lp.netzbetreiber_id = :netz and (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}
+ ]
+}
+]
More information about the Lada-commits
mailing list