annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java @ 1809:f6a190f6aaff

Give outputname to artifacts getInitialFacetActivity, generate second pair of MainvalueFacets for discharge curves. flys-artifacts/trunk@3138 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 11:21:57 +0000
parents 33ade8153d74
children 9eedda250280
rev   line source
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.util.HashMap;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.List;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.util.Map;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import javax.xml.xpath.XPathConstants;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import org.apache.log4j.Logger;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import org.w3c.dom.Document;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import org.w3c.dom.Element;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.w3c.dom.Node;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.Artifact;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.artifacts.ArtifactNamespaceContext;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.artifacts.CallContext;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import de.intevation.artifacts.Hook;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import de.intevation.artifacts.common.utils.XMLUtils;
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
21 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
1654
33ade8153d74 Little modifications for making recommendations - will now work for states with background calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1015
diff changeset
23 import de.intevation.artifactdatabase.state.State;
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
24 import de.intevation.artifactdatabase.state.Output;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
25
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
26 import de.intevation.flys.artifacts.datacage.Recommendations;
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
27
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public class CollectionMonitor implements Hook {
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
31 public static final String XPATH_RESULT = "/art:result";
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 private static final Logger logger =
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 Logger.getLogger(CollectionMonitor.class);
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 @Override
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 public void setup(Node cfg) {
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 @Override
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
44 public void execute(Artifact artifact, CallContext context, Document doc) {
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 FLYSArtifact flys = (FLYSArtifact) artifact;
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
47 Element result = (Element) XMLUtils.xpath(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
48 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
49 XPATH_RESULT,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
50 XPathConstants.NODE,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
51 ArtifactNamespaceContext.INSTANCE);
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
53 ElementCreator creator = new ElementCreator(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
54 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
55 ArtifactNamespaceContext.NAMESPACE_URI,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
56 ArtifactNamespaceContext.NAMESPACE_PREFIX);
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
58 Element recommended = creator.create("recommended-artifacts");
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
59 result.appendChild(recommended);
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
61 String[] outs = extractOutputNames(flys, context);
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 965
diff changeset
62 Map<String, Object> params = getNoneUserSpecificParameters(flys, context);
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
63
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
64 Recommendations rec = Recommendations.getInstance();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
65 rec.recommend(flys, null, outs, params, recommended);
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
66 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
67
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
68
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
69 public static String[] extractOutputNames(
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
70 FLYSArtifact flys,
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
71 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
72 {
1654
33ade8153d74 Little modifications for making recommendations - will now work for states with background calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1015
diff changeset
73 State state = flys.getCurrentState(context);
33ade8153d74 Little modifications for making recommendations - will now work for states with background calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1015
diff changeset
74 List<Output> outs = state.getOutputs();
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
75
1012
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
76 int num = outs == null ? 0 : outs.size();
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
77
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
78 String[] names = new String[num];
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
79
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
80 for (int i = 0; i < num; i++) {
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
81 names[i] = outs.get(i).getName();
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
84 return names;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
85 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
86
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
87
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 965
diff changeset
88 protected Map<String, Object> getNoneUserSpecificParameters(
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
89 FLYSArtifact flys,
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
90 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
91 {
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
92 Map<String, Object> params = new HashMap<String, Object>(1);
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
93 params.put("recommended", "true");
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
94
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
95 return params;
937
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org