Mercurial > dive4elements > gnv-client
changeset 598:9681ac6b6527
Added the possibility to use the data which are send using the MapServer-Interface during the Workflow of the GNV-Artifacts.
gnv-artifacts/trunk@656 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 02 Feb 2010 13:12:11 +0000 (2010-02-02) |
parents | cf38b983d1f3 |
children | c5710a8d2825 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/PreSettingArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java |
diffstat | 8 files changed, 210 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Feb 02 13:12:11 2010 +0000 @@ -1,3 +1,39 @@ +2010-02-02 Tim Englich <tim.englich@intevation.de> + + * src/main/java/de/intevation/gnv/state/DefaultInputData.java (splitValue), + src/main/java/de/intevation/gnv/state/InputData.java (splitValue): + Added Method which spilts the Values using the same Separator which is + used to concart the Values. + + * src/main/java/de/intevation/gnv/state/StateBase.java: + Added the usage of the Presettings during the Loading of the Data + which is nessesary to describe the current State. + If Values are given in the Presettings which are identified by the + name wwhich is specified in the Configurationelement presettings-name + only the Intersection of the fetched Objects and the PresettingsObjects + are used. + + * src/main/java/de/intevation/gnv/state/State.java (setPreSettings): + Added new Method setPreSettings to be Able to put the Presettings from the + current Artifact to the different States. + + * src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java (setup): + The Method Setup now extracts the given PreSettingsparameter from the + XML-Document and put them to the ProductArtifacts which are instantiated in + the advance()-Method using the Methods of the PreSettingArtifact-Interface. + + * src/main/java/de/intevation/gnv/artifacts/PreSettingArtifact.java (setPreSettings): + New interfacedefinition. Artifacts which are implementing this Interface + are able to exchange the given Presettings using the given getter and + setter methods of this Interface. + + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: + The GNVArtifactBase now implements the Interface PreSettingsArtifacts. + So it is able to manage Data which is set during the construction of an + new ArtifactInstance. + It also put the PreSettings-data to the different States. So that they are + able to use it during their livecycle. + 2010-02-01 Tim Englich <tim.englich@intevation.de> * doc/conf/conf.xml:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Feb 02 13:12:11 2010 +0000 @@ -53,7 +53,9 @@ * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ -public abstract class GNVArtifactBase extends GNVDefaultArtifact { +public abstract class GNVArtifactBase extends GNVDefaultArtifact + implements PreSettingArtifact { + /** * the logger, used to log exceptions and additonaly information */ @@ -104,7 +106,6 @@ */ protected Collection<Transition> transitions = null; - /** * The current product */ @@ -116,6 +117,13 @@ protected String name = null; /** + * The Presettings of InputData which can be used to + * travel through the States in different Ways or + * manipulate the InputData + */ + private Map<String, InputData> preSettings = null; + + /** * Constructor */ public GNVArtifactBase() { @@ -157,6 +165,7 @@ // 2. Transfer Results next.putInputData(current.getInputData(), identifier); next.setParent(current); + next.setPreSettings(this.preSettings); if (current != null) { current.endOfLife(context.globalContext()); @@ -834,7 +843,7 @@ public void setProduct(Product product) { - this.product = product; + this.product = product; } public void endOfLife(Object globalContext) { @@ -844,5 +853,22 @@ current.endOfLife(globalContext); } } + + /** + * @see de.intevation.gnv.artifacts.PreSettingArtifact#getPreSettings() + */ + public Map<String, InputData> getPreSettings() { + return this.preSettings; + } + + /** + * @see de.intevation.gnv.artifacts.PreSettingArtifact#setPreSettings(java.util.Map) + */ + public void setPreSettings(Map<String, InputData> preSettings) { + this.preSettings = preSettings; + if (this.current != null){ + this.current.setPreSettings(preSettings); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/PreSettingArtifact.java Tue Feb 02 13:12:11 2010 +0000 @@ -0,0 +1,20 @@ +/** + * + */ +package de.intevation.gnv.artifacts; + +import java.util.Map; + +import de.intevation.gnv.state.InputData; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface PreSettingArtifact { + + + Map<String,InputData> getPreSettings(); + + void setPreSettings(Map<String,InputData> preSettings); +}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java Tue Feb 02 13:12:11 2010 +0000 @@ -3,13 +3,17 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import javax.xml.xpath.XPathConstants; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import de.intevation.artifactdatabase.ProxyArtifact; import de.intevation.artifactdatabase.XMLUtils; @@ -21,8 +25,10 @@ import de.intevation.gnv.artifacts.GNVArtifactBase; import de.intevation.gnv.artifacts.GNVDefaultArtifact; import de.intevation.gnv.artifacts.GNVProductArtifactFactory; +import de.intevation.gnv.artifacts.PreSettingArtifact; import de.intevation.gnv.artifacts.fis.product.Product; import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.state.DefaultInputData; import de.intevation.gnv.state.InputData; @@ -31,12 +37,20 @@ */ public class SelectProductArtifact extends GNVDefaultArtifact { + /** + * THE UID of this Class. + */ + private static final long serialVersionUID = -7952357683127758677L; + public static final String XPATH_UUID = "art:action/art:uuid/@value"; public static final String XPATH_HASH = "art:action/art:hash/@value"; public static final String XPATH_INPUT_DATA_VALUE = "art:action/art:data/art:input[@name='product']/@value"; + + public static final String XPATH_SETUP_PARAMETER_NODES = + "/art:action/art:factory/art:parameter"; public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; public static final String XFORM_PREFIX = "xform"; @@ -47,6 +61,8 @@ private Product current; private Artifact artifact; private String name; + + private Map<String, InputData> preSettings = null; public SelectProductArtifact() { super(); @@ -62,6 +78,31 @@ log.debug("SelectProductArtifact.setup()"); super.setup(identifier, factory, context,data); this.name = factory.getName(); + + // Read the Parameters that should be used for the setup from the + // Data-XML.Document. + NodeList parameterNodes = (NodeList) XMLUtils.xpath(data, + XPATH_SETUP_PARAMETER_NODES, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + if (parameterNodes != null && parameterNodes.getLength() > 0){ + this.preSettings = new HashMap<String, InputData>(); + for (int i = 0; i < parameterNodes.getLength(); i++){ + Element parameterNode = (Element)parameterNodes.item(i); + String name = parameterNode.getAttribute("name"); + String value = parameterNode.getAttribute("value"); + log.debug("Name: "+name); + log.debug("Value: "+value); + InputData inputData = this.preSettings.get(name); + if (inputData == null){ + inputData = new DefaultInputData(name, value); + this.preSettings.put(name, inputData); + }else{ + inputData.concartValue(value); + } + } + } + } @@ -165,7 +206,11 @@ .getArtifactFactoryByName(current.getName()); artifact = factory.createArtifact(uuid, context, null); - Document feedDocument = feedDocument(uuid, hash); + + if (this.preSettings != null && artifact instanceof PreSettingArtifact){ + ((PreSettingArtifact)artifact).setPreSettings(this.preSettings); + } + artifact.feed(feedDocument(uuid, hash), context); result = ((GNVArtifactBase) artifact).initialize(context);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Tue Feb 02 13:12:11 2010 +0000 @@ -13,6 +13,9 @@ * */ private static final long serialVersionUID = 4308041648698108066L; + + private final static String VALUE_SEPARATOR = " , "; + private String name = null; private String value = null; @@ -50,7 +53,17 @@ * @see de.intevation.gnv.state.InputData#concartValue(java.lang.String) */ public void concartValue(String value) { - this.value = this.value + " , " + value; + this.value = this.value + VALUE_SEPARATOR + value; + } + + /** + * @see de.intevation.gnv.state.InputData#splitValue() + */ + public String[] splitValue() { + if (this.value != null){ + return this.value.split(VALUE_SEPARATOR); + } + return null; } }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Tue Feb 02 13:12:11 2010 +0000 @@ -16,4 +16,6 @@ public String getValue(); public void concartValue(String value); + + String[] splitValue(); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Tue Feb 02 13:12:11 2010 +0000 @@ -3,18 +3,16 @@ */ package de.intevation.gnv.state; -import de.intevation.artifacts.CallContext; - -import de.intevation.gnv.state.exception.StateException; - import java.io.Serializable; - import java.util.Collection; import java.util.Map; import org.w3c.dom.Document; import org.w3c.dom.Node; +import de.intevation.artifacts.CallContext; +import de.intevation.gnv.state.exception.StateException; + /** * @author Tim Englich (tim.englich@intevation.de) * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) @@ -57,4 +55,6 @@ public void reset(String uuid); public void endOfLife(Object globalContext); + + public void setPreSettings(Map<String,InputData> preSettings); }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Mon Feb 01 14:52:05 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Feb 02 13:12:11 2010 +0000 @@ -3,40 +3,8 @@ */ package de.intevation.gnv.state; -import de.intevation.artifactdatabase.Config; -import de.intevation.artifactdatabase.XMLUtils; - -import de.intevation.artifacts.ArtifactNamespaceContext; -import de.intevation.artifacts.CallContext; -import de.intevation.artifacts.CallMeta; - -import de.intevation.gnv.artifacts.GNVArtifactBase; - -import de.intevation.gnv.artifacts.cache.CacheFactory; - -import de.intevation.gnv.artifacts.ressource.RessourceFactory; - -import de.intevation.gnv.geobackend.base.Result; - -import de.intevation.gnv.geobackend.base.query.QueryExecutor; -import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; - -import de.intevation.gnv.geobackend.base.query.exception.QueryException; - -import de.intevation.gnv.geobackend.util.DateUtils; - -import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; -import de.intevation.gnv.state.describedata.KeyValueDescibeData; -import de.intevation.gnv.state.describedata.MinMaxDescribeData; -import de.intevation.gnv.state.describedata.NamedArrayList; -import de.intevation.gnv.state.describedata.NamedCollection; -import de.intevation.gnv.state.describedata.SingleValueDescribeData; - -import de.intevation.gnv.state.exception.StateException; - -import de.intevation.gnv.utils.InputValidator; - import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; @@ -50,12 +18,33 @@ import javax.xml.xpath.XPathConstants; import org.apache.log4j.Logger; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; +import de.intevation.gnv.artifacts.GNVArtifactBase; +import de.intevation.gnv.artifacts.cache.CacheFactory; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.base.query.QueryExecutor; +import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; +import de.intevation.gnv.geobackend.base.query.exception.QueryException; +import de.intevation.gnv.geobackend.util.DateUtils; +import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.MinMaxDescribeData; +import de.intevation.gnv.state.describedata.NamedArrayList; +import de.intevation.gnv.state.describedata.NamedCollection; +import de.intevation.gnv.state.describedata.SingleValueDescribeData; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.utils.InputValidator; + /** * @author Tim Englich (tim.englich@intevation.de) * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) @@ -88,6 +77,8 @@ private String description = null; protected String dataName = null; + + protected String preSettingsName = null; protected boolean dataMultiSelect = false; @@ -103,6 +94,7 @@ protected Map<String, InputData> inputData = null; + private Map<String, InputData> preSettings = null; /** * Constructor @@ -197,6 +189,8 @@ this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue); } + this.preSettingsName = Config.getStringXPath(configuration, "presettings-name"); + } /** @@ -296,7 +290,15 @@ log.warn("No Inputdata given"); } } - + + /** + * + * @see de.intevation.gnv.state.State#setPreSettings(java.util.Map) + */ + public void setPreSettings(Map<String, InputData> preSettings) { + this.preSettings = preSettings; + } + private String getInputValue4ID(Collection<InputData> inputData, String inputName){ Iterator<InputData> it = inputData.iterator(); while (it.hasNext()) { @@ -523,7 +525,16 @@ int keyPos = 0; int valuePos = 1; String previousKey = null; - + InputData preSettingsData = (this.preSettings != null && + this.preSettingsName != null) ? + this.preSettings.get(this.preSettingsName) : + null; + boolean filterWithPresettings = preSettingsData != null; + + List<String> preSettingValues = null; + if(filterWithPresettings){ + preSettingValues = Arrays.asList(preSettingsData.splitValue()); + } while (rit.hasNext()) { Result resultValue = rit.next(); if (!initialized){ @@ -535,10 +546,19 @@ initialized = true; } String tmpKey = resultValue.getString(keyPos); - // TODO: FIXME: We have to do that because the arcsde does not support a distinct Query on Layers. + + // TODO: FIXME: We have to do that because the arcsde does not + // support a distinct Query on Layers. if (previousKey == null || !tmpKey.equals(previousKey)){ previousKey = tmpKey; - keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos), getID())); + if (!filterWithPresettings || preSettingValues.contains(tmpKey)){ + keyValueDescibeData.add( + new DefaultKeyValueDescribeData( + tmpKey, + resultValue.getString(valuePos), + getID()) + ); + } } } return keyValueDescibeData;