# HG changeset patch # User Ingo Weinzierl # Date 1302257114 0 # Node ID 907b61e4d702bbe841de683dcf12828415c2ff58 # Parent 4b0fb079ead903a09d258e4c1e8222493cacfbda Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers. flys-client/trunk@1659 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/ChangeLog Fri Apr 08 10:05:14 2011 +0000 @@ -1,3 +1,24 @@ +2011-04-08 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/UserServiceImpl.java, + src/main/java/de/intevation/flys/client/client/services/UserService.java: + This service now throws an AuthenticationException if an error occured + while user authentication. + + * src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java, + src/main/java/de/intevation/flys/client/client/services/RiverService.java: + This service now throws a ServerException if an error occured while + reading the supported rivers from artifact server. + + * src/main/java/de/intevation/flys/client/client/FLYS.java: Show warnings + if errors occur while fetching supported rivers or + + * src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java: + Added further strings for error messages. + 2011-04-08 Ingo Weinzierl * src/main/java/de/intevation/flys/client/shared/exceptions/AuthenticationException.java: diff -r 4b0fb079ead9 -r 907b61e4d702 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 Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Fri Apr 08 10:05:14 2011 +0000 @@ -6,6 +6,7 @@ import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.xml.client.XMLParser; +import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.HLayout; @@ -35,6 +36,9 @@ */ public class FLYS implements EntryPoint { + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + /** The UserService used to retrieve information about the current user. */ protected UserServiceAsync userService = GWT.create(UserService.class); @@ -102,7 +106,7 @@ userService.getCurrentUser(serverUrl, new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("Could not find a logged in user."); - // TODO do something + SC.warn(MSG.getString(caught.getMessage())); } public void onSuccess(User user) { @@ -115,6 +119,8 @@ workspace = new FLYSWorkspace(); view.setProjectList(projectList); view.setFLYSWorkspace(workspace); + + readRivers(); } }); } @@ -162,31 +168,47 @@ * @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 + "'"); + return rivers; + } - 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; - } - }); - } + protected void readRivers() { + String url = Config.getInstance().getServerUrl(); + GWT.log("Fetch rivers from server '" + url + "'"); - return rivers; + riverService.list(url, new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not recieve a list of rivers."); + SC.warn(MSG.getString(caught.getMessage())); + } + + public void onSuccess(River[] newRivers) { + GWT.log("Retrieved " + newRivers.length + " new rivers."); + rivers = newRivers; + } + }); } /** * This method creates a new CollectionView and adds it to the workspace. + * NOTEThe user needs to be logged in and there need to at least one + * river - otherwise a warning is displayed and no CollectionView is + * created. */ public void newProject() { + if (getCurrentUser() == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + if (getRivers() == null) { + SC.warn(MSG.error_no_rivers_found()); + readRivers(); + + return; + } + CollectionView view = new CollectionView(this); workspace.addView(view); diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Apr 08 10:05:14 2011 +0000 @@ -125,5 +125,11 @@ String error_create_collection(); String error_describe_collection(); + + String error_no_rivers_found(); + + String error_no_such_user(); + + String error_not_logged_in(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Apr 08 10:05:14 2011 +0000 @@ -60,3 +60,6 @@ error_add_artifact = Error while inserting new data. error_create_collection = Error while creating a new collection. error_describe_collection = Error while fetching the projects state. +error_no_rivers_found = Error while reading supported rivers. +error_no_such_user = Error - no such user found. +error_not_logged_in = You need to log in before you are allowed to start your work. diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Apr 08 10:05:14 2011 +0000 @@ -60,3 +60,6 @@ error_add_artifact = Fehler beim Hinzuf\u00fcgen neuer Daten. error_create_collection = Fehler beim Erstellen einer neuen Collection. error_describe_collection = Fehler beim Laden des Projektzustandes. +error_no_rivers_found = Fehler beim Lesen der unterst\u00fctzten Fl\u00fcsse. +error_no_such_user = Fehler - Kein Benutzer vorhanden. +error_not_logged_in = Sie m\u00fcssen sich erst einloggen um mit der Arbeit beginnen zu k\u00f6nnen. diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Apr 08 10:05:14 2011 +0000 @@ -60,3 +60,6 @@ error_add_artifact = Error while inserting new data. error_create_collection = Error while creating a new collection. error_describe_collection = Error while fetching the projects state. +error_no_rivers_found = Error while reading supported rivers. +error_no_such_user = Error - no such user. +error_not_logged_in = You need to log in before you are allowed to start your work. diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/RiverService.java Fri Apr 08 10:05:14 2011 +0000 @@ -3,6 +3,7 @@ import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; +import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.River; /** @@ -21,6 +22,7 @@ * * @return a list of rivers provided by the artifact server. */ - public River[] list(String serverUrl); + public River[] list(String serverUrl) + throws ServerException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/UserService.java Fri Apr 08 10:05:14 2011 +0000 @@ -3,6 +3,7 @@ import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; +import de.intevation.flys.client.shared.exceptions.AuthenticationException; import de.intevation.flys.client.shared.model.User; @@ -21,6 +22,7 @@ * * @return the current {@link User}. */ - User getCurrentUser(String serverUrl); + User getCurrentUser(String serverUrl) + throws AuthenticationException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java Fri Apr 08 10:05:14 2011 +0000 @@ -18,6 +18,7 @@ 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.shared.model.DefaultRiver; import de.intevation.flys.client.shared.model.River; import de.intevation.flys.client.client.services.RiverService; @@ -36,8 +37,14 @@ /** The XPath string that points to the rivers in the resulting document.*/ public static final String XPATH_RIVERS = "/art:rivers/art:river"; + /** The error message key that is thrown if an error occured while reading + * the supported rivers from server.*/ + public static final String ERROR_NO_RIVERS_FOUND = "error_no_rivers_found"; - public River[] list(String serverUrl) { + + public River[] list(String serverUrl) + throws ServerException + { Document doc = XMLUtils.newDocument(); XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( @@ -58,6 +65,10 @@ XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE); + if (rivers == null || rivers.getLength() == 0) { + throw new ServerException(ERROR_NO_RIVERS_FOUND); + } + int count = rivers.getLength(); List theRivers = new ArrayList(count); @@ -77,7 +88,7 @@ System.err.println(ce.getLocalizedMessage()); } - return null; + throw new ServerException(ERROR_NO_RIVERS_FOUND); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4b0fb079ead9 -r 907b61e4d702 flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java Fri Apr 08 09:51:41 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/UserServiceImpl.java Fri Apr 08 10:05:14 2011 +0000 @@ -16,6 +16,7 @@ import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.flys.client.client.services.UserService; +import de.intevation.flys.client.shared.exceptions.AuthenticationException; import de.intevation.flys.client.shared.model.DefaultUser; import de.intevation.flys.client.shared.model.User; @@ -27,7 +28,11 @@ extends RemoteServiceServlet implements UserService { - public User getCurrentUser(String serverUrl) { + public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; + + public User getCurrentUser(String serverUrl) + throws AuthenticationException + { HttpClient client = new HttpClientImpl(serverUrl); try { @@ -57,7 +62,7 @@ } System.err.println("No users existing in the server."); - return null; + throw new AuthenticationException(ERROR_NO_SUCH_USER); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :