diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentState.java @ 8951:322b0e6298ea

Work on SINFO FlowDepth-Development
author gernotbelger
date Fri, 16 Mar 2018 18:08:38 +0100
parents
children c40db8e8dcae
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthdev/FlowDepthDevelopmentState.java	Fri Mar 16 18:08:38 2018 +0100
@@ -0,0 +1,113 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.sinfo.flowdepthdev;
+
+import java.util.List;
+
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.ChartArtifact;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.EmptyFacet;
+import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
+import org.dive4elements.river.artifacts.states.DefaultState;
+
+/**
+ * @author Gernot Belger
+ */
+public class FlowDepthDevelopmentState extends DefaultState {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * From this state can only be continued trivially.
+     */
+    @Override
+    protected String getUIProvider() {
+        return "continue";
+    }
+
+    @Override
+    public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
+        // FIXME: why is this necessary?
+        if (artifact instanceof ChartArtifact) {
+            facets.add(new EmptyFacet());
+            return null;
+        }
+
+        return compute((SINFOArtifact) artifact, context, hash, facets, old);
+    }
+
+    @Override
+    public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
+        if (artifact instanceof ChartArtifact) {
+            facets.add(new EmptyFacet());
+            return null;
+        }
+        return compute((SINFOArtifact) artifact, context, hash, facets, old);
+    }
+
+    /**
+     * Compute result or returned object from cache, create facets.
+     *
+     * @param old
+     *            Object that was cached.
+     */
+    private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) {
+
+        final CalculationResult res = doCompute(sinfo, context, old);
+
+        if (facets == null)
+            return res;
+
+        // final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData();
+        //
+        // /* add themes for chart, for each result */
+        // final List<FlowDepthCalculationResult> resultList = results.getResults();
+        // for (int index = 0; index < resultList.size(); index++) {
+        //
+        // final FlowDepthCalculationResult result = resultList.get(index);
+        //
+        // /* filtered (zoom dependent mean) flow depth */
+        // facets.add(FlowDepthProcessor.createFlowDepthFacet(context, hash, this.id, result, index));
+        //
+        // if (results.isUseTkh()) {
+        // /* filtered (zoom dependent mean) flow depth including tkh */
+        // facets.add(FlowDepthProcessor.createFlowDepthTkhFacet(context, hash, this.id, result, index));
+        //
+        // facets.add(TkhProcessor.createTkhFacet(context, hash, this.id, result, index));
+        // }
+        // }
+        //
+        // if (!resultList.isEmpty()) {
+        // final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id);
+        // final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id);
+        //
+        // facets.add(csv);
+        // facets.add(pdf);
+        // }
+        //
+        // final Calculation report = res.getReport();
+        //
+        // if (report.hasProblems()) {
+        // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id));
+        // }
+
+        return res;
+    }
+
+    private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) {
+        if (old instanceof CalculationResult)
+            return (CalculationResult) old;
+
+        return new FlowDepthDevelopmentCalculation(context).calculate(sinfo);
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org