# HG changeset patch # User Felix Wolfsteller # Date 1323346198 0 # Node ID fc8ff0ed64cad6741a03ba7eca9ac1cfd46a7db9 # Parent bc06a671ef60712e91c371a550e231dfeefbf0d3 Added client for CrossSectionKMService. flys-client/trunk@3369 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r bc06a671ef60 -r fc8ff0ed64ca flys-client/ChangeLog --- a/flys-client/ChangeLog Thu Dec 08 09:12:27 2011 +0000 +++ b/flys-client/ChangeLog Thu Dec 08 12:09:58 2011 +0000 @@ -1,4 +1,11 @@ -2011-11-17 Raimund Renkert +2011-12-08 Felix Wolfsteller + + * src/main/java/de/intevation/flys/client/server/CrossSectionKMServiceImpl.java, + src/main/java/de/intevation/flys/client/client/services/CrossSectionKMServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/CrossSectionKMService.java: + Added client to CrossSectionKMService. + +2011-12-08 Raimund Renkert * src/main/java/de/intevation/flys/client/server/LoadArtifactServiceImpl.java, src/main/java/de/intevation/flys/client/server/CollectionItemAttributeServiceImpl.java, diff -r bc06a671ef60 -r fc8ff0ed64ca flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMService.java Thu Dec 08 12:09:58 2011 +0000 @@ -0,0 +1,30 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; + +/** + * This interface provides access to CrossSectionKMService . + */ +@RemoteServiceRelativePath("cross-section-km") +public interface CrossSectionKMService extends RemoteService { + + /** + * @param serverUrl The url of the artifact server. + * @param locale The locale used for the request. + * @param artifact The artifact. + * @param data The data that should be inserted. + * + * @return the artifact which description might have been changed. + */ + public Map getCrossSectionKMs( + String locale, + Map data, + int nNeightbours) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r bc06a671ef60 -r fc8ff0ed64ca flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMServiceAsync.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/CrossSectionKMServiceAsync.java Thu Dec 08 12:09:58 2011 +0000 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import java.util.Map; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * Talk-to interface for crosssectionkm service. + */ +public interface CrossSectionKMServiceAsync { + + void getCrossSectionKMs( + String locale, + Map data, + int nNeighbours, + AsyncCallback> cb); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r bc06a671ef60 -r fc8ff0ed64ca flys-client/src/main/java/de/intevation/flys/client/server/CrossSectionKMServiceImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CrossSectionKMServiceImpl.java Thu Dec 08 12:09:58 2011 +0000 @@ -0,0 +1,134 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import org.apache.log4j.Logger; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.httpclient.exceptions.ConnectionException; +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.client.services.CrossSectionKMService; + +/** + * Interact with not documented service. + */ +public class CrossSectionKMServiceImpl +extends RemoteServiceServlet +implements CrossSectionKMService +{ + private static final Logger logger = + Logger.getLogger(CrossSectionKMServiceImpl.class); + + /** XPath that points to the found cross section measurements. */ + public static final String XPATH_CROSS_SECTIONS + = "/cross-sections/cross-section"; + + /** The error message key that is thrown if an error occured while getting + * new data. */ + public static final String ERROR_GET_CROSS_SECTION + = "error_get_cross_section"; + + + /** + * Fetches positions (kms) at which measurements for given cross-sections + * exists. + * + * @param data Map of Integer (cross-section-id) to km. + * + */ + public Map getCrossSectionKMs( + String locale, + Map data, + int nNeighbours) + throws ServerException + { + logger.info("CrossSectionKMService.getCrossSectionKMs"); + + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + Element crossSection = ec.create("cross-sections"); + + doc.appendChild(crossSection); + + for(Map.Entry oneCrossSection : data.entrySet()) { + Element cs = ec.create("cross-section"); + cs.setAttribute("id", oneCrossSection.getKey().toString()); + cs.setAttribute("km", oneCrossSection.getValue().toString()); + cs.setAttribute("n", Integer.valueOf(nNeighbours).toString()); + crossSection.appendChild(cs); + } + + HttpClient client = new HttpClientImpl(url, locale); + logger.debug("Created httpclient"); + + try { + // Document should contain: + // crosse-sections: + // attribute(id), attribute(km) attribute(n) + Document response = client.callService(url, "cross-section-km", doc); + //... + + NodeList nodeList = (NodeList) XMLUtils.xpath(response, + XPATH_CROSS_SECTIONS, + XPathConstants.NODESET); + + int num = nodeList.getLength(); + + Map result = new HashMap(); + + try{ + for (int i = 0; i < num; i++) { + Element csElement = (Element) nodeList.item(i); + + int idx = Integer.parseInt(csElement.getAttribute("id")); + ArrayList kms = new ArrayList(); + + NodeList lineNodes = csElement.getElementsByTagName("line"); + int numLines = lineNodes.getLength(); + for (int k = 0; k < numLines; k++) { + Element line = (Element) lineNodes.item(i); + double d = Double.parseDouble(line.getAttribute("km")); + kms.add(d); + } + + Double[] doubles = new Double[kms.size()]; + kms.toArray(doubles); + result.put(Integer.valueOf(idx), doubles); + } + } + catch(NumberFormatException nfe) { + logger.error("Response was not parsable"); + } + + return result; + } + catch (ConnectionException ce) { + logger.error("ConnectionExsp", ce); + } + + logger.warn("CrossSectionKMService.getCrossSectionKMS() - FAILED"); + throw new ServerException(ERROR_GET_CROSS_SECTION); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :