# HG changeset patch # User Ingo Weinzierl # Date 1265802215 0 # Node ID 292fbcd5e9acc407f9faf2b0876d6540dc95d53f # Parent 9efc1c256dbbe54aa4ae282a601ba34f197c8fc2 Parted the cache blob into pieces and changed the way how user input is stored on each state. gnv-artifacts/trunk@673 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/ChangeLog Wed Feb 10 11:43:35 2010 +0000 @@ -1,3 +1,45 @@ +2010-02-10 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/state/State.java: New method 'feed' in + this interface. It should be used to feed this state with new data + selected by the user. + + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: Use new + method 'feed' instead of 'putInputData' to feed the state with new data. + + * src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java, + src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java, + src/main/java/de/intevation/gnv/state/SingleInputState.java: Method + 'purifyResult' just cleans values from database and returns it. DO NOT + put these results into cache at this place! + + * src/main/java/de/intevation/gnv/state/InputData.java, + src/main/java/de/intevation/gnv/state/DefaultInputData.java: Some new + methods to store objects in such an InputData object. Objects are used to + store MinMaxDescribeData objects for example. And further new methods to + store a description for each InputData object. This is used to render the + static GUI part. Until now, this object stored the id's of the + selected parameter, only - which are useless to show in GUI. The + description should be the string shown in the GUI, later. + + * src/main/java/de/intevation/gnv/state/MinMaxState.java: This type of state + overrides 'feed' and 'appendToStaticNode'. 'feed' takes user input and + parses min and max values from it (used for time periods for example). + 'appendToStaticNode' will append these fields to the static GUI part. + + * src/main/java/de/intevation/gnv/state/StateBase.java: Removed the big + cache blob and parted it into pieces. Each state will now put its + database data into cache. In this way, we are able to reuse these data + when the user steps back in history. Data, inserted by the user, will be + stored via 'feed'. Special input fields like multi selection or ranges + need to override this method to parse the input data and store them in + special objects. + + TODOs: + - The output modes are based on this big cache blob and search for + parameterid, measurementid and dateid in it. + TimeSeriesOutputState.getCollection() needs to be adapted! + 2010-02-09 Tim Englich * src/main/java/de/intevation/gnv/artifacts/services/requestobjects/DefaultFIS.java (addParameter), diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Wed Feb 10 11:43:35 2010 +0000 @@ -388,7 +388,7 @@ XPATH_INPUT_DATA); if (!inputData.isEmpty()){ - this.current.putInputData(inputData, super.identifier); + current.feed(inputData, super.identifier); result = new ArtifactXMLUtilities().createSuccessReport( "Feed success", XMLUtils.newDocument()); }else{ diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java Wed Feb 10 11:43:35 2010 +0000 @@ -66,18 +66,17 @@ } @Override - protected void purifyResult(Collection result, String uuid) { + protected List purifyResult(Collection result, String uuid) { log.debug("CoordinateSelectionState.purifyResult"); - List describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = this - .extractKVP(result, "FEATUREID", "SHAPE"); + List describeData = new ArrayList(); + + NamedCollection keyValueDescibeData = + extractKVP(result, "FEATUREID", "SHAPE"); + describeData.add(keyValueDescibeData); - this.setDescibeData(uuid, describeData); + return describeData; } - + /** * @see de.intevation.gnv.state.StateBase#prepareInputData4RegionDBQuery(java.lang.String) */ diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Wed Feb 10 11:43:35 2010 +0000 @@ -16,8 +16,11 @@ private final static String VALUE_SEPARATOR = " , "; - private String name = null; - private String value = null; + protected String name; + protected String value; + protected String description; + protected Object object; + /** * Constructor @@ -27,6 +30,11 @@ this.value = value; } + public DefaultInputData(String name, Object object) { + this.name = name; + this.object = object; + } + /** * @see de.intevation.gnv.state.InputData#getName() */ @@ -41,6 +49,22 @@ return this.value; } + public void setObject(Object object) { + this.object = object; + } + + public Object getObject() { + return object; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + /** * @see java.lang.Object#toString() */ diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Wed Feb 10 11:43:35 2010 +0000 @@ -15,6 +15,14 @@ public String getValue(); + public void setObject(Object o); + + public Object getObject(); + + public void setDescription(String description); + + public String getDescription(); + public void concartValue(String value); String[] splitValue(); diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java Wed Feb 10 11:43:35 2010 +0000 @@ -1,21 +1,40 @@ -/** - * - */ package de.intevation.gnv.state; +import de.intevation.artifactdatabase.XMLUtils; + +import de.intevation.artifacts.CallMeta; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; + +import de.intevation.gnv.geobackend.base.Result; + +import de.intevation.gnv.geobackend.util.DateUtils; + +import de.intevation.gnv.state.describedata.DefaultMinMaxDescribeData; +import de.intevation.gnv.state.describedata.DescribeData; +import de.intevation.gnv.state.describedata.MinMaxDescribeData; + +import de.intevation.gnv.state.exception.StateException; + +import de.intevation.gnv.utils.InputValidator; + import java.util.ArrayList; import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.state.describedata.DefaultMinMaxDescribeData; -import de.intevation.gnv.state.describedata.DescribeData; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** - * @author Tim Englich - * + * @author Tim Englich (tim.englich@intevation.de) + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ public class MinMaxState extends StateBase { @@ -40,26 +59,151 @@ * java.lang.String) */ @Override - protected void purifyResult(Collection result, String uuid) { - log.debug("MinMaxState.purifyResult"); - List describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } + protected List purifyResult( + Collection result, String uuid) + { + List describeData = new ArrayList(); + if (result != null && result.size() == 1) { - Result value = result.iterator().next(); DescribeData values = new DefaultMinMaxDescribeData( - dataName, - value.getObject("MIN"), + dataName, + value.getObject("MIN"), value.getObject("MAX"), getID()); - log.debug(values.toString()); describeData.add(values); } else { log.warn("Result cannot be handled as MinMax Resultset"); } - this.setDescibeData(uuid, describeData); + + return describeData; } + + /** + * @see de.intevation.gnv.state.StateBase#feed(java.util.Collection, + * java.lang.String) + */ + @Override + public void feed(Collection inputData, String uuid) + throws StateException + { + if (inputData == null) + return; + + InputValidator iv = new InputValidator(); + Iterator iter = inputData.iterator(); + + Object min = null; + Object max = null; + + while (iter.hasNext()) { + InputData tmp = (InputData) iter.next(); + InputValue meta = inputValues.get(tmp.getName()); + String value = tmp.getValue(); + String name = tmp.getName(); + + if (meta == null) { + log.warn("Input data not expected here. Data will be ignored."); + return; + } + + boolean valid = iv.isInputValid(value, meta.getType()); + if (!valid) { + String msg = "Input is not valid for this state."; + log.error(msg); + throw new StateException(msg); + } + + if (name.equals(MINVALUEFIELDNAME)) { + min = value; + } + + if (name.equals(MAXVALUEFIELDNAME)) { + max = value; + } + } + + if (min != null && max != null) { + DescribeData values = new DefaultMinMaxDescribeData( + dataName, min, max, getID()); + + this.inputData.put(dataName, new DefaultInputData(dataName, values)); + } + } + + + @Override + protected void appendToStaticNode( + XMLUtils.ElementCreator artCreator, + XMLUtils.ElementCreator creator, + Document document, + Node staticNode, + CallMeta callMeta, + String inputKey + ) { + InputData data = inputData.get(dataName); + + if (data == null) { + return; + } + + MinMaxDescribeData minMax = (MinMaxDescribeData) data.getObject(); + + Object min = minMax.getMinValue(); + Object max = minMax.getMaxValue(); + if (min instanceof GregorianCalendar) { + Date d = ((GregorianCalendar) min).getTime(); + min = DateUtils.getPatternedDateAmer(d); + } + + if (max instanceof GregorianCalendar) { + Date d = ((GregorianCalendar) max).getTime(); + max = DateUtils.getPatternedDateAmer(d); + } + + Element groupNode = creator.create("group"); + artCreator.addAttr(groupNode, "state", minMax.getState(), true); + + creator.addAttr(groupNode, "ref", minMax.getName()); + Element groupNodeLableNode = creator.create("label"); + groupNodeLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), + minMax.getName(), + minMax.getName())); + groupNode.appendChild(groupNodeLableNode); + + Element inputMinNode = creator.create("input"); + creator.addAttr(inputMinNode, "ref", MINVALUEFIELDNAME); + Element inputMinLableNode = creator.create("label"); + inputMinLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MINVALUEFIELDNAME, + MINVALUEFIELDNAME)); + inputMinNode.appendChild(inputMinLableNode); + + Element inputMinValueNode = creator.create("value"); + inputMinValueNode.setTextContent(min.toString()); + inputMinNode.appendChild(inputMinValueNode); + + Element inputMaxNode = creator.create("input"); + creator.addAttr(inputMaxNode, "ref", MAXVALUEFIELDNAME); + Element inputMaxLableNode = creator.create("label"); + inputMaxLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MAXVALUEFIELDNAME, + MAXVALUEFIELDNAME)); + inputMaxNode.appendChild(inputMaxLableNode); + + Element inputMaxValueNode = creator.create("value"); + inputMaxValueNode.setTextContent(max.toString()); + inputMaxNode.appendChild(inputMaxValueNode); + + groupNode.appendChild(inputMinNode); + groupNode.appendChild(inputMaxNode); + + staticNode.appendChild(groupNode); + } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java Wed Feb 10 11:43:35 2010 +0000 @@ -39,12 +39,10 @@ * java.lang.String) */ @Override - protected void purifyResult(Collection result, String uuid) { + protected List purifyResult(Collection result, String uuid) { log.debug("SingleInputState.purifyResult"); - List describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } + List describeData = new ArrayList(); + String value = null; if (result != null && result.size() == 1) { Result tmpItem = result.iterator().next(); @@ -55,7 +53,8 @@ describeData.add(new DefaultSingleValueDescribeData( this.dataName, value, getID())); - this.setDescibeData(uuid, describeData); + + return describeData; } } diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Wed Feb 10 11:43:35 2010 +0000 @@ -33,6 +33,9 @@ String uuid ); + public void feed(Collection inputData, String uuid) + throws StateException; + public void setParent(State state); public State getParent(); diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Wed Feb 10 11:43:35 2010 +0000 @@ -14,6 +14,8 @@ import javax.xml.xpath.XPathConstants; +import net.sf.ehcache.Cache; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -59,8 +61,8 @@ */ private static Logger log = Logger.getLogger(GNVArtifactBase.class); - private final static String MINVALUEFIELDNAME = "minvalue"; - private final static String MAXVALUEFIELDNAME = "maxvalue"; + protected final static String MINVALUEFIELDNAME = "minvalue"; + protected final static String MAXVALUEFIELDNAME = "maxvalue"; private final static String NODATASELECTIONKEY = "n/n"; @@ -88,13 +90,13 @@ protected Collection inputValueNames = null; - private Map inputValues = null; + protected Map inputValues = null; - private State parent = null; + protected State parent = null; protected Map inputData = null; - private Map preSettings = null; + protected Map preSettings = null; /** * Constructor @@ -128,7 +130,7 @@ public void reset(String uuid) { - + if (parent != null) { inputData = parent.inputData(); } @@ -139,7 +141,6 @@ * @see de.intevation.gnv.state.State#setup(org.w3c.dom.Node) */ public void setup(Node configuration) { - log.debug("StateBase.setup"); this.id = ((Element)configuration).getAttribute("id"); this.description = ((Element)configuration).getAttribute("description"); @@ -167,7 +168,6 @@ inputValueNode.getAttribute("type"), Boolean.parseBoolean(inputValueNode. getAttribute("multiselect")), usedinQuery); - log.debug(inputValue.toString()); this.inputValues.put(inputValue.getName(), inputValue); this.inputValueNames.add(inputValue.getName()); } @@ -207,12 +207,10 @@ this.parent = state; } - /** - * @see de.intevation.gnv.state.State#putInputData(java.util.Collection) - */ - public void putInputData(Collection inputData, String uuid) - throws StateException { - log.debug("StateBase.putInputData"); + + public void feed(Collection inputData, String uuid) + throws StateException + { if (inputData != null) { Iterator it = inputData.iterator(); InputValidator iv = new InputValidator(); @@ -224,7 +222,7 @@ this.inputData = new HashMap( inputData.size()); } - + boolean valid = iv.isInputValid(tmpItem.getValue(), inputValue.getType()); if (valid) { @@ -239,8 +237,8 @@ log.warn(errMsg); throw new StateException(errMsg); } - - valid = iv.isInputValid(minValue, + + valid = iv.isInputValid(minValue, maxValue, inputValue.getType()); if (!valid){ @@ -259,8 +257,8 @@ log.warn(errMsg); throw new StateException(errMsg); } - - valid = iv.isInputValid(minValue, + + valid = iv.isInputValid(minValue, maxValue, inputValue.getType()); if (!valid){ @@ -269,7 +267,6 @@ throw new StateException(errMsg); } } - this.setSelection(tmpItem, uuid); this.inputData.put(tmpItem.getName(), tmpItem); } else { String errMsg = "Wrong input for " + tmpItem.getValue() @@ -292,6 +289,99 @@ } /** + * @see de.intevation.gnv.state.State#putInputData(java.util.Collection) + */ + public void putInputData(Collection inputData, String uuid) + throws StateException { + if (inputData != null) { + Iterator it = inputData.iterator(); + InputValidator iv = new InputValidator(); + while (it.hasNext()) { + InputData tmpItem = it.next(); + InputValue inputValue = this.inputValues.get(tmpItem.getName()); + if (inputValue != null) { + if (this.inputData == null) { + this.inputData = new HashMap( + inputData.size()); + } + + boolean valid = iv.isInputValid(tmpItem.getValue(), + inputValue.getType()); + if (valid) { + if (tmpItem.getName().equals(MINVALUEFIELDNAME)){ + String minValue = tmpItem.getValue(); + String maxValue = this.getInputValue4ID(inputData, MAXVALUEFIELDNAME); + valid = iv.isInputValid(maxValue,inputValue.getType()); + if (!valid){ + String errMsg = "Wrong input for " + tmpItem.getValue() + + " is not an " + inputValue.getType() + + " Value."; + log.warn(errMsg); + throw new StateException(errMsg); + } + + valid = iv.isInputValid(minValue, + maxValue, + inputValue.getType()); + if (!valid){ + String errMsg = "MaxValue-Input is less than MinValue-Input "; + log.warn(errMsg); + throw new StateException(errMsg); + } + }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){ + String minValue = this.getInputValue4ID(inputData, MINVALUEFIELDNAME); + String maxValue = tmpItem.getValue(); + valid = iv.isInputValid(minValue,inputValue.getType()); + if (!valid){ + String errMsg = "Wrong input for " + tmpItem.getValue() + + " is not an " + inputValue.getType() + + " Value."; + log.warn(errMsg); + throw new StateException(errMsg); + } + + valid = iv.isInputValid(minValue, + maxValue, + inputValue.getType()); + if (!valid){ + String errMsg = "MaxValue-Input is less than MinValue-Input "; + log.warn(errMsg); + throw new StateException(errMsg); + } + } + this.inputData.put(tmpItem.getName(), tmpItem); + } else { + String errMsg = "Wrong input for " + tmpItem.getValue() + + " is not an " + inputValue.getType() + + " Value."; + log.warn(errMsg); + throw new StateException(errMsg); + } + + } else { + String errMsg = "No Inputvalue given for Inputdata " + + tmpItem.getName(); + log.warn(errMsg + "Value will be ignored"); + + } + } + } else { + log.warn("No Inputdata given"); + } + + debugInputData(); + } + + private void debugInputData() { + if (log.isDebugEnabled()) { + Iterator iter = inputData.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + } + } + } + + /** * * @see de.intevation.gnv.state.State#setPreSettings(java.util.Map) */ @@ -311,7 +401,6 @@ } private void setSelection(InputData inputData, String uuid) { - log.debug("StateBase.setSelection"); Object o = this.getDescribeData(inputData.getName(),uuid); if (o != null) { @@ -348,7 +437,6 @@ } private Object getDescribeData(String name, String uuid) { - log.debug("StateBase.getDescribeData"); Collection descibeData = this.getDescibeData(uuid); if (descibeData != null) { Iterator it = descibeData.iterator(); @@ -383,27 +471,14 @@ throws StateException { } - + public void initialize(String uuid, CallContext context) throws StateException { - log.debug("StateBase.initialize"); try { - String[] filterValues = this - .generateFilterValuesFromInputData(); - Collection result = null; - try { - if (this.queryID != null) { - QueryExecutor queryExecutor = QueryExecutorFactory - .getInstance().getQueryExecutor(); - result = queryExecutor.executeQuery(this.queryID, - filterValues); - } - this.purifyResult(result, uuid); - } catch (RuntimeException e) { - log.error(e, e); - } - } catch (QueryException e) { + getDescibeData(uuid); + } + catch (RuntimeException e) { log.error(e, e); throw new StateException(e); } @@ -449,7 +524,6 @@ } private String prepareInputData4DateDBQuery(String value) { - log.debug("StateBase.prepareInputData4DateDBQuery"); if (value != null) { String[] values = value.split(","); String newValue = ""; @@ -468,7 +542,6 @@ } private String prepareInputData4DBQuery(String value) { - log.debug("StateBase.prepareInputData4DBQuery"); if (value != null) { String[] values = value.split(","); String newValue = ""; @@ -488,15 +561,15 @@ /** * @param result */ - protected void purifyResult(Collection result, String uuid) { - log.debug("StateBase.purifyResult"); - List describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); - describeData.add(keyValueDescibeData); - this.setDescibeData(uuid, describeData); + protected List purifyResult(Collection result, String uuid) { + List describeData = new ArrayList(); + + NamedCollection keyValueDescibeData = + extractKVP(result, "KEY", "VALUE"); + + describeData.add(keyValueDescibeData); + + return describeData; } /** @@ -508,11 +581,11 @@ String valueid) { Iterator rit = result.iterator(); int dataSize = (this.dataNoSelect ? result.size()+1 : result.size()); - + NamedCollection keyValueDescibeData = new NamedArrayList( this.dataName, dataSize); keyValueDescibeData.setMultiSelect(this.dataMultiSelect); - + if (this.dataNoSelect){ keyValueDescibeData.add(new DefaultKeyValueDescribeData( NODATASELECTIONKEY, @@ -525,12 +598,12 @@ int keyPos = 0; int valuePos = 1; String previousKey = null; - InputData preSettingsData = (this.preSettings != null && - this.preSettingsName != null) ? - this.preSettings.get(this.preSettingsName) : - null; + InputData preSettingsData = + (this.preSettings != null && this.preSettingsName != null) + ? this.preSettings.get(this.preSettingsName) + : null; boolean filterWithPresettings = preSettingsData != null; - + List preSettingValues = null; if(filterWithPresettings){ preSettingValues = Arrays.asList(preSettingsData.splitValue()); @@ -546,7 +619,7 @@ 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. if (previousKey == null || !tmpKey.equals(previousKey)){ @@ -612,70 +685,12 @@ * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, * java.lang.String) */ - /* - public void describe( - Document document, - Node rootNode, - CallContext context, - String uuid - ) { - log.debug("StateBase.describe"); - CallMeta callMeta = context.getMeta(); - - List descibeData = this.getDescibeData(uuid); - if (descibeData != null) { - Iterator it = descibeData.iterator(); - - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - document, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX - ); - - Node staticNode = (Node) XMLUtils.xpath( - rootNode, - XPATH_STATIC_UI, - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE - ); - - Node dynamic = (Node) XMLUtils.xpath( - rootNode, - XPATH_DYNAMIC_UI, - XPathConstants.NODE, - ArtifactNamespaceContext.INSTANCE - ); - - XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator( - document, - XMLUtils.XFORM_URL, - XMLUtils.XFORM_PREFIX - ); - - while (it.hasNext()) { - Object o = it.next(); - if ((!it.hasNext() && dataName != null)) { - appendToDynamicNode( - creator, xCreator, document, dynamic, callMeta, o); - } - else { - appendToStaticNode( - creator, xCreator, document, staticNode, callMeta, o); - } - } - } - } - */ - - public void describe( Document document, Node rootNode, CallContext context, String uuid) { - log.debug("StateBase.describe"); - XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator( document, XMLUtils.XFORM_URL, @@ -720,9 +735,12 @@ CallContext context, String uuid) { - log.debug("StateBase.describeDynamic"); CallMeta callMeta = context.getMeta(); + String newInput = findNewValue(); + if (newInput == null && parent != null) + return; + List descibeData = getDescibeData(uuid); if (descibeData != null) { Iterator it = descibeData.iterator(); @@ -835,7 +853,7 @@ } else { Object[] names = this.inputValueNames.toArray(); name = names[names.length - 1].toString(); - } + } Element selectNode = creator.create(multiselect?"select":"select1"); creator.addAttr(selectNode, "ref", name); @@ -994,33 +1012,77 @@ node.appendChild(groupNode); } - /** - * @see de.intevation.gnv.state.State#getDescibeData() - */ - protected List getDescibeData(String uuid) { - if (CacheFactory.getInstance().isInitialized()) { - String key = uuid + DESCRIBEDATAKEY; - log.debug("Hash for Queryelements: " + key); - net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); - if (value != null) { - return (List) (value.getObjectValue()); - } - } - return null; + + protected String getHash(String uuid) { + return uuid + id + inputData.hashCode(); } + /** * @see de.intevation.gnv.state.State#getDescibeData() */ - protected void setDescibeData(String uuid, List describeData) { - - if (CacheFactory.getInstance().isInitialized()) { - String key = uuid + DESCRIBEDATAKEY; - log.debug("Hash for Queryelements: " + key); - CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, describeData)); + public List getDescibeData(String uuid) { + CacheFactory factory = CacheFactory.getInstance(); + if (factory.isInitialized()) { + // we use a cache + Cache cache = factory.getCache(); + + String key = getHash(uuid); + + net.sf.ehcache.Element value = cache.get(key); + if (value != null) { + // element already in cache, so return it. + return (List) (value.getObjectValue()); + } + else { + // element is not in cache yet, so we need to fetch data from + // database and put it into cache right now + try { + String[] filterValues = generateFilterValuesFromInputData(); + List data = queryDatabase(filterValues, uuid); + + cache.put(new net.sf.ehcache.Element(key, data)); + + return data; + } + catch (QueryException qe) { + log.error(qe, qe); + } + } } + else { + // we don't use a cache, so we have to query the database every + // single time + String[] filterValues = generateFilterValuesFromInputData(); + Collection result = null; + try { + return queryDatabase(filterValues, uuid); + } + catch (RuntimeException e) { + log.error(e, e); + } + catch (QueryException e) { + log.error(e, e); + } + } + + return null; } + protected List queryDatabase(String[] filterValues, String uuid) + throws QueryException { + Collection result = null; + + if (queryID != null) { + QueryExecutor queryExecutor = + QueryExecutorFactory.getInstance().getQueryExecutor(); + + result = queryExecutor.executeQuery(queryID, filterValues); + } + return purifyResult(result, uuid); + } + + public Map inputData() { return inputData; } diff -r 9efc1c256dbb -r 292fbcd5e9ac gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java Tue Feb 09 15:23:07 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java Wed Feb 10 11:43:35 2010 +0000 @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.List; /** * @author Tim Englich @@ -34,6 +35,8 @@ */ private static final long serialVersionUID = -7989531326553305293L; + protected CallMeta callMeta; + /** * Constructor */ @@ -44,23 +47,12 @@ * @see de.intevation.gnv.state.StateBase#purifyResult(java.util.Collection, java.lang.String) */ @Override - protected void purifyResult(Collection result, String uuid) { - } - - /** - * @see de.intevation.gnv.state.StateBase#initialize(java.lang.String, de.intevation.artifacts.CallMeta) - */ - @Override - public void initialize(String uuid, CallContext context) - throws StateException - { - CallMeta callMeta = context.getMeta(); - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = new NamedArrayList( - this.dataName, 2); + protected List purifyResult(Collection result, String uuid) { + List describeData = new ArrayList(); + + NamedCollection keyValueDescibeData = + new NamedArrayList(dataName, 2); + keyValueDescibeData.setMultiSelect(super.dataMultiSelect); keyValueDescibeData.add(new DefaultKeyValueDescribeData("IPOSITION", RessourceFactory.getInstance().getRessource( @@ -69,6 +61,18 @@ RessourceFactory.getInstance().getRessource( callMeta.getLanguages(), "jposition", "jposition"))); describeData.add(keyValueDescibeData); + + return describeData; + } + + /** + * @see de.intevation.gnv.state.StateBase#initialize(java.lang.String, de.intevation.artifacts.CallMeta) + */ + @Override + public void initialize(String uuid, CallContext context) + throws StateException + { + this.callMeta = context.getMeta(); }