9299
|
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.dive4elements.artifactdatabase.data.StateData; |
|
19 import org.dive4elements.artifacts.CallContext; |
|
20 import org.dive4elements.river.artifacts.D4EArtifact; |
|
21 import org.dive4elements.river.utils.RiverUtils; |
|
22 |
|
23 /** |
|
24 * Very specialized function the resolves the 'year' (als middle of all used events) from a fix-analysis-vollmer |
|
25 * artifact). |
|
26 * |
|
27 * @author Gernot Belger |
|
28 */ |
|
29 public class DataFromArtifactXPathFunction implements XPathFunction { |
|
30 |
|
31 public static final String ID = "data_from_artifact"; |
|
32 |
|
33 public static final int ARITY = 2; |
|
34 |
|
35 private final CallContext context; |
|
36 |
|
37 public DataFromArtifactXPathFunction(final CallContext context) { |
|
38 this.context = context; |
|
39 } |
|
40 |
|
41 @Override |
|
42 public Object evaluate(final List args) throws XPathFunctionException { |
|
43 |
|
44 final UUID uuid = (UUID) args.get(0); |
|
45 if (uuid == null) |
|
46 return null; |
|
47 |
|
48 final D4EArtifact artifact = RiverUtils.getArtifact(uuid.toString(), this.context); |
|
49 if (!(args.get(1) instanceof String)) |
|
50 return null; |
|
51 |
|
52 final StateData data = artifact.getData(args.get(1).toString()); |
|
53 return data.getValue(); |
|
54 |
|
55 } |
|
56 } |