# HG changeset patch # User Tim Englich # Date 1265720480 0 # Node ID 938ce81a6bd029095783406e80e05448627dd97c # Parent 78499af390a20ee2861e3b5ea2cb68bfd003bac7 Integrated Database-Support for the Mapviewer-Interface gnv-artifacts/trunk@666 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 78499af390a2 -r 938ce81a6bd0 gnv-artifacts/ChangeLog --- 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 + + * 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 Issue170 diff -r 78499af390a2 -r 938ce81a6bd0 gnv-artifacts/doc/conf/conf.xml --- 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 @@ de.intevation.artifactdatabase.DefaultServiceFactory diff -r 78499af390a2 -r 938ce81a6bd0 gnv-artifacts/doc/conf/queries.properties --- 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 diff -r 78499af390a2 -r 938ce81a6bd0 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/DummyMetaDataService.java --- 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 - * - */ -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 getFIS(Collection mapServices) - throws MetaDataServiceException { - log.debug("DummyMetaDataService.getFIS ==> MapServices"); - Collection returnValue = null; - if (mapServices != null && !mapServices.isEmpty()){ - returnValue = new ArrayList(mapServices.size()); - Iterator mit = mapServices.iterator(); - while(mit.hasNext()){ - MapService mapService = mit.next(); - Collection layer = mapService.getLayer(); - Collection parameter = - new ArrayList(layer.size()); - if (layer != null){ - Iterator 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 getFIS(Geometry g) - throws MetaDataServiceException { - log.debug("DummyMetaDataService.getFIS ==> Geometry"); - Collection returnValue = null; - if (g != null){ - returnValue = new ArrayList(2); - returnValue.add(new DefaultFIS("fis_modeldata")); - returnValue.add(new DefaultFIS("fis_marnet")); - } - return returnValue; - } -} \ No newline at end of file diff -r 78499af390a2 -r 938ce81a6bd0 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/services/MetaDataService.java --- 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 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 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 result2 = queryExecutor.executeQuery( + MAPSERVICES_HAS_PARAMETER_QUERY_ID, + new String[]{"'"+mapServiceID+"'"}); Collection parameter = null; + if (result2 != null && result2.size() == 1){ + Iterator it2 = result2.iterator(); + parameter = new ArrayList(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 = service.getLayer(); + if (layer != null && !layer.isEmpty()){ + String layerQueryString = + this.createLayerQueryString(layer); + Collection parameterResult = + queryExecutor.executeQuery( + MAPSERVICES_HAS_PARAMETER_USING_LAYER_QUERY_ID, + new String[]{"'"+mapServiceID+"'", + layerQueryString}); + if (parameterResult != null && + !parameterResult.isEmpty()){ + Iterator it2 = parameterResult.iterator(); + parameter = new ArrayList(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 mapServices, + String mapServiceID){ + log.debug("MetaDataService.getMapService"); + Iterator it = mapServices.iterator(); + while (it.hasNext()){ + MapService service = it.next(); + if (service.getID().equals(mapServiceID)){ + return service; + } + } + return null; + } + + private String createLayerQueryString(Collection layer){ + log.debug("MetaDataService.createLayerQueryString"); + StringBuffer sb = new StringBuffer();; + Iterator 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)