Mercurial > dive4elements > river
changeset 947:db8d93cb65fd
Made meta data template configurable.
flys-artifacts/trunk@2363 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 19 Jul 2011 16:39:32 +0000 |
parents | 854620e52971 |
children | 0881cd4be773 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/meta-data-template.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java flys-artifacts/src/main/resources/metadata/template.xml |
diffstat | 5 files changed, 253 insertions(+), 220 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Jul 19 16:14:52 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Jul 19 16:39:32 2011 +0000 @@ -1,3 +1,14 @@ +2011-07-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/resources/metadata/template.xml: Deleted. + + * doc/conf/meta-data-template.xml: New. Was template.xml + + * doc/conf/conf.xml: Made meta data template configurable. + + * src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java: + Load template from configuration not from resources. + 2011-07-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/resources/metadata/template.xml: s/[a-z]+-id/db-id/
--- a/flys-artifacts/doc/conf/conf.xml Tue Jul 19 16:14:52 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Tue Jul 19 16:39:32 2011 +0000 @@ -90,6 +90,9 @@ <output-generator name="computed_dischargecurve_at_export">de.intevation.flys.exports.ATExporter</output-generator> </output-generators> + <!-- path to the template file of the meta data --> + <metadata template="${artifacts.config.dir}/meta-data-template.xml"/> + <rest-server> <!-- at this Point it is possible to Change the Port the ArtifactDatabase will bind to.--> <port>8181</port>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/doc/conf/meta-data-template.xml Tue Jul 19 16:39:32 2011 +0000 @@ -0,0 +1,215 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<dc:template xmlns:dc="http://www.intevation.org/2011/Datacage"> +<datacage> + <dc:context> + <dc:statement> + SELECT id AS river_id, name as river_name FROM rivers + WHERE name ILIKE ${river} + </dc:statement> + <dc:elements> + <river> + <dc:attribute name="name" value="${river_name}"/> + <dc:attribute name="db-id" value="${river_id}"/> + <discharge-table-nn> + <discharge-table-gauge> + <dc:context> + <dc:statement> + SELECT id AS gauge_id, + name AS gauge_name + FROM gauges WHERE river_id = ${river_id} + </dc:statement> + <dc:elements> + <gauge> + <dc:attribute name="name" value="${gauge_name}"/> + <dc:attribute name="db-id" value="${gauge_id}"/> + <dc:context> + <dc:statement> + SELECT description AS gauge_desc, + d.id AS discharge_id, + ti.start_time AS g_start, + ti.stop_time AS g_stop + FROM discharge_tables d JOIN time_intervals ti + ON d.time_interval_id = ti.id + WHERE d.gauge_id = ${gauge_id} AND d.kind = 1 + </dc:statement> + <dc:elements> + <historical> + <dc:attribute name="name" value="${gauge_desc}"/> + <dc:attribute name="from" value="${g_start}"/> + <dc:attribute name="to" value="${g_stop}"/> + <dc:attribute name="db-id" value="${discharge_id}"/></historical> + </dc:elements> + </dc:context> + </gauge> + </dc:elements> + </dc:context> + </discharge-table-gauge> + <fixations> + <dc:attribute name="id" value="fixations-${river_id}"/> + <dc:context> + <dc:statement> + SELECT id AS fix_id, + description AS fix_description + FROM wsts WHERE kind = 2 AND river_id = ${river_id} + </dc:statement> + <dc:elements> + <fixation> + <dc:attribute name="name" value="${fix_description}"/> + <dc:attribute name="db-id" value="${fix_id}"/> + <columns> + <dc:context> + <dc:statement> + SELECT id AS fix_column_id, + name AS fix_column_name + FROM wst_columns WHERE wst_id = ${fix_id} + ORDER by position + </dc:statement> + <dc:elements> + <column> + <dc:attribute name="name" value="${fix_column_name}"/> + <dc:attribute name="db-id" value="${fix_column_id}"/></column> + </dc:elements> + </dc:context> + </columns> + </fixation> + </dc:elements> + </dc:context> + </fixations> + <flood-protections> + <dc:attribute name="id" value="flood-protections-${river_id}"/> + <dc:context> + <dc:statement> + SELECT id AS prot_id, + description AS prot_description + FROM wsts WHERE kind = 5 AND river_id = ${river_id} + </dc:statement> + <dc:elements> + <flood-protection> + <dc:attribute name="name" value="${prot_description}"/> + <dc:attribute name="db-id" value="${prot_id}"/> + <columns> + <dc:context> + <dc:statement> + SELECT id AS prot_column_id, + name AS prot_column_name + FROM wst_columns WHERE wst_id = ${prot_id} + ORDER by position + </dc:statement> + <dc:elements> + <column> + <dc:attribute name="name" value="${prot_column_name}"/> + <dc:attribute name="db-id" value="${prot_column_id}"/></column> + </dc:elements> + </dc:context> + </columns> + </flood-protection> + </dc:elements> + </dc:context> + </flood-protections> + <flood-water-marks> + <dc:attribute name="id" value="flood-water-marks-${river_id}"/> + <dc:context> + <dc:statement> + SELECT id AS fw_id, + description AS fw_description + FROM wsts WHERE kind = 4 AND river_id = ${river_id} + </dc:statement> + <dc:elements> + <flood-water-mark> + <dc:attribute name="name" value="${fw_description}"/> + <dc:attribute name="db-id" value="${fw_id}"/> + <columns> + <dc:context> + <dc:statement> + SELECT id AS fw_column_id, + name AS fw_column_name + FROM wst_columns WHERE wst_id = ${fw_id} + ORDER by position + </dc:statement> + <dc:elements> + <column> + <dc:attribute name="name" value="${fw_column_name}"/> + <dc:attribute name="db-id" value="${fw_column_id}"/></column> + </dc:elements> + </dc:context> + </columns> + </flood-water-mark> + </dc:elements> + </dc:context> + </flood-water-marks> + <water-levels> + <dc:attribute name="id" value="water-levels-${river_id}"/> + <dc:context> + <dc:statement> + SELECT id AS wl_id, + description AS wl_description + FROM wsts WHERE kind = 0 AND river_id = ${river_id} + </dc:statement> + <dc:elements> + <water-level> + <dc:attribute name="name" value="${wl_description}"/> + <dc:attribute name="db-id" value="${wl_id}"/> + <columns> + <dc:context> + <dc:statement> + SELECT id AS wl_column_id, + name AS wl_column_name + FROM wst_columns WHERE wst_id = ${wl_id} + ORDER by position + </dc:statement> + <dc:elements> + <column> + <dc:attribute name="name" value="${wl_column_name}"/> + <dc:attribute name="db-id" value="${wl_column_id}"/></column> + </dc:elements> + </dc:context> + </columns> + </water-level> + </dc:elements> + </dc:context> + </water-levels> + <extra-longitudinal-sections> + <dc:attribute name="id" value="extra-longitudinal-sections-${river_id}"/> + <dc:context> + <dc:statement> + SELECT id AS els_id, + description AS els_description + FROM wsts WHERE kind = 1 AND river_id = ${river_id} + </dc:statement> + <dc:elements> + <extra-longitudinal-section> + <dc:attribute name="name" value="${els_description}"/> + <dc:attribute name="db-id" value="${els_id}"/> + <columns> + <dc:context> + <dc:statement> + SELECT id AS els_column_id, + name AS els_column_name + FROM wst_columns WHERE wst_id = ${els_id} + ORDER by position + </dc:statement> + <dc:elements> + <column> + <dc:attribute name="name" value="${els_column_name}"/> + <dc:attribute name="db-id" value="${els_column_id}"/></column> + </dc:elements> + </dc:context> + </columns> + </extra-longitudinal-section> + </dc:elements> + </dc:context> + </extra-longitudinal-sections> + </discharge-table-nn> + <longitudinal-section> + <fixations><dc:attribute name="ref" value="fixations-${river_id}"/></fixations> + <flood-protections><dc:attribute name="ref" value="flood-protections-${river_id}"/></flood-protections> + <flood-water-marks><dc:attribute name="ref" value="flood-water-marks-${river_id}"/></flood-water-marks> + <water-levels><dc:attribute name="ref" value="water-levels-${river_id}"/></water-levels> + <extra-longitudinal-sections><dc:attribute name="ref" value="extra-longitudinal-sections-${river_id}"/></extra-longitudinal-sections> + </longitudinal-section> + </river> + </dc:elements> + </dc:context> +</datacage> +</dc:template> +
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java Tue Jul 19 16:14:52 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java Tue Jul 19 16:39:32 2011 +0000 @@ -2,6 +2,8 @@ import java.io.InputStream; import java.io.IOException; +import java.io.File; +import java.io.FileInputStream; import java.sql.Connection; import java.sql.SQLException; @@ -18,6 +20,7 @@ import de.intevation.artifactdatabase.DefaultService; +import de.intevation.artifacts.common.utils.Config; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.common.ArtifactNamespaceContext; @@ -35,10 +38,11 @@ { private static Logger log = Logger.getLogger(MetaDataService.class); + public static final String XPATH_META_DATA_TEMPLATE = + "/artifact-database/metadata/@template"; + public static final String XPATH_RIVER = "/art:river/text()"; - public static final String META_DATA_TEMPLATE = "/metadata/template.xml"; - protected Builder builder; public MetaDataService() { @@ -100,14 +104,26 @@ public void setup(ServiceFactory factory, Object globalContext) { log.debug("MetaDataService.setup"); - InputStream in = getClass().getResourceAsStream(META_DATA_TEMPLATE); + String path = Config.getStringXPath(XPATH_META_DATA_TEMPLATE); - if (in == null) { - log.error("cannot get template resource"); + if (path == null) { + log.error("no path to template file given"); return; } + path = Config.replaceConfigDir(path); + + File file = new File(path); + + if (!file.isFile() || !file.canRead()) { + log.error("Cannot open template file '" + file + "'"); + return; + } + + InputStream in = null; + try { + in = new FileInputStream(file); Document template = XMLUtils.parseDocument(in); if (template == null) { log.error("cannot parse meta data template"); @@ -116,6 +132,9 @@ builder = new Builder(template); } } + catch (IOException ioe) { + log.error(ioe); + } finally { try { in.close();
--- a/flys-artifacts/src/main/resources/metadata/template.xml Tue Jul 19 16:14:52 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<dc:template xmlns:dc="http://www.intevation.org/2011/Datacage"> -<datacage> - <dc:context> - <dc:statement> - SELECT id AS river_id, name as river_name FROM rivers - WHERE name ILIKE ${river} - </dc:statement> - <dc:elements> - <river> - <dc:attribute name="name" value="${river_name}"/> - <dc:attribute name="db-id" value="${river_id}"/> - <discharge-table-nn> - <discharge-table-gauge> - <dc:context> - <dc:statement> - SELECT id AS gauge_id, - name AS gauge_name - FROM gauges WHERE river_id = ${river_id} - </dc:statement> - <dc:elements> - <gauge> - <dc:attribute name="name" value="${gauge_name}"/> - <dc:attribute name="db-id" value="${gauge_id}"/> - <dc:context> - <dc:statement> - SELECT description AS gauge_desc, - d.id AS discharge_id, - ti.start_time AS g_start, - ti.stop_time AS g_stop - FROM discharge_tables d JOIN time_intervals ti - ON d.time_interval_id = ti.id - WHERE d.gauge_id = ${gauge_id} AND d.kind = 1 - </dc:statement> - <dc:elements> - <historical> - <dc:attribute name="name" value="${gauge_desc}"/> - <dc:attribute name="from" value="${g_start}"/> - <dc:attribute name="to" value="${g_stop}"/> - <dc:attribute name="db-id" value="${discharge_id}"/></historical> - </dc:elements> - </dc:context> - </gauge> - </dc:elements> - </dc:context> - </discharge-table-gauge> - <fixations> - <dc:attribute name="id" value="fixations-${river_id}"/> - <dc:context> - <dc:statement> - SELECT id AS fix_id, - description AS fix_description - FROM wsts WHERE kind = 2 AND river_id = ${river_id} - </dc:statement> - <dc:elements> - <fixation> - <dc:attribute name="name" value="${fix_description}"/> - <dc:attribute name="db-id" value="${fix_id}"/> - <columns> - <dc:context> - <dc:statement> - SELECT id AS fix_column_id, - name AS fix_column_name - FROM wst_columns WHERE wst_id = ${fix_id} - ORDER by position - </dc:statement> - <dc:elements> - <column> - <dc:attribute name="name" value="${fix_column_name}"/> - <dc:attribute name="db-id" value="${fix_column_id}"/></column> - </dc:elements> - </dc:context> - </columns> - </fixation> - </dc:elements> - </dc:context> - </fixations> - <flood-protections> - <dc:attribute name="id" value="flood-protections-${river_id}"/> - <dc:context> - <dc:statement> - SELECT id AS prot_id, - description AS prot_description - FROM wsts WHERE kind = 5 AND river_id = ${river_id} - </dc:statement> - <dc:elements> - <flood-protection> - <dc:attribute name="name" value="${prot_description}"/> - <dc:attribute name="db-id" value="${prot_id}"/> - <columns> - <dc:context> - <dc:statement> - SELECT id AS prot_column_id, - name AS prot_column_name - FROM wst_columns WHERE wst_id = ${prot_id} - ORDER by position - </dc:statement> - <dc:elements> - <column> - <dc:attribute name="name" value="${prot_column_name}"/> - <dc:attribute name="db-id" value="${prot_column_id}"/></column> - </dc:elements> - </dc:context> - </columns> - </flood-protection> - </dc:elements> - </dc:context> - </flood-protections> - <flood-water-marks> - <dc:attribute name="id" value="flood-water-marks-${river_id}"/> - <dc:context> - <dc:statement> - SELECT id AS fw_id, - description AS fw_description - FROM wsts WHERE kind = 4 AND river_id = ${river_id} - </dc:statement> - <dc:elements> - <flood-water-mark> - <dc:attribute name="name" value="${fw_description}"/> - <dc:attribute name="db-id" value="${fw_id}"/> - <columns> - <dc:context> - <dc:statement> - SELECT id AS fw_column_id, - name AS fw_column_name - FROM wst_columns WHERE wst_id = ${fw_id} - ORDER by position - </dc:statement> - <dc:elements> - <column> - <dc:attribute name="name" value="${fw_column_name}"/> - <dc:attribute name="db-id" value="${fw_column_id}"/></column> - </dc:elements> - </dc:context> - </columns> - </flood-water-mark> - </dc:elements> - </dc:context> - </flood-water-marks> - <water-levels> - <dc:attribute name="id" value="water-levels-${river_id}"/> - <dc:context> - <dc:statement> - SELECT id AS wl_id, - description AS wl_description - FROM wsts WHERE kind = 0 AND river_id = ${river_id} - </dc:statement> - <dc:elements> - <water-level> - <dc:attribute name="name" value="${wl_description}"/> - <dc:attribute name="db-id" value="${wl_id}"/> - <columns> - <dc:context> - <dc:statement> - SELECT id AS wl_column_id, - name AS wl_column_name - FROM wst_columns WHERE wst_id = ${wl_id} - ORDER by position - </dc:statement> - <dc:elements> - <column> - <dc:attribute name="name" value="${wl_column_name}"/> - <dc:attribute name="db-id" value="${wl_column_id}"/></column> - </dc:elements> - </dc:context> - </columns> - </water-level> - </dc:elements> - </dc:context> - </water-levels> - <extra-longitudinal-sections> - <dc:attribute name="id" value="extra-longitudinal-sections-${river_id}"/> - <dc:context> - <dc:statement> - SELECT id AS els_id, - description AS els_description - FROM wsts WHERE kind = 1 AND river_id = ${river_id} - </dc:statement> - <dc:elements> - <extra-longitudinal-section> - <dc:attribute name="name" value="${els_description}"/> - <dc:attribute name="db-id" value="${els_id}"/> - <columns> - <dc:context> - <dc:statement> - SELECT id AS els_column_id, - name AS els_column_name - FROM wst_columns WHERE wst_id = ${els_id} - ORDER by position - </dc:statement> - <dc:elements> - <column> - <dc:attribute name="name" value="${els_column_name}"/> - <dc:attribute name="db-id" value="${els_column_id}"/></column> - </dc:elements> - </dc:context> - </columns> - </extra-longitudinal-section> - </dc:elements> - </dc:context> - </extra-longitudinal-sections> - </discharge-table-nn> - <longitudinal-section> - <fixations><dc:attribute name="ref" value="fixations-${river_id}"/></fixations> - <flood-protections><dc:attribute name="ref" value="flood-protections-${river_id}"/></flood-protections> - <flood-water-marks><dc:attribute name="ref" value="flood-water-marks-${river_id}"/></flood-water-marks> - <water-levels><dc:attribute name="ref" value="water-levels-${river_id}"/></water-levels> - <extra-longitudinal-sections><dc:attribute name="ref" value="extra-longitudinal-sections-${river_id}"/></extra-longitudinal-sections> - </longitudinal-section> - </river> - </dc:elements> - </dc:context> -</datacage> -</dc:template> -