comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 655:6eccb68a8b99

Added WMS-Publishing to Product Layer gnv-artifacts/trunk@747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 08 Mar 2010 14:04:28 +0000
parents 4fc97074eb90
children 199982e8866e
comparison
equal deleted inserted replaced
654:a6081d76fa1c 655:6eccb68a8b99
5 5
6 import java.io.File; 6 import java.io.File;
7 import java.io.IOException; 7 import java.io.IOException;
8 import java.io.OutputStream; 8 import java.io.OutputStream;
9 import java.util.Collection; 9 import java.util.Collection;
10 import java.util.HashMap;
10 import java.util.Iterator; 11 import java.util.Iterator;
12 import java.util.Map;
11 13
12 import org.apache.log4j.Logger; 14 import org.apache.log4j.Logger;
13 import org.w3c.dom.Document; 15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
14 import org.w3c.dom.Node; 17 import org.w3c.dom.Node;
15 18
16 import com.vividsolutions.jts.geom.Geometry; 19 import com.vividsolutions.jts.geom.Geometry;
17 import com.vividsolutions.jts.io.ParseException; 20 import com.vividsolutions.jts.io.ParseException;
18 import com.vividsolutions.jts.io.WKTReader; 21 import com.vividsolutions.jts.io.WKTReader;
24 import de.intevation.gnv.artifacts.context.GNVArtifactContext; 27 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
25 import de.intevation.gnv.geobackend.base.Result; 28 import de.intevation.gnv.geobackend.base.Result;
26 import de.intevation.gnv.geobackend.base.query.QueryExecutor; 29 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
27 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; 30 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
28 import de.intevation.gnv.geobackend.base.query.exception.QueryException; 31 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
32 import de.intevation.gnv.raster.PaletteManager;
29 import de.intevation.gnv.state.InputData; 33 import de.intevation.gnv.state.InputData;
30 import de.intevation.gnv.state.OutputStateBase; 34 import de.intevation.gnv.state.OutputStateBase;
31 import de.intevation.gnv.state.exception.StateException; 35 import de.intevation.gnv.state.exception.StateException;
32 import de.intevation.gnv.utils.FileUtils; 36 import de.intevation.gnv.utils.FileUtils;
33 import de.intevation.gnv.utils.MapfileGenerator; 37 import de.intevation.gnv.utils.MapfileGenerator;
38 import de.intevation.gnv.utils.MetaWriter;
34 import de.intevation.gnv.utils.ShapeFileWriter; 39 import de.intevation.gnv.utils.ShapeFileWriter;
35 40
36 /** 41 /**
37 * @author Tim Englich <tim.englich@intevation.de> 42 * @author Tim Englich <tim.englich@intevation.de>
38 * 43 *
46 51
47 /** 52 /**
48 * The UID of this Class. 53 * The UID of this Class.
49 */ 54 */
50 private static final long serialVersionUID = 9180957321704424049L; 55 private static final long serialVersionUID = 9180957321704424049L;
56
57 // TODO: Replace
58 public static final String LAYER_MODEL = "layer";
51 59
52 /** 60 /**
53 * The ID for the Query fetching the Layer from the DB 61 * The ID for the Query fetching the Layer from the DB
54 */ 62 */
55 private String dataQueryID = null; 63 private String dataQueryID = null;
66 private String geometryID = null; 74 private String geometryID = null;
67 75
68 private Boolean shapeFileLock = new Boolean(true); 76 private Boolean shapeFileLock = new Boolean(true);
69 77
70 private String shapeFilePath; 78 private String shapeFilePath;
79
80 private String geometryType = null;
71 81
72 public static final String SHAPEFILE_NAME = "data.shp"; 82 public static final String SHAPEFILE_NAME = "data.shp";
73 83
74 /** 84 /**
75 * Constructor 85 * Constructor
90 log.debug("LayerOutputState.out"); 100 log.debug("LayerOutputState.out");
91 String outputMode = XMLUtils.xpathString( 101 String outputMode = XMLUtils.xpathString(
92 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); 102 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE);
93 if (outputMode.equalsIgnoreCase("wms")) { 103 if (outputMode.equalsIgnoreCase("wms")) {
94 Collection<Result> data = this.fetchData(); 104 Collection<Result> data = this.fetchData();
95 // TODO USE ME 105 XMLUtils.toStream(this.getWMS(uuid, callContext, data),outputStream);
96 }else if (outputMode.equalsIgnoreCase("zip")){ 106 }else if (outputMode.equalsIgnoreCase("zip")){
97 Collection<Result> data = this.fetchData(); 107 Collection<Result> data = this.fetchData();
98 this.writeZip(uuid, callContext, outputStream, data); 108 this.writeZip(uuid, callContext, outputStream, data);
99 } 109 }
100 } 110 }
225 } 235 }
226 createdDir = true; 236 createdDir = true;
227 } 237 }
228 238
229 File shapeFile = new File(shapeDir, SHAPEFILE_NAME); 239 File shapeFile = new File(shapeDir, SHAPEFILE_NAME);
230 if (!ShapeFileWriter.writeDataToFile(shapeFile, "data", data)){ 240 if ((geometryType = ShapeFileWriter.writeDataToFile(shapeFile, "data", data)) == null){
231 log.error("writing data into shapefile failed"); 241 log.error("writing data into shapefile failed");
232 return null; 242 return null;
233 } 243 }
234 244
235 shapeFilePath = shapeDir.getAbsolutePath(); 245 shapeFilePath = shapeDir.getAbsolutePath();
331 341
332 public String resetShapeFilePath() { 342 public String resetShapeFilePath() {
333 synchronized (shapeFileLock) { 343 synchronized (shapeFileLock) {
334 String path = shapeFilePath; 344 String path = shapeFilePath;
335 shapeFilePath = null; 345 shapeFilePath = null;
346 geometryType = null;
336 return path; 347 return path;
337 } 348 }
338 } 349 }
339 350 protected Document getWMS(String uuid,
351 CallContext callContext,
352 Collection<Result> data)
353 throws StateException
354 {
355 // TODO: Do the real WMS publishing here!
356 Document document = XMLUtils.newDocument();
357
358 Element pathElement = document.createElement("path");
359 document.appendChild(pathElement);
360
361 String path = getShapeFilePath();
362
363 if (path != null && new File(path).isDirectory()) {
364 pathElement.setTextContent(path);
365 }
366 else {
367
368 if (data != null &&
369 (path = writeToShapeFile(uuid, data, callContext)) != null) {
370
371 String paramType = LAYER_MODEL+"_"+this.geometryType.toLowerCase();
372
373 Document meta = MetaWriter.writeLayerMeta(callContext, uuid,
374 path, paramType,
375 this.determineGeometryType());
376 if (meta != null) {
377 MapfileGenerator.getInstance().update();
378 return meta;
379 }
380
381 pathElement.setTextContent(path);
382 }
383 }
384
385 return document;
386 }
387
388 private String determineGeometryType(){
389
390 String returnValue = this.geometryType.toLowerCase();
391
392 if (returnValue.equalsIgnoreCase("linestring")){
393 returnValue = "Line";
394 }
395 return returnValue;
396 }
397
398 private static Map<Integer, PaletteManager> getPalettes(
399 CallContext callContext
400 ) {
401 //TODO: customize for product Layer
402 GNVArtifactContext context =
403 (GNVArtifactContext)callContext.globalContext();
404 Map<Integer, PaletteManager> palettes =
405 (Map<Integer, PaletteManager>)context.get(
406 GNVArtifactContext.PALETTES_KEY);
407 return palettes != null
408 ? palettes
409 : new HashMap<Integer, PaletteManager>();
410 }
340 411
341 } 412 }

http://dive4elements.wald.intevation.org