changeset 8133:45b1d71110c3

Correctly handle not creating facets and error reports.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 25 Aug 2014 20:01:44 +0200
parents 58e3fed51e9e
children dfcc96deebd8
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java	Mon Aug 25 20:00:45 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadDataCalculate.java	Mon Aug 25 20:01:44 2014 +0200
@@ -138,8 +138,6 @@
         CallContext context, List<Facet> facets, Object old) {
         logger.debug("SedimentLoadDataCalculate.computeAdvance");
 
-        List<Facet> newFacets = new ArrayList<Facet>();
-
         SedimentLoadAccess access = new SedimentLoadAccess(artifact);
 
         CalculationResult res = old instanceof CalculationResult
@@ -151,13 +149,21 @@
             logger.error ("No calculation result.");
         }
 
+        if (facets == null) {
+            /* No need to create facets as they already exist in this case. */
+            return res;
+        }
+
+        Calculation report = res.getReport();
+
+        if (report != null && report.hasProblems()) {
+            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
+            logger.warn ("Problems : " + report.problemsToString());
+        }
+
         Object raw = res.getData();
         if (raw == null) {
             logger.warn("No result data.");
-            Calculation report = res.getReport();
-            if (report != null) {
-                logger.warn ("Problems : " + report.problemsToString());
-            }
             return res;
         }
 
@@ -168,23 +174,18 @@
             logger.error ("Unknown result");
             return null;
         }
+        String unit = access.getUnit().replace("_per_","/");
 
         int i = 0;
         for (Fraction fract: sdRes.getFractions()) {
             logger.debug("Adding facet for fraction: " + fract.getName());
-            newFacets.add(new SedimentLoadDataFacet(i++, fract.getName(),
-                          fract.getUnit(), ComputeType.ADVANCE, id, hash, context));
+            facets.add(new SedimentLoadDataFacet(i++, fract.getName(),
+                          unit, ComputeType.ADVANCE, id, hash, context));
         }
 
-        newFacets.add(
+        facets.add(
             new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id));
 
-        if (facets != null) {
-            facets.addAll(newFacets);
-        } else {
-            facets = newFacets;
-        }
-
         /* XXX: THIS IS ALL BROKEN
 
         SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData();

http://dive4elements.wald.intevation.org