changeset 6903:b3e2abe359d8

ETL: Take care of the fact that one river in AFT/SGM may correspond to N rivers in FLYS.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 22 Aug 2013 15:31:09 +0200
parents 143063f07405
children d710bd3df387
files etl/src/main/java/org/dive4elements/river/etl/aft/Rivers.java
diffstat 1 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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) {

http://dive4elements.wald.intevation.org