annotate artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 7434:505b05e223b1

Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 25 Oct 2013 03:47:04 +0200
parents af13ceeba52a
children f16dce7a2407
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
9 package org.dive4elements.river.artifacts;
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
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 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
12 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
13 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
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 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
16
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 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
18 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
19 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
20
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
21 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
22 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
23 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
24 import org.dive4elements.artifacts.Hook;
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
25
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
26 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
27 import org.dive4elements.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
28
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
29 import org.dive4elements.artifactdatabase.state.Output;
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
30
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
31 import org.dive4elements.river.artifacts.datacage.Recommendations;
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
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4527
diff changeset
33 /** Monitors collection changes. */
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
34 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
35
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
36 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
37
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4527
diff changeset
38
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
39 @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
40 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
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
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 @Override
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
45 public void execute(Artifact artifact, CallContext context, Document doc) {
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
46 D4EArtifact flys = (D4EArtifact) artifact;
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
47
7434
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
48 // Do not generate recommendations for a loaded artifact.
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
49 String out = flys.getBoundToOut();
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
50 if (out != null && !out.isEmpty()) {
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
51 return;
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
52 }
505b05e223b1 Experimental patch: Do not run datacage on artifacts that are loaded from datacage. His hopefully minimizes the datacage runs when a lot of data is loaded.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
53
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
54 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
55 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
56 XPATH_RESULT,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
57 XPathConstants.NODE,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
58 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
59
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
60 ElementCreator creator = new ElementCreator(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
61 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
62 ArtifactNamespaceContext.NAMESPACE_URI,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
63 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
64
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
65 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
66 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
67
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
68 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
69 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
70
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
71 Recommendations rec = Recommendations.getInstance();
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
72
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
73 // TODO For newer official-lines recommendations we actually
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
74 // need user-id (null here).
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
75 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
76 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
77
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
78
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
79 /**
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
80 * 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
81 * 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
82 */
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
83 public static String[] extractOutputNames(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
84 D4EArtifact flys,
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
85 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
86 {
2132
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
87 if (flys instanceof ChartArtifact) {
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
88 return new String[0];
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
89 }
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
90
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
91 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
92
1012
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
93 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
94
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
95 String[] names = new String[num];
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
96
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
97 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
98 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
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
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
101 return names;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
102 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
103
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
104
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
105 /**
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
106 * Creates Map from Strings "recommended" to "true".
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
107 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 965
diff changeset
108 protected Map<String, Object> getNoneUserSpecificParameters(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
109 D4EArtifact flys,
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
110 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
111 {
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
112 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
113 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
114
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
115 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
116 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org