# HG changeset patch # User Ingo Weinzierl # Date 1274433419 0 # Node ID 461d4489705c008ab6d18fa0e1ff3838f6f731ff # Parent d955571cdf2a53c40b5fe5f84978ca0552708610 Improved directoy handling for incoming wms requests on product 'Layer' (issue269). gnv-artifacts/trunk@1116 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r d955571cdf2a -r 461d4489705c gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Fri May 21 08:28:49 2010 +0000 +++ b/gnv-artifacts/ChangeLog Fri May 21 09:16:59 2010 +0000 @@ -1,3 +1,15 @@ +2010-05-21 Ingo Weinzierl + + Issue269 + + * src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java: + Improved the directory handling for wms requests (directories are created + if there is no directory existing for the shapefiles; the content of + directories is deleted if the directory is existing). The shapefiles are + always generated again as well if there is an directory existing and it + contains files - we cannot know if these files are shapefiles that have + been created by our application. + 2010-05-21 Tim Englich * doc/conf/queries.properties: diff -r d955571cdf2a -r 461d4489705c gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java Fri May 21 08:28:49 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java Fri May 21 09:16:59 2010 +0000 @@ -501,6 +501,16 @@ } } + + /** + * Set the shapefile path. + */ + public void setShapeFilePath(String shapeFilePath) { + synchronized (shapeFileLock) { + this.shapeFilePath = shapeFilePath; + } + } + /** * Returns the basic-directory where the Shapefiles should be placed in. * @param callContext the Context of this Call @@ -576,26 +586,37 @@ * type, time to live of the current artifact, etc). * @throws StateException if an error occured while shapefile writing. */ - protected Document getWMS(String uuid, - CallContext callContext, - Collection layerMetaData, - Collection inputData) + protected Document getWMS( + String uuid, + CallContext callContext, + Collection layerMetaData, + Collection inputData) throws StateException { - String path = getShapeFilePath(); - if (path != null && new File(path).isDirectory()){ - return this.refreshMetaFile(layerMetaData, inputData, - uuid, callContext); - }else{ - Document document = XMLUtils.newDocument(); - if (this.shapeFilePath == null){ - File baseDir = shapefileDirectory(callContext); - if (!this.createShapeDir(baseDir, uuid)){ - // TODO Insert Error Report - return document; + Document document = XMLUtils.newDocument(); + + File baseDir = shapefileDirectory(callContext); + File shapeDir = new File(baseDir, uuid); + + boolean success = false; + boolean createdDir = false; + + try { + // create shapefile directory or delete content if it already exists + synchronized (shapeFileLock) { + if (shapeDir.exists()) { + FileUtils.deleteContent(shapeDir); } + else if (!shapeDir.mkdirs()) { + log.error("cannot create directory '" + + shapeDir.getAbsolutePath() + "'"); + return null; + } + setShapeFilePath(shapeDir.getAbsolutePath()); + createdDir = true; } - path = getShapeFilePath(); + + // process data Iterator it = layerMetaData.iterator(); Node meta = null; int layerNumber = 0; @@ -626,8 +647,11 @@ createShapeFileName(layerNumber), title); } + + success = true; + if (meta != null && !it.hasNext()) { - MetaWriter.writeMetaFile(path,document); + MetaWriter.writeMetaFile(getShapeFilePath(),document); MapfileGenerator.getInstance().update(); return document; } @@ -637,6 +661,11 @@ } return document; } + finally { + if (!success && createdDir) { + FileUtils.deleteRecursive(shapeDir); + } + } } /** @@ -648,57 +677,6 @@ return SHAPEFILE_NAME+"_"+layerNumber+".shp"; } - /** - * Method that refreshes the Metadatafile for publishing the WMS - * Without generating the Data ones again. - * @param layerMetaData the Metadata which is required to create the Layers - * @param inputData the Inputdata which was sent by the Client - * @param uuid the uuid of the Artifact - * @param callContext the context of this Call - * @return a refreshed Metadata-Document - */ - private Document refreshMetaFile(Collection layerMetaData, - Collection inputData, - String uuid, - CallContext callContext){ - Document document = XMLUtils.newDocument(); - Node meta = null; - int layerNumber = 0; - Iterator it = layerMetaData.iterator(); - while (it.hasNext()){ - LayerMetaData lmd = it.next(); - layerNumber ++; - String geometryType = lmd.getGeometryType(); - String templateId = lmd.getTemplateID(); - String title = getLayerTitle(inputData); - if (title == null) { - title = uuid+"_"+layerNumber; - }else{ - title = title+"_"+layerNumber; - } - callContext.putContextValue( - MetaWriter.CONTEXT_LAYER_TITLE, title); - String paramType = findParameterTitle(geometryType,templateId); - if (log.isDebugEnabled()) { - log.debug("Layer title: " + title); - log.debug("Layer type: " + paramType); - } - if (meta == null){ - meta = MetaWriter.writeLayerMeta(callContext,document); - } - MetaWriter.writeLayerMeta(callContext, document, - meta, uuid, paramType, - this.determineGeometryType(geometryType), - createShapeFileName(layerNumber), - title); - if (meta != null && !it.hasNext()) { - MetaWriter.writeMetaFile(getShapeFilePath(),document); - MapfileGenerator.getInstance().update(); - return document; - } - } - return document; - } /** * Returns the parameterType for the Layer.