diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 23b4ff116015
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceCurveState.java	Fri Sep 28 12:14:35 2012 +0200
@@ -0,0 +1,87 @@
+package de.intevation.flys.artifacts.states;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.WINFOArtifact;
+
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.ReferenceCurveFacet;
+import de.intevation.flys.artifacts.model.ReportFacet;
+import de.intevation.flys.artifacts.model.WWQQ;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+
+/** State of WINFO in which reference curves can be produced. */
+public class ReferenceCurveState
+extends      DefaultState
+implements   FacetTypes
+{
+    private static Logger logger = Logger.getLogger(ReferenceCurveState.class);
+
+
+    public ReferenceCurveState() {
+    }
+
+
+    @Override
+    public Object computeAdvance(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        if (!(artifact instanceof WINFOArtifact)) {
+            return null;
+        }
+
+        String id = getID();
+
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getReferenceCurveData(context);
+
+        if (facets == null) {
+            return res;
+        }
+
+        WWQQ [] wws = (WWQQ [])res.getData();
+
+        for (int i = 0; i < wws.length; ++i) {
+            String wwsName = wws[i].getName();
+            facets.add(new ReferenceCurveFacet(i,
+                REFERENCE_CURVE,
+                wwsName
+                ));
+            facets.add(new ReferenceCurveFacet(i,
+                REFERENCE_CURVE_NORMALIZED,
+                wwsName
+                ));
+        }
+
+        if (wws.length > 0) {
+            logger.debug("Adding CSV and PDF data facet.");
+            Facet csv = new DataFacet (CSV, "CSV data", ComputeType.ADVANCE, hash, id);
+            Facet pdf = new DataFacet (PDF, "PDF data", ComputeType.ADVANCE, hash, id);
+            facets.add(csv);
+            facets.add(pdf);
+        }
+
+        if (res.getReport().hasProblems()) {
+            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
+        }
+
+        return res;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org