Mercurial > dive4elements > river
view flys-aft/src/main/java/de/intevation/aft/River.java @ 4083:44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 21 Dec 2011 14:56:29 +0000 |
parents | d13011e53022 |
children | 9178beeb7b05 |
line wrap: on
line source
package de.intevation.aft; import java.util.Map; import java.util.HashMap; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Element; import de.intevation.db.ConnectedStatements; public class River extends IdPair { private static Logger log = Logger.getLogger(River.class); protected String name; public River() { } public River(int id1, int id2, String name) { super(id1, id2); this.name = name; } public String getName() { return name; } public static Long numberToLong(String s) { try { return Long.valueOf(s.trim()); } catch (NumberFormatException nfe) { } return null; } public static Map<Long, DIPSGauge> indexByNumber(Document document) { Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); NodeList nodes = document.getElementsByTagName("PEGELSTATION"); for (int i = nodes.getLength()-1; i >= 0; --i) { Element element = (Element)nodes.item(i); String numberString = element.getAttribute("NUMMER"); Long number = numberToLong(numberString); if (number != null) { DIPSGauge newG = new DIPSGauge(element); DIPSGauge oldG = map.put(number, newG); if (oldG != null) { log.warn("DIPS: '" + newG.getName() + "' collides with '" + oldG.getName() + "' on gauge number " + number + "."); } } else { log.warn("DIPS: gauge '" + element.getAttribute("NAME") + "' has invalid gauge number '" + numberString + "'"); } } return map; } public void sync(SyncContext context) throws SQLException { log.info("sync river: " + this); Map<Long, DIPSGauge> dipsGauges = indexByNumber(context.getDips()); ConnectedStatements flysStatements = context.getFlysStatements(); ConnectedStatements aftStatements = context.getAftStatements(); ResultSet messstellenRs = aftStatements .getStatement("select.messstelle") .clearParameters() .setInt("GEWAESSER_NR", id2).executeQuery(); while (messstellenRs.next()) { String name = messstellenRs.getString("NAME"); String num = messstellenRs.getString("MESSSTELLE_NR"); Long number = numberToLong(num); if (number == null) { log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'"); continue; } DIPSGauge dipsGauge = dipsGauges.get(number); if (dipsGauges == null) { log.warn("MESSSTELLE '" + name + "' not found in DIPS."); continue; } } messstellenRs.close(); ResultSet gaugesRs = flysStatements .getStatement("select.gauges") .clearParameters() .setInt("river_id", id1).executeQuery(); while (gaugesRs.next()) { int gaugeId = gaugesRs.getInt("id"); String name = gaugesRs.getString("name"); } gaugesRs.close(); } public String toString() { return "[River: name=" + name + ", " + super.toString() + "]"; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :