changeset 221:f03c34bec364

Added a new service to query an artifact description. flys-client/trunk@1666 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 12 Apr 2011 07:56:33 +0000
parents 35094660f91a
children 9bd9c24f4935
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactService.java flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 5 files changed, 143 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Apr 11 15:38:43 2011 +0000
+++ b/flys-client/ChangeLog	Tue Apr 12 07:56:33 2011 +0000
@@ -1,3 +1,13 @@
+2011-04-12  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/services/GetArtifactServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/GetArtifactService.java,
+	  src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java:
+	  New. A service that queries the artifact description based on the
+	  identifier of an artifact.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the new GetArtifactService.
+
 2011-04-11  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactService.java	Tue Apr 12 07:56:33 2011 +0000
@@ -0,0 +1,29 @@
+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.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Artifact;
+
+/**
+ * This interface provides a method to retrieve an artifact based on its uuid.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+@RemoteServiceRelativePath("getartifact")
+public interface GetArtifactService extends RemoteService {
+
+    /**
+     * This method inserts new data into the an existing artifact.
+     *
+     * @param serverUrl The url of the artifact server.
+     * @param uuid The artifact's identifier.
+     * @param hash The artifact's hash.
+     *
+     * @return the artifact.
+     */
+    Artifact getArtifact(String url, String uuid, String hash)
+    throws ServerException;
+}
+// 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/client/services/GetArtifactServiceAsync.java	Tue Apr 12 07:56:33 2011 +0000
@@ -0,0 +1,19 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.Artifact;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface GetArtifactServiceAsync {
+
+    public void getArtifact(
+        String                  serverUrl,
+        String                  uuid,
+        String                  hash,
+        AsyncCallback<Artifact> callback);
+}
+// 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/server/GetArtifactServiceImpl.java	Tue Apr 12 07:56:33 2011 +0000
@@ -0,0 +1,74 @@
+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.ClientProtocolUtils;
+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.Artifact;
+import de.intevation.flys.client.client.services.GetArtifactService;
+
+
+/**
+ * This service provides a method that returns an artifact based on its
+ * identifier.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class GetArtifactServiceImpl
+extends      RemoteServiceServlet
+implements   GetArtifactService
+{
+    public static final String ERROR_DESCRIBE_ARTIFACT =
+        "error_describe_artifact";
+
+    public static final String XPATH_RESULT = "/art:result/text()";
+
+    public static final String OPERATION_FAILURE = "FAILED";
+
+
+    public Artifact getArtifact(String serverUrl, String uuid, String hash)
+    throws ServerException
+    {
+        Document describe = ClientProtocolUtils.newDescribeDocument(
+            uuid, hash, true);
+
+        HttpClient client = new HttpClientImpl(serverUrl);
+
+        try {
+            Document description = (Document) client.describe(
+                new de.intevation.artifacts.httpclient.objects.Artifact(
+                    uuid, hash),
+                describe,
+                new DocumentResponseHandler());
+
+            if (description == null) {
+                throw new ServerException(ERROR_DESCRIBE_ARTIFACT);
+            }
+
+            String result = XMLUtils.xpathString(
+                description,
+                XPATH_RESULT,
+                ArtifactNamespaceContext.INSTANCE);
+
+            if (result == null || !result.equals(OPERATION_FAILURE)) {
+                return (Artifact) new FLYSArtifactCreator().create(description);
+            }
+        }
+        catch (ConnectionException ce) {
+            System.err.println(ce.getLocalizedMessage());
+        }
+
+        throw new ServerException(ERROR_DESCRIBE_ARTIFACT);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Mon Apr 11 15:38:43 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Tue Apr 12 07:56:33 2011 +0000
@@ -27,6 +27,17 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>getartifact</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.GetArtifactServiceImpl</servlet-class>
+  </servlet>
+  
+  <servlet-mapping>
+    <servlet-name>getartifact</servlet-name>
+    <url-pattern>/flys/getartifact</url-pattern>
+  </servlet-mapping>
+
+
+  <servlet>
     <servlet-name>create-collection</servlet-name>
     <servlet-class>de.intevation.flys.client.server.CreateCollectionServiceImpl</servlet-class>
   </servlet>

http://dive4elements.wald.intevation.org