Mercurial > dive4elements > river
changeset 624:929137ee8154
ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
flys-artifacts/trunk@1982 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon May 23 15:11:55 2011 +0000 @@ -1,3 +1,22 @@ +2011-05-23 Ingo Weinzierl <ingo@intevation.de> + + ISSUE-62 (part II/II) + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Dump the + artifacts state/data in DEBUG mode in describe(). + + * src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java, + src/main/java/de/intevation/flys/artifacts/states/DefaultState.java, + src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java, + src/main/java/de/intevation/flys/artifacts/states/WQSelect.java, + src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java, + src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java, + src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java: + States will no longer store data. The only reason for states storing + StateData is to know about the necessary data for this state. If a State + needs to access the user input for a specific StateData object, it needs + to query the FLYSArtifact which stores the data. + 2011-05-23 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 23 15:11:55 2011 +0000 @@ -370,41 +370,8 @@ } } - State current = getCurrentState(context); - DefaultState toValidate = (DefaultState) fillState(current); - - toValidate.validate(this, context); - } - - - /** - * This method fills a state object with the data that have been inserted to - * this artifact. This is necessary to use the isStateReachable() method, - * because the Transitions need to know about the inserted data. - * - * @param state The state that needs to be filled with data. - * - * @return the filled state. - */ - protected State fillState(State state) { - Map<String, StateData> stateData = state.getData(); - - if (stateData == null) { - return state; - } - - Set<String> keys = stateData.keySet(); - - for (String key: keys) { - StateData tmp = getData(key); - - if (tmp != null) { - StateData data = stateData.get(key); - data.setValue(tmp.getValue()); - } - } - - return state; + DefaultState current = (DefaultState) getCurrentState(context); + current.validate(this, context); } @@ -424,7 +391,7 @@ FLYSContext flysContext = getFlysContext(context); - State currentState = fillState(getCurrentState(context)); + State currentState = getCurrentState(context); StateEngine sEngine = (StateEngine) flysContext.get( FLYSContext.STATE_ENGINE_KEY);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Mon May 23 15:11:55 2011 +0000 @@ -75,6 +75,10 @@ public Document describe(Document data, CallContext context) { logger.debug("Describe: the current state is: " + getCurrentStateId()); + if (logger.isDebugEnabled()) { + dumpArtifact(); + } + FLYSContext flysContext = null; if (context instanceof FLYSContext) { flysContext = (FLYSContext) context; @@ -178,6 +182,7 @@ List<Output> list = state.getOutputs(); if (list == null || list.size() == 0) { + logger.debug("-> No output modes for this state."); continue; } @@ -226,9 +231,8 @@ for (String stateId: stateIds) { logger.debug("Append static data for state: " + stateId); DefaultState state = (DefaultState) engine.getState(stateId); - state = (DefaultState) fillState(state); - ui.appendChild(state.describeStatic(doc, ui, context, uuid)); + ui.appendChild(state.describeStatic(this, doc, ui, context, uuid)); } }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon May 23 15:11:55 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts.states; -import java.util.Map; - import org.apache.log4j.Logger; import org.w3c.dom.Element; @@ -15,6 +13,7 @@ import de.intevation.artifactdatabase.ProtocolUtils; import de.intevation.artifactdatabase.data.StateData; +import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.resources.Resources; /** @@ -26,6 +25,9 @@ private static Logger logger = Logger.getLogger(CalculationSelect.class); + + public static final String FIELD_MODE = "calculation_mode"; + /** Constant value for the reference line calculation.*/ public static final String CALCULATION_SURFACE_CURVE = "calc.surface.curve"; @@ -110,10 +112,10 @@ throws IllegalArgumentException { logger.debug("CalculationSelect.validate"); + FLYSArtifact flys = (FLYSArtifact) artifact; - Map<String, StateData> data = getData(); - - String calc = (String) data.get("calculation_mode").getValue(); + StateData data = getData(flys, FIELD_MODE); + String calc = data != null ? (String) data.getValue() : null; if (calc == null) { throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Mon May 23 15:11:55 2011 +0000 @@ -1,6 +1,6 @@ package de.intevation.flys.artifacts.states; -import java.util.Collection; +import java.util.Iterator; import java.util.Map; import org.apache.log4j.Logger; @@ -20,6 +20,7 @@ import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.AbstractState; +import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.resources.Resources; @@ -32,7 +33,13 @@ private static Logger logger = Logger.getLogger(DefaultState.class); + protected StateData getData(FLYSArtifact artifact, String name) { + return artifact.getData(name); + } + + public Element describeStatic( + Artifact artifact, Document document, Node root, CallContext context, @@ -56,11 +63,14 @@ return ui; } - Collection<StateData> dataItems = theData.values(); + Iterator<String> iter = theData.keySet().iterator(); + FLYSArtifact flys = (FLYSArtifact) artifact; - for (StateData data: dataItems) { - String name = data.getName(); - String value = (String) data.getValue(); + while (iter.hasNext()) { + String name = iter.next(); + StateData data = getData(flys, name); + + String value = data != null ? (String) data.getValue() : null; if (value == null) { continue; @@ -117,10 +127,15 @@ return ui; } - Collection<StateData> dataItems = theData.values(); + Iterator<String> iter = theData.keySet().iterator(); + FLYSArtifact flys = (FLYSArtifact) artifact; - for (StateData data: dataItems) { - String name = data.getName(); + while (iter.hasNext()) { + String name = iter.next(); + StateData data = getData(flys, name); + + data = data != null ? data : getData(name); + Element select = createData(creator, artifact, data, context); Element choices = ProtocolUtils.createArtNode(
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Mon May 23 15:11:55 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts.states; -import java.util.Map; - import org.apache.log4j.Logger; import org.w3c.dom.Element; @@ -140,9 +138,9 @@ protected double[] getMinMaxDistance(Artifact artifact) { FLYSArtifact flysArtifact = (FLYSArtifact) artifact; - StateData data = flysArtifact.getData("river"); + StateData data = getData(flysArtifact, "river"); - String name = (String) data.getValue(); + String name = data != null ? (String) data.getValue() : ""; logger.debug("Search for the min/max distances of '" + name + "'"); @@ -158,11 +156,15 @@ { logger.debug("LocationDistanceSelect.validate"); - Map<String, StateData> data = getData(); + FLYSArtifact flys = (FLYSArtifact) artifact; - String fromStr = (String) data.get(FROM).getValue(); - String toStr = (String) data.get(TO).getValue(); - String stepStr = (String) data.get(STEP).getValue(); + StateData dFrom = getData(flys, FROM); + StateData dTo = getData(flys, TO); + StateData dStep = getData(flys, STEP); + + String fromStr = dFrom != null ? (String) dFrom.getValue() : null; + String toStr = dTo != null ? (String) dTo.getValue() : null; + String stepStr = dStep != null ? (String) dStep.getValue() : null; if (fromStr == null || toStr == null || stepStr == null) { throw new IllegalArgumentException("error_empty_state");
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java Mon May 23 15:11:55 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts.states; -import java.util.Map; - import gnu.trove.TDoubleArrayList; import org.apache.log4j.Logger; @@ -11,6 +9,8 @@ import de.intevation.artifactdatabase.data.StateData; +import de.intevation.flys.artifacts.FLYSArtifact; + /** * This state is used to realize the input of multiple locations as string. The @@ -45,9 +45,10 @@ { logger.debug("LocationSelect.validate"); - Map<String, StateData> data = getData(); + FLYSArtifact flys = (FLYSArtifact) artifact; + StateData data = getData(flys, FIELD_LOCATIONS); - String locationStr = (String) data.get(FIELD_LOCATIONS).getValue(); + String locationStr = data != null ? (String) data.getValue() : null; if (locationStr == null || locationStr.length() == 0) { logger.error("No locations given.");
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java Mon May 23 15:11:55 2011 +0000 @@ -1,7 +1,6 @@ package de.intevation.flys.artifacts.states; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; @@ -18,6 +17,7 @@ import de.intevation.flys.model.River; +import de.intevation.flys.artifacts.FLYSArtifact; import de.intevation.flys.artifacts.model.RiverFactory; import de.intevation.flys.artifacts.resources.Resources; @@ -136,9 +136,9 @@ { logger.debug("RiverSelect.validate"); - Map<String, StateData> data = getData(); + FLYSArtifact flys = (FLYSArtifact) artifact; - StateData dRiver = data.get("river"); + StateData dRiver = getData(flys, "river"); if (dRiver == null || dRiver.getValue() == null) { throw new IllegalArgumentException(ERROR_NO_RIVER_SELECTED);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java Mon May 23 15:11:55 2011 +0000 @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; @@ -160,9 +159,10 @@ { logger.debug("WQAdapted.validate"); - Map<String, StateData> data = getData(); + FLYSArtifact flys = (FLYSArtifact) artifact; + StateData data = getData(flys, FIELD_WQ_MODE); - String mode = (String) data.get(FIELD_WQ_MODE).getValue(); + String mode = data != null ? (String) data.getValue() : null; if (mode != null && mode.equals("W")) { return validateW(artifact, context); @@ -180,8 +180,14 @@ throws IllegalArgumentException { logger.debug("WQAdapted.validateW"); + FLYSArtifact flys = (FLYSArtifact) artifact; - RangeWithValues[] rwvs = extractInput(getData("wq_values")); + RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); + + if (rwvs == null) { + throw new IllegalArgumentException("error_missing_wq_data"); + } + List<Gauge> gauges = ((FLYSArtifact) artifact).getGauges(); for (Gauge gauge: gauges) { @@ -204,8 +210,14 @@ throws IllegalArgumentException { logger.debug("WQAdapted.validateQ"); + FLYSArtifact flys = (FLYSArtifact) artifact; - RangeWithValues[] rwvs = extractInput(getData("wq_values")); + RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); + + if (rwvs == null) { + throw new IllegalArgumentException("error_missing_wq_data"); + } + List<Gauge> gauges = ((FLYSArtifact) artifact).getGauges(); River river = ((FLYSArtifact) artifact).getRiver(); Wst wst = WstFactory.getWst(river); @@ -287,6 +299,10 @@ protected RangeWithValues[] extractInput(StateData data) { + if (data == null) { + return null; + } + String dataString = (String) data.getValue(); String[] ranges = dataString.split(":");
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon May 23 14:32:17 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon May 23 15:11:55 2011 +0000 @@ -1,7 +1,5 @@ package de.intevation.flys.artifacts.states; -import java.util.Map; - import gnu.trove.TDoubleArrayList; import org.apache.log4j.Logger; @@ -203,9 +201,10 @@ { logger.debug("WQSelect.validate"); - Map<String, StateData> data = getData(); + FLYSArtifact flys = (FLYSArtifact) artifact; - String selectionMode = (String) data.get(WQ_SELECTION).getValue(); + StateData data = getData(flys, WQ_SELECTION); + String selectionMode = data != null ? (String) data.getValue() : null; if (selectionMode == null || selectionMode.equals("single")) { return validateSingle(artifact, context); @@ -221,7 +220,10 @@ { logger.debug("WQSelect.validateSingle"); - String tmp = (String) data.get(WQ_SINGLE).getValue(); + FLYSArtifact flys = (FLYSArtifact) artifact; + StateData data = getData(flys, WQ_SINGLE); + + String tmp = data != null ? (String) data.getValue() : null; if (tmp == null || tmp.length() == 0) { throw new IllegalArgumentException("error_empty_state"); @@ -241,7 +243,9 @@ all.sort(); - String mode = (String) data.get(WQ_MODE).getValue(); + StateData dMode = getData(flys, WQ_MODE); + String mode = dMode != null ? (String) data.getValue() : null; + logger.debug("WQ Mode: " + mode); double[] minmax = null;