diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java @ 8169:856701739443

Handle missing years in bed height differences without assuming an unknown year to be BC 1.
author "Tom Gottfried <tom@intevation.de>"
date Mon, 01 Sep 2014 09:43:55 +0200
parents b5cba2690347
children e4606eae8ea5
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java	Fri Aug 29 17:00:26 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.java	Mon Sep 01 09:43:55 2014 +0200
@@ -20,9 +20,11 @@
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.BedDifferencesAccess;
+import org.dive4elements.river.artifacts.model.Calculation;
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.DataFacet;
 import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.ReportFacet;
 import org.dive4elements.river.artifacts.model.minfo.BedDiffCalculation;
 import org.dive4elements.river.artifacts.model.minfo.BedDiffFacet;
 import org.dive4elements.river.artifacts.model.minfo.BedDiffHeightMinFacet;
@@ -98,6 +100,12 @@
 
         facets.addAll(newFacets);
 
+        Calculation report = res.getReport();
+        if (report != null && report.hasProblems()) {
+            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
+            logger.warn("Problems: " + report.problemsToString());
+        }
+
         return res;
     }
 
@@ -172,16 +180,31 @@
                     ComputeType.ADVANCE,
                     stateId,
                     hash));
-                newFacets.add(new BedDiffPerYearFacet(
-                    idx,
-                    BED_DIFFERENCE_HEIGHT_YEAR,
-                    createBedDiffAbsoluteDescription(
-                        meta,
-                        (BedDiffYearResult)results[idx],
-                        true),
-                    ComputeType.ADVANCE,
-                    stateId,
-                    hash));
+                if (((BedDiffYearResult)results[idx])
+                    .getHeightPerYearData()[1].length > 0) {
+                    /* Skip facets with data per year if there are none
+                       (because of missing start or end year) */
+                    newFacets.add(new BedDiffPerYearFacet(
+                        idx,
+                        BED_DIFFERENCE_HEIGHT_YEAR,
+                        createBedDiffAbsoluteDescription(
+                            meta,
+                            (BedDiffYearResult)results[idx],
+                            true),
+                        ComputeType.ADVANCE,
+                        stateId,
+                        hash));
+                    newFacets.add(new BedDiffPerYearFilterFacet(
+                        idx,
+                        BED_DIFFERENCE_HEIGHT_YEAR_FILTERED,
+                        createBedDiffAbsoluteDescription(
+                            meta,
+                            (BedDiffYearResult)results[idx],
+                            false),
+                        ComputeType.ADVANCE,
+                        stateId,
+                        hash));
+                }
                 newFacets.add(new BedDiffFilterFacet(
                     idx,
                     BED_DIFFERENCE_YEAR_FILTERED,
@@ -214,16 +237,6 @@
                     ComputeType.ADVANCE,
                     stateId,
                     hash));
-                newFacets.add(new BedDiffPerYearFilterFacet(
-                    idx,
-                    BED_DIFFERENCE_HEIGHT_YEAR_FILTERED,
-                    createBedDiffAbsoluteDescription(
-                        meta,
-                        (BedDiffYearResult)results[idx],
-                        false),
-                    ComputeType.ADVANCE,
-                    stateId,
-                    hash));
             }
         }
     }
@@ -255,13 +268,17 @@
         BedDiffYearResult result,
         boolean raw
     ) {
-        String range = result.getStart() + " - " + result.getEnd();
+        String start = result.getStart() != null ?
+            result.getStart().toString() : result.getNameFirst();
+        String end = result.getEnd() != null ?
+            result.getEnd().toString() : result.getNameSecond();
+        String range = start + " - " + end;
 
         String i18n = I18N_FACET_BED_DIFF_YEAR;
         if (raw) {
             i18n = I18N_FACET_BED_DIFF_YEAR_RAW;
         }
-        return Resources.getMsg(meta, i18n, i18n, new Object[] { range });
+        return Resources.getMsg(meta, i18n, new Object[] { range });
     }
 
     protected String createBedDiffSoundingDescription(

http://dive4elements.wald.intevation.org