annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FixAnalysisYearXPathFunction.java @ 9234:2d4750874c57

Cleanup and more fail safe
author gernotbelger
date Fri, 06 Jul 2018 13:12:04 +0200
parents 5030c46d8cb4
children abf4d0b10270
rev   line source
9232
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
2 * Software engineering by
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
5 *
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
9 */
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
10 package org.dive4elements.river.artifacts.datacage.templating;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
11
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
12 import java.util.List;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
13 import java.util.UUID;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
14
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
15 import javax.xml.xpath.XPathFunction;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
16 import javax.xml.xpath.XPathFunctionException;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
17
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
18 import org.dive4elements.artifacts.CallContext;
9234
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
19 import org.dive4elements.river.artifacts.D4EArtifact;
9232
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
20 import org.dive4elements.river.artifacts.FixationArtifact;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
21 import org.dive4elements.river.artifacts.access.FixRealizingAccess;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
22 import org.dive4elements.river.artifacts.model.fixings.FixRealizingCalculationExtended;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
23 import org.dive4elements.river.utils.RiverUtils;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
24
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
25 /**
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
26 * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
27 * artifact).
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
28 *
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
29 * @author Gernot Belger
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
30 */
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
31 public class FixAnalysisYearXPathFunction implements XPathFunction {
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
32
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
33 public static final String ID = "fix_analysis_year";
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
34
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
35 public static final int ARITY = 1;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
36
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
37 private final CallContext context;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
38
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
39 public FixAnalysisYearXPathFunction(final CallContext context) {
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
40 this.context = context;
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
41 }
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
42
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
43 @Override
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
44 public Object evaluate(final List args) throws XPathFunctionException {
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
45
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
46 final UUID uuid = (UUID) args.get(0);
9234
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
47 if (uuid == null)
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
48 return null;
9232
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
49
9234
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
50 final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context);
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
51 if (!(artifact instanceof FixationArtifact))
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
52 return null;
9232
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
53
9234
2d4750874c57 Cleanup and more fail safe
gernotbelger
parents: 9232
diff changeset
54 final FixationArtifact fixation = (FixationArtifact) artifact;
9232
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
55
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
56 // Get W/Q input per gauge for this case.
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
57 final FixRealizingAccess fixAccess = new FixRealizingAccess(fixation);
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
58
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
59 /* ugly but necessary to keep this logic at least a bit inside the FixRealizing stuff */
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
60 final FixRealizingCalculationExtended calculation = new FixRealizingCalculationExtended(fixAccess);
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
61 return calculation.determineMeanYear();
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
62 }
5030c46d8cb4 Implemented xpath function that selectes the 'mean year' of a fixation-artifact.
gernotbelger
parents:
diff changeset
63 }

http://dive4elements.wald.intevation.org