Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 7477:bc16d5031b31
issue1657: Spawn BEDHEIGHT_SOUNDING_WIDTH facet if asked to. Twiggly.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 31 Oct 2013 11:43:32 +0100 |
parents | fff862f4ef76 |
children | f8e1af4e2f69 |
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 |
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
|
15 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
|
16 |
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
|
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; |
7464
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
20 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
|
21 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
22 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
23 import org.dive4elements.artifacts.ArtifactNamespaceContext; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
24 import org.dive4elements.artifacts.CallContext; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
25 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
|
26 |
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
|
27 import org.dive4elements.artifacts.common.utils.XMLUtils; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
28 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
|
29 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
30 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
|
31 |
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
|
32 import org.dive4elements.river.artifacts.cache.CacheFactory; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5107
diff
changeset
|
33 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
|
34 |
5107
a929d9a9fa1e
Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4527
diff
changeset
|
35 /** 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
|
36 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
|
37 |
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
|
38 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
|
39 |
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
|
40 @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
|
41 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
|
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 |
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 @Override |
940
f4439e015278
Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
937
diff
changeset
|
46 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
|
47 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
|
48 |
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
|
49 // 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
|
50 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
|
51 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
|
52 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
|
53 } |
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 |
7464
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
55 NodeList results = doc.getElementsByTagNameNS( |
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
56 ArtifactNamespaceContext.NAMESPACE_URI, "result"); |
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
57 |
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
58 if (results.getLength() < 1) { |
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
59 return; |
f16dce7a2407
Simplified recommendattion monitor code a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7434
diff
changeset
|
60 } |
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 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
|
63 |
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
|
64 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
|
65 } |
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 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
|
68 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
|
69 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
|
70 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
|
71 ) { |
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 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
|
73 |
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 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
|
75 |
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 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
|
77 |
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 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
|
79 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
|
80 |
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 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
|
82 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
|
83 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
|
84 // 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
|
85 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
|
86 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
|
87 } |
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 } 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
|
89 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
|
90 |
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 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
|
92 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
|
93 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
|
94 |
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 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
|
96 |
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 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
|
98 } |
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 } 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
|
100 |
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 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
|
102 |
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 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
|
104 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
|
105 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
|
106 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
|
107 } |
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 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
|
110 } |
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 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
|
113 ElementCreator creator = new ElementCreator( |
f4439e015278
Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
937
diff
changeset
|
114 doc, |
f4439e015278
Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
937
diff
changeset
|
115 ArtifactNamespaceContext.NAMESPACE_URI, |
f4439e015278
Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
937
diff
changeset
|
116 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
|
117 |
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
|
118 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
|
119 } |
940
f4439e015278
Append artifact recommendations to the artifact's describe document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
937
diff
changeset
|
120 |
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
|
121 private static final String generateCacheKey(D4EArtifact artifact, String [] 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
|
122 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
|
123 // 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
|
124 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
|
125 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
|
126 } |
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 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
|
128 } |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
129 |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
130 |
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
|
131 /** |
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
|
132 * 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
|
133 * 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
|
134 */ |
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
|
135 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
|
136 D4EArtifact flys, |
964
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
137 CallContext context) |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
138 { |
2132
e8fc770d2f8c
'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1858
diff
changeset
|
139 if (flys instanceof ChartArtifact) { |
e8fc770d2f8c
'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1858
diff
changeset
|
140 return new String[0]; |
e8fc770d2f8c
'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1858
diff
changeset
|
141 } |
e8fc770d2f8c
'New Chart' for computed discharge curve.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1858
diff
changeset
|
142 |
4527
06c10ad39280
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
143 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
|
144 |
1012
388e709224ec
Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
145 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
|
146 |
388e709224ec
Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
147 String[] names = new String[num]; |
388e709224ec
Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
148 |
388e709224ec
Fixed potential NPE in collection monitor
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
998
diff
changeset
|
149 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
|
150 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
|
151 } |
9e813e9137a5
Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 |
964
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
153 return names; |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
154 } |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
155 |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
156 |
4527
06c10ad39280
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
157 /** |
06c10ad39280
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
158 * Creates Map from Strings "recommended" to "true". |
06c10ad39280
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
159 */ |
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
|
160 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
|
161 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
|
162 CallContext context) |
964
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
163 { |
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
|
164 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
|
165 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
|
166 |
ff6ce301c472
Modified the CollectionMonitor (for recommended artifacts) to use the DataCage.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
940
diff
changeset
|
167 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
|
168 } |
9e813e9137a5
Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
169 } |
9e813e9137a5
Added a monitor that creates new artifacts for default themes in charts and maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |