# HG changeset patch # User Ingo Weinzierl # Date 1302594993 0 # Node ID f03c34bec3642ae3b92365d0609a0df27c744606 # Parent 35094660f91a280ec7961aaddc1fde1ef5913a2c Added a new service to query an artifact description. flys-client/trunk@1666 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 35094660f91a -r f03c34bec364 flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, diff -r 35094660f91a -r f03c34bec364 flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactService.java --- /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 Ingo Weinzierl + */ +@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 : diff -r 35094660f91a -r f03c34bec364 flys-client/src/main/java/de/intevation/flys/client/client/services/GetArtifactServiceAsync.java --- /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 Ingo Weinzierl + */ +public interface GetArtifactServiceAsync { + + public void getArtifact( + String serverUrl, + String uuid, + String hash, + AsyncCallback callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 35094660f91a -r f03c34bec364 flys-client/src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java --- /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 Ingo Weinzierl + */ +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 : diff -r 35094660f91a -r f03c34bec364 flys-client/src/main/webapp/WEB-INF/web.xml --- 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 @@ + getartifact + de.intevation.flys.client.server.GetArtifactServiceImpl + + + + getartifact + /flys/getartifact + + + + create-collection de.intevation.flys.client.server.CreateCollectionServiceImpl