# HG changeset patch # User Ingo Weinzierl # Date 1299657606 0 # Node ID 44c63e7fd0d03d9babc313da2078e8bd2846f2d5 # Parent dfdb927b137d739a65e1bf232e58ffd0439666d4 Added a service to list the supported rivers of the artifact server. The FLYS instance serves a method that retrieves this list. flys-client/trunk@1431 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Mar 08 16:20:34 2011 +0000 +++ b/flys-client/ChangeLog Wed Mar 09 08:00:06 2011 +0000 @@ -1,3 +1,21 @@ +2011-03-09 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/RiverService.java, + src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java: + New. A service that retrieves a list of supported rivers by the artifact + server. + + * src/main/java/de/intevation/flys/client/shared/model/River.java, + src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java: + New. A model class and its default implementation to store rivers. + + * src/main/java/de/intevation/flys/client/client/FLYS.java: At application + start, the provided rivers by the artifact server are fetched using the + RiverService. The rivers are queriable via a getRivers() method. + + * src/main/webapp/WEB-INF/web.xml: Registered the RiverService. + 2011-03-08 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties, diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Tue Mar 08 16:20:34 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Wed Mar 09 08:00:06 2011 +0000 @@ -11,10 +11,13 @@ import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.shared.model.River; import de.intevation.flys.client.shared.model.User; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.RiverService; +import de.intevation.flys.client.client.services.RiverServiceAsync; import de.intevation.flys.client.client.services.UserService; import de.intevation.flys.client.client.services.UserServiceAsync; import de.intevation.flys.client.client.ui.CollectionView; @@ -35,6 +38,9 @@ /** The UserService used to retrieve information about the current user. */ protected UserServiceAsync userService = GWT.create(UserService.class); + /** The RiverService used to retrieve the supported rivers of the server.*/ + protected RiverServiceAsync riverService = GWT.create(RiverService.class); + /** The ArtifactService used to communicate with the Artifact server. */ protected ArtifactServiceAsync artifactService = GWT.create(ArtifactService.class); @@ -54,6 +60,9 @@ /** The user who is currently logged in.*/ protected User currentUser; + /** The list of rivers supported by the server.*/ + protected River[] rivers; + /** * This is the entry point method. @@ -78,6 +87,8 @@ initConfiguration(); String serverUrl = Config.getInstance().getServerUrl(); + getRivers(); + userService.getCurrentUser(serverUrl, new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("Could not find a logged in user."); @@ -136,6 +147,33 @@ /** + * Returns a list of rivers supported by the artifact server. + * + * @return a list of rivers supported by the artifact server. + */ + public River[] getRivers() { + if (rivers == null) { + String url = Config.getInstance().getServerUrl(); + GWT.log("Fetch rivers from server '" + url + "'"); + + riverService.list(url, new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of rivers."); + GWT.log(caught.getMessage()); + } + + public void onSuccess(River[] newRivers) { + GWT.log("Retrieved " + newRivers.length + " new rivers."); + rivers = newRivers; + } + }); + } + + return rivers; + } + + + /** * This method creates a new CollectionView and adds it to the workspace. */ public void newProject() { diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java Wed Mar 09 08:00:06 2011 +0000 @@ -0,0 +1,26 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.model.River; + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author Ingo Weinzierl + */ +@RemoteServiceRelativePath("rivers") +public interface RiverService extends RemoteService { + + /** + * This method returns a list of rivers provided by the artifact server. + * + * @param serverUrl The url of the artifact server. + * + * @return a list of rivers provided by the artifact server. + */ + public River[] list(String serverUrl); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverServiceAsync.java Wed Mar 09 08:00:06 2011 +0000 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.River; + + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author Ingo Weinzierl + */ +public interface RiverServiceAsync { + + public void list(String serverUrl, AsyncCallback callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java Wed Mar 09 08:00:06 2011 +0000 @@ -0,0 +1,83 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; + +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.model.DefaultRiver; +import de.intevation.flys.client.shared.model.River; +import de.intevation.flys.client.client.services.RiverService; + + +/** + * This interface provides a method to list the supported rivers of the artifact + * server. + * + * @author Ingo Weinzierl + */ +public class RiverServiceImpl +extends RemoteServiceServlet +implements RiverService +{ + /** The XPath string that points to the rivers in the resulting document.*/ + public static final String XPATH_RIVERS = "/art:rivers/art:river"; + + + public River[] list(String serverUrl) { + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + doc.appendChild(ec.create("action")); + + HttpClient client = new HttpClientImpl(serverUrl); + + try { + Document res = client.callService(serverUrl, "rivers", doc); + + NodeList rivers = (NodeList) XMLUtils.xpath( + res, + XPATH_RIVERS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int count = rivers.getLength(); + + List theRivers = new ArrayList(count); + + for (int i = 0; i < count; i++) { + Node tmp = rivers.item(i); + + String name = XMLUtils.xpathString( + tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); + + theRivers.add(new DefaultRiver(name)); + } + + return (River[]) theRivers.toArray(new River[count]); + } + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultRiver.java Wed Mar 09 08:00:06 2011 +0000 @@ -0,0 +1,50 @@ +package de.intevation.flys.client.shared.model; + + +/** + * The simpliest default implementation of a River that just stores a name. + * + * @author Ingo Weinzierl + */ +public class DefaultRiver implements River { + + /** The name of the river.*/ + protected String name; + + /** + * The default constructor that creates empty river objects. + */ + public DefaultRiver() { + } + + + /** + * This constructor should be used to create new rivers. + * + * @param name The name of the river. + */ + public DefaultRiver(String name) { + this.name = name; + } + + + /** + * Sets the name of the river. + * + * @param name The name of the river. + */ + public void setName(String name) { + this.name = name; + } + + + /** + * Returns the name of the river. + * + * @return the name of the river. + */ + public String getName() { + return name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/java/de/intevation/flys/client/shared/model/River.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/River.java Wed Mar 09 08:00:06 2011 +0000 @@ -0,0 +1,12 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + +/** + * @author Ingo Weinzierl + */ +public interface River extends Serializable { + + String getName(); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dfdb927b137d -r 44c63e7fd0d0 flys-client/src/main/webapp/WEB-INF/web.xml --- a/flys-client/src/main/webapp/WEB-INF/web.xml Tue Mar 08 16:20:34 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Wed Mar 09 08:00:06 2011 +0000 @@ -36,6 +36,16 @@ /flys/create-collection + + rivers + de.intevation.flys.client.server.RiverServiceImpl + + + + rivers + /flys/rivers + + FLYS.html