changeset 8692:67e53dbe05d2

(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
author Tom Gottfried <tom@intevation.de>
date Fri, 17 Apr 2015 15:04:16 +0200
parents bfca77cbf353
children 851ea37d35f3
files backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java
diffstat 3 files changed, 46 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Apr 17 15:04:16 2015 +0200
@@ -39,8 +39,6 @@
     }
 
     public void storeDependencies() {
-        log.info("store dependencies");
-
         SQRelation peer = getPeer();
 
         if (peer != null) {
@@ -64,8 +62,6 @@
     }
 
     public SQRelation getPeer() {
-        log.debug("getPeer()");
-
         if (peer == null) {
             TimeInterval timeInter = timeInterval.getPeer();
 
--- a/backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java	Fri Apr 17 15:04:16 2015 +0200
@@ -206,6 +206,28 @@
         return range;
     }
 
+    public MeasurementStation getMeasurementStation(
+        River river,
+        double station,
+        String measurementType
+    ) {
+        List<MeasurementStation> stations = getMeasurementStations(
+            river, station);
+
+        if (stations != null) {
+            /* Assume there is only one MeasurementStation per type at
+               any station. Should be enforced in database schema. */
+            for (MeasurementStation m: stations) {
+                if (m.getMeasurementType().equals(measurementType)) {
+                    return m;
+                }
+                continue;
+            }
+        }
+
+        return null;
+    }
+
     public List<MeasurementStation> getMeasurementStations(
         River river,
         double station
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 17 14:55:42 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java	Fri Apr 17 15:04:16 2015 +0200
@@ -146,24 +146,32 @@
             return;
         }
 
-        List<MeasurementStation> ms =
-            ImporterSession.getInstance().getMeasurementStations(
-                river, km);
+        MeasurementStation mStation = ImporterSession.getInstance()
+            .getMeasurementStation(
+                river,
+                km,
+                parameter.equals("A") || parameter.equals("B")
+                ? MeasurementStation.MEASUREMENT_TYPE_SUSP
+                : MeasurementStation.MEASUREMENT_TYPE_BEDLOAD);
 
-        if (ms != null && !ms.isEmpty()) {
-            current.addValue(new ImportSQRelationValue(
-                    cols[1],
-                    ms.get(0),
-                    a,
-                    b,
-                    qMax,
-                    rSq,
-                    nTot,
-                    nOutlier,
-                    cFer,
-                    cDuan
-                ));
+        if (mStation == null) {
+            log.warn("No measurement station fitting parameter " +
+                parameter + " at km " + km + ". Line ignored.");
+            return;
         }
+
+        current.addValue(new ImportSQRelationValue(
+                parameter,
+                mStation,
+                a,
+                b,
+                qMax,
+                rSq,
+                nTot,
+                nOutlier,
+                cFer,
+                cDuan
+            ));
     }
 
     private Double parseDouble(String[] values, int idx) {

http://dive4elements.wald.intevation.org