annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java @ 2102:16e74c5e636f

Cosmetics. flys-artifacts/trunk@3659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 12 Jan 2012 12:20:56 +0000
parents 94871b7ce9e9
children e8fc770d2f8c
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
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
23 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
24
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
25 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
26
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
27
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 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
29
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
30 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
31
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 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
34 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
35
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 @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
38 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
39 }
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 @Override
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
43 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
44 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
45
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
46 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
47 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
48 XPATH_RESULT,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
49 XPathConstants.NODE,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
50 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
51
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
52 ElementCreator creator = new ElementCreator(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
53 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
54 ArtifactNamespaceContext.NAMESPACE_URI,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
55 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
56
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
57 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
58 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
59
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
60 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
61 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
62
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
63 Recommendations rec = Recommendations.getInstance();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
64 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
65 }
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
1834
9eedda250280 Extract output names from artifact, not from state. Important when querying recommendations for an artifact with these outputs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1654
diff changeset
68 /**
9eedda250280 Extract output names from artifact, not from state. Important when querying recommendations for an artifact with these outputs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1654
diff changeset
69 * Get outputnames from current state (only the ones for which
9eedda250280 Extract output names from artifact, not from state. Important when querying recommendations for an artifact with these outputs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1654
diff changeset
70 * facets exist).
9eedda250280 Extract output names from artifact, not from state. Important when querying recommendations for an artifact with these outputs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1654
diff changeset
71 */
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
72 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
73 FLYSArtifact flys,
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
74 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
75 {
1834
9eedda250280 Extract output names from artifact, not from state. Important when querying recommendations for an artifact with these outputs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1654
diff changeset
76 List<Output> outs = flys.getCurrentOutputs(context);
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
77
1012
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
78 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
79
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
80 String[] names = new String[num];
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
81
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
82 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
83 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
84 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
86 return names;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
87 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
88
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
89
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 965
diff changeset
90 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
91 FLYSArtifact flys,
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
92 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
93 {
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
94 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
95 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
96
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
97 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
98 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org