comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 813:79c1db3ca7cc

Added some more javadocs. gnv-artifacts/trunk@897 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 09 Apr 2010 13:09:25 +0000
parents feae2f9d6c6f
children ac1b9f00603f
comparison
equal deleted inserted replaced
812:41a7c49b5cb4 813:79c1db3ca7cc
87 */ 87 */
88 public LayerOutputState() { 88 public LayerOutputState() {
89 super(); 89 super();
90 } 90 }
91 91
92 /** 92
93 * @see de.intevation.gnv.state.OutputState#out(org.w3c.dom.Document,
94 * java.util.Collection, java.io.OutputStream,
95 * java.lang.String, de.intevation.artifacts.CallContext)
96 */
97 public void out(Document format, Collection<InputData> inputData, 93 public void out(Document format, Collection<InputData> inputData,
98 OutputStream outputStream, String uuid, 94 OutputStream outputStream, String uuid,
99 CallContext callContext) throws StateException { 95 CallContext callContext) throws StateException {
100 96
101 log.debug("LayerOutputState.out"); 97 log.debug("LayerOutputState.out");
121 117
122 } 118 }
123 } 119 }
124 120
125 /** 121 /**
126 * @param outputStream 122 * Writes an exception to an output stream.
127 */ 123 *
124 * @param outputStream The output stream used to write the exception to.
125 */
126 @SuppressWarnings("static-access")
128 private void writeExceptionReport2Stream(OutputStream outputStream) { 127 private void writeExceptionReport2Stream(OutputStream outputStream) {
129 Document document = XMLUtils.newDocument(); 128 Document document = XMLUtils.newDocument();
130 new ArtifactXMLUtilities(). 129 ArtifactXMLUtilities.
131 createExceptionReport("No Data to Export", document); 130 createExceptionReport("No Data to Export", document);
132 XMLUtils.toStream(document,outputStream); 131 XMLUtils.toStream(document,outputStream);
133 } 132 }
134 133
135 134
136 /** 135 /**
137 * Fetches the Data from the Databasebackend 136 * Fetches the Data from the Databasebackend.
138 * @return 137 *
138 * @return the resulting data.
139 */ 139 */
140 protected Collection<Result> fetchData(){ 140 protected Collection<Result> fetchData(){
141 log.debug("LayerOutputState.fetchData"); 141 log.debug("LayerOutputState.fetchData");
142 // TODO PUT ALL in CACHE 142 // TODO PUT ALL in CACHE
143 Collection<Result> result = this.getData(this.queryID); 143 Collection<Result> result = this.getData(this.queryID);
244 } 244 }
245 } 245 }
246 return data; 246 return data;
247 } 247 }
248 248
249
250 /**
251 * This method determines the geometry type on basis of a table name.
252 *
253 * @param tableName Name of the table in the database.
254 * @param queryExecutor The QueryExecutor.
255 * @return the geometry type as string (e.g. MultiPolygon, Polygon, etc).
256 */
249 private String getGeometryType(String tableName, 257 private String getGeometryType(String tableName,
250 QueryExecutor queryExecutor){ 258 QueryExecutor queryExecutor){
251 String returnValue = null; 259 String returnValue = null;
252 String[] tables = tableName.toUpperCase().split(","); 260 String[] tables = tableName.toUpperCase().split(",");
253 String[] filter = tables[0].split("\\."); 261 String[] filter = tables[0].split("\\.");
284 log.error(e,e); 292 log.error(e,e);
285 } 293 }
286 294
287 return returnValue; 295 return returnValue;
288 } 296 }
297
298
299 /**
300 * Fetch the columns of a specific table.
301 *
302 * @param tableName The name of the table.
303 * @return the columns as string.
304 */
289 private String fetchColumns(String tableName){ 305 private String fetchColumns(String tableName){
290 String returnValue = null; 306 String returnValue = null;
291 try { 307 try {
292 String[] tables = tableName.toUpperCase().split(","); 308 String[] tables = tableName.toUpperCase().split(",");
293 String[] filter = tables[0].split("\\."); 309 String[] filter = tables[0].split("\\.");
316 } catch (QueryException e) { 332 } catch (QueryException e) {
317 log.error(e,e); 333 log.error(e,e);
318 } 334 }
319 return returnValue; 335 return returnValue;
320 } 336 }
337
338
321 @Override 339 @Override
322 public void setup(Node configuration) { 340 public void setup(Node configuration) {
323 log.debug("LayerOutputState.setup"); 341 log.debug("LayerOutputState.setup");
324 super.setup(configuration); 342 super.setup(configuration);
325 this.dataQueryID = Config.getStringXPath(configuration, 343 this.dataQueryID = Config.getStringXPath(configuration,
332 this.columnQueryID = "layer_colums"; //Config.getStringXPath(configuration, 350 this.columnQueryID = "layer_colums"; //Config.getStringXPath(configuration,
333 // "queryID-columns"); 351 // "queryID-columns");
334 this.geometryTypeQueryID = "geometry_type"; 352 this.geometryTypeQueryID = "geometry_type";
335 } 353 }
336 354
355
356 /**
357 * Write the resulting data to shapefiles.
358 *
359 * @param uuid The UUID of the current artifact.
360 * @param data The finalized data used for shapefile creation.
361 * @param callContext The CallContext object.
362 * @param geometryType The geometry type.
363 * @return the shapefile path.
364 */
337 protected String writeToShapeFile( 365 protected String writeToShapeFile(
338 String uuid, 366 String uuid,
339 Collection<Result> data, 367 Collection<Result> data,
340 CallContext callContext, 368 CallContext callContext,
341 String geometryType 369 String geometryType
380 FileUtils.deleteRecursive(shapeDir); 408 FileUtils.deleteRecursive(shapeDir);
381 } 409 }
382 } 410 }
383 } 411 }
384 412
413
414 /**
415 * Create a zip archive with the shapefiles of the given shapefiles path and
416 * write it to <code>output</code>.
417 *
418 * @param uuid The UUID of the current artifact.
419 * @param callContext The CallContext object.
420 * @param output The output stream.
421 * @param data The data to be written to shapefile.
422 * @param geometryType The geometry type.
423 * @throws StateException if an error occured while zipfile creation.
424 */
385 protected void writeZip( 425 protected void writeZip(
386 String uuid, 426 String uuid,
387 CallContext callContext, 427 CallContext callContext,
388 OutputStream output, 428 OutputStream output,
389 Collection<Result> data, 429 Collection<Result> data,
409 catch (IOException ioe) { 449 catch (IOException ioe) {
410 log.error(ioe.getLocalizedMessage(), ioe); 450 log.error(ioe.getLocalizedMessage(), ioe);
411 } 451 }
412 } 452 }
413 453
454 /**
455 * Returns the shapefile path.
456 *
457 * @return the shapefile path.
458 */
414 public String getShapeFilePath() { 459 public String getShapeFilePath() {
415 synchronized (shapeFileLock) { 460 synchronized (shapeFileLock) {
416 return shapeFilePath; 461 return shapeFilePath;
417 } 462 }
418 } 463 }
419 464
465
420 private static File shapefileDirectory(CallContext callContext) { 466 private static File shapefileDirectory(CallContext callContext) {
421 // TODO: Refactoring nessessary it should be used only one Shapefilepath 467 // TODO: Refactoring nessessary it should be used only one Shapefilepath
422 // for alle Modes. Code was taken from HorizontalCrossSectionMeshOutputState 468 // for alle Modes. Code was taken from HorizontalCrossSectionMeshOutputState
423 GNVArtifactContext context = 469 GNVArtifactContext context =
424 (GNVArtifactContext)callContext.globalContext(); 470 (GNVArtifactContext)callContext.globalContext();
427 return dir != null 473 return dir != null
428 ? dir 474 ? dir
429 : GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SHAPEFILE_PATH; 475 : GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SHAPEFILE_PATH;
430 } 476 }
431 477
432 /** 478
433 * @see de.intevation.gnv.state.StateBase#endOfLife(java.lang.Object)
434 */
435 @Override 479 @Override
436 public void endOfLife(Object globalContext) { 480 public void endOfLife(Object globalContext) {
437 super.endOfLife(globalContext); 481 super.endOfLife(globalContext);
438 482
439 // do it in background 483 // do it in background
440 new Thread() { 484 new Thread() {
485 @Override
441 public void run() { 486 public void run() {
442 // TODO: Do the un-publishing WMS stuff. 487 // TODO: Do the un-publishing WMS stuff.
443 String path = resetShapeFilePath(); 488 String path = resetShapeFilePath();
444 489
445 if (path == null) { 490 if (path == null) {
464 log.error("failed to remove directory '" + path + "'"); 509 log.error("failed to remove directory '" + path + "'");
465 } // run 510 } // run
466 }.start(); 511 }.start();
467 } 512 }
468 513
514
469 public String resetShapeFilePath() { 515 public String resetShapeFilePath() {
470 synchronized (shapeFileLock) { 516 synchronized (shapeFileLock) {
471 String path = shapeFilePath; 517 String path = shapeFilePath;
472 shapeFilePath = null; 518 shapeFilePath = null;
473 templateID = null; 519 templateID = null;
474 return path; 520 return path;
475 } 521 }
476 } 522 }
523
524
525 /**
526 * Write data to shapefiles and feed a map service with information about
527 * these shapefiles. The map service can be queried for displaying
528 * corresponding layers as WMS.
529 *
530 * @param uuid The UUID of the current artifact.
531 * @param callContext The CallContext object.
532 * @param data A collection with some input data.
533 * @param geometryType The geometry type.
534 * @return a document with some meta information (shapefile path, geometry
535 * type, time to live of the current artifact, etc).
536 * @throws StateException if an error occured while shapefile writing.
537 */
477 protected Document getWMS(String uuid, 538 protected Document getWMS(String uuid,
478 CallContext callContext, 539 CallContext callContext,
479 Collection<Result> data, 540 Collection<Result> data,
480 String geometryType) 541 String geometryType)
481 throws StateException 542 throws StateException
516 } 577 }
517 578
518 return document; 579 return document;
519 } 580 }
520 581
582
583 /**
584 * Turns the geometry type into a form used for the templating mechanism
585 * while mapfile generation.
586 *
587 * @param geometryType The original geometry type.
588 * @return a valid geometry type fpr the template mechanism.
589 */
521 private String determineGeometryType(String geometryType){ 590 private String determineGeometryType(String geometryType){
522 591
523 String returnValue = geometryType.toLowerCase(); 592 String returnValue = geometryType.toLowerCase();
524 593
525 if (returnValue.equalsIgnoreCase("linestring")){ 594 if (returnValue.equalsIgnoreCase("linestring")){
530 returnValue = "Polygon"; 599 returnValue = "Polygon";
531 } 600 }
532 return returnValue; 601 return returnValue;
533 } 602 }
534 603
604
605 /**
606 * Determine the default template name if no special template is existing
607 * for this layer.
608 *
609 * @param geometryType The geometry type.
610 * @return a default geometry fitting to the original geometry type.
611 */
535 private String determineDefaultTemplateName(String geometryType){ 612 private String determineDefaultTemplateName(String geometryType){
536 613
537 String returnValue = geometryType.toLowerCase(); 614 String returnValue = geometryType.toLowerCase();
538 615
539 if (returnValue.equalsIgnoreCase("multilinestring")){ 616 if (returnValue.equalsIgnoreCase("multilinestring")){
544 returnValue = "point"; 621 returnValue = "point";
545 } 622 }
546 return returnValue; 623 return returnValue;
547 } 624 }
548 } 625 }
626 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org