Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 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
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 14 Dec 2011 10:20:56 +0000 |
parents | 0b466bd4ab24 |
children | 158b3aabda2c |
line wrap: on
line diff
--- 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,