annotate artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents f8e1af4e2f69
children 5030c46d8cb4
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
7482
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
11 import java.util.Arrays;
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
12 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
13 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
14 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
15
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
16 import net.sf.ehcache.Cache;
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
17
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
18 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
19 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
20 import org.w3c.dom.Node;
7464
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
21 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
22
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
23 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
24 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
25 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
26 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
27
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
28 import org.dive4elements.artifacts.common.utils.XMLUtils;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
29 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
30
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
31 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
32
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
33 import org.dive4elements.river.artifacts.cache.CacheFactory;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5107
diff changeset
34 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
35
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4527
diff changeset
36 /** 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
37 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
38
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
39 public static final String CACHE_NAME = "recommendations";
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
40
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
41 @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
42 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
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
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
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 @Override
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
47 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
48 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
49
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
50 // 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
51 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
52 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
53 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
54 }
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
55
7464
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
56 NodeList results = doc.getElementsByTagNameNS(
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
57 ArtifactNamespaceContext.NAMESPACE_URI, "result");
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
58
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
59 if (results.getLength() < 1) {
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
60 return;
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
61 }
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
62
f16dce7a2407 Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7434
diff changeset
63 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
64
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
65 result.appendChild(getRecommendedElement(flys, context, doc));
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
66 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
67
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
68 protected Element getRecommendedElement(
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
69 D4EArtifact artifact,
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
70 CallContext context,
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
71 Document doc
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
72 ) {
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
73 String [] outs = extractOutputNames(artifact, context);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
74
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
75 Element recommendations = null;
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
76
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
77 Cache cache = CacheFactory.getCache(CACHE_NAME);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
78
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
79 if (cache != null) {
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
80 String key = generateCacheKey(artifact, outs);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
81
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
82 net.sf.ehcache.Element ce = cache.get(key);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
83 if (ce != null) { // Found in cache.
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
84 Element e = (Element)ce.getValue();
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
85 // Sync to avoid thread issues with XML DOM docs.
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
86 synchronized (e.getOwnerDocument()) {
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
87 recommendations = (Element)doc.importNode(e, true);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
88 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
89 } else { // Not found in cache -> generate it.
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
90 Element r = createElement(XMLUtils.newDocument());
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
91
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
92 Recommendations.getInstance().recommend(
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
93 artifact, null, outs,
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
94 getNoneUserSpecificParameters(artifact, context), r);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
95
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
96 recommendations = (Element)doc.importNode(r, true);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
97
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
98 cache.put(new net.sf.ehcache.Element(key, r));
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
99 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
100 } else { // No cache configured -> append directly.
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
101
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
102 recommendations = createElement(doc);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
103
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
104 Recommendations.getInstance().recommend(
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
105 artifact, null, outs,
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
106 getNoneUserSpecificParameters(artifact, context),
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
107 recommendations);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
108 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
109
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
110 return recommendations;
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
111 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
112
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
113 private static final Element createElement(Document doc) {
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
114 ElementCreator creator = new ElementCreator(
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
115 doc,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
116 ArtifactNamespaceContext.NAMESPACE_URI,
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
117 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
118
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
119 return creator.create("recommended-artifacts");
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
120 }
940
f4439e015278 Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 937
diff changeset
121
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 7482
diff changeset
122 private static final String generateCacheKey(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 7482
diff changeset
123 D4EArtifact artifact,
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 7482
diff changeset
124 String [] outs
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 7482
diff changeset
125 ) {
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
126 StringBuilder sb = new StringBuilder(artifact.hash());
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
127 // XXX: The hash really should be unique enough.
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
128 for (String out: outs) {
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
129 sb.append(';').append(out);
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
130 }
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
131 return sb.toString();
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
132 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
133
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
134
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
135 /**
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
136 * 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
137 * 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
138 */
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
139 private static final String [] extractOutputNames(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
140 D4EArtifact flys,
7482
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
141 CallContext context
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
142 ) {
2132
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
143 if (flys instanceof ChartArtifact) {
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
144 return new String[0];
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
145 }
e8fc770d2f8c 'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1858
diff changeset
146
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
147 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
148
1012
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
149 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
150
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
151 String[] names = new String[num];
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
152
388e709224ec Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 998
diff changeset
153 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
154 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
155 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156
7482
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
157 // Sort them to make cache key generation consistent.
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
158 Arrays.sort(names);
f8e1af4e2f69 Datacage recommendations: Sort outs to to generate consistent cache keys.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7471
diff changeset
159
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
160 return names;
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
161 }
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
162
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
163
4527
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
164 /**
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
165 * Creates Map from Strings "recommended" to "true".
06c10ad39280 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
166 */
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
167 private static final Map<String, Object> getNoneUserSpecificParameters(
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
168 D4EArtifact flys,
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
169 CallContext context)
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
170 {
7471
fff862f4ef76 Experimental caching of datacage recommendations. The respective hook is called a lot and running the datacage over and over again when loading data can be expensive. So the generated recommendations are cached for some time.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7464
diff changeset
171 Map<String, Object> params = new HashMap<String, Object>();
964
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
172 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
173
ff6ce301c472 Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 940
diff changeset
174 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
175 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
9e813e9137a5 Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org