Mercurial > dive4elements > gnv-client
changeset 558:8032da9e8b70
Added further business logic for the MapViewer-Interface
gnv/trunk@654 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 01 Feb 2010 15:08:39 +0000 |
parents | 9f4a0b990d27 |
children | 2183c764b403 |
files | gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactFactory.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactFactory.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactObject.java gnv/src/main/webapp/WEB-INF/config/struts-config.xml |
diffstat | 8 files changed, 295 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv/ChangeLog Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/ChangeLog Mon Feb 01 15:08:39 2010 +0000 @@ -1,3 +1,38 @@ +2010-02-01 Tim Englich <tim.englich@intevation.de> + + * src/main/webapp/WEB-INF/config/struts-config.xml: + Added am Action for handling the MapViewer-Interface. + if /gnv/extcall.do is called the processing of the defined + Information will be done and the GUI will be displayed. + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactFactory.java: + Implementation of the interface ParametrizedArtifactObject fro the + representation of ArtifactFactories which has further Information. + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactObject.java (addParameters): + Added new Interfacedefinition ParametrizedArtifactObjects for representing those + ArtifactObjects which includes further Informations. E.g. for creating an + new Artifact. + + * src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactFactory.java (equals): + Override equals-method to get ap proper comparisons of the kinds of objects. + + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java (getArtifactFactoryMetaInformation): + Added Method to retrieve Metainformations form the ArtifactDatabases. + Also added the possibility to send further Informations (e.g: Parameters) + in the Request-body of an Create-Artifact-Call. + + * src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java (getArtifactFactoryMetaInformation): + Added Method to retrieve Metainformations form the ArtifactDatabases. + + * src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java (execute): + Added further Businesslogic to the Action which will handle the MapViewer- + InterfaceCall. Now the retrieved Informations will be sent to the + ArtifactDatabase an the retrieved Informations will be used to reduce + the displayed "Fachinformationssysteme". And also will be used to + send these Informations (e.g: Parameters) during the creation of an + new Artifact. + 2010-01-27 Hans Plum <hans@intevation.de> RELEASE 0.3
--- a/gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/mapviewer/MapViewerCallAction.java Mon Feb 01 15:08:39 2010 +0000 @@ -1,7 +1,10 @@ package de.intevation.gnv.action.mapviewer; +import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -14,7 +17,10 @@ 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.action.sessionmodel.SessionModel; +import de.intevation.gnv.action.sessionmodel.SessionModelFactory; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; +import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import de.intevation.gnv.artifactdatabase.objects.map.MapService; /** @@ -44,7 +50,14 @@ HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("MapViewerCallAction.execute"); - InputStream inputStream = request.getInputStream(); + InputStream inputStream = null; + String documentvalue = request.getParameter("document"); + if (documentvalue != null){ + inputStream = new ByteArrayInputStream(documentvalue.getBytes()); + }else{ + inputStream = request.getInputStream(); + } + if (inputStream != null){ try { ExternalCallParser ecp = new XMLExternalCallParser(inputStream); @@ -53,16 +66,37 @@ String srs = ecp.getSRS(); Collection<MapService> mapServices = ecp.getMapServices(); - ArtifactDatabaseClientFactory + Collection<ArtifactObject> availableFactories = + 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 + Collection<ArtifactObject> providedFactories = + ArtifactDatabaseClientFactory + .getInstance() + .getArtifactDatabaseClient(getLocale(request)) + .getArtifactFactories(); + + // Sort out which ArtifactFactories should not be used. + Collection<ArtifactObject> usedFactories = + new ArrayList<ArtifactObject>(availableFactories.size()); + + Iterator<ArtifactObject> it = availableFactories.iterator(); + while (it.hasNext()){ + ArtifactObject ao = it.next(); + if (providedFactories.contains(ao)){ + usedFactories.add(ao); + } + } + + SessionModel sm = SessionModelFactory + .getInstance() + .getSessionModel(request); + sm.resetModel(); + sm.setArtifacteFactories(usedFactories); } catch (Exception e) { log.error(e,e); }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Mon Feb 01 15:08:39 2010 +0000 @@ -10,7 +10,6 @@ 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; @@ -118,7 +117,7 @@ public void setLocale(Locale locale); - public Collection<ArtifactFactory> getArtifactFactoryMetaInformation(Collection<MapService> mapServices, + public Collection<ArtifactObject> getArtifactFactoryMetaInformation(Collection<MapService> mapServices, String geometry, String srs) throws ArtifactDatabaseClientException;
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Mon Feb 01 15:08:39 2010 +0000 @@ -10,22 +10,19 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; import java.util.List; import java.util.Locale; +import java.util.Map; import org.apache.log4j.Logger; - import org.restlet.Client; - +import org.restlet.data.ClientInfo; +import org.restlet.data.Language; import org.restlet.data.Method; +import org.restlet.data.Preference; import org.restlet.data.Protocol; import org.restlet.data.Request; import org.restlet.data.Response; -import org.restlet.data.Preference; -import org.restlet.data.Language; -import org.restlet.data.ClientInfo; - import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.w3c.dom.Document; @@ -46,6 +43,9 @@ 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.ParametrizedArtifactFactory; +import de.intevation.gnv.artifactdatabase.objects.ParametrizedArtifactObject; +import de.intevation.gnv.artifactdatabase.objects.map.Layer; import de.intevation.gnv.artifactdatabase.objects.map.MapService; import de.intevation.gnv.propertiesreader.PropertiesReader; import de.intevation.gnv.propertiesreader.PropertiesReaderFactory; @@ -139,9 +139,31 @@ "@art:name"); String description = xmlUtils.getStringXPath( artifactFactoryNode, "@art:description"); - ArtifactFactory artifactFactory = new ArtifactFactory(name, - description, server); - resultValues.add(artifactFactory); + + NodeList parameterNodeList = xmlUtils.getNodeSetXPath( + artifactFactoryNode, + "art:parameter"); + + if (parameterNodeList != null && + parameterNodeList.getLength() > 0){ + Collection<String> parameters = + new ArrayList<String>(parameterNodeList.getLength()); + for (int j = 0; j < parameterNodeList.getLength(); j++){ + Element parameterNode = (Element)parameterNodeList.item(j); + parameters.add(parameterNode.getAttribute("id")); + } + ParametrizedArtifactObject pao = + new ParametrizedArtifactFactory(name, + description, + server); + pao.addParameters("parameter", parameters); + resultValues.add(pao); + }else{ + ArtifactObject artifactFactory = new ArtifactFactory(name, + description, + server); + resultValues.add(artifactFactory); + } } } log.debug("Artifact Factories: " + resultValues.size()); @@ -255,8 +277,7 @@ throws ArtifactDatabaseClientException { try { - Document request = this.createCreateRequestBody(artifactFactory - .getId()); + Document request = this.createCreateRequestBody(artifactFactory); Document result = doPostRequest(artifactFactory, request, "create"); return this.getArtifact(result); } catch (IOException e) { @@ -273,17 +294,36 @@ return new Artifact(uuid, hash); } - private Document createCreateRequestBody(String artifactFactoryName) { + private Document createCreateRequestBody(ArtifactObject artifactFactory) { Document document = new XMLUtils().newDocument(); Node rootNode = this.createRootNode(document); Element typeNode = this.createArtifactElement(document, "type"); typeNode.setAttribute("name", "create"); rootNode.appendChild(typeNode); - Element factoyNode = this.createArtifactElement(document, "factory"); - factoyNode.setAttribute("name", artifactFactoryName); - rootNode.appendChild(factoyNode); - + Element factoryNode = this.createArtifactElement(document, "factory"); + factoryNode.setAttribute("name", artifactFactory.getId()); + rootNode.appendChild(factoryNode); + + if (artifactFactory instanceof ParametrizedArtifactObject){ + Map<String, Collection<String>> parameterMap = + ((ParametrizedArtifactObject)artifactFactory).getParameters(); + if (parameterMap != null && !parameterMap.isEmpty() ){ + Iterator<String> keyIt = parameterMap.keySet().iterator(); + while (keyIt.hasNext()){ + String key = keyIt.next(); + Iterator<String> valueIt = parameterMap.get(key).iterator(); + while (valueIt.hasNext()){ + String value = valueIt.next(); + Element parameterNode = + this.createArtifactElement(document, "parameter"); + parameterNode.setAttribute("name", key); + parameterNode.setAttribute("value", value); + factoryNode.appendChild(parameterNode); + } + } + } + } return document; } @@ -763,12 +803,80 @@ /** * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getArtifactFactoryMetaInformation(java.util.Collection, java.lang.String, java.lang.String) */ - public Collection<ArtifactFactory> getArtifactFactoryMetaInformation( + public Collection<ArtifactObject> getArtifactFactoryMetaInformation( Collection<MapService> mapServices, String geometry, String srs) throws ArtifactDatabaseClientException { - // TODO: Implement me - return null; + log.debug("DefaultArtifactDatabaseClient.getArtifactFactories"); + Collection<ArtifactObject> resultValues = null; + try { + this.initialize(); + Iterator<String> it = artifactDatabases.iterator(); + Document requestBody = this.createMetaDataRequestBody(mapServices, + geometry, + srs); + while (it.hasNext()) { + String server = it.next(); + String url = server + "/service/metadata/"; + log.debug(url); + + InputStream resultStream = this.doPostRequest(url, requestBody); + resultValues = this.parseMetaDataResult(resultStream, server); + } + } catch (IOException e) { + log.error(e,e); + } + return resultValues; + } + + private Collection<ArtifactObject> parseMetaDataResult( + InputStream inputStream, + String server) throws ArtifactDatabaseClientException{ + XMLUtils xmlUtils = new XMLUtils(); + Document document = xmlUtils.readDocument(inputStream); + this.check4ExceptionReport(document); + return this.getArtifactFactories(document, server); + } + + private Document createMetaDataRequestBody(Collection<MapService> mapServices, + String geometry, + String srs){ + log.debug("DefaultArtifactDatabaseClient.createMetaDataRequestBody"); + Document document = new XMLUtils().newDocument(); + Node rootNode = this.createArtifactElement(document, "GetMetaData"); + document.appendChild(rootNode); + + Element locationNode = this.createArtifactElement(document, "location"); + locationNode.setAttribute("srs", srs); + locationNode.appendChild(document.createTextNode(geometry)); + rootNode.appendChild(locationNode); + + Element mapServicesNode = this.createArtifactElement(document, + "mapservices"); + Iterator<MapService> it = mapServices.iterator(); + while (it.hasNext()){ + MapService mapService = it.next(); + Element mapServiceNode = this.createArtifactElement(document, + "mapservice"); + mapServiceNode.setAttribute("id", mapService.getID()); + mapServiceNode.setAttribute("type", mapService.getType()); + mapServiceNode.setAttribute("url", mapService.getURL()); + Iterator<Layer> layer = mapService.getLayer().iterator(); + while (layer.hasNext()){ + Layer tmpLayer = layer.next(); + Element layerNode = this.createArtifactElement(document, + "layer"); + layerNode.setAttribute("id", tmpLayer.getID()); + layerNode.setAttribute("name", tmpLayer.getName()); + layerNode.setAttribute("isgrouplayer", + ""+tmpLayer.isGroupLayer()); + layerNode.setAttribute("parentid", tmpLayer.parentID()); + mapServiceNode.appendChild(layerNode); + } + mapServicesNode.appendChild(mapServiceNode); + } + rootNode.appendChild(mapServicesNode); + return document; } }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactFactory.java Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactFactory.java Mon Feb 01 15:08:39 2010 +0000 @@ -86,4 +86,15 @@ return null; } + @Override + public boolean equals(Object obj) { + boolean returnValue = false; + if (obj instanceof ArtifactFactory){ + ArtifactFactory af = (ArtifactFactory)obj; + returnValue = this.getName().equals(af.getName()) && + this.getDataBaseUrl().equals(af.getDataBaseUrl()); + } + return returnValue; + } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactFactory.java Mon Feb 01 15:08:39 2010 +0000 @@ -0,0 +1,49 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class ParametrizedArtifactFactory extends ArtifactFactory implements + ParametrizedArtifactObject { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 4516368434861819032L; + + private Map<String, Collection<String>> parameters = null; + + /** + * Constructor + * @param name + * @param description + * @param dataBaseUrl + */ + public ParametrizedArtifactFactory(String name, String description, + String dataBaseUrl) { + super(name, description, dataBaseUrl); + this.parameters = new HashMap<String, Collection<String>>(); + } + + /** + * @see de.intevation.gnv.artifactdatabase.objects.ParametrizedArtifactObject#getParameters() + */ + @Override + public Map<String, Collection<String>> getParameters() { + return parameters; + } + + @Override + public void addParameters(String key, Collection<String> values) { + this.parameters.put(key, values); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ParametrizedArtifactObject.java Mon Feb 01 15:08:39 2010 +0000 @@ -0,0 +1,24 @@ +/** + * + */ +package de.intevation.gnv.artifactdatabase.objects; + +import java.util.Collection; +import java.util.Map; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface ParametrizedArtifactObject extends ArtifactObject { + + /** + * Returns the Parameters which could be used to manage (e.g. create) an + * ArtifactObject. + * @return + */ + Map<String, Collection<String>> getParameters(); + + void addParameters(String key, Collection<String> values); + +}
--- a/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Wed Jan 27 14:26:30 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/struts-config.xml Mon Feb 01 15:08:39 2010 +0000 @@ -17,6 +17,14 @@ name="success" path="/WEB-INF/jsp/version.jsp"/> </action> + <action path="/extcall" + type="de.intevation.gnv.action.mapviewer.MapViewerCallAction" + scope="request" + validate="false"> + <forward + name="success" + path="/WEB-INF/jsp/mainlayout.jsp"/> + </action> <action path="/start" type="de.intevation.gnv.action.FetchArtifactFactoriesAction" scope="request"