annotate artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 7464:f16dce7a2407

Simplified recommendattion monitor code a bit.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 11:57:04 +0100
parents 505b05e223b1
children fff862f4ef76
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 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
16 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
17 import org.w3c.dom.Node;
7464
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
18 import org.w3c.dom.NodeList;
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
19
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
20 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
21 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
22 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
23 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
24
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
25 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
26
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
27 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
28
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
29 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
30
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4527
diff changeset
31 /** 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
32 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
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 @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
35 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
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
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
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
40 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
41 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
42
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
43 // 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
44 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
45 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
46 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
47 }
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
7464
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
49 NodeList results = doc.getElementsByTagNameNS(
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
50 ArtifactNamespaceContext.NAMESPACE_URI, "result");
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
51
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
52 if (results.getLength() < 1) {
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
53 return;
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
54 }
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
55
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
56 Element result = (Element)results.item(0);
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 ElementCreator creator = new ElementCreator(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
59 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
60 ArtifactNamespaceContext.NAMESPACE_URI,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
61 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
62
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
63 Element recommended = creator.create("recommended-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
64
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
65 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
66 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
67
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1012
diff changeset
68 Recommendations rec = Recommendations.getInstance();
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
69
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
70 // TODO For newer official-lines recommendations we actually
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3317
diff changeset
71 // 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
72 rec.recommend(flys, null, outs, params, recommended);
7464
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
73
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
74 result.appendChild(recommended);
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
75 }
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
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
78 /**
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 * 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
80 * 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
81 */
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
82 public static String[] extractOutputNames(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
83 D4EArtifact flys,
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
84 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
85 {
2132
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
86 if (flys instanceof ChartArtifact) {
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
87 return new String[0];
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
88 }
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
89
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
90 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
91
1012
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
92 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
93
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
94 String[] names = new String[num];
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
95
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
96 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
97 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
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
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
100 return names;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
101 }
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
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
104 /**
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
105 * Creates Map from Strings "recommended" to "true".
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
106 */
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 965
diff changeset
107 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
108 D4EArtifact flys,
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
109 CallContext context)
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
110 {
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
111 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
112 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
113
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
114 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
115 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org