changeset 828:28028979c813

Integrated the possibility to change the Title of an Layer in Product Layer. gnv-artifacts/trunk@922 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Apr 2010 14:22:52 +0000
parents fe0263926870
children 95733e564896
files gnv-artifacts/doc/conf/products/layer/conf.xml gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java
diffstat 2 files changed, 92 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/doc/conf/products/layer/conf.xml	Tue Apr 13 12:39:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/layer/conf.xml	Tue Apr 13 14:22:52 2010 +0000
@@ -88,7 +88,11 @@
             </inputvalues>
             <outputsModes>
                 <outputsMode name="zip" description="Export als ZIP-Archiv" mime-type="application/zip"/>
-                <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url"/>
+                <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url">
+                    <parameters>
+                        <inputvalue name="title" type="String" value="Layer Title"/>
+                    </parameters>
+                </outputsMode>
             </outputsModes>
         </state>
          
@@ -122,7 +126,11 @@
             </inputvalues>
             <outputsModes>
                 <outputsMode name="zip" description="Export als ZIP-Archiv" mime-type="application/zip"/>
-                <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url"/>
+                <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url">
+                    <parameters>
+                        <inputvalue name="title" type="String" value="Layer Title"/>
+                    </parameters>
+                </outputsMode>
             </outputsModes>
          </state>
         
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Tue Apr 13 12:39:16 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Tue Apr 13 14:22:52 2010 +0000
@@ -28,6 +28,7 @@
 import de.intevation.gnv.state.OutputStateBase;
 import de.intevation.gnv.state.exception.StateException;
 import de.intevation.gnv.utils.ArtifactXMLUtilities;
+import de.intevation.gnv.utils.ExclusiveExec;
 import de.intevation.gnv.utils.FileUtils;
 import de.intevation.gnv.utils.MapfileGenerator;
 import de.intevation.gnv.utils.MetaWriter;
@@ -127,7 +128,8 @@
             Collection<Result> data = this.fetchData();
             if (data != null && !data.isEmpty()){
                 XMLUtils.toStream(this.getWMS(uuid, callContext,
-                                              data, geometryType),
+                                              data, geometryType,
+                                              inputData),
                                   outputStream);
             }else{
                 this.writeExceptionReport2Stream(outputStream);
@@ -399,13 +401,10 @@
 
         try {
             synchronized (shapeFileLock) {
-                int count = 0;
-                while (shapeDir.exists()) {
-                    shapeDir = new File(baseDir, uuid + "-" + count);
-                    ++count;
+                if (shapeDir.exists()) {
+                    FileUtils.deleteContent(shapeDir);
                 }
-
-                if (!shapeDir.mkdirs()) {
+                else if (!shapeDir.mkdirs()) {
                     log.error("cannot create directory '"
                         + shapeDir.getAbsolutePath() + "'");
                     return null;
@@ -556,6 +555,7 @@
      * @param callContext The CallContext object.
      * @param data A collection with some input data.
      * @param geometryType The geometry type.
+     * @param inputData the Parameters which are send by the out-Call.
      * @return a document with some meta information (shapefile path, geometry
      * type, time to live of the current artifact, etc).
      * @throws StateException if an error occured while shapefile writing.
@@ -563,7 +563,8 @@
     protected Document getWMS(String uuid,
                               CallContext callContext,
                               Collection<Result> data,
-                              String geometryType)
+                              String geometryType,
+                              Collection<InputData> inputData)
     throws StateException
     {
         Document document = XMLUtils.newDocument();
@@ -574,35 +575,89 @@
         String path = getShapeFilePath();
 
         if (path != null && new File(path).isDirectory()) {
+            String title = getLayerTitle(inputData);
+            if (title == null) {
+                title = uuid;
+            }
+
+            callContext.putContextValue(
+                MetaWriter.CONTEXT_LAYER_TITLE, title);
+
+            String paramType = findParameterTitle(geometryType);
+
+            if (log.isDebugEnabled()) {
+                log.debug("Layer title: " + title);
+                log.debug("Layer type: " + paramType);
+            }
+
+            Document meta = MetaWriter.writeHorizontalcrosssectionMeta(
+                callContext, uuid, path, paramType);
+            if (meta != null) {
+                MapfileGenerator.getInstance().update();
+                return meta;
+            }
+
             pathElement.setTextContent(path);
         }
         else {
-
-            if (data != null &&
-                (path = writeToShapeFile(uuid, data, callContext,geometryType)) != null) {
-
-                String paramType = LAYER_MODEL+"_"+templateID;
-
-                if (!MapfileGenerator.getInstance().templateExists(paramType)){
-                    // If the template doesn't exist the Defaulttemplates will be used.
-                    paramType = LAYER_MODEL+"_"+
-                                this.determineDefaultTemplateName(geometryType);
+            ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid);
+            try{
+                if (data != null &&
+                    (path = writeToShapeFile(uuid, data, callContext,geometryType)) != null) {
+                    String paramType = findParameterTitle(geometryType);
+                    String    title      = getLayerTitle(inputData);
+                    if (title == null) {
+                        title = uuid;
+                    }
+                    Document meta = MetaWriter.writeLayerMeta(callContext, uuid,
+                                                              path, paramType,
+                                                              this.determineGeometryType(geometryType));
+                    if (meta != null) {
+                        MapfileGenerator.getInstance().update();
+                        return meta;
+                    }
+                    pathElement.setTextContent(path);
                 }
-                Document meta = MetaWriter.writeLayerMeta(callContext, uuid,
-                                                          path, paramType,
-                                                          this.determineGeometryType(geometryType));
-                if (meta != null) {
-                    MapfileGenerator.getInstance().update();
-                    return meta;
-                }
-
-                pathElement.setTextContent(path);
+            }finally{
+                ExclusiveExec.INSTANCE.release(key);
             }
         }
 
         return document;
     }
 
+    /**
+     * Returns the parameterType for the Layer.
+     * @param geometryType
+     * @return
+     */
+    private String findParameterTitle(String geometryType) {
+        String paramType = LAYER_MODEL+"_"+templateID;
+   
+        if (!MapfileGenerator.getInstance().templateExists(paramType)){
+            // If the template doesn't exist the Defaulttemplates will be used.
+            paramType = LAYER_MODEL+"_"+
+                        this.determineDefaultTemplateName(geometryType);
+        }
+        return paramType;
+    }
+
+    /**
+     * Find the title for a wms layer specified by the user.
+     *
+     * @param inputData A collection with InputData objects.
+     * @return the title.
+     */
+    protected String getLayerTitle(Collection<InputData> inputData) {
+        for (InputData data: inputData) {
+            String name = data.getName();
+            if (name != null && name.equals("title")) {
+                return (String) data.getValue();
+            }
+        }
+        return null;
+    }
+
 
     /**
      * Turns the geometry type into a form used for the templating mechanism

http://dive4elements.wald.intevation.org