changeset 604:938ce81a6bd0

Integrated Database-Support for the Mapviewer-Interface gnv-artifacts/trunk@666 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 09 Feb 2010 13:01:20 +0000
parents 78499af390a2
children e8ebdbc7f1e3
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/doc/conf/queries.properties gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/DummyMetaDataService.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/MetaDataService.java
diffstat 5 files changed, 134 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Fri Feb 05 14:15:09 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Feb 09 13:01:20 2010 +0000
@@ -1,3 +1,18 @@
+2010-02-09  Tim Englich  <tim.englich@intevation.de>
+
+	* doc/conf/conf.xml: 
+	  Switched the usage of DummyMetaDataService to MetaDataService because
+	  the Service is now able to work properly.
+	* doc/conf/queries.properties: 
+	  Added the required SQL-Statements for fetching the Metadata from the 
+	  Database.
+	* src/main/java/de/intevation/gnv/artifacts/services/MetaDataService.java:
+	  Added the Database-Lookup of FIS and Parameters.
+	  Now the Metadata will be looked up using the specified Databaseschema as
+	  defined in doc/schema/externalinterface_schema.sql
+	* src/main/java/de/intevation/gnv/artifacts/services/DummyMetaDataService.java 
+	  Removed Dummyservice because it is not required any more.
+
 2010-02-05  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	  Issue170
--- a/gnv-artifacts/doc/conf/conf.xml	Fri Feb 05 14:15:09 2010 +0000
+++ b/gnv-artifacts/doc/conf/conf.xml	Tue Feb 09 13:01:20 2010 +0000
@@ -38,7 +38,7 @@
         <service-factories>
             <service-factory
                 name="metadata"
-                service="de.intevation.gnv.artifacts.services.DummyMetaDataService"
+                service="de.intevation.gnv.artifacts.services.MetaDataService"
                 description="This is the Service for getting Metadata from the GNV-Artuifact-Services">de.intevation.artifactdatabase.DefaultServiceFactory</service-factory>
         </service-factories>
     </factories>
--- a/gnv-artifacts/doc/conf/queries.properties	Fri Feb 05 14:15:09 2010 +0000
+++ b/gnv-artifacts/doc/conf/queries.properties	Tue Feb 09 13:01:20 2010 +0000
@@ -1191,3 +1191,25 @@
 rasterQuery = SELECT ST_ASTEXT(RASTER) \
     FROM MEDIAN.TOPO_WORLD_2MIN \
     WHERE INTERSECTS(RASTER, "?")
+    
+mapviewer_interface_fis_region = SELECT ID_FIS \
+    FROM MEDIAN.FEATUREAREA, \
+         MEDIAN.FIS_HAS_REGION FHR \
+    WHERE FHR.FEATUREID = MEDIAN.FEATUREAREA.FEATUREID AND \
+          FHR.FEATURETYPE = MEDIAN.FEATUREAREA.FEATURETYPE AND \
+          FHR.FEATURECODE = MEDIAN.FEATUREAREA.FEATURECODE AND \
+          INTERSECTS(SHAPE,"?")
+          
+mapviewer_interface_mapservices_has_fis = SELECT DISTINCT ID_FIS, \
+         ID_MAPSERVICE \
+    FROM MEDIAN.FIS_HAS_MAPSERVICE \
+    WHERE ID_MAPSERVICE IN (?)
+
+mapviewer_interface_mapservices_has_parameter = SELECT DISTINCT ID_PARAMETER \
+    FROM MEDIAN.MAPSERVICE_HAS_PARAMETER \
+    WHERE ID_MAPSERVICE = ?
+
+mapviewer_interface_mapservices_has_parameter_using_layer = SELECT DISTINCT ID_PARAMETER \
+   FROM MEDIAN.LAYER_HAS_PARAMETER \
+   WHERE ID_MAPSERVICE = ? AND \
+         ID_LAYER IN (?)
\ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/DummyMetaDataService.java	Fri Feb 05 14:15:09 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/**
- *
- */
-package de.intevation.gnv.artifacts.services;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.log4j.Logger;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-import de.intevation.gnv.artifacts.services.requestobjects.DefaultFIS;
-import de.intevation.gnv.artifacts.services.requestobjects.DefaultParameter;
-import de.intevation.gnv.artifacts.services.requestobjects.FIS;
-import de.intevation.gnv.artifacts.services.requestobjects.Layer;
-import de.intevation.gnv.artifacts.services.requestobjects.MapService;
-import de.intevation.gnv.artifacts.services.requestobjects.Parameter;
-
-/**
- * Dummy of the MetaDataWebservice to simulate an answering Service
- * until the Databasebackend will serve the required Data.
- * bb
- * @author Tim Englich <tim.englich@intevation.de>
- *
- */
-public class DummyMetaDataService extends MetaDataService{
-
-    /**
-     * the logger, used to log exceptions and additionally information
-     */
-    private static Logger log = Logger.getLogger(DummyMetaDataService.class);
-    /**
-     * The UID of this Class.
-     */
-    private static final long serialVersionUID = 4712607258043392650L;
-
-    /**
-     * Constructor
-     */
-    public DummyMetaDataService() {
-        super();
-    }
-
-    /**
-     * @see de.intevation.gnv.artifacts.services.MetaDataService#getFIS(java.util.Collection)
-     */
-    @Override
-    protected Collection<FIS> getFIS(Collection<MapService> mapServices)
-                                                                        throws MetaDataServiceException {
-        log.debug("DummyMetaDataService.getFIS ==> MapServices");
-        Collection<FIS> returnValue = null;
-        if (mapServices != null && !mapServices.isEmpty()){
-            returnValue = new ArrayList<FIS>(mapServices.size());
-            Iterator<MapService> mit = mapServices.iterator();
-            while(mit.hasNext()){
-                MapService mapService = mit.next();
-                Collection<Layer> layer = mapService.getLayer();
-                Collection<Parameter> parameter = 
-                    new ArrayList<Parameter>(layer.size());
-                if (layer != null){
-                    Iterator<Layer> layerIt = layer.iterator();
-                    while (layerIt.hasNext()){
-                        Layer tmpLayer = layerIt.next();
-                        if (!tmpLayer.isGroupLayer()){
-                            parameter.add(new DefaultParameter(tmpLayer.getID(), 
-                                                               tmpLayer.getName()));
-                        }
-                    }
-                }
-                returnValue.add(new DefaultFIS(mapService.getID(),parameter));
-            }
-        }
-        return returnValue;
-    }
-
-    /**
-     * @see de.intevation.gnv.artifacts.services.MetaDataService#getFIS(com.vividsolutions.jts.geom.Geometry)
-     */
-    @Override
-    protected Collection<FIS> getFIS(Geometry g)
-                                                throws MetaDataServiceException {
-        log.debug("DummyMetaDataService.getFIS ==> Geometry");
-        Collection<FIS> returnValue = null;
-        if (g != null){
-            returnValue = new ArrayList<FIS>(2);
-            returnValue.add(new DefaultFIS("fis_modeldata"));
-            returnValue.add(new DefaultFIS("fis_marnet"));
-        }
-        return returnValue;
-    }
-}
\ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/MetaDataService.java	Fri Feb 05 14:15:09 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/MetaDataService.java	Tue Feb 09 13:01:20 2010 +0000
@@ -27,6 +27,7 @@
 import de.intevation.gnv.artifacts.services.requestobjects.DefaultFIS;
 import de.intevation.gnv.artifacts.services.requestobjects.DefaultLayer;
 import de.intevation.gnv.artifacts.services.requestobjects.DefaultMapService;
+import de.intevation.gnv.artifacts.services.requestobjects.DefaultParameter;
 import de.intevation.gnv.artifacts.services.requestobjects.FIS;
 import de.intevation.gnv.artifacts.services.requestobjects.Layer;
 import de.intevation.gnv.artifacts.services.requestobjects.MapService;
@@ -49,9 +50,15 @@
     private static Logger log = Logger.getLogger(MetaDataService.class);
 
     
-    private final static String FIS_REGION_QUERY_ID = "fis_region";
+    private final static String FIS_REGION_QUERY_ID = 
+                                      "mapviewer_interface_fis_region";
     private final static String MAPSERVICES_HAS_FIS_QUERY_ID = 
-                                                      "mapservices_has_fis";
+                                      "mapviewer_interface_mapservices_has_fis";
+    private final static String MAPSERVICES_HAS_PARAMETER_QUERY_ID = 
+                                "mapviewer_interface_mapservices_has_parameter";
+    
+    private final static String MAPSERVICES_HAS_PARAMETER_USING_LAYER_QUERY_ID = 
+        "mapviewer_interface_mapservices_has_parameter_using_layer";
     
     private static String ATTRIBUTE_ID = "id";
     private static String ATTRIBUTE_NAME = "name";
@@ -95,6 +102,7 @@
                                                       this.getFIS(mapServices));
             document = XMLUtils.newDocument();
             this.writeFIS2Document(document, resultFIS);
+            log.debug(new ArtifactXMLUtilities().writeDocument2String(document));
         } catch (MetaDataServiceException e) {
             log.error(e,e);
             document = new ArtifactXMLUtilities()
@@ -267,7 +275,7 @@
                     Iterator<Result> it = result.iterator();
                     while (it.hasNext()){
                         Result value = it.next();
-                        String fis_id = value.getString(0);
+                        String fis_id = value.getString(0).trim();
                         resultValue.add(new DefaultFIS(fis_id));
                     }
                 }
@@ -297,7 +305,7 @@
                     if (mapServiceNames.length() > 0){
                         mapServiceNames += " , ";
                     }
-                    mapServiceNames += "\""+mit.next().getID()+"\"";
+                    mapServiceNames += "'"+mit.next().getID()+"'";
                 }
                 
                 QueryExecutor queryExecutor = QueryExecutorFactory
@@ -311,13 +319,53 @@
                     Iterator<Result> it = result.iterator();
                     while (it.hasNext()){
                         Result value = it.next();
-                        String fis_id = value.getString(0);
-                        
-                        // TODO: QUERY PARAMS
+                        String fis_id = value.getString(0).trim();
+                        String mapServiceID = value.getString(1).trim();
+                       
                         // FIRST LOOK IF ONE MAPSERVICE REPRESENTS ONLY ONE PARAM
-                        // IF FALSE LOOK IF THE GIVEN LAYERs TO AN MAPSERVICE
-                        // REPRESENTS DIFFERENT PARAMS
+                        Collection<Result> result2 = queryExecutor.executeQuery(
+                                MAPSERVICES_HAS_PARAMETER_QUERY_ID,
+                                new String[]{"'"+mapServiceID+"'"});
                         Collection<Parameter> parameter = null;
+                        if (result2 != null && result2.size() == 1){
+                            Iterator<Result> it2 = result2.iterator();
+                            parameter = new ArrayList<Parameter>(1);
+                            while (it2.hasNext()){
+                                Result parameterValue = it2.next();
+                                String parameterID = parameterValue.getString(0)
+                                                                   .trim();
+                                parameter.add(new DefaultParameter(parameterID, 
+                                                                   parameterID));
+                            }
+                        }else{
+                            // IF FALSE LOOK IF THE GIVEN LAYERs TO AN MAPSERVICE
+                            // REPRESENTS DIFFERENT PARAMS
+                            MapService service = this.getMapService(mapServices,
+                                                                    mapServiceID);
+                            Collection<Layer> layer = service.getLayer();
+                            if (layer != null && !layer.isEmpty()){
+                                String layerQueryString = 
+                                    this.createLayerQueryString(layer);
+                                Collection<Result> parameterResult = 
+                                    queryExecutor.executeQuery(
+                                        MAPSERVICES_HAS_PARAMETER_USING_LAYER_QUERY_ID,
+                                        new String[]{"'"+mapServiceID+"'",
+                                                     layerQueryString});
+                                if (parameterResult != null && 
+                                    !parameterResult.isEmpty()){
+                                    Iterator<Result> it2 = parameterResult.iterator();
+                                    parameter = new ArrayList<Parameter>(parameterResult.size());
+                                    while (it2.hasNext()){
+                                        Result parameterValue = it2.next();
+                                        String parameterID = parameterValue.getString(0)
+                                                                           .trim();
+                                        parameter.add(new DefaultParameter(parameterID, 
+                                                                           parameterID));
+                                    }
+                                }
+                            }
+                            
+                        }
                         resultValue.add(new DefaultFIS(fis_id, parameter));
                     }
                 }
@@ -329,6 +377,45 @@
         }
         return resultValue;
     }
+    
+    
+    private MapService getMapService(Collection<MapService> mapServices,
+                                     String mapServiceID){
+        log.debug("MetaDataService.getMapService");
+        Iterator<MapService> it = mapServices.iterator();
+        while (it.hasNext()){
+            MapService service = it.next();
+            if (service.getID().equals(mapServiceID)){
+                return service;
+            }
+        }
+        return null;
+    }
+    
+    private String createLayerQueryString(Collection<Layer> layer){
+        log.debug("MetaDataService.createLayerQueryString");
+        StringBuffer sb = new StringBuffer();;
+        Iterator<Layer> it = layer.iterator();
+        synchronized (sb) {
+            while (it.hasNext()){
+                Layer l = it.next();
+                if (!l.isGroupLayer()){
+                    sb.append(l.getID());
+                    if (it.hasNext()){
+                        sb.append(" , ");
+                    }
+                }
+                
+            }
+        }
+        String returnValue = sb.toString();
+        if (returnValue.endsWith(" , ")){
+            returnValue = returnValue.substring(0,returnValue
+                                                  .lastIndexOf(","))
+                                                  .trim();
+        }
+        return returnValue;
+    }
 
     /**
      * @see de.intevation.artifactdatabase.DefaultService#setup(de.intevation.artifacts.ServiceFactory, java.lang.Object)

http://dive4elements.wald.intevation.org