Mercurial > dive4elements > river
changeset 25:2da6be38d8b6
Added a User interface and a default implementation to handle users in this client.
flys-client/trunk@1411 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Mar 2011 13:40:37 +0000 |
parents | 8825ce0a537e |
children | c19985f75118 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultUser.java flys-client/src/main/java/de/intevation/flys/client/shared/model/User.java |
diffstat | 9 files changed, 211 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/ChangeLog Mon Mar 07 13:40:37 2011 +0000 @@ -1,3 +1,24 @@ +2011-03-07 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/shared/model/DefaultUser.java, + src/main/java/de/intevation/flys/client/shared/model/User.java: A user + interface and its default implementation. + + * src/main/java/de/intevation/flys/client/client/services/UserService.java, + src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java, + * src/main/java/de/intevation/flys/client/server/UserServiceImpl.java: This + service will currently return the first user that is returned by the + artifact server. + + * src/main/java/de/intevation/flys/client/client/FLYS.java: The FLYS + instance stores the user that is logged in, because we need to make use of + this user in many services. + + * src/main/java/de/intevation/flys/client/client/ui/ProjectList.java, + src/main/java/de/intevation/flys/client/client/ui/MainMenu.java: Make use + of the User of this package - the User of the common package is not used + any longer. + 2011-03-02 Sascha L. Teichmann <sascha.teichmann@intevation.de> * pom.xml: Added missing SmartGWT repository.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Mon Mar 07 13:40:37 2011 +0000 @@ -8,11 +8,10 @@ import com.smartgwt.client.widgets.layout.VLayout; -import de.intevation.artifacts.common.model.User; - 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.User; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; @@ -51,6 +50,9 @@ /** The FLYSWorkspace.*/ protected FLYSWorkspace workspace; + /** The user who is currently logged in.*/ + protected User currentUser; + /** * This is the entry point method. @@ -72,15 +74,18 @@ RootPanel.get("app").add(vertical); initConfiguration(); + String serverUrl = Config.getInstance().getServerUrl(); - userService.getCurrentUser(new AsyncCallback<User>() { + userService.getCurrentUser(serverUrl, new AsyncCallback<User>() { public void onFailure(Throwable caught) { GWT.log("Could not find a logged in user."); // TODO do something } public void onSuccess(User user) { - GWT.log("Found a user. Set '"+ user.getLastName()+"'"); + GWT.log("Found a user. Set '"+ user.getName() + "'"); + setCurrentUser(user); + menu.setCurrentUser(user); projectList = new ProjectList(user); @@ -103,6 +108,24 @@ /** + * Returns the user that is currently logged in. + * + * @return the current user. + */ + public User getCurrentUser() { + return currentUser; + } + + + /** + * Sets the current user. + */ + public void setCurrentUser(User user) { + currentUser = user; + } + + + /** * This method creates a new CollectionView and adds it to the workspace. */ public void newProject() {
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java Mon Mar 07 13:40:37 2011 +0000 @@ -3,7 +3,7 @@ import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; -import de.intevation.artifacts.common.model.User; +import de.intevation.flys.client.shared.model.User; /** @@ -17,8 +17,10 @@ /** * This method retrieves the user that is currently logged in. * + * @param serverUrl The url of the artifact server. + * * @return the current {@link User}. */ - User getCurrentUser(); + User getCurrentUser(String serverUrl); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserServiceAsync.java Mon Mar 07 13:40:37 2011 +0000 @@ -2,7 +2,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; -import de.intevation.artifacts.common.model.User; +import de.intevation.flys.client.shared.model.User; /** @@ -12,6 +12,6 @@ */ public interface UserServiceAsync { - void getCurrentUser(AsyncCallback<User> callback); + void getCurrentUser(String serverUrl, AsyncCallback<User> callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java Mon Mar 07 13:40:37 2011 +0000 @@ -9,10 +9,9 @@ import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.layout.HLayout; -import de.intevation.artifacts.common.model.User; - import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSMessages; +import de.intevation.flys.client.shared.model.User; /** @@ -104,7 +103,7 @@ */ public void updateCurrentUser() { String name = currentUser != null - ? currentUser.getLastName() + ", " + currentUser.getFirstName() + ? currentUser.getName() : messages.guest(); GWT.log("Update the current user: " + name);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Mon Mar 07 13:40:37 2011 +0000 @@ -8,13 +8,12 @@ import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.VLayout; -import de.intevation.artifacts.common.model.User; - import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.CollectionRecord; import de.intevation.flys.client.shared.model.DefaultCollection; import de.intevation.flys.client.client.FLYSMessages; +import de.intevation.flys.client.shared.model.User; /**
--- a/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java Wed Mar 02 10:00:17 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java Mon Mar 07 13:40:37 2011 +0000 @@ -1,13 +1,26 @@ package de.intevation.flys.client.server; +import javax.xml.xpath.XPathConstants; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.core.client.GWT; -import de.intevation.artifacts.common.model.DefaultUser; -import de.intevation.artifacts.common.model.User; +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.artifacts.httpclient.http.response.DocumentResponseHandler; import de.intevation.flys.client.client.services.UserService; +import de.intevation.flys.client.shared.model.DefaultUser; +import de.intevation.flys.client.shared.model.User; /** @@ -17,9 +30,37 @@ extends RemoteServiceServlet implements UserService { - public User getCurrentUser() { - GWT.log("Return the current user 'Max Mustermann'."); - return new DefaultUser("Max", "Mustermann"); + public User getCurrentUser(String serverUrl) { + HttpClient client = new HttpClientImpl(serverUrl); + + try { + Document users = (Document) client.listUsers(); + + String XPATH_USERS = "/art:users/art:user"; + + NodeList theUsers = (NodeList) XMLUtils.xpath( + users, + XPATH_USERS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (theUsers != null && theUsers.getLength() > 0) { + Node user = theUsers.item(0); + + String uuid = XMLUtils.xpathString( + user, "@art:uuid", ArtifactNamespaceContext.INSTANCE); + String name = XMLUtils.xpathString( + user, "@art:name", ArtifactNamespaceContext.INSTANCE); + + return new DefaultUser(uuid, name); + } + } + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); + } + + System.err.println("No users existing in the server."); + return null; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultUser.java Mon Mar 07 13:40:37 2011 +0000 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.flys.client.shared.model; + + +/** + * Trivial implementation of a user. Useful to be subclassed. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DefaultUser +implements User +{ + /** The identifier of the user.*/ + protected String identifier; + + /** The name of the user.*/ + protected String name; + + + /** + * The default constructor. + */ + public DefaultUser() { + } + + + /** + * A constructor that creates a new user. + * + * @param identifier The uuid of the user. + * @param name The name of the user. + */ + public DefaultUser(String identifier, String name) { + this.identifier = identifier; + this.name = name; + } + + + /** + * Returns the identifier of this user. + * + * @return the identifier of this user. + */ + public String identifier() { + return identifier; + } + + + /** + * Returns the name of the user. + * + * @return the name of the user. + */ + public String getName() { + return name; + } + + + /** + * Set the identifier of the user. + * + * @param identifier The new identifier. + */ + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + + /** + * Set the name of the user. + * + * @param name The name for this user. + */ + public void setName(String name) { + this.name = name; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/User.java Mon Mar 07 13:40:37 2011 +0000 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public interface User +extends Serializable +{ + String identifier(); + + String getName(); + + void setName(String name); + + void setIdentifier(String identifier); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :