annotate gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 780:c4156275c1e1

Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>' gnv-artifacts/trunk@857 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 09:35:44 +0000
parents b1f5f2a8840f
children feeaf5aec552
rev   line source
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.state.layer;
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
3 import com.vividsolutions.jts.geom.Geometry;
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
4
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
5 import com.vividsolutions.jts.io.ParseException;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
6 import com.vividsolutions.jts.io.WKTReader;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
7
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
8 import de.intevation.artifactdatabase.Config;
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 import de.intevation.artifactdatabase.XMLUtils;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
10
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.ArtifactNamespaceContext;
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.CallContext;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
14 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
15
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 import de.intevation.gnv.geobackend.base.Result;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
17
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
18 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
19 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
20
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
21 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
22
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
23 import de.intevation.gnv.state.InputData;
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 import de.intevation.gnv.state.OutputStateBase;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
25
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 import de.intevation.gnv.state.exception.StateException;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
27
723
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
28 import de.intevation.gnv.utils.ArtifactXMLUtilities;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
29 import de.intevation.gnv.utils.FileUtils;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
30 import de.intevation.gnv.utils.MapfileGenerator;
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
31 import de.intevation.gnv.utils.MetaWriter;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
32 import de.intevation.gnv.utils.ShapeFileWriter;
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
33
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
34 import java.io.File;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
35 import java.io.IOException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
36 import java.io.OutputStream;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
37
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
38 import java.util.Collection;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
39 import java.util.Iterator;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
40
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
41 import org.apache.log4j.Logger;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
42
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
43 import org.w3c.dom.Document;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
44 import org.w3c.dom.Element;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
45 import org.w3c.dom.Node;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
46
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 /**
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
48 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49 *
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50 */
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 public class LayerOutputState extends OutputStateBase {
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
53 /**
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54 * the logger, used to log exceptions and additonaly information
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 */
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
56 private static Logger log = Logger.getLogger(LayerOutputState.class);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
57
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
58 /**
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
59 * The UID of this Class.
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
60 */
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 private static final long serialVersionUID = 9180957321704424049L;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
62
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
63 // TODO: Replace
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
64 public static final String LAYER_MODEL = "layer";
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
65
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
66 /**
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
67 * The ID for the Query fetching the Layer from the DB
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
68 */
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
69 private String dataQueryID = null;
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
70
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
71 /**
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
72 * The ID for the Query fetching the Geometry from the DB
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
73 * which should be used to Clip the Layerdata
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
74 */
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
75 private String geometryQueryID = null;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
76
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
77 private String columnQueryID = null;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
78
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
79 /**
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
80 * The ID for the Value which will hold the Geometrie-Value
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
81 */
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
82 private String geometryID = null;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
83
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
84 private Boolean shapeFileLock = new Boolean(true);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
85
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
86 private String shapeFilePath;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
87
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
88 private String geometryType = null;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
89
724
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
90 private String templateID = null;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
91
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
92 public static final String SHAPEFILE_NAME = "data.shp";
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
93
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
94 /**
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
95 * Constructor
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
96 */
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
97 public LayerOutputState() {
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
98 super();
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
99 }
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
100
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
101 /**
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
102 * @see de.intevation.gnv.state.OutputState#out(org.w3c.dom.Document,
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
103 * java.util.Collection, java.io.OutputStream,
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
104 * java.lang.String, de.intevation.artifacts.CallContext)
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
105 */
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
106 public void out(Document format, Collection<InputData> inputData,
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
107 OutputStream outputStream, String uuid,
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
108 CallContext callContext) throws StateException {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
109
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
110 log.debug("LayerOutputState.out");
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
111 String outputMode = XMLUtils.xpathString(
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
112 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE);
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
113 if (outputMode.equalsIgnoreCase("wms")) {
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
114 Collection<Result> data = this.fetchData();
723
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
115 if (data != null && !data.isEmpty()){
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
116 XMLUtils.toStream(this.getWMS(uuid, callContext, data),
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
117 outputStream);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
118 }else{
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
119 this.writeExceptionReport2Stream(outputStream);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
120 }
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
121 }else if (outputMode.equalsIgnoreCase("zip")){
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
122 Collection<Result> data = this.fetchData();
723
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
123 if (data != null && !data.isEmpty()){
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
124 this.writeZip(uuid, callContext, outputStream, data);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
125 }else{
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
126 this.writeExceptionReport2Stream(outputStream);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
127 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
128
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
129 }
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
130 }
723
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
131
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
132 /**
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
133 * @param outputStream
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
134 */
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
135 private void writeExceptionReport2Stream(OutputStream outputStream) {
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
136 Document document = XMLUtils.newDocument();
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
137 new ArtifactXMLUtilities().
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
138 createExceptionReport("No Data to Export", document);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
139 XMLUtils.toStream(document,outputStream);
199982e8866e Integrated ExceptionHandling if no Data was found for the given Layer.
Tim Englich <tim.englich@intevation.de>
parents: 655
diff changeset
140 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
141
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
142
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
143 /**
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
144 * Fetches the Data from the Databasebackend
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
145 * @return
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
146 */
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
147 protected Collection<Result> fetchData(){
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
148 log.debug("LayerOutputState.fetchData");
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
149 // TODO PUT ALL in CACHE
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
150 Collection<Result> result = this.getData(this.queryID);
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
151 Collection<Result> data = null;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
152 String geometryWKT = null;
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
153 if (result != null){
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
154 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance()
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
155 .getQueryExecutor();
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
156 Iterator<Result> it = result.iterator();
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
157 String[] queryValues = null;
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
158 if (it.hasNext()){
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
159 Result resultValue = it.next();
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
160 String table = resultValue.getString(0);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
161 String where = resultValue.getString(1);
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
162 String columns = this.fetchColumns(table);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
163
724
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
164 templateID = resultValue.getString(2);
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
165 if (this.geometryID != null){
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
166 InputData geometryInputData =
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
167 this.inputData.get(this.geometryID);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
168 if (geometryInputData != null){
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
169
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
170 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
171 Collection<Result> geometryData = queryExecutor
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
172 .executeQuery(this.geometryQueryID,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
173 new String[]{geometryInputData.getValue()});
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
174 Iterator<Result> git = geometryData.iterator();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
175 if (git.hasNext()){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
176 Result geometryValue = git.next();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
177 geometryWKT = geometryValue.getString(0);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
178 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
179 } catch (QueryException e) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
180 log.error(e,e);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
181 // TODO: what should happen??
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
182 }
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
183 queryValues = new String[]{columns,
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
184 table,
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
185 where,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
186 geometryWKT};
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
187 }else{
729
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
188 //Look into the presetting for an WKT
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
189 InputData geometryWKTData = this.preSettings != null ?
742
cae93c709548 Fixed NPE using the Presettings-Object without given Presettings.
Tim Englich <tim.englich@intevation.de>
parents: 729
diff changeset
190 this.preSettings.get("geometry") :
cae93c709548 Fixed NPE using the Presettings-Object without given Presettings.
Tim Englich <tim.englich@intevation.de>
parents: 729
diff changeset
191 null ;
729
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
192 if (geometryWKTData != null){
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
193 queryValues = new String[]{columns,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
194 table,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
195 where,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
196 geometryWKTData.getValue()};
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
197 }else{
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
198 queryValues = new String[]{columns,table,where};
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
199 }
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
200 }
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
201 }else{
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
202 //Look into the presetting for an WKT
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
203 InputData geometryWKTData = this.preSettings != null ?
742
cae93c709548 Fixed NPE using the Presettings-Object without given Presettings.
Tim Englich <tim.englich@intevation.de>
parents: 729
diff changeset
204 this.preSettings.get("geometry") :
cae93c709548 Fixed NPE using the Presettings-Object without given Presettings.
Tim Englich <tim.englich@intevation.de>
parents: 729
diff changeset
205 null ;
729
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
206 if (geometryWKTData != null){
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
207 queryValues = new String[]{columns,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
208 table,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
209 where,
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
210 geometryWKTData.getValue()};
d23ad22bcfe7 Integrated lookup of the Geometry which was put to the Artifact during the Instantiation
Tim Englich <tim.englich@intevation.de>
parents: 728
diff changeset
211 }else{
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
212 queryValues = new String[]{columns,table,where};
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
213 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
214 }
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
215 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
216
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
217 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
218 data = queryExecutor.executeQuery(dataQueryID,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
219 queryValues);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
220 if (data != null && geometryWKT != null){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
221 WKTReader wktReader = new WKTReader();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
222 Geometry border = wktReader.read(geometryWKT);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
223
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
224 Iterator<Result> dataIt = data.iterator();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
225 while (dataIt.hasNext()){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
226 // Trim the Geometries using the
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
227 // Geometry if on is available.
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
228 Result current = dataIt.next();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
229 String currentWKT = current.getString(0);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
230 Geometry currentGeometry = null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
231 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
232 currentGeometry = wktReader.read(currentWKT);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
233 } catch (Exception e) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
234 log.error("Error parsing Geometry "+ currentWKT);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
235 log.error(e,e);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
236 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
237
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
238 if (currentGeometry != null){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
239 Geometry newGeometry = currentGeometry.intersection(border);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
240 current.addColumnValue(0, newGeometry.toText());
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
241 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
242 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
243 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
244 } catch (QueryException e) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
245 log.error(e,e);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
246 } catch (ParseException e){
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
247 log.error(e,e);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
248 }
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
249 }
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
250 return data;
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
251 }
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
252
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
253 private String fetchColumns(String tableName){
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
254 String returnValue = null;
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
255 try {
756
1614b27dcbfa Added Support of Layers which are Joined from two Tables.
Tim Englich <tim.englich@intevation.de>
parents: 742
diff changeset
256 String[] tables = tableName.toUpperCase().split(",");
1614b27dcbfa Added Support of Layers which are Joined from two Tables.
Tim Englich <tim.englich@intevation.de>
parents: 742
diff changeset
257 String[] filter = tables[0].split("\\.");
1614b27dcbfa Added Support of Layers which are Joined from two Tables.
Tim Englich <tim.englich@intevation.de>
parents: 742
diff changeset
258 // Only use the first Table the second one will be ignored.
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
259 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance()
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
260 .getQueryExecutor();
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
261
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
262 Collection<Result> columnData = queryExecutor.
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
263 executeQuery(this.columnQueryID,
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
264 filter);
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
265 if (columnData != null && !columnData.isEmpty()){
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
266 StringBuffer sb = new StringBuffer();
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
267 synchronized (sb) {
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
268 Iterator<Result> it = columnData.iterator();
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
269 while(it.hasNext()){
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
270 Result current = it.next();
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
271 sb.append(current.getString(0));
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
272 if (it.hasNext()){
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
273 sb.append(" , ");
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
274 }
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
275 }
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
276 }
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
277 returnValue = sb.toString();
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
278 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
279
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
280 } catch (QueryException e) {
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
281 log.error(e,e);
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
282 }
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
283 return returnValue;
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
284 }
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
285 @Override
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
286 public void setup(Node configuration) {
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
287 log.debug("LayerOutputState.setup");
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
288 super.setup(configuration);
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
289 this.dataQueryID = Config.getStringXPath(configuration,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
290 "queryID-layerdata");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
291 this.geometryID = Config.getStringXPath(configuration,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
292 "inputvalue-geometry");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
293 this.geometryQueryID = Config.getStringXPath(configuration,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
294 "queryID-geometry");
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
295
728
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
296 this.columnQueryID = "layer_colums"; //Config.getStringXPath(configuration,
f6630d0203da Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 724
diff changeset
297 // "queryID-columns");
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
298 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
299
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
300 protected String writeToShapeFile(
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
301 String uuid,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
302 Collection<Result> data,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
303 CallContext callContext
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
304 ) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
305 File baseDir = shapefileDirectory(callContext);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
306
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
307 File shapeDir = new File(baseDir, uuid);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
308 boolean success = false;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
309 boolean createdDir = false;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
310
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
311 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
312 synchronized (shapeFileLock) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
313 int count = 0;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
314 while (shapeDir.exists()) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
315 shapeDir = new File(baseDir, uuid + "-" + count);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
316 ++count;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
317 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
318
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
319 if (!shapeDir.mkdirs()) {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
320 log.error("cannot create directory '"
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
321 + shapeDir.getAbsolutePath() + "'");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
322 return null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
323 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
324 createdDir = true;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
325 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
326
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
327 File shapeFile = new File(shapeDir, SHAPEFILE_NAME);
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
328 if ((geometryType = ShapeFileWriter.writeDataToFile(shapeFile, "data", data)) == null){
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
329 log.error("writing data into shapefile failed");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
330 return null;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
331 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
332
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
333 shapeFilePath = shapeDir.getAbsolutePath();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
334 success = true;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
335
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
336 callContext.afterCall(CallContext.STORE);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
337
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
338 return shapeFilePath;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
339 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
340 finally {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
341 if (!success && createdDir) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
342 FileUtils.deleteRecursive(shapeDir);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
343 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
344 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
345 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
346
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
347 protected void writeZip(
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
348 String uuid,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
349 CallContext callContext,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
350 OutputStream output,
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
351 Collection<Result> data
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
352 )
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
353 throws StateException
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
354 {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
355 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
356 String p = getShapeFilePath();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
357 if (p != null) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
358 File dir = new File(p);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
359 if (dir.isDirectory()) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
360 FileUtils.createZipArchive(dir, output);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
361 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
362 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
363 else {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
364
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
365 if ((p = writeToShapeFile(uuid, data, callContext)) != null) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
366 FileUtils.createZipArchive(new File(p), output);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
367 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
368 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
369 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
370 catch (IOException ioe) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
371 log.error(ioe.getLocalizedMessage(), ioe);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
372 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
373 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
374
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
375 public String getShapeFilePath() {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
376 synchronized (shapeFileLock) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
377 return shapeFilePath;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
378 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
379 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
380
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
381 private static File shapefileDirectory(CallContext callContext) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
382 // TODO: Refactoring nessessary it should be used only one Shapefilepath
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
383 // for alle Modes. Code was taken from HorizontalCrossSectionMeshOutputState
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
384 GNVArtifactContext context =
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
385 (GNVArtifactContext)callContext.globalContext();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
386 File dir = (File)context.get(
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
387 GNVArtifactContext.HORIZONTAL_CROSS_SECTION_RESULT_SHAPEFILE_PATH_KEY);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
388 return dir != null
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
389 ? dir
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
390 : GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SHAPEFILE_PATH;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
391 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
392
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
393 /**
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
394 * @see de.intevation.gnv.state.StateBase#endOfLife(java.lang.Object)
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
395 */
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
396 @Override
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
397 public void endOfLife(Object globalContext) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
398 super.endOfLife(globalContext);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
399
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
400 // do it in background
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
401 new Thread() {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
402 public void run() {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
403 // TODO: Do the un-publishing WMS stuff.
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
404 String path = resetShapeFilePath();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
405
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
406 if (path == null) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
407 return;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
408 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
409
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
410 File dir = new File(path);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
411
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
412 for (int i = 0; i < 10; ++i) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
413 if (!dir.exists() || FileUtils.deleteRecursive(dir)) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
414 MapfileGenerator.getInstance().update();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
415 return;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
416 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
417
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
418 try {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
419 Thread.sleep(10000L);
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
420 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
421 catch (InterruptedException ie) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
422 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
423 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
424
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
425 log.error("failed to remove directory '" + path + "'");
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
426 } // run
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
427 }.start();
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
428 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
429
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
430 public String resetShapeFilePath() {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
431 synchronized (shapeFileLock) {
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
432 String path = shapeFilePath;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
433 shapeFilePath = null;
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
434 geometryType = null;
724
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
435 templateID = null;
649
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
436 return path;
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
437 }
4fc97074eb90 Added Support for writing Shapefiles and Export them as an Zipfile for the Product Layer.
Tim Englich <tim.englich@intevation.de>
parents: 616
diff changeset
438 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
439 protected Document getWMS(String uuid,
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
440 CallContext callContext,
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
441 Collection<Result> data)
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
442 throws StateException
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
443 {
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
444 // TODO: Do the real WMS publishing here!
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
445 Document document = XMLUtils.newDocument();
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
446
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
447 Element pathElement = document.createElement("path");
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
448 document.appendChild(pathElement);
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
449
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
450 String path = getShapeFilePath();
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
451
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
452 if (path != null && new File(path).isDirectory()) {
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
453 pathElement.setTextContent(path);
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
454 }
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
455 else {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
456
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
457 if (data != null &&
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
458 (path = writeToShapeFile(uuid, data, callContext)) != null) {
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
459
724
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
460 String paramType = LAYER_MODEL+"_"+templateID;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
461
724
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
462 if (!MapfileGenerator.getInstance().templateExists(paramType)){
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
463 // If the template doesn't exist the Defaulttemplates will be used.
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
464 paramType = LAYER_MODEL+"_"+this.geometryType.toLowerCase();
9ba6bb85d6dd Integrate lookup for MapFileTemplate for the different Layer.
Tim Englich <tim.englich@intevation.de>
parents: 723
diff changeset
465 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
466 Document meta = MetaWriter.writeLayerMeta(callContext, uuid,
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
467 path, paramType,
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
468 this.determineGeometryType());
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
469 if (meta != null) {
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
470 MapfileGenerator.getInstance().update();
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
471 return meta;
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
472 }
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
473
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
474 pathElement.setTextContent(path);
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
475 }
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
476 }
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
477
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
478 return document;
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
479 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
480
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
481 private String determineGeometryType(){
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
482
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
483 String returnValue = this.geometryType.toLowerCase();
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
484
655
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
485 if (returnValue.equalsIgnoreCase("linestring")){
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
486 returnValue = "Line";
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
487 }
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
488 return returnValue;
6eccb68a8b99 Added WMS-Publishing to Product Layer
Tim Englich <tim.englich@intevation.de>
parents: 649
diff changeset
489 }
616
93978859fa9e Added the Configuration and the Classes for the new Product Layer.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
490 }

http://dive4elements.wald.intevation.org