# HG changeset patch # User Ingo Weinzierl # Date 1308747020 0 # Node ID 1dbffe4c6d1204c056206df2764e97172488954e # Parent 031357c3e23e5e6ffe7ae685e4db5e957c46951b Implemented the RPC stubs to set the TTL and name of a collection and to delete an existing collection. flys-client/trunk@2203 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/ChangeLog --- a/flys-client/ChangeLog Wed Jun 22 11:47:07 2011 +0000 +++ b/flys-client/ChangeLog Wed Jun 22 12:50:20 2011 +0000 @@ -1,3 +1,19 @@ +2011-06-22 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/DoCollectionAction.java: + New. This base RPC service implementation handles collecion specific + actions. It has a doAction() method that takes a Collection, the action + document and a server url. + + * src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java, + src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java, + src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java: + Trigger the collection actions on the server using the + DoCollectionAction class which handles the Http stuff. + + * src/main/java/de/intevation/flys/client/client/ui/ProjectList.java: + Bugfix: If no user collections returned, we will clear the project list. + 2011-06-22 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/services/SetCollectionNameServiceAsync.java, diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Wed Jun 22 11:47:07 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java Wed Jun 22 12:50:20 2011 +0000 @@ -433,10 +433,6 @@ GWT.log("Received " + num + " user collections."); - if (num == 0) { - return; - } - updateGrid(collections); } } @@ -456,6 +452,10 @@ protected void updateGrid(Collection[] collections) { clearGrid(); + if (collections == null || collections.length == 0) { + return; + } + for (Collection c: collections) { grid.addData(new CollectionRecord(c)); } diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java Wed Jun 22 11:47:07 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/DeleteCollectionServiceImpl.java Wed Jun 22 12:50:20 2011 +0000 @@ -2,15 +2,8 @@ import org.w3c.dom.Document; -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - import de.intevation.artifacts.common.utils.ClientProtocolUtils; -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.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.client.services.DeleteCollectionService; @@ -20,14 +13,20 @@ * @author Ingo Weinzierl */ public class DeleteCollectionServiceImpl -extends RemoteServiceServlet +extends DoCollectionAction implements DeleteCollectionService { + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + public void delete(Collection c, String url) throws ServerException { - // TODO IMPLEMENT ME - throw new ServerException("Delete Service NOT IMPLEMENTED"); + System.out.println("Delete collection: " + c.identifier()); + + Document del = ClientProtocolUtils.newDeleteCollectionDocument(); + + doAction(c, del, url); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/src/main/java/de/intevation/flys/client/server/DoCollectionAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/DoCollectionAction.java Wed Jun 22 12:50:20 2011 +0000 @@ -0,0 +1,54 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +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.artifacts.httpclient.http.response.DocumentResponseHandler; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author Ingo Weinzierl + */ +public class DoCollectionAction extends RemoteServiceServlet { + + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + public static final String FAILURE_EXCEPTION = "collection_action_failed"; + + + protected void doAction(Collection c, Document action, String url) + throws ServerException + { + HttpClient client = new HttpClientImpl(url); + + try { + Document res = (Document) client.doCollectionAction( + action, c.identifier(), + new DocumentResponseHandler()); + + String result = XMLUtils.xpathString( + res, + XPATH_RESULT, + ArtifactNamespaceContext.INSTANCE); + + if (result == null || result.equals(OPERATION_FAILURE)) { + System.err.println("Operation failed."); + throw new ServerException(FAILURE_EXCEPTION); + } + } + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); + throw new ServerException(FAILURE_EXCEPTION); + } + } +} diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java Wed Jun 22 11:47:07 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionNameServiceImpl.java Wed Jun 22 12:50:20 2011 +0000 @@ -2,15 +2,8 @@ import org.w3c.dom.Document; -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - import de.intevation.artifacts.common.utils.ClientProtocolUtils; -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.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.client.services.SetCollectionNameService; @@ -20,14 +13,18 @@ * @author Ingo Weinzierl */ public class SetCollectionNameServiceImpl -extends RemoteServiceServlet +extends DoCollectionAction implements SetCollectionNameService { public void setName(Collection c, String url) throws ServerException { - // TODO IMPLEMENT ME - throw new ServerException("Name Service NOT IMPLEMENTED"); + System.out.println("Set name of collection: " + c.identifier()); + + String name = c.getName(); + Document set = ClientProtocolUtils.newSetCollectionNameDocument(name); + + doAction(c, set, url); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 031357c3e23e -r 1dbffe4c6d12 flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java Wed Jun 22 11:47:07 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/SetCollectionTTLServiceImpl.java Wed Jun 22 12:50:20 2011 +0000 @@ -2,15 +2,8 @@ import org.w3c.dom.Document; -import com.google.gwt.user.server.rpc.RemoteServiceServlet; - import de.intevation.artifacts.common.utils.ClientProtocolUtils; -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.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.client.services.SetCollectionTTLService; @@ -20,14 +13,33 @@ * @author Ingo Weinzierl */ public class SetCollectionTTLServiceImpl -extends RemoteServiceServlet +extends DoCollectionAction implements SetCollectionTTLService { + public static final String XPATH_RESULT = "/art:result/text()"; + public static final String OPERATION_FAILURE = "FAILED"; + public void setTTL(Collection c, String url) throws ServerException { - // TODO IMPLEMENT ME - throw new ServerException("TTL Service NOT IMPLEMENTED"); + System.out.println("Set ttl of collection: " + c.identifier()); + + long ttl = c.getTTL(); + String value = null; + + if (ttl == 0) { + value = "INF"; + } + else if (ttl < 0) { + value = "DEFAULT"; + } + else { + value = String.valueOf(ttl); + } + + Document set = ClientProtocolUtils.newSetCollectionTTLDocument(value); + + doAction(c, set, url); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :