diff artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FixAnalysisYearXPathFunction.java @ 9232:5030c46d8cb4

Implemented xpath function that selectes the 'mean year' of a fixation-artifact. Needs to provide the ArtifactDatabase to the builder implementation.
author gernotbelger
date Fri, 06 Jul 2018 13:09:54 +0200
parents
children 2d4750874c57
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FixAnalysisYearXPathFunction.java	Fri Jul 06 13:09:54 2018 +0200
@@ -0,0 +1,66 @@
+/** 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.datacage.templating;
+
+import java.util.List;
+import java.util.UUID;
+
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.FixationArtifact;
+import org.dive4elements.river.artifacts.access.FixRealizingAccess;
+import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended;
+import org.dive4elements.river.utils.RiverUtils;
+
+/**
+ * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer
+ * artifact).
+ *
+ * @author Gernot Belger
+ */
+public class FixAnalysisYearXPathFunction implements XPathFunction {
+
+    public static final String ID = "fix_analysis_year";
+
+    public static final int ARITY = 1;
+
+    private static Logger log = Logger.getLogger(FixAnalysisYearXPathFunction.class);
+
+    private final CallContext context;
+
+    public FixAnalysisYearXPathFunction(final CallContext context) {
+        this.context = context;
+    }
+
+    @Override
+    public Object evaluate(final List args) throws XPathFunctionException {
+
+        // FIXME: get artifact id
+        final UUID uuid = (UUID) args.get(0);
+
+        final FixationArtifact fixation = (FixationArtifact) RiverUtils.getArtifact(uuid.toString(), this.context);
+
+        // FIXME: fetch year
+        // final CalculationResult r = (CalculationResult) fixation.compute(this.context, ComputeType.ADVANCE, false);
+        // final FixRealizingResult frR = (FixRealizingResult) r.getData();
+
+        // Get W/Q input per gauge for this case.
+        final FixRealizingAccess fixAccess = new FixRealizingAccess(fixation);
+        // final List<Segment> segments = fixAccess.getSegments();
+        // final boolean isFixRealize = (segments != null && !segments.isEmpty());
+
+        /* ugly but necessary to keep this logic at least a bit inside the FixRealizing stuff */
+        final FixRealizingCalculationExtended calculation = new FixRealizingCalculationExtended(fixAccess);
+        return calculation.determineMeanYear();
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org