Mercurial > dive4elements > river
changeset 99:5c3d685546a6
Added a new service to describe collections.
flys-client/trunk@1613 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 30 Mar 2011 07:35:59 +0000 |
parents | 83bf2fb17b7c |
children | 95b30a5d6350 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeCollectionService.java flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeCollectionServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml |
diffstat | 6 files changed, 301 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Wed Mar 30 07:31:50 2011 +0000 +++ b/flys-client/ChangeLog Wed Mar 30 07:35:59 2011 +0000 @@ -1,3 +1,21 @@ +2011-03-29 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java, + src/main/java/de/intevation/flys/client/client/services/DescribeCollectionServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/DescribeCollectionService.java: + New. This service is used to fetch the DESCRIBE document of a specific + collection and returns a Collection object that contains the information of + that document. The code to parse the DESCRIBE has been moved here from + the AddArtifactServiceImpl which now derives the + DescribeCollectionServiceImpl. + + * src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java: + This service is derived from DescribeCollectionServiceImpl now, because + the methods to parse the DESCRIBE document are moved to that service. + + * src/main/webapp/WEB-INF/web.xml: Registered the + DescribeCollectionService. + 2011-03-29 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/FLYSMessages_de.properties:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/DescribeCollectionService.java Wed Mar 30 07:35:59 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.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; + + +/** + * This service describes an operation the fetches the DESCRIBE document of a + * specific collection and returns a Collection. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("describe-collection") +public interface DescribeCollectionService extends RemoteService { + + /** + * Adds an artifact to a collection. + * + * @param uuid The uuid of the desired collection. + * @param url The url of the artifact server. + * + * @return the Collection after the operation. + */ + Collection describe(String uuid, String url); +} +// 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/DescribeCollectionServiceAsync.java Wed Mar 30 07:35:59 2011 +0000 @@ -0,0 +1,18 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.Collection; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface DescribeCollectionServiceAsync { + + public void describe( + String uuid, + String url, + AsyncCallback<Collection> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java Wed Mar 30 07:31:50 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/AddArtifactServiceImpl.java Wed Mar 30 07:35:59 2011 +0000 @@ -34,11 +34,11 @@ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class AddArtifactServiceImpl -extends RemoteServiceServlet +extends DescribeCollectionServiceImpl implements AddArtifactService { public Collection add(Collection collection, Artifact artifact, String url) { - System.out.println("AddArtifactServiceImpl - add()"); + System.out.println("AddArtifactServiceImpl.add"); Document add = ClientProtocolUtils.newAddArtifactDocument( artifact.getUuid(), null); @@ -63,158 +63,5 @@ return null; } - - - /** - * This method takes the DESCRIBE document of the Collections describe() - * operation and extracts the information about the collection itself and - * the collection items. - * - * @param description The DESCRIBE document of the Collections describe() - * operation. - * - * @return a Collection with CollectionItems. - */ - protected Collection parseCollection(Document description) { - System.out.println("AddArtifactServiceImpl.parseCollection"); - - if (description == null) { - System.err.println("The DESCRIBE of the Collection is null!"); - return null; - } - - String uuid = XMLUtils.xpathString( - description, - "art:artifact-collection/@art:uuid", - ArtifactNamespaceContext.INSTANCE); - - if (uuid == null || uuid.equals("")) { - System.err.println("Found an invalid Collection!"); - return null; - } - - Collection c = new DefaultCollection(uuid); - - NodeList items = (NodeList) XMLUtils.xpath( - description, - "art:artifact-collection/art:artifacts/art:artifact", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (items == null || items.getLength() == 0) { - System.out.println("No collection item found for this collection."); - - return c; - } - - int size = items.getLength(); - - for (int i = 0; i < size; i++) { - CollectionItem item = parseCollectionItem(items.item(i)); - - if (item != null) { - c.addItem(item); - } - } - - System.out.println( - "Found " + c.getItemLength() + " collection items " + - "for the Collection '" + c.identifier() + "'."); - - return c; - } - - - /** - * This method extracts the CollectionItem from <i>node</i> with its output - * modes. The output modes are parsed using the parseOutputModes() method. - * - * @param node A node that contains information about a CollectionItem. - * - * @return a CollectionItem. - */ - protected CollectionItem parseCollectionItem(Node node) { - System.out.println("AddArtifactServiceImpl.parseCollectionItem"); - - if (node == null) { - System.err.println("The node for parsing CollectionItem is null!"); - return null; - } - - String uuid = XMLUtils.xpathString( - node, "@art:uuid", ArtifactNamespaceContext.INSTANCE); - - String hash = XMLUtils.xpathString( - node, "@art:hash", ArtifactNamespaceContext.INSTANCE); - - if (uuid == null || uuid.equals("")) { - System.err.println("Found an invalid CollectionItem!"); - } - - Node outputmodes = (Node) XMLUtils.xpath( - node, - "art:outputmodes", - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE); - - List<OutputMode> modes = parseOutputModes(outputmodes); - - return new DefaultCollectionItem(uuid, hash, modes); - } - - - /** - * This method extracts the OutputModes available for a specific - * CollectionItem and returns them as list. - * - * @param node The root node of the outputmodes list. - * - * @return a list of OutputModes. - */ - protected List<OutputMode> parseOutputModes(Node node) { - System.out.println("AddArtifactServiceImpl.parseOutputModes"); - - if (node == null) { - System.err.println("The node for parsing OutputModes is null!"); - return null; - } - - NodeList list = (NodeList) XMLUtils.xpath( - node, - "art:output", - XPathConstants.NODESET, - ArtifactNamespaceContext.INSTANCE); - - if (list == null || list.getLength() == 0) { - System.err.println("No outputmode nodes found!"); - return null; - } - - int size = list.getLength(); - - List<OutputMode> modes = new ArrayList<OutputMode>(size); - - for (int i = 0; i < size; i++) { - Node tmp = list.item(i); - String name = XMLUtils.xpathString( - tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); - String desc = XMLUtils.xpathString( - tmp, "@art:description", ArtifactNamespaceContext.INSTANCE); - String mime = XMLUtils.xpathString( - tmp, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); - - if (name == null || name.equals("")) { - System.err.println("Found an invalid output mode."); - - continue; - } - - // TODO Parse Facets - - modes.add(new DefaultOutputMode(name, desc, mime)); - } - - return modes; - } } // 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/DescribeCollectionServiceImpl.java Wed Mar 30 07:35:59 2011 +0000 @@ -0,0 +1,224 @@ +package de.intevation.flys.client.server; + +import java.util.ArrayList; +import java.util.List; + +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 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.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; +import de.intevation.flys.client.shared.model.DefaultCollection; +import de.intevation.flys.client.shared.model.DefaultCollectionItem; +import de.intevation.flys.client.shared.model.DefaultOutputMode; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.client.services.DescribeCollectionService; + + +/** + * This service implements a method that queries the DESCRIBE document of a + * specific collection and returns a Collection object with the information of + * the document. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class DescribeCollectionServiceImpl +extends RemoteServiceServlet +implements DescribeCollectionService +{ + public Collection describe(String uuid, String serverUrl) { + System.out.println("DescribeCollectionServiceImpl.describe"); + + Document describe = ClientProtocolUtils.newDescribeCollectionDocument( + uuid); + + HttpClient client = new HttpClientImpl(serverUrl); + + try { + Document response = (Document) client.doCollectionAction( + describe, uuid, new DocumentResponseHandler()); + + Collection c = parseCollection(response); + + if (c == null) { + throw new NullPointerException("No collection returned."); + } + + return c; + } + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); + } + + return null; + } + + + /** + * This method takes the DESCRIBE document of the Collections describe() + * operation and extracts the information about the collection itself and + * the collection items. + * + * @param description The DESCRIBE document of the Collections describe() + * operation. + * + * @return a Collection with CollectionItems. + */ + protected Collection parseCollection(Document description) { + System.out.println("AddArtifactServiceImpl.parseCollection"); + + if (description == null) { + System.err.println("The DESCRIBE of the Collection is null!"); + return null; + } + + String uuid = XMLUtils.xpathString( + description, + "art:artifact-collection/@art:uuid", + ArtifactNamespaceContext.INSTANCE); + + if (uuid == null || uuid.equals("")) { + System.err.println("Found an invalid Collection!"); + return null; + } + + Collection c = new DefaultCollection(uuid); + + NodeList items = (NodeList) XMLUtils.xpath( + description, + "art:artifact-collection/art:artifacts/art:artifact", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (items == null || items.getLength() == 0) { + System.out.println("No collection item found for this collection."); + + return c; + } + + int size = items.getLength(); + + for (int i = 0; i < size; i++) { + CollectionItem item = parseCollectionItem(items.item(i)); + + if (item != null) { + c.addItem(item); + } + } + + System.out.println( + "Found " + c.getItemLength() + " collection items " + + "for the Collection '" + c.identifier() + "'."); + + return c; + } + + + /** + * This method extracts the CollectionItem from <i>node</i> with its output + * modes. The output modes are parsed using the parseOutputModes() method. + * + * @param node A node that contains information about a CollectionItem. + * + * @return a CollectionItem. + */ + protected CollectionItem parseCollectionItem(Node node) { + System.out.println("AddArtifactServiceImpl.parseCollectionItem"); + + if (node == null) { + System.err.println("The node for parsing CollectionItem is null!"); + return null; + } + + String uuid = XMLUtils.xpathString( + node, "@art:uuid", ArtifactNamespaceContext.INSTANCE); + + String hash = XMLUtils.xpathString( + node, "@art:hash", ArtifactNamespaceContext.INSTANCE); + + if (uuid == null || uuid.equals("")) { + System.err.println("Found an invalid CollectionItem!"); + } + + Node outputmodes = (Node) XMLUtils.xpath( + node, + "art:outputmodes", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + List<OutputMode> modes = parseOutputModes(outputmodes); + + return new DefaultCollectionItem(uuid, hash, modes); + } + + + /** + * This method extracts the OutputModes available for a specific + * CollectionItem and returns them as list. + * + * @param node The root node of the outputmodes list. + * + * @return a list of OutputModes. + */ + protected List<OutputMode> parseOutputModes(Node node) { + System.out.println("AddArtifactServiceImpl.parseOutputModes"); + + if (node == null) { + System.err.println("The node for parsing OutputModes is null!"); + return null; + } + + NodeList list = (NodeList) XMLUtils.xpath( + node, + "art:output", + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (list == null || list.getLength() == 0) { + System.err.println("No outputmode nodes found!"); + return null; + } + + int size = list.getLength(); + + List<OutputMode> modes = new ArrayList<OutputMode>(size); + + for (int i = 0; i < size; i++) { + Node tmp = list.item(i); + String name = XMLUtils.xpathString( + tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); + String desc = XMLUtils.xpathString( + tmp, "@art:description", ArtifactNamespaceContext.INSTANCE); + String mime = XMLUtils.xpathString( + tmp, "@art:mime-type", ArtifactNamespaceContext.INSTANCE); + + if (name == null || name.equals("")) { + System.err.println("Found an invalid output mode."); + + continue; + } + + // TODO Parse Facets + + modes.add(new DefaultOutputMode(name, desc, mime)); + } + + return modes; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Wed Mar 30 07:31:50 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Wed Mar 30 07:35:59 2011 +0000 @@ -76,6 +76,16 @@ <url-pattern>/flys/add-artifact</url-pattern> </servlet-mapping> + <servlet> + <servlet-name>describe-collection</servlet-name> + <servlet-class>de.intevation.flys.client.server.DescribeCollectionServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>describe-collection</servlet-name> + <url-pattern>/flys/describe-collection</url-pattern> + </servlet-mapping> + <servlet> <servlet-name>user-collections</servlet-name> <servlet-class>de.intevation.flys.client.server.UserCollectionsServiceImpl</servlet-class>