# HG changeset patch # User Tim Englich # Date 1265965909 0 # Node ID e86d37008fd144d7ef4fe00ec5f3bd64628b0070 # Parent 4b818f13e20a02dd4e6a335ce9ac32b538760306 Added new Transition and State for using the PreSettingsValue for the decision if a Transition could be used and the usage of PreSettings as InputValues. gnv-artifacts/trunk@678 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4b818f13e20a -r e86d37008fd1 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Thu Feb 11 14:10:15 2010 +0000 +++ b/gnv-artifacts/ChangeLog Fri Feb 12 09:11:49 2010 +0000 @@ -1,3 +1,27 @@ +2010-02-12 Tim Englich + + * src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java: + This new State ist Implemented for the Case that Values of the PreSettings + has to be used instead of InputValues. This States will look into the + Presettings and put Values identified by the configurable Names into the + InputData-Collection. + For the Configuration you can insert the following XML-Element into the + Configuration of a State. + + + * src/main/java/de/intevation/gnv/state/StateBase.java (getPreSettings), + src/main/java/de/intevation/gnv/state/State.java (getPreSettings): + Added a getter-method for the PreSettings that are set at the State. + Using this way e.g the PresettingsValueCompareTransition can reach the + Settings an can evaluate them. + + * src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java (operator): + This transition will have a look at the Values which where ste during the + instantiation of an Artifact. If a defined Value is given an the Value is + Equal to the configured Value using the configured Operator the Transition + to the configured State could be used. Otherwise the Transition could not + be used. + 2010-02-11 Ingo Weinzierl * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java: diff -r 4b818f13e20a -r e86d37008fd1 gnv-artifacts/src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/PreSettingsTransferState.java Fri Feb 12 09:11:49 2010 +0000 @@ -0,0 +1,75 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifacts.CallContext; +import de.intevation.gnv.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public class PreSettingsTransferState extends DefaultState { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 573381812690806922L; + + private String transferPreSettingsName = null; + + private String transferInputDataname = null; + /** + * Constructor + */ + public PreSettingsTransferState() { + super(); + } + + /** + * @see de.intevation.gnv.state.StateBase#initialize(java.lang.String, de.intevation.artifacts.CallContext) + */ + @Override + public void initialize(String uuid, CallContext context) + throws StateException { + Map preSettings = this.getPreSettings(); + if (preSettings != null){ + InputData ip = preSettings.get(transferPreSettingsName); + if (ip != null){ + Collection localInputdata = new ArrayList(1); + localInputdata.add(new DefaultInputData(transferInputDataname, + ip.getValue())); + this.putInputData(localInputdata, uuid); + } + } + + super.initialize(uuid, context); + } + + /** + * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node) + */ + @Override + public void setup(Node configuration) { + + Element preSettingsNode = (Element)Config.getNodeXPath(configuration, + "presettings-transfer"); + if (preSettingsNode != null){ + this.transferPreSettingsName = preSettingsNode.getAttribute("presetting"); + this.transferPreSettingsName = preSettingsNode.getAttribute("inputvalue"); + } + super.setup(configuration); + } + + + +} diff -r 4b818f13e20a -r e86d37008fd1 gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Thu Feb 11 14:10:15 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Fri Feb 12 09:11:49 2010 +0000 @@ -60,4 +60,6 @@ public void endOfLife(Object globalContext); public void setPreSettings(Map preSettings); + + public Map getPreSettings(); } diff -r 4b818f13e20a -r e86d37008fd1 gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Thu Feb 11 14:10:15 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Fri Feb 12 09:11:49 2010 +0000 @@ -365,6 +365,12 @@ public void setPreSettings(Map preSettings) { this.preSettings = preSettings; } + + + + public Map getPreSettings() { + return this.preSettings; + } protected String getInputValue4ID(Collection inputData, String inputName){ Iterator it = inputData.iterator(); diff -r 4b818f13e20a -r e86d37008fd1 gnv-artifacts/src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/PresettingsValueCompareTransition.java Fri Feb 12 09:11:49 2010 +0000 @@ -0,0 +1,72 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import java.util.Map; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.Config; +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.State; + +/** + * @author Tim Englich + * + */ +public class PresettingsValueCompareTransition extends TransitionBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(PresettingsValueCompareTransition.class); + + private String dataName = null; + private String dataValue = null; + private String operator = null; + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -7846722158776823205L; + + /** + * Constructor + */ + public PresettingsValueCompareTransition() { + super(); + } + + /** + * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State) + */ + public boolean isValid(State state) { + Map preSettings = state.getPreSettings(); + if (preSettings != null){ + boolean dataAvailable = preSettings.containsKey(dataName); + if (dataAvailable){ + if (operator.equals("equal")){ + return preSettings.get(dataName).getValue().startsWith(dataValue); + }else if (operator.equals("notequal")){ + return !preSettings.get(dataName).getValue().startsWith(dataValue); + } + } + } + if (operator.equals("notequal")){ + return true; + } + return false; + } + + @Override + public void setup(Node configuration) { + super.setup(configuration); + this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue"); + this.dataValue = Config.getStringXPath(configuration,"condition/@value"); + this.operator = Config.getStringXPath(configuration,"condition/@operator"); + } + + +}