diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 772:cd64ab8a46a7

Put time to live of an artifact into meta document which is created while wms publishing (issue197). gnv-artifacts/trunk@829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 26 Mar 2010 09:21:31 +0000
parents 452fad121560
children 5fb1ea68e19c
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Thu Mar 25 09:01:14 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Fri Mar 26 09:21:31 2010 +0000
@@ -5,6 +5,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Date;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -26,6 +27,7 @@
     public static final String NODE_MAPSERVER = "mapserver";
     public static final String NODE_SERVER    = "server";
     public static final String NODE_MAP       = "map";
+    public static final String NODE_TTL       = "ttl";
 
     public static final String META_FILE_NAME = "meta.xml";
     public static final String ISOLINES_NAME  = "isolines.shp";
@@ -156,8 +158,10 @@
         String map = (String)
             context.get(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY);
 
-        logger.debug("MAPSERVER PATH: " + server);
-        logger.debug("MAP PATH: " + map);
+        if (logger.isDebugEnabled()) {
+            logger.debug("MAPSERVER PATH: " + server);
+            logger.debug("MAP PATH: " + map);
+        }
 
         Element mapserver  = creator.create(NODE_MAPSERVER);
         Element serverPath = creator.create(NODE_SERVER);
@@ -172,7 +176,7 @@
     }
 
     protected static void writeLayerMeta(
-        CallContext context,
+        CallContext callContext,
         Document    document,
         Element     meta,
         String      uuid,
@@ -184,24 +188,33 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        Element layer  = creator.create(LayerInfo.LAYER);
-        Element model  = creator.create(LayerInfo.LAYER_MODEL);
-        Element name   = creator.create(LayerInfo.LAYER_NAME);
-        Element type   = creator.create(LayerInfo.LAYER_TYPE);
-        Element status = creator.create(LayerInfo.LAYER_STATUS);
-        Element data   = creator.create(LayerInfo.LAYER_DATA);
+        Long time  = callContext.getTimeToLive();
+        time      += new Date().getTime();
+        String ttl = time != null ? time.toString() : null;
+
+        logger.debug("Artifacts time to live: " + ttl);
+
+        Element layer      = creator.create(LayerInfo.LAYER);
+        Element model      = creator.create(LayerInfo.LAYER_MODEL);
+        Element name       = creator.create(LayerInfo.LAYER_NAME);
+        Element type       = creator.create(LayerInfo.LAYER_TYPE);
+        Element status     = creator.create(LayerInfo.LAYER_STATUS);
+        Element data       = creator.create(LayerInfo.LAYER_DATA);
+        Element timeToLive = creator.create(NODE_TTL);
 
         model.setTextContent(paramType);
         name.setTextContent(uuid);
         type.setTextContent(layerType);
         status.setTextContent("OFF");
         data.setTextContent(LAYER_DATA_NAME);
+        timeToLive.setTextContent(ttl);
 
         layer.appendChild(model);
         layer.appendChild(name);
         layer.appendChild(type);
         layer.appendChild(status);
         layer.appendChild(data);
+        layer.appendChild(timeToLive);
 
         meta.appendChild(layer);
     }
@@ -220,6 +233,12 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
+        Long time  = context.getTimeToLive();
+        time      += new Date().getTime();
+        String ttl = time != null ? time.toString() : null;
+
+        logger.debug("Artifacts time to live: " + ttl);
+
         Element layer  = creator.create(LayerInfo.LAYER);
         Element model  = creator.create(LayerInfo.LAYER_MODEL);
         Element name   = creator.create(LayerInfo.LAYER_NAME);
@@ -227,6 +246,7 @@
         Element type   = creator.create(LayerInfo.LAYER_TYPE);
         Element status = creator.create(LayerInfo.LAYER_STATUS);
         Element data   = creator.create(LayerInfo.LAYER_DATA);
+        Element timeToLive = creator.create(NODE_TTL);
 
         model.setTextContent(paramType);
         name.setTextContent(uuid);
@@ -235,6 +255,7 @@
         type.setTextContent("POLYGON");
         status.setTextContent("OFF");
         data.setTextContent(POLYGON_NAME);
+        timeToLive.setTextContent(ttl);
 
         layer.appendChild(model);
         layer.appendChild(name);
@@ -242,6 +263,7 @@
         layer.appendChild(type);
         layer.appendChild(status);
         layer.appendChild(data);
+        layer.appendChild(timeToLive);
 
         meta.appendChild(layer);
     }
@@ -260,6 +282,12 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
+        Long time  = context.getTimeToLive();
+        time      += new Date().getTime();
+        String ttl = time != null ? time.toString() : null;
+
+        logger.debug("Artifacts time to live: " + ttl);
+
         Element layer  = creator.create(LayerInfo.LAYER);
         Element model  = creator.create(LayerInfo.LAYER_MODEL);
         Element name   = creator.create(LayerInfo.LAYER_NAME);
@@ -267,6 +295,7 @@
         Element type   = creator.create(LayerInfo.LAYER_TYPE);
         Element status = creator.create(LayerInfo.LAYER_STATUS);
         Element data   = creator.create(LayerInfo.LAYER_DATA);
+        Element timeToLive = creator.create(NODE_TTL);
 
         model.setTextContent(paramType+"_isolines");
         name.setTextContent(uuid);
@@ -275,6 +304,7 @@
         type.setTextContent("LINE");
         status.setTextContent("OFF");
         data.setTextContent(ISOLINES_NAME);
+        timeToLive.setTextContent(ttl);
 
         layer.appendChild(model);
         layer.appendChild(name);
@@ -282,6 +312,7 @@
         layer.appendChild(type);
         layer.appendChild(status);
         layer.appendChild(data);
+        layer.appendChild(timeToLive);
 
         meta.appendChild(layer);
     }

http://dive4elements.wald.intevation.org