Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 1057:04967dc9c83f
The title of a layer can be changed by the user. Product 'Layer' and 'Horizontalschnitt' now use the same code path to write the meta information file. (issue198)
gnv-artifacts/trunk@1134 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 27 May 2010 16:43:00 +0000 |
parents | 461d4489705c |
children | 7096a2e13676 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java Thu May 27 08:48:16 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java Thu May 27 16:43:00 2010 +0000 @@ -170,6 +170,7 @@ String where = resultValue.getString(1); String columns = this.fetchColumns(table); String templateID = resultValue.getString(2); + String layername = resultValue.getString(3); String[] queryValues = null; String geometryWKT = null; if (this.geometryID != null){ @@ -221,10 +222,9 @@ queryValues = new String[]{columns,table,where}; } } - returnValue.add(new LayerMetaData(table, geometryType, - where, columns, - templateID, queryValues, - geometryWKT)); + returnValue.add(new LayerMetaData( + table, geometryType, where, columns, + templateID, queryValues, geometryWKT, layername)); } } return returnValue; @@ -618,42 +618,54 @@ // process data Iterator<LayerMetaData> it = layerMetaData.iterator(); - Node meta = null; + + // create meta file + Document meta = MetaWriter.initMeta(); + MetaWriter.insertAbstractMeta(callContext, meta); + + String path = getShapeFilePath(); + String prefix = getLayerPrefix(inputData); + + if (prefix == null) { + prefix = uuid; + } + int layerNumber = 0; while (it.hasNext()){ LayerMetaData lmd = it.next(); layerNumber ++; + String geometryType = lmd.getGeometryType(); - String templateId = lmd.getTemplateID(); + String templateId = lmd.getTemplateID(); + ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid); try{ - Collection<Result> data = this.fetchData(lmd); - if (data != null && - (this.writeToShapeFile(uuid, data, callContext, - geometryType,layerNumber)) != null) { - String paramType = findParameterTitle(geometryType,templateId); - String title = getLayerTitle(inputData); - if (title == null) { - title = uuid+"_"+layerNumber; - }else{ - title = title+"_"+layerNumber; - } - if (meta == null){ - meta = MetaWriter.writeLayerMeta(callContext,document); - } - MetaWriter.writeLayerMeta(callContext, document, - meta, uuid, paramType, - this.determineGeometryType(geometryType), - createShapeFileName(layerNumber), - title); + Collection<Result> results = this.fetchData(lmd); + if (results != null && writeToShapeFile(uuid, results, + callContext, + geometryType, + layerNumber) != null) { + String name = getLayerName(uuid, layerNumber); + String base = lmd.getLayertitle(); + String title = getLayerTitle(prefix, base); + String data = getLayerData( + uuid, createShapeFileName(layerNumber)); + String type = determineGeometryType(geometryType); + String status = "OFF"; + String model = findParameterTitle( + geometryType, templateId); + + MetaWriter.insertLayer( + callContext, meta, name, title, + data, model, type, status); } success = true; if (meta != null && !it.hasNext()) { - MetaWriter.writeMetaFile(getShapeFilePath(),document); + MetaWriter.writeMetaFile(path, meta); MapfileGenerator.getInstance().update(); - return document; + return meta; } }finally{ ExclusiveExec.INSTANCE.release(key); @@ -678,6 +690,23 @@ } + protected String getLayerName(String uuid, int idx) { + return uuid + "_" + idx; + } + + + protected String getLayerTitle(String prefix, String base) { + return prefix + "_" + base; + } + + + protected String getLayerData(String shapeDir, String filename) { + File path = new File(shapeDir, filename); + + return path.toString(); + } + + /** * Returns the parameterType for the Layer. * @param geometryType @@ -699,7 +728,7 @@ * @param inputData A collection with InputData objects. * @return the title. */ - protected String getLayerTitle(Collection<InputData> inputData) { + protected String getLayerPrefix(Collection<InputData> inputData) { for (InputData data: inputData) { String name = data.getName(); if (name != null && name.equals("title")) {