# HG changeset patch # User Ingo Weinzierl # Date 1306486766 0 # Node ID 26e38b79658d76ef5d4a4593b809f5c6712dbe96 # Parent a1048d3108292670786442c6493295c50afbfde9 Connected the CollectionAttributeService with the artifact server - Collection modifications will now be stored in the artifact databae. flys-client/trunk@2018 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a1048d310829 -r 26e38b79658d flys-client/ChangeLog --- a/flys-client/ChangeLog Fri May 27 08:53:22 2011 +0000 +++ b/flys-client/ChangeLog Fri May 27 08:59:26 2011 +0000 @@ -1,3 +1,14 @@ +2011-05-27 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java: + Connected this service with the artifact server. Modifications of a + Collection will be stored in the artifact database now. + + * src/main/java/de/intevation/flys/client/server/CollectionHelper.java: + New. This helper is currently used to create the attribute document of a + collection based on a Collection itself. This helper now takes the + attributes of the Collection and transforms those values into XML. + 2011-05-27 Ingo Weinzierl * src/main/java/de/intevation/flys/client/shared/model/Theme.java, diff -r a1048d310829 -r 26e38b79658d flys-client/src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java Fri May 27 08:53:22 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionAttributeServiceImpl.java Fri May 27 08:59:26 2011 +0000 @@ -1,5 +1,14 @@ package de.intevation.flys.client.server; +import org.w3c.dom.Document; + +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; @@ -13,20 +22,36 @@ extends DescribeCollectionServiceImpl implements CollectionAttributeService { + public static final String ERROR_UPDATING_COLLECTION_ATTRIBUTE = + "error_update_collection_attribute"; + + public Collection update(Collection collection, String url, String locale) throws ServerException { System.out.println("CollectionAttributeServiceImpl.update"); - // TODO Implement the correct update process here! + Document attribute = CollectionHelper.createAttribute(collection); + Document action = ClientProtocolUtils.newSetAttributeDocument( + collection.identifier(), + attribute); + try { - Thread.currentThread().sleep(5000); + HttpClient http = new HttpClientImpl(url, locale); + Document res = (Document) http.doCollectionAction( + action, + collection.identifier(), + new DocumentResponseHandler()); + + System.out.println("Collection attribute successfully set."); + + return describe(collection.identifier(), url, locale); } - catch (InterruptedException ie) { - // do nothing + catch (ConnectionException ce) { + System.err.println(ce.getLocalizedMessage()); } - return describe(collection.identifier(), url, locale); + throw new ServerException(ERROR_UPDATING_COLLECTION_ATTRIBUTE); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a1048d310829 -r 26e38b79658d flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java Fri May 27 08:59:26 2011 +0000 @@ -0,0 +1,156 @@ +package de.intevation.flys.client.server; + +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + + +/** + * @author Ingo Weinzierl + */ +public class CollectionHelper { + + public static Document createAttribute(Collection collection) { + System.out.println("CollectionHelper.createAttribute"); + + Document doc = XMLUtils.newDocument(); + + ElementCreator cr = new ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element attr = cr.create("attribute"); + + doc.appendChild(attr); + + Map tmpOuts = collection.getOutputModes(); + + Element outs = createOutputElements(cr, collection, tmpOuts); + + if (outs != null) { + attr.appendChild(outs); + } + + return doc; + } + + + /** + * Creates a whole block with art:output nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param modes The OutputModes that should be included. + * + * @return an element with output modes. + */ + protected static Element createOutputElements( + ElementCreator cr, + Collection c, + Map mmodes) + { + System.out.println("CollectionHelper.createOutputElements"); + + java.util.Collection modes = mmodes != null + ? mmodes.values() + : null; + + if (modes == null || modes.size() == 0) { + System.err.println("Collection has no modes: " + c.identifier()); + return null; + } + + Element outs = cr.create("outputs"); + + for (OutputMode mode: modes) { + Element out = createOutputElement(cr, c, mode); + + if (out != null) { + outs.appendChild(out); + } + } + + return outs; + } + + + /** + * Create a node art:output that further consist of art:theme nodes. + * + * @param cr The ElementCreator used to create new elements. + * @param c The collection. + * @param mode The OutputMode. + * + * @return an element that represents an output mode with its themes. + */ + protected static Element createOutputElement( + ElementCreator cr, + Collection collection, + OutputMode mode) + { + System.out.println("CollectionHelper.createOutputElement"); + + Element out = cr.create("output"); + cr.addAttr(out, "name", mode.getName(), false); + + ThemeList themeList = collection.getThemeList(mode.getName()); + List themes = themeList != null ? themeList.getThemes() : null; + + if (themes == null || themes.size() == 0) { + System.err.println("No themes for output mode: " + mode.getName()); + return null; + } + + for (Theme theme: themes) { + Element t = createThemeElement(cr, collection, theme); + + if (t != null) { + out.appendChild(t); + } + } + + return out; + } + + + /** + * Creates a theme node art:theme that represents a curve in a chart or map. + * + * @param cr The ElementCreator used to create new elements. + * @param collection The collection. + * @param theme The theme whose attributes should be written to an element. + * + * @return an element that contains the informtion of the given theme. + */ + protected static Element createThemeElement( + ElementCreator cr, + Collection collection, + Theme theme) + { + if (theme == null) { + return null; + } + + Element t = cr.create("theme"); + + cr.addAttr(t, "active", theme.isActive() ? "1" : "0", true); + cr.addAttr(t, "artifact", theme.getArtifact(), true); + cr.addAttr(t, "facet", theme.getFacet(), true); + cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true); + + return t; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :