changeset 2092:0ccabd82ec76

Added missing service to invalidate the caches via the REST interface. flys-artifacts/trunk@3620 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 07 Jan 2012 08:02:56 +0000
parents 5d158f8ad080
children ebc2aa64c1be
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CacheInvalidationService.java
diffstat 2 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jan 06 14:19:35 2012 +0000
+++ b/flys-artifacts/ChangeLog	Sat Jan 07 08:02:56 2012 +0000
@@ -1,3 +1,8 @@
+2012-01-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/CacheInvalidationService.java:
+	  New. The service to invalidate the caches. (Argh! Forgot to 'svn add')
+
 2012-01-06  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue298 (Karte: Automatischer Zoom auf Berechnungsergebnisse)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CacheInvalidationService.java	Sat Jan 07 08:02:56 2012 +0000
@@ -0,0 +1,54 @@
+package de.intevation.flys.artifacts.services;
+
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.GlobalContext;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifactdatabase.DefaultService;
+
+import de.intevation.flys.artifacts.cache.CacheFactory;
+
+import net.sf.ehcache.Cache;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class CacheInvalidationService 
+extends      DefaultService
+{
+    @Override
+    public Document process(
+        Document      data,
+        GlobalContext globalContext,
+        CallMeta      callMeta
+    ) {
+        Document result = XMLUtils.newDocument();
+
+        Element all = result.createElement("caches");
+
+        NodeList caches = data.getElementsByTagName("cache");
+
+        for (int i = 0, C = caches.getLength(); i < C; ++i) {
+            Element c = (Element)caches.item(i);
+            String name = c.getAttribute("name");
+            Element e = result.createElement("cache");
+            e.setAttribute("name", name);
+            Cache cache = CacheFactory.getCache(name);
+            if (cache != null) {
+                cache.removeAll();
+                e.setTextContent("All elements removed.");
+            }
+            else {
+                e.setTextContent("Error: Cache not found.");
+            }
+            all.appendChild(e);
+        }
+
+        result.appendChild(all);
+
+        return result;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org