Mercurial > dive4elements > river
changeset 1979:a7c437c9547e
Added a getSettings() operation to OutGenerator - FLYSArtifactCollection will now evaluate all available Outputs and create initial Settings using OutGenerators if the Settings for an Output is missing.
flys-artifacts/trunk@3409 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Dec 14 10:20:56 2011 +0000 @@ -1,3 +1,32 @@ +2011-12-14 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/EmptySettings.java: An + implementation of the Settings interface defined in the artifact-database + module. This implementation accepts no Section objects at all and creates + an empty "settings" Node in its toXML() operation. + + * src/main/java/de/intevation/flys/exports/OutGenerator.java: Defined a new + method getSettings() that returns a Settings instance. + + * src/main/java/de/intevation/flys/exports/ChartGenerator.java, + src/main/java/de/intevation/flys/exports/ReportGenerator.java, + src/main/java/de/intevation/flys/exports/MapGenerator.java, + src/main/java/de/intevation/flys/exports/AbstractExporter.java, + src/main/java/de/intevation/flys/exports/ATExporter.java, + src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java: + Implemented the getSettings() operation. All OutGenerators will currently + return an instance of EmptySettings. + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Before the DESCRIBE document is created, we gonna evaluate each Output + defined in the Collection's attribute document, if it has a Settings + object set. If this is not the case, the relevant OutGenerator is called + to retrieve a new instance of Settings. + + * src/main/java/de/intevation/flys/collections/CollectionAttribute.java: + Append the Settings of Outputs to the Output nodes in the XML + representation. + 2011-12-13 Felix Wolfsteller <felix.wolfsteller@intevation.de> Recommend cross-sections.
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionAttribute.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionAttribute.java Wed Dec 14 10:20:56 2011 +0000 @@ -20,6 +20,7 @@ import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; +import de.intevation.artifactdatabase.state.Settings; public class CollectionAttribute { @@ -196,12 +197,23 @@ Element outputEl = ec.create("output"); ec.addAttr(outputEl, "name", name); + appendSettings(outputEl, output.getSettings()); appendFacets(outputEl, output.getFacets()); root.appendChild(outputEl); } + protected void appendSettings(Element root, Settings settings) { + if (settings == null) { + logger.warn("Tried to append Settings, but Settings is empty!"); + return; + } + + settings.toXML(root); + } + + protected void appendFacets(Element root, List<Facet> facets) { if (facets == null || facets.size() == 0) { logger.warn("Tried to append 0 Facets.");
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Wed Dec 14 10:20:56 2011 +0000 @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import javax.xml.xpath.XPathConstants; @@ -30,6 +31,8 @@ import de.intevation.artifactdatabase.Backend.PersistentArtifact; import de.intevation.artifactdatabase.DefaultArtifactCollection; import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Output; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.artifactdatabase.state.StateEngine; import de.intevation.flys.artifacts.context.FLYSContext; @@ -92,6 +95,10 @@ CollectionAttribute newAttr = mergeAttributes( db, context, parser, aUUIDs); + if (checkOutputSettings(newAttr, context)) { + saveCollectionAttribute(db, context, newAttr); + } + helper.setAttribute(newAttr); // Make it an empty array if null. @@ -131,17 +138,42 @@ cAttribute.setLoadedRecommendations( getLoadedRecommendations(oldParser.getAttributeDocument())); - Document doc = cAttribute.toXML(); + saveCollectionAttribute(db, context, cAttribute); + + return cAttribute; + } + + + /** + * @param db The ArtifactDatabase which is required to save the attribute + * into. + * @param attribute The CollectionAttribute that should be stored in the + * database. + * + * @return true, if the transaction was successful, otherwise false. + */ + protected boolean saveCollectionAttribute( + ArtifactDatabase db, + CallContext context, + CollectionAttribute attribute + ) { + log.info("Save new CollectionAttribute into database."); + + Document doc = attribute.toXML(); try { // Save the merged document into database. db.setCollectionAttribute(identifier(), context.getMeta(), doc); + + log.info("Saving CollectionAttribute was successful."); + + return true; } catch (ArtifactDatabaseException adb) { log.error(adb, adb); } - return cAttribute; + return false; } @@ -162,6 +194,64 @@ } + /** + * Evaluates the Output settings. If an Output has no Settings set, the + * relevant OutGenerator is used to initialize a default Settings object. + * + * @param attribute The CollectionAttribute. + * @param cc The CallContext. + * + * @return true, if the CollectionAttribute was modified, otherwise false. + */ + protected boolean checkOutputSettings( + CollectionAttribute attribute, + CallContext cc + ) { + boolean modified = false; + + Map<String, Output> outputMap = attribute != null + ? attribute.getOutputs() + : null; + + if (outputMap == null || outputMap.size() == 0) { + log.debug("No Output Settings check necessary."); + return modified; + } + + Set<Map.Entry<String, Output>> entries = outputMap.entrySet(); + + for (Map.Entry<String, Output> entry: entries) { + String outName = entry.getKey(); + Output output = entry.getValue(); + + Settings settings = output.getSettings(); + + if (settings == null) { + log.debug("No Settings set for Output '" + outName + "'."); + output.setSettings(createInitialOutputSettings(cc, outName)); + + modified = true; + } + } + + return modified; + } + + + /** + * This method uses the the OutGenerator for the specified Output + * <i>out</i> to create an initial Settings object. + */ + protected Settings createInitialOutputSettings(CallContext cc, String out) { + OutGenerator outGen = getOutGenerator(cc, out, null); + + // TODO simulate a real out() process and return finally the Settings + // object retrieved by the OutGenerator. + + return outGen.getSettings(); + } + + @Override public void out( String type,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java Wed Dec 14 10:20:56 2011 +0000 @@ -11,10 +11,11 @@ import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; + import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.artifactdatabase.state.ArtifactAndFacet; - import de.intevation.flys.artifacts.model.WQ; import de.intevation.flys.utils.FLYSUtils; @@ -81,5 +82,15 @@ river, kms[0]); } + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java Wed Dec 14 10:20:56 2011 +0000 @@ -14,6 +14,7 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; @@ -219,5 +220,15 @@ writer.close(); } + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Wed Dec 14 10:20:56 2011 +0000 @@ -21,10 +21,12 @@ import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; + import de.intevation.flys.model.River; import de.intevation.flys.artifacts.WINFOArtifact; -import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.flys.artifacts.resources.Resources; import de.intevation.flys.utils.FLYSUtils; @@ -285,5 +287,15 @@ boolean visible); public abstract void generate() throws IOException; + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Wed Dec 14 10:20:56 2011 +0000 @@ -23,6 +23,7 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.artifacts.common.utils.XMLUtils; @@ -147,5 +148,15 @@ XMLUtils.toStream(doc, out); } + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // 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-artifacts/src/main/java/de/intevation/flys/exports/EmptySettings.java Wed Dec 14 10:20:56 2011 +0000 @@ -0,0 +1,68 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.state.Settings; +import de.intevation.artifactdatabase.state.Section; + + +/** + * An implementation of <i>Settings</i> that doesn't take new <i>Section</i>s + * and that always creates an empty <b>settings</b> DOM node in its + * <i>toXML()</i> operation. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class EmptySettings implements Settings { + + public EmptySettings() { + } + + + /** + * This method has no function. It is not implemented! + * + * @param section A Section. + */ + @Override + public void addSection(Section section) { + // do nothing + } + + + /** + * Always returns 0. + * + * @return 0. + */ + @Override + public int getSectionCount() { + return 0; + } + + + /** + * This method always returns null. It is not implemented! + * + * @param pos A position. + * + * @return null. + */ + @Override + public Section getSection(int pos) { + return null; + } + + + /** + * This method creates an empty <i>settings</i> DOM node. + * + * @param parent A parent DOM node. + */ + @Override + public void toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + parent.appendChild(owner.createElement("art:settings")); + } +}
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Wed Dec 14 10:20:56 2011 +0000 @@ -23,6 +23,7 @@ import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.FacetTypes; @@ -283,5 +284,15 @@ parent.appendChild(initExtent); parent.appendChild(srid); } + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java Wed Dec 14 10:20:56 2011 +0000 @@ -6,6 +6,7 @@ import org.w3c.dom.Document; import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; @@ -54,5 +55,12 @@ * init()). */ void generate() throws IOException; + + /** + * Returns the Settings for the Output produced by this OutGenerator. + * + * @return the Settings for the Output produced by this OutGenerator. + */ + Settings getSettings(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java Tue Dec 13 13:37:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java Wed Dec 14 10:20:56 2011 +0000 @@ -10,9 +10,9 @@ import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifactdatabase.state.ArtifactAndFacet; import de.intevation.artifactdatabase.state.Facet; - -import de.intevation.artifactdatabase.state.ArtifactAndFacet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.flys.artifacts.model.Calculation; @@ -62,5 +62,15 @@ logger.debug("generate"); XMLUtils.toStream(result, out); } + + + /** + * Returns an instance of <i>EmptySettings</i> currently! + * + * @return an instance of <i>EmptySettings</i>. + */ + public Settings getSettings() { + return new EmptySettings(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :