diff 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
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Fri Mar 12 11:28:36 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Fri Mar 12 11:36:38 2010 +0000
@@ -7,9 +7,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -29,7 +27,6 @@
 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
-import de.intevation.gnv.raster.PaletteManager;
 import de.intevation.gnv.state.InputData;
 import de.intevation.gnv.state.OutputStateBase;
 import de.intevation.gnv.state.exception.StateException;
@@ -69,6 +66,8 @@
      */
     private String geometryQueryID = null;
     
+    private String columnQueryID = null;
+    
     /**
      * The ID for the Value which will hold the Geometrie-Value
      */
@@ -152,6 +151,8 @@
                 Result resultValue = it.next();
                 String table = resultValue.getString(0);
                 String where = resultValue.getString(1);
+                String columns = this.fetchColumns(table);
+                
                 templateID = resultValue.getString(2);
                 if (this.geometryID != null){
                     InputData geometryInputData = 
@@ -171,16 +172,17 @@
                             log.error(e,e);
                             // TODO: what should happen??
                         }
-                       queryValues = new String[]{table,
+                       queryValues = new String[]{columns,
+                                                  table,
                                                   where,
                                                   geometryWKT};
                     }else{
                         // TODO: Look into the presetting for an WKT
-                        queryValues = new String[]{table,where};
+                        queryValues = new String[]{columns,table,where};
                     }
                 }else{
                     // TODO: Look into the presetting for an WKT
-                    queryValues = new String[]{table,where};
+                    queryValues = new String[]{columns,table,where};
                     
                 }
             }
@@ -221,6 +223,36 @@
         return data;
     }
 
+    private String fetchColumns(String tableName){
+        String returnValue = null;
+        try {
+            String[] filter = tableName.toUpperCase().split("\\.");
+            QueryExecutor queryExecutor = QueryExecutorFactory.getInstance()
+            .getQueryExecutor();
+            
+            Collection<Result> columnData = queryExecutor.
+                                                executeQuery(this.columnQueryID, 
+                                                             filter);
+            if (columnData != null && !columnData.isEmpty()){
+                StringBuffer sb = new StringBuffer();
+                synchronized (sb) {
+                    Iterator<Result> it = columnData.iterator();
+                    while(it.hasNext()){
+                        Result current = it.next();
+                        sb.append(current.getString(0));
+                        if (it.hasNext()){
+                            sb.append(" , ");
+                        }
+                    }
+                }
+                returnValue = sb.toString();
+            }
+            
+        } catch (QueryException e) {
+            log.error(e,e);
+        }
+        return returnValue;
+    }
     @Override
     public void setup(Node configuration) {
         log.debug("LayerOutputState.setup");
@@ -231,6 +263,9 @@
                                                 "inputvalue-geometry");
         this.geometryQueryID =  Config.getStringXPath(configuration,
                                                 "queryID-geometry");
+        
+        this.columnQueryID =   "layer_colums"; //Config.getStringXPath(configuration,
+                                               // "queryID-columns");
     }
     
     protected String writeToShapeFile(
@@ -423,19 +458,4 @@
         }
         return returnValue;
     }
-    
-    private static Map<Integer, PaletteManager> getPalettes(
-            CallContext callContext
-        ) {
-        //TODO: customize for product Layer
-            GNVArtifactContext context = 
-                (GNVArtifactContext)callContext.globalContext();
-            Map<Integer, PaletteManager> palettes =
-                (Map<Integer, PaletteManager>)context.get(
-                    GNVArtifactContext.PALETTES_KEY);
-            return palettes != null
-                ? palettes
-                : new HashMap<Integer, PaletteManager>();
-        }
-
 }

http://dive4elements.wald.intevation.org