[PATCH] ETL: Take care of the fact that one river in AFT/SGM may correspond to N rivers in FLYS

Wald Commits scm-commit at wald.intevation.org
Thu Aug 22 15:31:13 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1377178269 -7200
# Node ID b3e2abe359d87ba1e60a02b688672c016ba71b5b
# Parent  143063f07405c739de6fa30b2072806a05d094d0
ETL: Take care of the fact that one river in AFT/SGM may correspond to N rivers in FLYS.

diff -r 143063f07405 -r b3e2abe359d8 etl/src/main/java/org/dive4elements/river/etl/aft/Rivers.java
--- a/etl/src/main/java/org/dive4elements/river/etl/aft/Rivers.java	Thu Aug 22 15:22:59 2013 +0200
+++ b/etl/src/main/java/org/dive4elements/river/etl/aft/Rivers.java	Thu Aug 22 15:31:09 2013 +0200
@@ -14,9 +14,7 @@
 import java.sql.SQLException;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.log4j.Logger;
 
@@ -27,6 +25,24 @@
     public Rivers() {
     }
 
+    private static List<River> findFLYSRivers(
+        List<River> flysRivers,
+        String      needle
+    ) {
+        List<River> rivers = new ArrayList<River>();
+
+        needle = needle.toLowerCase();
+
+        for (River river: rivers) {
+            String name = river.getName().toLowerCase();
+            if (name.contains(needle)) {
+                rivers.add(river);
+            }
+        }
+
+        return rivers;
+    }
+
     public boolean sync(SyncContext context) throws SQLException {
 
         log.info("sync: rivers");
@@ -34,7 +50,7 @@
         ConnectedStatements flysStatements = context.getFlysStatements();
         ConnectedStatements aftStatements  = context.getAftStatements();
 
-        Map<String, River> flysRivers = new HashMap<String, River>();
+        List<River> flysRivers = new ArrayList<River>();
 
         ResultSet flysRs = flysStatements
             .getStatement("select.rivers").executeQuery();
@@ -45,7 +61,7 @@
                 String name = flysRs.getString("name");
                 double from = flysRs.getDouble("min_km");
                 double to   = flysRs.getDouble("max_km");
-                flysRivers.put(name.toLowerCase(), new River(id, name, from, to));
+                flysRivers.add(new River(id, name, from, to));
             }
         }
         finally {
@@ -60,9 +76,8 @@
         try {
             while (aftRs.next()) {
                 String name = aftRs.getString("NAME");
-                River river = flysRivers.get(name.toLowerCase());
-                if (river != null) {
-                    int id2 = aftRs.getInt("GEWAESSER_NR");
+                int    id2  = aftRs.getInt("GEWAESSER_NR");
+                for (River river: findFLYSRivers(flysRivers, name)) {
                     river.setId2(id2);
                     commonRivers.add(river);
                 }
@@ -72,7 +87,6 @@
             aftRs.close();
         }
 
-
         boolean modified = false;
 
         for (River river: commonRivers) {


More information about the Dive4elements-commits mailing list