# HG changeset patch # User Ingo Weinzierl # Date 1336982950 0 # Node ID edaa2297aea314a101a83d14dfcf297101225754 # Parent 32b1e28edb150c7206bf3f4775ddb35497ab433f Started module MINFO (MINFOArtifact, state to choose calculations, configurations). flys-artifacts/trunk@4397 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon May 14 08:09:10 2012 +0000 @@ -1,3 +1,22 @@ +2012-05-14 Ingo Weinzierl + + * doc/conf/artifacts/minfo.xml: New Artifact configuration for module + MINFO. + + * src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java: New + Artifact for module INFO. + + * src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java: + New. The state is used for choosing the calculation in module MINFO. + + * doc/conf/conf.xml: Registered the MINFO Artifact. + + * src/main/resources/messages.properties, + src/main/resources/messages_de_DE.properties, + src/main/resources/messages_en.properties, + src/main/resources/messages_de.properties: New strings for states and + calculations. + 2012-05-13 Felix Wolfsteller * src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java: diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/doc/conf/artifacts/minfo.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/doc/conf/artifacts/minfo.xml Mon May 14 08:09:10 2012 +0000 @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/doc/conf/conf.xml --- a/flys-artifacts/doc/conf/conf.xml Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/doc/conf/conf.xml Mon May 14 08:09:10 2012 +0000 @@ -98,6 +98,11 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + + + de.intevation.artifactdatabase.DefaultArtifactFactory de.intevation.artifactdatabase.DefaultUserFactory @@ -171,6 +176,7 @@ + diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java Mon May 14 08:09:10 2012 +0000 @@ -0,0 +1,248 @@ +package de.intevation.flys.artifacts; + +import de.intevation.artifactdatabase.ProtocolUtils; + +import de.intevation.artifactdatabase.state.Output; +import de.intevation.artifactdatabase.state.State; +import de.intevation.artifactdatabase.state.StateEngine; + +import de.intevation.artifactdatabase.transition.TransitionEngine; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.Message; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; + +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.artifacts.context.FLYSContext; + +import de.intevation.flys.artifacts.model.CalculationMessage; +import de.intevation.flys.artifacts.model.FacetTypes; + +import de.intevation.flys.artifacts.states.DefaultState; + +import de.intevation.flys.utils.FLYSUtils; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * The default MINFO artifact. + * + * @author Ingo Weinzierl + */ +public class MINFOArtifact +extends FLYSArtifact +implements FacetTypes { + + /** The logger for this class. */ + private static Logger logger = Logger.getLogger(MINFOArtifact.class); + + /** The name of the artifact. */ + public static final String ARTIFACT_NAME = "minfo"; + + /** XPath */ + public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static"; + + + /** + * The default constructor. + */ + public MINFOArtifact() { + } + + + /** + * This method returns a description of this artifact. + * + * @param data Some data. + * @param context The CallContext. + * + * @return the description of this artifact. + */ + public Document describe(Document data, CallContext context) { + logger.debug("Describe: the current state is: " + getCurrentStateId()); + + FLYSContext flysContext = FLYSUtils.getFlysContext(context); + StateEngine stateEngine = (StateEngine) flysContext.get( + FLYSContext.STATE_ENGINE_KEY); + + TransitionEngine transitionEngine = (TransitionEngine) flysContext.get( + FLYSContext.TRANSITION_ENGINE_KEY); + + List reachable = transitionEngine.getReachableStates( + this, getCurrentState(context), stateEngine); + + Document description = XMLUtils.newDocument(); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + description, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = ProtocolUtils.createRootNode(creator); + description.appendChild(root); + + State current = getCurrentState(context); + + ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); + ProtocolUtils.appendState(creator, root, current); + ProtocolUtils.appendReachableStates(creator, root, reachable); + + appendBackgroundActivity(creator, root, context); + + Element name = ProtocolUtils.createArtNode( + creator, "name", + new String[] { "value" }, + new String[] { getName() }); + + Element ui = ProtocolUtils.createArtNode( + creator, "ui", null, null); + + Element staticUI = ProtocolUtils.createArtNode( + creator, "static", null, null); + + Element outs = ProtocolUtils.createArtNode( + creator, "outputmodes", null, null); + appendOutputModes(description, outs, context, identifier()); + + appendStaticUI(description, staticUI, context, identifier()); + + Element dynamic = current.describe( + this, + description, + root, + context, + identifier()); + + if (dynamic != null) { + ui.appendChild(dynamic); + } + + ui.appendChild(staticUI); + + root.appendChild(name); + root.appendChild(ui); + root.appendChild(outs); + + return description; + } + + + /** + * Returns the name of the concrete artifact. + * + * @return the name of the concrete artifact. + */ + public String getName() { + return ARTIFACT_NAME; + } + + + protected static void appendBackgroundActivity( + ElementCreator cr, + Element root, + CallContext context + ) { + Element inBackground = cr.create("background-processing"); + root.appendChild(inBackground); + + cr.addAttr( + inBackground, + "value", + String.valueOf(context.isInBackground()), + true); + + LinkedList messages = context.getBackgroundMessages(); + + if (messages == null) { + return; + } + + CalculationMessage message = (CalculationMessage) messages.getLast(); + cr.addAttr( + inBackground, + "steps", + String.valueOf(message.getSteps()), + true); + + cr.addAttr( + inBackground, + "currentStep", + String.valueOf(message.getCurrentStep()), + true); + + inBackground.setTextContent(message.getMessage()); + } + + + /** + * Append output mode nodes to a document. + */ + protected void appendOutputModes( + Document doc, + Element outs, + CallContext context, + String uuid) + { + List generated = getOutputs(context); + logger.debug("This Artifact has " + generated.size() + " Outputs."); + + ProtocolUtils.appendOutputModes(doc, outs, generated); + } + + + /** + * This method appends the static data - that has already been inserted by + * the user - to the static node of the DESCRIBE document. + * + * @param doc The document. + * @param ui The root node. + * @param context The CallContext. + * @param uuid The identifier of the artifact. + */ + protected void appendStaticUI( + Document doc, + Node ui, + CallContext context, + String uuid) + { + List stateIds = getPreviousStateIds(); + + FLYSContext flysContext = FLYSUtils.getFlysContext(context); + StateEngine engine = (StateEngine) flysContext.get( + FLYSContext.STATE_ENGINE_KEY); + + for (String stateId: stateIds) { + logger.debug("Append static data for state: " + stateId); + DefaultState state = (DefaultState) engine.getState(stateId); + + ui.appendChild(state.describeStatic(this, doc, ui, context, uuid)); + } + } + + + /** + * Determines Facets initial disposition regarding activity (think of + * selection in Client ThemeList GUI). This will be checked one time + * when the facet enters a collections describe document. + * + * @param facetName name of the facet. + * @param index index of the facet. + * @return 0 if not active + */ + @Override + public int getInitialFacetActivity(String outputName, String facetName, int index) { + logger.warn("MINFOArtifact.getInitialFacetActivity: not implemented!"); + return 1; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java Mon May 14 08:09:10 2012 +0000 @@ -0,0 +1,109 @@ +package de.intevation.flys.artifacts.states; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Element; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifactdatabase.data.StateData; + +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.resources.Resources; + +/** + * @author Ingo Weinzierl + */ +public class CalculationSelectMinfo extends DefaultState { + + /** The logger that is used in this class. */ + private static Logger logger = Logger.getLogger(CalculationSelectMinfo.class); + + + public static final String FIELD_MODE = "calculation_mode"; + + public static final String CALC_BED_MIDDLE = "calc.bed.middle"; + public static final String CALC_BED_DIFF = "calc.bed.diff"; + public static final String CALC_BED_QUALITY = "calc.bed.quality"; + public static final String CALC_SEDIMENT_LOAD = "calc.sediment.load"; + public static final String CALC_FLOW_VELOCITY = "calc.flow.velocity"; + public static final String CALC_SQ_RELATION = "calc.sq.relation"; + + /** An array that holds all available calculation modes. */ + public static final String[] CALCULATIONS = { + CALC_BED_MIDDLE, + CALC_BED_DIFF, + CALC_BED_QUALITY, + CALC_SEDIMENT_LOAD, + CALC_FLOW_VELOCITY, + CALC_SQ_RELATION + }; + + + /** Error message that is thrown if no mode has been chosen. */ + public static final String ERROR_NO_CALCULATION_MODE = + "error_feed_no_calculation_mode"; + + /** Error message that is thrown if an invalid calculation mode has been + * chosen. */ + public static final String ERROR_INVALID_CALCULATION_MODE = + "error_feed_invalid_calculation_mode"; + + + public CalculationSelectMinfo() { + } + + + @Override + protected Element[] createItems( + XMLUtils.ElementCreator cr, + Artifact artifact, + String name, + CallContext context) + { + CallMeta meta = context.getMeta(); + Element[] calcs = new Element[CALCULATIONS.length]; + + for (int i = 0; i < CALCULATIONS.length; ++i) { + String calc = CALCULATIONS[i]; + calcs[i] = createItem( + cr, new String[] { + Resources.getMsg(meta, calc, calc), + calc + }); + } + + return calcs; + } + + + @Override + public boolean validate(Artifact artifact) + throws IllegalArgumentException + { + logger.debug("CalculationSelect.validate"); + FLYSArtifact flys = (FLYSArtifact) artifact; + + StateData data = getData(flys, FIELD_MODE); + String calc = (data != null) ? (String) data.getValue() : null; + + if (calc == null) { + throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); + } + + calc = calc.trim().toLowerCase(); + + for (String mode: CALCULATIONS) { + if (mode.equals(calc)) { + return true; + } + } + + throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/resources/messages.properties --- a/flys-artifacts/src/main/resources/messages.properties Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages.properties Mon May 14 08:09:10 2012 +0000 @@ -21,6 +21,9 @@ state.fix.river = River state.fix.calculation.mode = Calculation Mode +state.minfo.river = River +state.minfo.calculation_mode = Calculation Mode + historical.mode.w = Waterlevel Analyse historical.mode.q = Discharge Analyse @@ -34,6 +37,12 @@ calc.reference.curve = Reference Curve calc.fixation.default = Fixation calc.fixation.volmer = Balanced Waterlevel +calc.bed.middle = Middle Bed Height +calc.bed.diff = Bed Height Difference +calc.bed.quality = Bed Quality +calc.sediment.load = Sediment Load +calc.flow.velocity = Flow Velocity +calc.sq.relation = Load Discharge Relation state.chart.river = River state.chart.type = Charttype diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/resources/messages_de.properties --- a/flys-artifacts/src/main/resources/messages_de.properties Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de.properties Mon May 14 08:09:10 2012 +0000 @@ -21,6 +21,9 @@ state.fix.river = Gew\u00e4sser state.fix.calculation.mode = Berechnungsart +state.minfo.river = Gew\u00e4sser +state.minfo.calculation_mode = Berechnungsart + historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse @@ -34,6 +37,12 @@ calc.reference.curve = Bezugslinie calc.fixation.default = Fixierungsanalyse calc.fixation.volmer = Ausgeglichene Wasserspiegellage +calc.bed.middle = Mittlere Sohlh\u00f6he +calc.bed.diff = Sohlh\u00f6hendifferenz +calc.bed.quality = Sohlbeschaffenheit +calc.sediment.load = Sedimentfracht +calc.flow.velocity = Flie\u00dfgeschwindigkeit +calc.sq.relation = Transport-Abfluss Beziehung state.chart.river = Gew\u00e4sser state.chart.type = Diagrammtyp diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/resources/messages_de_DE.properties --- a/flys-artifacts/src/main/resources/messages_de_DE.properties Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Mon May 14 08:09:10 2012 +0000 @@ -21,6 +21,9 @@ state.fix.river = Gew\u00e4sser state.fix.calculation.mode = Berechnungsart +state.minfo.river = Gew\u00e4sser +state.minfo.calculation_mode = Berechnungsart + historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse @@ -32,6 +35,12 @@ calc.w.differences = Differenzen calc.historical.discharge.curve = Hist. Abflusskurven calc.reference.curve = Bezugslinie +calc.bed.middle = Mittlere Sohlh\u00f6he +calc.bed.diff = Sohlh\u00f6hendifferenz +calc.bed.quality = Sohlbeschaffenheit +calc.sediment.load = Sedimentfracht +calc.flow.velocity = Flie\u00dfgeschwindigkeit +calc.sq.relation = Transport-Abfluss Beziehung state.chart.river = Gew\u00e4sser state.chart.type = Diagrammtyp diff -r 32b1e28edb15 -r edaa2297aea3 flys-artifacts/src/main/resources/messages_en.properties --- a/flys-artifacts/src/main/resources/messages_en.properties Sun May 13 21:39:55 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_en.properties Mon May 14 08:09:10 2012 +0000 @@ -21,6 +21,9 @@ state.fix.river = River state.fix.calculation.mode = Calculation Mode +state.minfo.river = River +state.minfo.calculation_mode = Calculation Mode + historical.mode.w = Waterlevel Analyse historical.mode.q = Discharge Analyse @@ -34,6 +37,12 @@ calc.reference.curve = Reference Curve calc.fixation.default = Fixation calc.fixation.volmer = Balanced Waterlevel +calc.bed.middle = Middle Bed Height +calc.bed.diff = Bed Height Difference +calc.bed.quality = Bed Quality +calc.sediment.load = Sediment Load +calc.flow.velocity = Flow Velocity +calc.sq.relation = Load Discharge Relation state.chart.river = River state.chart.type = Charttype