Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 822:ac1b9f00603f
Added more Javadoc. Removed obsolet TODO-Flags. Added missing Files to Revision 907
gnv-artifacts/trunk@909 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 13 Apr 2010 08:17:00 +0000 |
parents | 79c1db3ca7cc |
children | 28028979c813 |
comparison
equal
deleted
inserted
replaced
821:9b41dbe92d9d | 822:ac1b9f00603f |
---|---|
32 import de.intevation.gnv.utils.MapfileGenerator; | 32 import de.intevation.gnv.utils.MapfileGenerator; |
33 import de.intevation.gnv.utils.MetaWriter; | 33 import de.intevation.gnv.utils.MetaWriter; |
34 import de.intevation.gnv.utils.ShapeFileWriter; | 34 import de.intevation.gnv.utils.ShapeFileWriter; |
35 | 35 |
36 /** | 36 /** |
37 * This <code>OutputState</code> is used for Layer-Products. | |
37 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> | 38 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
38 * | 39 * |
39 */ | 40 */ |
40 public class LayerOutputState extends OutputStateBase { | 41 public class LayerOutputState extends OutputStateBase { |
41 | 42 |
47 /** | 48 /** |
48 * The UID of this Class. | 49 * The UID of this Class. |
49 */ | 50 */ |
50 private static final long serialVersionUID = 9180957321704424049L; | 51 private static final long serialVersionUID = 9180957321704424049L; |
51 | 52 |
52 // TODO: Replace | 53 /** |
54 * The Basename of the Templates for the WMS-Exports | |
55 */ | |
53 public static final String LAYER_MODEL = "layer"; | 56 public static final String LAYER_MODEL = "layer"; |
57 | |
58 /** | |
59 * The Name of the Shapefile which will be generated. | |
60 */ | |
61 public static final String SHAPEFILE_NAME = "data.shp"; | |
54 | 62 |
55 /** | 63 /** |
56 * The ID for the Query fetching the Layer from the DB | 64 * The ID for the Query fetching the Layer from the DB |
57 */ | 65 */ |
58 private String dataQueryID = null; | 66 private String dataQueryID = null; |
61 * The ID for the Query fetching the Geometry from the DB | 69 * The ID for the Query fetching the Geometry from the DB |
62 * which should be used to Clip the Layerdata | 70 * which should be used to Clip the Layerdata |
63 */ | 71 */ |
64 private String geometryQueryID = null; | 72 private String geometryQueryID = null; |
65 | 73 |
74 /** | |
75 * The ID of the Query for fetching the Columnnames of the Table which | |
76 * should put into the Shapefile. | |
77 */ | |
66 private String columnQueryID = null; | 78 private String columnQueryID = null; |
67 | 79 |
80 /** | |
81 * The ID of the Query for fetching the Information which kind of Geometry | |
82 * should be put into the Shapefile. | |
83 */ | |
68 private String geometryTypeQueryID = null; | 84 private String geometryTypeQueryID = null; |
69 | 85 |
70 /** | 86 /** |
71 * The ID for the Value which will hold the Geometrie-Value | 87 * The ID for the Value which will hold the Geometry-Value |
72 */ | 88 */ |
73 private String geometryID = null; | 89 private String geometryID = null; |
74 | 90 |
91 /** | |
92 * Flag for synchronized Access of the Shapefile. | |
93 */ | |
75 private Boolean shapeFileLock = new Boolean(true); | 94 private Boolean shapeFileLock = new Boolean(true); |
76 | 95 |
96 /** | |
97 * The Path where the Shapefile is stored. | |
98 */ | |
77 private String shapeFilePath; | 99 private String shapeFilePath; |
78 | 100 |
101 /** | |
102 * The ID of the Template which should be used to generate the Layerentry | |
103 * in the Mapfile. | |
104 */ | |
79 private String templateID = null; | 105 private String templateID = null; |
80 | 106 |
107 /** | |
108 * The Kind of Geometry which should be used to generate the Shapefile. | |
109 */ | |
81 private String geometryType = null; | 110 private String geometryType = null; |
82 | |
83 public static final String SHAPEFILE_NAME = "data.shp"; | |
84 | 111 |
85 /** | 112 /** |
86 * Constructor | 113 * Constructor |
87 */ | 114 */ |
88 public LayerOutputState() { | 115 public LayerOutputState() { |
89 super(); | 116 super(); |
90 } | 117 } |
91 | |
92 | 118 |
93 public void out(Document format, Collection<InputData> inputData, | 119 public void out(Document format, Collection<InputData> inputData, |
94 OutputStream outputStream, String uuid, | 120 OutputStream outputStream, String uuid, |
95 CallContext callContext) throws StateException { | 121 CallContext callContext) throws StateException { |
96 | 122 |
121 /** | 147 /** |
122 * Writes an exception to an output stream. | 148 * Writes an exception to an output stream. |
123 * | 149 * |
124 * @param outputStream The output stream used to write the exception to. | 150 * @param outputStream The output stream used to write the exception to. |
125 */ | 151 */ |
126 @SuppressWarnings("static-access") | |
127 private void writeExceptionReport2Stream(OutputStream outputStream) { | 152 private void writeExceptionReport2Stream(OutputStream outputStream) { |
128 Document document = XMLUtils.newDocument(); | 153 Document document = XMLUtils.newDocument(); |
129 ArtifactXMLUtilities. | 154 ArtifactXMLUtilities. |
130 createExceptionReport("No Data to Export", document); | 155 createExceptionReport("No Data to Export", document); |
131 XMLUtils.toStream(document,outputStream); | 156 XMLUtils.toStream(document,outputStream); |
133 | 158 |
134 | 159 |
135 /** | 160 /** |
136 * Fetches the Data from the Databasebackend. | 161 * Fetches the Data from the Databasebackend. |
137 * | 162 * |
138 * @return the resulting data. | 163 * @return the resultdata. |
139 */ | 164 */ |
140 protected Collection<Result> fetchData(){ | 165 protected Collection<Result> fetchData(){ |
141 log.debug("LayerOutputState.fetchData"); | 166 log.debug("LayerOutputState.fetchData"); |
142 // TODO PUT ALL in CACHE | |
143 Collection<Result> result = this.getData(this.queryID); | 167 Collection<Result> result = this.getData(this.queryID); |
144 Collection<Result> data = null; | 168 Collection<Result> data = null; |
145 String geometryWKT = null; | 169 String geometryWKT = null; |
146 if (result != null){ | 170 if (result != null){ |
147 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance() | 171 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance() |
172 Result geometryValue = git.next(); | 196 Result geometryValue = git.next(); |
173 geometryWKT = geometryValue.getString(0); | 197 geometryWKT = geometryValue.getString(0); |
174 } | 198 } |
175 } catch (QueryException e) { | 199 } catch (QueryException e) { |
176 log.error(e,e); | 200 log.error(e,e); |
177 // TODO: what should happen?? | |
178 } | 201 } |
179 queryValues = new String[]{columns, | 202 queryValues = new String[]{columns, |
180 table, | 203 table, |
181 where, | 204 where, |
182 geometryWKT}; | 205 geometryWKT}; |
352 this.geometryTypeQueryID = "geometry_type"; | 375 this.geometryTypeQueryID = "geometry_type"; |
353 } | 376 } |
354 | 377 |
355 | 378 |
356 /** | 379 /** |
357 * Write the resulting data to shapefiles. | 380 * Write the resultdata to shapefiles. |
358 * | 381 * |
359 * @param uuid The UUID of the current artifact. | 382 * @param uuid The UUID of the current artifact. |
360 * @param data The finalized data used for shapefile creation. | 383 * @param data The finalized data used for shapefile creation. |
361 * @param callContext The CallContext object. | 384 * @param callContext The CallContext object. |
362 * @param geometryType The geometry type. | 385 * @param geometryType The geometry type. |
482 | 505 |
483 // do it in background | 506 // do it in background |
484 new Thread() { | 507 new Thread() { |
485 @Override | 508 @Override |
486 public void run() { | 509 public void run() { |
487 // TODO: Do the un-publishing WMS stuff. | |
488 String path = resetShapeFilePath(); | 510 String path = resetShapeFilePath(); |
489 | 511 |
490 if (path == null) { | 512 if (path == null) { |
491 return; | 513 return; |
492 } | 514 } |
509 log.error("failed to remove directory '" + path + "'"); | 531 log.error("failed to remove directory '" + path + "'"); |
510 } // run | 532 } // run |
511 }.start(); | 533 }.start(); |
512 } | 534 } |
513 | 535 |
514 | 536 /** |
515 public String resetShapeFilePath() { | 537 * Resets the Settings e.g shapeFilePath and templateID |
538 * @return | |
539 */ | |
540 private String resetShapeFilePath() { | |
516 synchronized (shapeFileLock) { | 541 synchronized (shapeFileLock) { |
517 String path = shapeFilePath; | 542 String path = shapeFilePath; |
518 shapeFilePath = null; | 543 shapeFilePath = null; |
519 templateID = null; | 544 templateID = null; |
520 return path; | 545 return path; |
539 CallContext callContext, | 564 CallContext callContext, |
540 Collection<Result> data, | 565 Collection<Result> data, |
541 String geometryType) | 566 String geometryType) |
542 throws StateException | 567 throws StateException |
543 { | 568 { |
544 // TODO: Do the real WMS publishing here! | |
545 Document document = XMLUtils.newDocument(); | 569 Document document = XMLUtils.newDocument(); |
546 | 570 |
547 Element pathElement = document.createElement("path"); | 571 Element pathElement = document.createElement("path"); |
548 document.appendChild(pathElement); | 572 document.appendChild(pathElement); |
549 | 573 |