comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 728:f6630d0203da

Put all Attributes of the Databasetables into the Shapefile which will be produced for the Product Layer gnv-artifacts/trunk@764 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 12 Mar 2010 11:36:38 +0000
parents 9ba6bb85d6dd
children d23ad22bcfe7
comparison
equal deleted inserted replaced
727:22dc921cd8b1 728:f6630d0203da
5 5
6 import java.io.File; 6 import java.io.File;
7 import java.io.IOException; 7 import java.io.IOException;
8 import java.io.OutputStream; 8 import java.io.OutputStream;
9 import java.util.Collection; 9 import java.util.Collection;
10 import java.util.HashMap;
11 import java.util.Iterator; 10 import java.util.Iterator;
12 import java.util.Map;
13 11
14 import org.apache.log4j.Logger; 12 import org.apache.log4j.Logger;
15 import org.w3c.dom.Document; 13 import org.w3c.dom.Document;
16 import org.w3c.dom.Element; 14 import org.w3c.dom.Element;
17 import org.w3c.dom.Node; 15 import org.w3c.dom.Node;
27 import de.intevation.gnv.artifacts.context.GNVArtifactContext; 25 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
28 import de.intevation.gnv.geobackend.base.Result; 26 import de.intevation.gnv.geobackend.base.Result;
29 import de.intevation.gnv.geobackend.base.query.QueryExecutor; 27 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
30 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; 28 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
31 import de.intevation.gnv.geobackend.base.query.exception.QueryException; 29 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
32 import de.intevation.gnv.raster.PaletteManager;
33 import de.intevation.gnv.state.InputData; 30 import de.intevation.gnv.state.InputData;
34 import de.intevation.gnv.state.OutputStateBase; 31 import de.intevation.gnv.state.OutputStateBase;
35 import de.intevation.gnv.state.exception.StateException; 32 import de.intevation.gnv.state.exception.StateException;
36 import de.intevation.gnv.utils.ArtifactXMLUtilities; 33 import de.intevation.gnv.utils.ArtifactXMLUtilities;
37 import de.intevation.gnv.utils.FileUtils; 34 import de.intevation.gnv.utils.FileUtils;
66 /** 63 /**
67 * The ID for the Query fetching the Geometry from the DB 64 * The ID for the Query fetching the Geometry from the DB
68 * which should be used to Clip the Layerdata 65 * which should be used to Clip the Layerdata
69 */ 66 */
70 private String geometryQueryID = null; 67 private String geometryQueryID = null;
68
69 private String columnQueryID = null;
71 70
72 /** 71 /**
73 * The ID for the Value which will hold the Geometrie-Value 72 * The ID for the Value which will hold the Geometrie-Value
74 */ 73 */
75 private String geometryID = null; 74 private String geometryID = null;
150 String[] queryValues = null; 149 String[] queryValues = null;
151 if (it.hasNext()){ 150 if (it.hasNext()){
152 Result resultValue = it.next(); 151 Result resultValue = it.next();
153 String table = resultValue.getString(0); 152 String table = resultValue.getString(0);
154 String where = resultValue.getString(1); 153 String where = resultValue.getString(1);
154 String columns = this.fetchColumns(table);
155
155 templateID = resultValue.getString(2); 156 templateID = resultValue.getString(2);
156 if (this.geometryID != null){ 157 if (this.geometryID != null){
157 InputData geometryInputData = 158 InputData geometryInputData =
158 this.inputData.get(this.geometryID); 159 this.inputData.get(this.geometryID);
159 if (geometryInputData != null){ 160 if (geometryInputData != null){
169 } 170 }
170 } catch (QueryException e) { 171 } catch (QueryException e) {
171 log.error(e,e); 172 log.error(e,e);
172 // TODO: what should happen?? 173 // TODO: what should happen??
173 } 174 }
174 queryValues = new String[]{table, 175 queryValues = new String[]{columns,
176 table,
175 where, 177 where,
176 geometryWKT}; 178 geometryWKT};
177 }else{ 179 }else{
178 // TODO: Look into the presetting for an WKT 180 // TODO: Look into the presetting for an WKT
179 queryValues = new String[]{table,where}; 181 queryValues = new String[]{columns,table,where};
180 } 182 }
181 }else{ 183 }else{
182 // TODO: Look into the presetting for an WKT 184 // TODO: Look into the presetting for an WKT
183 queryValues = new String[]{table,where}; 185 queryValues = new String[]{columns,table,where};
184 186
185 } 187 }
186 } 188 }
187 189
188 try { 190 try {
219 } 221 }
220 } 222 }
221 return data; 223 return data;
222 } 224 }
223 225
226 private String fetchColumns(String tableName){
227 String returnValue = null;
228 try {
229 String[] filter = tableName.toUpperCase().split("\\.");
230 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance()
231 .getQueryExecutor();
232
233 Collection<Result> columnData = queryExecutor.
234 executeQuery(this.columnQueryID,
235 filter);
236 if (columnData != null && !columnData.isEmpty()){
237 StringBuffer sb = new StringBuffer();
238 synchronized (sb) {
239 Iterator<Result> it = columnData.iterator();
240 while(it.hasNext()){
241 Result current = it.next();
242 sb.append(current.getString(0));
243 if (it.hasNext()){
244 sb.append(" , ");
245 }
246 }
247 }
248 returnValue = sb.toString();
249 }
250
251 } catch (QueryException e) {
252 log.error(e,e);
253 }
254 return returnValue;
255 }
224 @Override 256 @Override
225 public void setup(Node configuration) { 257 public void setup(Node configuration) {
226 log.debug("LayerOutputState.setup"); 258 log.debug("LayerOutputState.setup");
227 super.setup(configuration); 259 super.setup(configuration);
228 this.dataQueryID = Config.getStringXPath(configuration, 260 this.dataQueryID = Config.getStringXPath(configuration,
229 "queryID-layerdata"); 261 "queryID-layerdata");
230 this.geometryID = Config.getStringXPath(configuration, 262 this.geometryID = Config.getStringXPath(configuration,
231 "inputvalue-geometry"); 263 "inputvalue-geometry");
232 this.geometryQueryID = Config.getStringXPath(configuration, 264 this.geometryQueryID = Config.getStringXPath(configuration,
233 "queryID-geometry"); 265 "queryID-geometry");
266
267 this.columnQueryID = "layer_colums"; //Config.getStringXPath(configuration,
268 // "queryID-columns");
234 } 269 }
235 270
236 protected String writeToShapeFile( 271 protected String writeToShapeFile(
237 String uuid, 272 String uuid,
238 Collection<Result> data, 273 Collection<Result> data,
421 if (returnValue.equalsIgnoreCase("linestring")){ 456 if (returnValue.equalsIgnoreCase("linestring")){
422 returnValue = "Line"; 457 returnValue = "Line";
423 } 458 }
424 return returnValue; 459 return returnValue;
425 } 460 }
426
427 private static Map<Integer, PaletteManager> getPalettes(
428 CallContext callContext
429 ) {
430 //TODO: customize for product Layer
431 GNVArtifactContext context =
432 (GNVArtifactContext)callContext.globalContext();
433 Map<Integer, PaletteManager> palettes =
434 (Map<Integer, PaletteManager>)context.get(
435 GNVArtifactContext.PALETTES_KEY);
436 return palettes != null
437 ? palettes
438 : new HashMap<Integer, PaletteManager>();
439 }
440
441 } 461 }

http://dive4elements.wald.intevation.org