Mercurial > dive4elements > river
changeset 964:ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
flys-artifacts/trunk@2384 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Jul 2011 10:45:52 +0000 |
parents | f48cef242e7f |
children | 79251b1d47da |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/meta-data-template.xml flys-artifacts/doc/conf/output-defaults.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java |
diffstat | 5 files changed, 290 insertions(+), 271 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Jul 20 22:03:50 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Jul 21 10:45:52 2011 +0000 @@ -1,3 +1,22 @@ +2011-07-21 Ingo Weinzierl <ingo@intevation.de> + + * doc/conf/meta-data-template.xml: Added conditions for each output type. + Splitted the "floodmap" output into two parts: a recommended one and a + complete one. The recommended part will only build the document tree for + the recommended artifacts; the complete part will build the whole document + tree that is available for a floodmap. + + * src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java: + This Hook now uses the DataCage to generate the recommended artifacts. + The output-defaults configurtion is needless now. + + * doc/conf/output-defaults.xml: Removed. The configuration of recommended + artifacts takes place in meta-data-template.xml. + + * src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java: + Bugfix: the DataCage didn't start working if its builder was NOT null, + but it shouldn't start if the builder IS null. + 2011-07-21 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/meta/Builder.java:
--- a/flys-artifacts/doc/conf/meta-data-template.xml Wed Jul 20 22:03:50 2011 +0000 +++ b/flys-artifacts/doc/conf/meta-data-template.xml Thu Jul 21 10:45:52 2011 +0000 @@ -10,203 +10,243 @@ <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> + <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> + <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:if> + <dc:if test="dc:contains($artifact-outs, 'floodmap')"> + <floodmap> + <dc:choose> + <dc:when test="$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"> + <kilometrage> + <riveraxis> + <dc:attribute name="factory" value="riveraxis"/> + </riveraxis> + </kilometrage> + <rastermap> + <background> + <dc:attribute name="factory" value="wmsbackground"/> + </background> + </rastermap> + </dc:macro> + <dc:macro name="flood-map-complete"> + <kilometrage> + <riveraxis> + <dc:attribute name="factory" value="riveraxis"/> + </riveraxis> + </kilometrage> + <rastermap> + <background> + <dc:attribute name="factory" value="wmsbackground"/> + </background> + </rastermap> + </dc:macro> + </dc:if> </river> </dc:elements> </dc:context>
--- a/flys-artifacts/doc/conf/output-defaults.xml Wed Jul 20 22:03:50 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -<output-defaults> - - <state id="state.winfo.uesk.uesk" artifact-factory="riveraxis" /> - <state id="state.winfo.uesk.uesk" artifact-factory="wmsbackground" /> - -</output-defaults>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java Wed Jul 20 22:03:50 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java Thu Jul 21 10:45:52 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts; -import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -13,72 +11,31 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.Hook; -import de.intevation.artifacts.common.utils.Config; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; +import de.intevation.artifactdatabase.state.Output; + +import de.intevation.flys.artifacts.services.meta.DataCage; + public class CollectionMonitor implements Hook { - public static final String XPATH_STATES = "output-defaults/state"; public static final String XPATH_RESULT = "/art:result"; - protected Map<String, List<String>> states; - - private static final Logger logger = Logger.getLogger(CollectionMonitor.class); @Override public void setup(Node cfg) { - Element config = (Element) cfg; - String xlink = config.getAttribute("xlink:href"); - xlink = Config.replaceConfigDir(xlink); - - File file = new File(xlink); - - if (file == null || !file.exists()) { - logger.error("The config file '" + xlink + "' does not exist."); - return; - } - - Document outputDefaults = XMLUtils.parseDocument(file); - - NodeList states = (NodeList) XMLUtils.xpath( - outputDefaults, - XPATH_STATES, - XPathConstants.NODESET); - - int len = states != null ? states.getLength() : 0; - - this.states = new HashMap<String, List<String>>(len); - - for (int i = 0; i < len; i++) { - Element state = (Element) states.item(i); - - String stateId = state.getAttribute("id"); - String factory = state.getAttribute("artifact-factory"); - - if (stateId != null && factory != null) { - List<String> factories = this.states.get(stateId); - - if (factories == null) { - factories = new ArrayList<String>(); - this.states.put(stateId, factories); - } - - factories.add(factory); - } - } } @@ -86,21 +43,6 @@ public void execute(Artifact artifact, CallContext context, Document doc) { FLYSArtifact flys = (FLYSArtifact) artifact; - String stateId = flys.getCurrentStateId(); - - List<String> factories = states.get(stateId); - - if (factories == null || factories.isEmpty()) { - return; - } - - logger.info("Found " + factories.size() + " recommended artifacts."); - - appendRecommendations(doc, factories); - } - - - protected void appendRecommendations(Document doc, List<String> factories) { Element result = (Element) XMLUtils.xpath( doc, XPATH_RESULT, @@ -113,15 +55,39 @@ ArtifactNamespaceContext.NAMESPACE_PREFIX); Element recommended = creator.create("recommended-artifacts"); + result.appendChild(recommended); - for (String factory: factories) { - Element fac = creator.create("artifact-factory"); - creator.addAttr(fac, "name", factory); + String[] outs = extractOutputNames(flys, context); + Map<String, Object> params = getDataCageParameters(flys, context); - recommended.appendChild(fac); + DataCage dc = DataCage.getInstance(); + dc.recommend(flys, outs, params, recommended); + } + + + public static String[] extractOutputNames( + FLYSArtifact flys, + CallContext context) + { + List<Output> outs = flys.getOutputs(context); + String[] names = new String[outs.size()]; + + for (int i = 0, num = outs != null ? outs.size() : 0; i < num; i++) { + names[i] = outs.get(i).getName(); } - result.appendChild(recommended); + return names; + } + + + protected Map<String, Object> getDataCageParameters( + FLYSArtifact flys, + CallContext context) + { + Map<String, Object> params = new HashMap<String, Object>(1); + params.put("recommended", "true"); + + return params; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java Wed Jul 20 22:03:50 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java Thu Jul 21 10:45:52 2011 +0000 @@ -92,7 +92,7 @@ final Map<String, Object> parameters, final Node result ) { - if (builder != null) { + if (builder == null) { log.error("builder not configured properly."); return; }