Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/services/CacheInvalidationService.java @ 8755:30b1ddadf275
(issue1801) Unify reference gauge finding code
The basic way as described in the method comment of the
determineRefGauge method is now used in the WINFOArtifact,
MainValuesService and RiverUtils.getGauge method.
RiverUtils.getGauge previously just returned the first
gauge found. While this is now a behavior change I believe
that it is always more correct then the undeterministic
behavior of the previous implmenentation.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 24 Jun 2015 14:07:26 +0200 |
parents | af13ceeba52a |
children |
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:
5863
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:
5863
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:
3076
diff
changeset
|
9 package org.dive4elements.river.artifacts.services; |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
11 import org.dive4elements.artifacts.CallMeta; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
12 import org.dive4elements.artifacts.GlobalContext; |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
14 import org.dive4elements.artifacts.common.utils.XMLUtils; |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
16 import org.dive4elements.artifactdatabase.XMLService; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
17 |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3076
diff
changeset
|
18 import org.dive4elements.river.artifacts.cache.CacheFactory; |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import net.sf.ehcache.Cache; |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.w3c.dom.Document; |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import org.w3c.dom.Element; |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.w3c.dom.NodeList; |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2607
diff
changeset
|
26 public class CacheInvalidationService |
2607
247f3e98a14b
Abjusted services to new hierachy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2092
diff
changeset
|
27 extends XMLService |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 { |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 @Override |
2607
247f3e98a14b
Abjusted services to new hierachy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2092
diff
changeset
|
30 public Document processXML( |
2092
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 Document data, |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 GlobalContext globalContext, |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 CallMeta callMeta |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 ) { |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 Document result = XMLUtils.newDocument(); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Element all = result.createElement("caches"); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 NodeList caches = data.getElementsByTagName("cache"); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 for (int i = 0, C = caches.getLength(); i < C; ++i) { |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Element c = (Element)caches.item(i); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 String name = c.getAttribute("name"); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 Element e = result.createElement("cache"); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 e.setAttribute("name", name); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 Cache cache = CacheFactory.getCache(name); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 if (cache != null) { |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 cache.removeAll(); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 e.setTextContent("All elements removed."); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 else { |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 e.setTextContent("Error: Cache not found."); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 all.appendChild(e); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 result.appendChild(all); |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 return result; |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
0ccabd82ec76
Added missing service to invalidate the caches via the REST interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |