Mercurial > dive4elements > gnv-client
changeset 402:b88e881e8e94
Added the first Implementation (not complete and not ready to use) for the Interface from the MapViewer to the GNV
gnv/trunk@573 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv/ChangeLog Mon Jan 18 16:21:54 2010 +0000 +++ b/gnv/ChangeLog Tue Jan 19 14:47:36 2010 +0000 @@ -1,3 +1,32 @@ +2010-01-19 Tim Englich <tim.englich@intevation.de> + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/map/DefaultMapService.java: + DefaultImplementation of the Interface MapService. + * src/main/java/de/intevation/gnv/artifactdatabase/objects/map/MapService.java : + Added a new Interfacespecification for representing an MapService retrieved + by an MapViewer-Call + * src/main/java/de/intevation/gnv/artifactdatabase/objects/map/DefaultLayer.java: + DefaultImplementation of the Interface Layer. + * src/main/java/de/intevation/gnv/artifactdatabase/objects/map/Layer.java: + Added a new Interfacespecification for representing an Layer retrieved + by an MapViewer-Call + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java (getArtifactFactoryMetaInformation), + src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java (getArtifactFactoryMetaInformation): + Added new Method for retrieving Metainformation for the ArtifactFactories using + the Data which is parsed using the ExternalCallParser. + * src/main/java/de/intevation/gnv/action/mapviewer/parser/ExternalCallParserException.java (ExternalCallParserException): + New ExceptionClass which is used to specify Exception which occurs during parsing + an ExternalCallParser. + * src/main/java/de/intevation/gnv/action/mapviewer/parser/XMLExternalCallParser.java : + Added an Implementation of the Inteface ExternalCallParser which is able to parse + an XML-Document. + * src/main/java/de/intevation/gnv/action/mapviewer/parser/ExternalCallParser.java : + Added a new Interface which provides the required Methods for parsing an + Request from the MapViewer an provide the parsed Data. + * src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java: + Added new Action which provied the reauired logic for Implementing the + Interface to the MapViewer. + 2010-01-18 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/webapp/WEB-INF/config/struts-config.xml: Added a new controller
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,75 @@ +package de.intevation.gnv.action.mapviewer; + +import java.io.InputStream; +import java.util.Collection; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import de.intevation.gnv.action.ArtifactDatabaseActionBase; +import de.intevation.gnv.action.mapviewer.parser.ExternalCallParser; +import de.intevation.gnv.action.mapviewer.parser.XMLExternalCallParser; +import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.map.MapService; + +/** + * + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class MapViewerCallAction extends ArtifactDatabaseActionBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(MapViewerCallAction.class); + + /** + * Constructor + */ + public MapViewerCallAction() { + super(); + } + + /** + * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) + */ + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws Exception { + log.debug("MapViewerCallAction.execute"); + InputStream inputStream = request.getInputStream(); + if (inputStream != null){ + try { + ExternalCallParser ecp = new XMLExternalCallParser(inputStream); + ecp.parse(); + String geometry = ecp.getGeometry(); + String srs = ecp.getSRS(); + Collection<MapService> mapServices = ecp.getMapServices(); + + ArtifactDatabaseClientFactory + .getInstance() + .getArtifactDatabaseClient(getLocale(request)) + .getArtifactFactoryMetaInformation(mapServices, + geometry, + srs); + + // 2. Call Artifactfactories. + // 3. Sort out which ArtifactFactories should not be used. + // 4. Store the retrieved Parameter to each ArtifactFactory + } catch (Exception e) { + log.error(e,e); + } + }else{ + log.error("Kein Anfragedokument übergeben."); + } + return super.execute(mapping, form, request, response); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/parser/ExternalCallParser.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,24 @@ +/** + * + */ +package de.intevation.gnv.action.mapviewer.parser; + +import java.util.Collection; + +import de.intevation.gnv.artifactdatabase.objects.map.MapService; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface ExternalCallParser { + + + String getGeometry(); + + String getSRS(); + + Collection<MapService> getMapServices(); + + void parse() throws ExternalCallParserException; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/parser/ExternalCallParserException.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,47 @@ +/** + * + */ +package de.intevation.gnv.action.mapviewer.parser; +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class ExternalCallParserException extends Exception { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = -4917914097058485262L; + + /** + * Constructor + */ + public ExternalCallParserException() { + } + + /** + * Constructor + * @param arg0 + */ + public ExternalCallParserException(String arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + */ + public ExternalCallParserException(Throwable arg0) { + super(arg0); + } + + /** + * Constructor + * @param arg0 + * @param arg1 + */ + public ExternalCallParserException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/parser/XMLExternalCallParser.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,155 @@ +/** + * + */ +package de.intevation.gnv.action.mapviewer.parser; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; + + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import de.intevation.gnv.artifactdatabase.objects.map.DefaultLayer; +import de.intevation.gnv.artifactdatabase.objects.map.DefaultMapService; +import de.intevation.gnv.artifactdatabase.objects.map.Layer; +import de.intevation.gnv.artifactdatabase.objects.map.MapService; +import de.intevation.gnv.util.XMLUtils; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class XMLExternalCallParser implements ExternalCallParser { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(XMLExternalCallParser.class); + + private static String XPATH_GEOMETRY = "/gnviewer/location/data"; + private static String XPATH_SRS = "/gnviewer/location/srs"; + private static String XPATH_MAPSERVICES_NODESET = "/gnviewer/mapservices/mapservice"; + private static String XPATH_LAYER = "layer"; + private static String ATTRIBUTE_ID = "id"; + private static String ATTRIBUTE_NAME = "name"; + private static String ATTRIBUTE_TYPE = "type"; + private static String ATTRIBUTE_URL = "url"; + + private String geometry = null; + private String srs = null; + + private Collection<MapService> mapServices = null; + + private InputStream inputStream = null; + + /** + * Constructor + */ + public XMLExternalCallParser(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * @see de.intevation.gnv.action.mapviewer.parser.ExternalCallParser#getGeometry() + */ + public String getGeometry() { + return this.geometry; + } + + /** + * @see de.intevation.gnv.action.mapviewer.parser.ExternalCallParser#getMapServices() + */ + public Collection<MapService> getMapServices() { + return this.mapServices; + } + + /** + * @see de.intevation.gnv.action.mapviewer.parser.ExternalCallParser#parse() + */ + public void parse() throws ExternalCallParserException { + if (inputStream != null){ + XMLUtils xmlUtils = new XMLUtils(); + Document document = xmlUtils.readDocument(this.inputStream); + if (document != null){ + + this.geometry = xmlUtils.getStringXPath(document, XPATH_GEOMETRY); + this.srs = xmlUtils.getStringXPath(document, XPATH_SRS); + NodeList mapservicesNodes = + xmlUtils.getNodeSetXPath(document, XPATH_MAPSERVICES_NODESET); + if (mapservicesNodes != null){ + this.mapServices = new ArrayList<MapService>(mapservicesNodes.getLength()); + for (int i = 0; i < mapservicesNodes.getLength(); i++){ + Element mapserviceNode = (Element)mapservicesNodes.item(i); + String mapserviceID = mapserviceNode.getAttribute(ATTRIBUTE_ID); + String mapserviceType = mapserviceNode.getAttribute(ATTRIBUTE_TYPE); + String mapserviceUrl = mapserviceNode.getAttribute(ATTRIBUTE_URL); + NodeList layerNodes = xmlUtils.getNodeSetXPath(mapserviceNode, XPATH_LAYER); + Collection<Layer> layer = null; + if (layerNodes != null && layerNodes.getLength() > 0){ + layer = new ArrayList<Layer>(layerNodes.getLength()); + layer = this.extractLayer(layer, null, layerNodes); + }else{ + log.debug("No Layer given for this Mapservice"); + } + MapService mapService = + new DefaultMapService(mapserviceID, layer, + mapserviceType, mapserviceUrl); + this.mapServices.add(mapService); + } + + }else{ + String errMsg = "XML-Document does not contain any Mapservices which are required."; + log.error(errMsg); + throw new ExternalCallParserException(errMsg); + } + + }else{ + String errMsg = "XML-Document could not be read from InputStream."; + log.error(errMsg); + throw new ExternalCallParserException(errMsg); + } + }else{ + String errMsg = "No InputStream given for parsing the Call."; + log.error(errMsg); + throw new ExternalCallParserException(errMsg); + } + } + + /** + * This Method extracts all Layers and put them into the Collection. + * @param layer + * @param groupId + * @param layerNodes + * @return + */ + private Collection<Layer> extractLayer(Collection<Layer> layer, String groupId, NodeList layerNodes){ + XMLUtils xmlUtils = new XMLUtils(); + for (int i = 0; i < layerNodes.getLength(); i++){ + Element layerNode = (Element)layerNodes.item(i); + String id = layerNode.getAttribute(ATTRIBUTE_ID); + String name = layerNode.getAttribute(ATTRIBUTE_NAME); + NodeList localLayerNodes = xmlUtils.getNodeSetXPath(layerNode, XPATH_LAYER); + Layer tmpLayer = new DefaultLayer(id, name, + (localLayerNodes != null && + localLayerNodes.getLength() > 0), + groupId); + layer.add(tmpLayer); + if (localLayerNodes != null && localLayerNodes.getLength() > 0){ + layer = this.extractLayer(layer, id, localLayerNodes); + } + } + return layer; + } + + /** + * @see de.intevation.gnv.action.mapviewer.parser.ExternalCallParser#getSRS() + */ + public String getSRS() { + return this.srs; + } + +}
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Mon Jan 18 16:21:54 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Tue Jan 19 14:47:36 2010 +0000 @@ -10,9 +10,11 @@ import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException; import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; +import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import de.intevation.gnv.artifactdatabase.objects.ArtifactStatisticsSet; import de.intevation.gnv.artifactdatabase.objects.InputParameter; +import de.intevation.gnv.artifactdatabase.objects.map.MapService; /** * @author Tim Englich <tim.englich@intevation.de> @@ -115,4 +117,10 @@ throws ArtifactDatabaseClientException; public void setLocale(Locale locale); + + public Collection<ArtifactFactory> getArtifactFactoryMetaInformation(Collection<MapService> mapServices, + String geometry, + String srs) + throws ArtifactDatabaseClientException; + }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Mon Jan 18 16:21:54 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Tue Jan 19 14:47:36 2010 +0000 @@ -46,6 +46,7 @@ import de.intevation.gnv.artifactdatabase.objects.InputParameter; import de.intevation.gnv.artifactdatabase.objects.OutputMode; import de.intevation.gnv.artifactdatabase.objects.OutputParameter; +import de.intevation.gnv.artifactdatabase.objects.map.MapService; import de.intevation.gnv.propertiesreader.PropertiesReader; import de.intevation.gnv.propertiesreader.PropertiesReaderFactory; import de.intevation.gnv.util.XMLUtils; @@ -758,4 +759,16 @@ public void setLocale(Locale locale) { this.locale = locale; } + + /** + * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getArtifactFactoryMetaInformation(java.util.Collection, java.lang.String, java.lang.String) + */ + public Collection<ArtifactFactory> getArtifactFactoryMetaInformation( + Collection<MapService> mapServices, + String geometry, + String srs) + throws ArtifactDatabaseClientException { + // TODO: Implement me + return null; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/map/DefaultLayer.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,67 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects.map; +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class DefaultLayer implements Layer { + + + private String id = null; + + private String name = null; + + private boolean groupLayer = false; + + private String parentId = null; + /** + * Constructor + */ + public DefaultLayer(String id,String name, + boolean groupLayer,String parentId) { + this.id = id; + this.name = name; + this.groupLayer = groupLayer; + this.parentId = parentId; + } + + + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.Layer#getID() + */ + public String getID() { + return this.id; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.Layer#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.Layer#isGroupLayer() + */ + public boolean isGroupLayer() { + return this.groupLayer; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.Layer#parentID() + */ + public String parentID() { + return this.parentId; + } + + @Override + public String toString() { + return "ID: "+ this.id + " Name: "+this.name+ + " IsGroupLayer: "+this.groupLayer+ + " ParentID: "+this.parentId; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/map/DefaultMapService.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,63 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects.map; + +import java.util.Collection; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class DefaultMapService implements MapService { + + private String id = null; + + + + private Collection<Layer> layer = null; + + private String type = null; + + private String url = null; + /** + * Constructor + */ + public DefaultMapService(String id, Collection<Layer> layer, + String type, String url) { + super(); + this.id = id; + this.layer = layer; + this.type = type; + this.url = url; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.MapService#getID() + */ + public String getID() { + return this.id; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.MapService#getLayer() + */ + public Collection<Layer> getLayer() { + return this.layer; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.MapService#getType() + */ + public String getType() { + return this.type; + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.map.MapService#getURL() + */ + public String getURL() { + return this.url; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/map/Layer.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,16 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects.map; +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface Layer { + + String getName(); + String getID(); + boolean isGroupLayer(); + String parentID(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/map/MapService.java Tue Jan 19 14:47:36 2010 +0000 @@ -0,0 +1,23 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects.map; + +import java.util.Collection; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface MapService { + + + String getID(); + + String getURL(); + + String getType(); + + Collection<Layer> getLayer(); + +}