Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9231:082e8e808902 | 9232:5030c46d8cb4 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.datacage.templating; | |
11 | |
12 import java.util.List; | |
13 import java.util.UUID; | |
14 | |
15 import javax.xml.xpath.XPathFunction; | |
16 import javax.xml.xpath.XPathFunctionException; | |
17 | |
18 import org.apache.log4j.Logger; | |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.artifacts.FixationArtifact; | |
21 import org.dive4elements.river.artifacts.access.FixRealizingAccess; | |
22 import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended; | |
23 import org.dive4elements.river.utils.RiverUtils; | |
24 | |
25 /** | |
26 * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer | |
27 * artifact). | |
28 * | |
29 * @author Gernot Belger | |
30 */ | |
31 public class FixAnalysisYearXPathFunction implements XPathFunction { | |
32 | |
33 public static final String ID = "fix_analysis_year"; | |
34 | |
35 public static final int ARITY = 1; | |
36 | |
37 private static Logger log = Logger.getLogger(FixAnalysisYearXPathFunction.class); | |
38 | |
39 private final CallContext context; | |
40 | |
41 public FixAnalysisYearXPathFunction(final CallContext context) { | |
42 this.context = context; | |
43 } | |
44 | |
45 @Override | |
46 public Object evaluate(final List args) throws XPathFunctionException { | |
47 | |
48 // FIXME: get artifact id | |
49 final UUID uuid = (UUID) args.get(0); | |
50 | |
51 final FixationArtifact fixation = (FixationArtifact) RiverUtils.getArtifact(uuid.toString(), this.context); | |
52 | |
53 // FIXME: fetch year | |
54 // final CalculationResult r = (CalculationResult) fixation.compute(this.context, ComputeType.ADVANCE, false); | |
55 // final FixRealizingResult frR = (FixRealizingResult) r.getData(); | |
56 | |
57 // Get W/Q input per gauge for this case. | |
58 final FixRealizingAccess fixAccess = new FixRealizingAccess(fixation); | |
59 // final List<Segment> segments = fixAccess.getSegments(); | |
60 // final boolean isFixRealize = (segments != null && !segments.isEmpty()); | |
61 | |
62 /* ugly but necessary to keep this logic at least a bit inside the FixRealizing stuff */ | |
63 final FixRealizingCalculationExtended calculation = new FixRealizingCalculationExtended(fixAccess); | |
64 return calculation.determineMeanYear(); | |
65 } | |
66 } |