Mercurial > dive4elements > river
changeset 1046:0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
flys-artifacts/trunk@2508 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 19 Aug 2011 09:48:13 +0000 |
parents | ba840385ad2e |
children | 38088c982db6 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/doc/conf/meta-data-system.xml flys-artifacts/doc/conf/meta-data-user.xml flys-artifacts/doc/conf/meta-data.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/App.java |
diffstat | 7 files changed, 389 insertions(+), 407 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Aug 18 14:58:17 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 19 09:48:13 2011 +0000 @@ -1,3 +1,20 @@ +2011-08-19 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Fixed flys/issue262 + + * src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java: + Unified user and system tempate. + Looks for "/artifact-database/metadata/template/text()" + in conf.xml. Defaults to "${artifacts.config.dir}/meta-data.xml". If user id is + given its the default connection for contexts. + + * doc/conf/conf.xml: Adjusted + * doc/conf/meta-data-system.xml, doc/conf/meta-data-user.xml: Deleted. + * doc/conf/meta-data.xml: Unified version of user and system template. + + * src/main/java/de/intevation/flys/artifacts/datacage/templating/App.java: + Adjusted the test program. + 2011-08-18 Sascha L. Teichmann <sascha.teichmann@intevation.de> Fixed flys/issue260
--- a/flys-artifacts/doc/conf/conf.xml Thu Aug 18 14:58:17 2011 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Fri Aug 19 09:48:13 2011 +0000 @@ -103,8 +103,7 @@ <!-- Path to the template file of the meta data. --> <metadata> - <system template="${artifacts.config.dir}/meta-data-system.xml"/> - <user template="${artifacts.config.dir}/meta-data-user.xml"/> + <template>${artifacts.config.dir}/meta-data.xml</template> </metadata> <!-- The WMS layer that is displayed as background layer in floodmaps. -->
--- a/flys-artifacts/doc/conf/meta-data-system.xml Thu Aug 18 14:58:17 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,268 +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}"/> - <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')"> - <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> - </dc:if> - <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')"> - <longitudinal-section> - <dc:call-macro name="longitudinal_section-recommended"/> - <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> - <dc:macro name="longitudinal_section-recommended"> - <annotation> - <dc:attribute name="factory" value="annotations"/> - <dc:attribute name="db-ids" value="${river_id}"/> - </annotation> - </dc:macro> - </dc:if> - <dc:if test="dc:contains($artifact-outs, 'floodmap')"> - <floodmap> - <dc:choose> - <dc:when test="dc:contains($parameters, 'recommended')"> - <dc:call-macro name="flood-map-recommended"/> - </dc:when> - <dc:otherwise> - <dc:call-macro name="flood-map-complete"/> - </dc:otherwise> - </dc:choose> - </floodmap> - <dc:macro name="flood-map-recommended"> - <dc:comment> - FIXME: Following two macros look identical to me. - </dc:comment> - <kilometrage> - <riveraxis> - <dc:attribute name="factory" value="riveraxis"/> - <dc:attribute name="db-ids" value="${river_id}"/> - </riveraxis> - </kilometrage> - <rastermap> - <background> - <dc:attribute name="factory" value="wmsbackground"/> - <dc:attribute name="db-ids" value="${river_id}"/> - </background> - </rastermap> - </dc:macro> - <dc:macro name="flood-map-complete"> - <kilometrage> - <riveraxis> - <dc:attribute name="factory" value="riveraxis"/> - <dc:attribute name="db-ids" value="${river_id}"/> - </riveraxis> - </kilometrage> - <rastermap> - <background> - <dc:attribute name="factory" value="wmsbackground"/> - <dc:attribute name="db-ids" value="${river_id}"/> - </background> - </rastermap> - </dc:macro> - </dc:if> - </river> - </dc:elements> - </dc:context> -</datacage> -</dc:template>
--- a/flys-artifacts/doc/conf/meta-data-user.xml Thu Aug 18 14:58:17 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<dc:template xmlns:dc="http://www.intevation.org/2011/Datacage"> -<datacage> - <dc:comment> - User specific part - ------------------ - </dc:comment> - <dc:if test="dc:contains($parameters, 'user-id')"> - <old_calculations> - <dc:context connection="user"> - <dc:statement>SELECT u.id AS user_id, c.id AS collection_id - FROM collections c JOIN users u ON c.user_id = u.id - WHERE u.gid = CAST(${user-id} AS uuid) - ORDER BY c.creation DESC - </dc:statement> - <dc:elements> - <dc:context> - <dc:statement>SELECT id AS a_id, state AS a_state, gid AS a_gid, creation AS a_creation - FROM master_artifacts m - WHERE collection_id = ${collection_id} AND gid <> CAST(${artifact-id} AS uuid) - AND EXISTS ( - SELECT id FROM artifact_data WHERE artifact_id = m.id AND k = 'river' AND v = ${river}) - </dc:statement> - <dc:elements> - <dc:choose> - <dc:when test="$current-state-id = 'state.winfo.waterlevel'"> - <dc:context> - <dc:statement>SELECT id AS out_id FROM outs WHERE artifact_id = ${a_id} AND name = 'longitudinal_section' - </dc:statement> - <dc:elements> - <dc:context> - <dc:statement>SELECT name AS facet_name, num as facet_num, description AS facet_description - FROM facets WHERE out_id = ${out_id} ORDER BY num ASC, name DESC - </dc:statement> - <longitudinal_section_columns> - <dc:attribute name="description" value="${river} ${a_creation}"/> - <dc:elements> - <dc:element name="${facet_name}"> - <dc:attribute name="description" value="${facet_description}"/> - <dc:attribute name="num" value="${facet_num}"/> - <dc:attribute name="factory" value="TODO"/> - <dc:attribute name="artifact-id" value="${a_gid}"/> - </dc:element> - </dc:elements> - </longitudinal_section_columns> - </dc:context> - </dc:elements> - </dc:context> - </dc:when> - </dc:choose> - </dc:elements> - </dc:context> - </dc:elements> - </dc:context> - </old_calculations> - </dc:if> -</datacage> -</dc:template>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/doc/conf/meta-data.xml Fri Aug 19 09:48:13 2011 +0000 @@ -0,0 +1,329 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<dc:template xmlns:dc="http://www.intevation.org/2011/Datacage"> +<datacage> + <dc:choose> + <dc:comment> + User specific part + ------------------ + </dc:comment> + <dc:when test="dc:contains($parameters, 'user-id')"> + <old_calculations> + <dc:context connection="user"> + <dc:statement>SELECT u.id AS user_id, c.id AS collection_id + FROM collections c JOIN users u ON c.user_id = u.id + WHERE u.gid = CAST(${user-id} AS uuid) + ORDER BY c.creation DESC + </dc:statement> + <dc:elements> + <dc:context> + <dc:statement>SELECT id AS a_id, state AS a_state, gid AS a_gid, creation AS a_creation + FROM master_artifacts m + WHERE collection_id = ${collection_id} AND gid <> CAST(${artifact-id} AS uuid) + AND EXISTS ( + SELECT id FROM artifact_data WHERE artifact_id = m.id AND k = 'river' AND v = ${river}) + </dc:statement> + <dc:elements> + <dc:choose> + <dc:when test="$current-state-id = 'state.winfo.waterlevel'"> + <dc:context> + <dc:statement>SELECT id AS out_id FROM outs WHERE artifact_id = ${a_id} AND name = 'longitudinal_section' + </dc:statement> + <dc:elements> + <dc:context> + <dc:statement>SELECT name AS facet_name, num as facet_num, description AS facet_description + FROM facets WHERE out_id = ${out_id} ORDER BY num ASC, name DESC + </dc:statement> + <longitudinal_section_columns> + <dc:attribute name="description" value="${river} ${a_creation}"/> + <dc:elements> + <dc:element name="${facet_name}"> + <dc:attribute name="description" value="${facet_description}"/> + <dc:attribute name="num" value="${facet_num}"/> + <dc:attribute name="factory" value="TODO"/> + <dc:attribute name="artifact-id" value="${a_gid}"/> + </dc:element> + </dc:elements> + </longitudinal_section_columns> + </dc:context> + </dc:elements> + </dc:context> + </dc:when> + </dc:choose> + </dc:elements> + </dc:context> + </dc:elements> + </dc:context> + </old_calculations> + </dc:when> + <dc:comment> + System specific part + -------------------- + </dc:comment> + <dc:otherwise> + <dc:context connection="system"> + <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}"/> + <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')"> + <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> + </dc:if> + <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')"> + <longitudinal-section> + <dc:call-macro name="longitudinal_section-recommended"/> + <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> + <dc:macro name="longitudinal_section-recommended"> + <annotation> + <dc:attribute name="factory" value="annotations"/> + <dc:attribute name="db-ids" value="${river_id}"/> + </annotation> + </dc:macro> + </dc:if> + <dc:if test="dc:contains($artifact-outs, 'floodmap')"> + <floodmap> + <dc:choose> + <dc:when test="dc:contains($parameters, 'recommended')"> + <dc:call-macro name="flood-map-recommended"/> + </dc:when> + <dc:otherwise> + <dc:call-macro name="flood-map-complete"/> + </dc:otherwise> + </dc:choose> + </floodmap> + <dc:macro name="flood-map-recommended"> + <dc:comment> + FIXME: Following two macros look identical to me. + </dc:comment> + <kilometrage> + <riveraxis> + <dc:attribute name="factory" value="riveraxis"/> + <dc:attribute name="db-ids" value="${river_id}"/> + </riveraxis> + </kilometrage> + <rastermap> + <background> + <dc:attribute name="factory" value="wmsbackground"/> + <dc:attribute name="db-ids" value="${river_id}"/> + </background> + </rastermap> + </dc:macro> + <dc:macro name="flood-map-complete"> + <kilometrage> + <riveraxis> + <dc:attribute name="factory" value="riveraxis"/> + <dc:attribute name="db-ids" value="${river_id}"/> + </riveraxis> + </kilometrage> + <rastermap> + <background> + <dc:attribute name="factory" value="wmsbackground"/> + <dc:attribute name="db-ids" value="${river_id}"/> + </background> + </rastermap> + </dc:macro> + </dc:if> + </river> + </dc:elements> + </dc:context> + </dc:otherwise> + </dc:choose> +</datacage> +</dc:template>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java Thu Aug 18 14:58:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java Fri Aug 19 09:48:13 2011 +0000 @@ -14,8 +14,6 @@ import java.sql.Connection; import java.sql.SQLException; -import javax.sql.DataSource; - import org.apache.log4j.Logger; import org.w3c.dom.Document; @@ -43,11 +41,11 @@ private static final boolean DEVELOPMENT_MODE = Boolean.getBoolean("flys.datacage.recommendations.development"); - public static final String XPATH_SYSTEM_TEMPLATE = - "/artifact-database/metadata/system/@template"; + public static final String XPATH_TEMPLATE = + "/artifact-database/metadata/template/text()"; - public static final String XPATH_USER_TEMPLATE = - "/artifact-database/metadata/user/@template"; + public static final String DEFAULT_TEMPLATE_PATH = + "${artifacts.config.dir}/meta-data.xml"; private static Recommendations INSTANCE; @@ -102,25 +100,17 @@ } } // class BuilderProvider - protected BuilderProvider systemBuilderProvider; - protected BuilderProvider userBuilderProvider; + protected BuilderProvider builderProvider; public Recommendations() { } - public Recommendations( - BuilderProvider systemBuilderProvider, - BuilderProvider userBuilderProvider) { - this.systemBuilderProvider = systemBuilderProvider; - this.userBuilderProvider = userBuilderProvider; + public Recommendations(BuilderProvider builderProvider) { + this.builderProvider = builderProvider; } - public Builder getUserBuilder() { - return userBuilderProvider.getBuilder(); - } - - public Builder getSystemBuilder() { - return systemBuilderProvider.getBuilder(); + public Builder getBuilder() { + return builderProvider.getBuilder(); } protected static void artifactToParameters( @@ -190,32 +180,29 @@ List<Builder.NamedConnection> connections = new ArrayList<Builder.NamedConnection>(2); - if (userId != null) { // Use system and user templates. - // Get connection to datacage db. - DataSource dataSource = DBConfig + Connection userConnection = userId != null + ? DBConfig .getInstance() .getDBConnection() - .getDataSource(); + .getDataSource() + .getConnection() + : null; - Connection userConnection = dataSource.getConnection(); - try { + try { + if (userConnection != null) { connections.add(new Builder.NamedConnection( Builder.CONNECTION_USER, userConnection, false)); - - connections.add(new Builder.NamedConnection( - Builder.CONNECTION_SYSTEM, systemConnection, true)); + } - getUserBuilder().build(connections, result, parameters); - } - finally { - userConnection.close(); - } - } - else { // Use system template only. connections.add(new Builder.NamedConnection( Builder.CONNECTION_SYSTEM, systemConnection, true)); - getSystemBuilder().build(connections, result, parameters); + getBuilder().build(connections, result, parameters); + } + finally { + if (userConnection != null) { + userConnection.close(); + } } } }); @@ -253,62 +240,42 @@ } } - public static Recommendations createRecommendations( - File systemFile, - File userFile - ) { + public static Recommendations createRecommendations(File file) { log.debug("Recommendations.createBuilder"); - if (!systemFile.isFile() || !systemFile.canRead()) { - log.error("Cannot open template file '" + systemFile + "'"); + if (!file.isFile() || !file.canRead()) { + log.error("Cannot open template file '" + file + "'"); return null; } - if (!userFile.isFile() || !userFile.canRead()) { - log.error("Cannot open template file '" + userFile + "'"); - return null; - } + FileBuilderProvider fbp = new FileBuilderProvider(file); - FileBuilderProvider ufbp = new FileBuilderProvider(userFile); - FileBuilderProvider sfbp = new FileBuilderProvider(systemFile); - - if (ufbp.getBuilder() == null || sfbp.getBuilder() == null) { + if (fbp.getBuilder() == null) { log.error("failed loading builder"); return null; } - BuilderProvider ubp; - BuilderProvider sbp; + BuilderProvider bp = DEVELOPMENT_MODE + ? fbp + : fbp.toStaticProvider(); - if (DEVELOPMENT_MODE) { - ubp = ufbp; - sbp = sfbp; - } - else { - ubp = ufbp.toStaticProvider(); - sbp = sfbp.toStaticProvider(); - } - - return new Recommendations(sbp, ubp); + return new Recommendations(bp); } protected static Recommendations createRecommendations() { log.debug("Recommendations.createRecommendations"); - String systemPath = Config.getStringXPath(XPATH_SYSTEM_TEMPLATE); - String userPath = Config.getStringXPath(XPATH_USER_TEMPLATE); + String path = Config.getStringXPath(XPATH_TEMPLATE); - if (systemPath == null || userPath == null) { - log.error("no path to template file given"); - return null; + if (path == null) { + path = DEFAULT_TEMPLATE_PATH; } - systemPath = Config.replaceConfigDir(systemPath); - userPath = Config.replaceConfigDir(userPath); + path = Config.replaceConfigDir(path); - return createRecommendations( - new File(systemPath), - new File(userPath)); + log.info("Meta data template: " + path); + + return createRecommendations(new File(path)); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/App.java Thu Aug 18 14:58:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/App.java Fri Aug 19 09:48:13 2011 +0000 @@ -24,11 +24,8 @@ { private static Logger log = Logger.getLogger(App.class); - public static final String systemTemplate = - System.getProperty("meta.data.template", "meta-data-system.xml"); - - public static final String userTemplate = - System.getProperty("meta.data.template", "meta-data-user.xml"); + public static final String template = + System.getProperty("meta.data.template", "meta-data.xml"); public static final String userId = System.getProperty("user.id"); @@ -56,8 +53,7 @@ public static void main(String [] args) { Recommendations rec = Recommendations.createRecommendations( - new File(systemTemplate), - new File(userTemplate)); + new File(template)); if (rec == null) { System.err.println("No recommendations created");