Mercurial > dive4elements > gnv-client
changeset 634:58c32df1a44d
Improved the describe document so that we are able to render a measurement-parameter-matrix with these data.
gnv-artifacts/trunk@713 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 26 Feb 2010 13:53:05 +0000 (2010-02-26) |
parents | 7a136b99ad71 |
children | 87f05cec1632 |
files | gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml gnv-artifacts/doc/conf/queries.properties 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/MeasurementState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/ExtendedKeyValueData.java |
diffstat | 8 files changed, 375 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/ChangeLog Fri Feb 26 13:53:05 2010 +0000 @@ -1,3 +1,27 @@ +2010-02-26 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * doc/conf/products/timeseries/conf_timeseriespoint.xml: Changed the + configured state class from DefaultState to MeasurementState. + + * doc/conf/queries.properties: Select parameterid from db as well, when + fetching all measurement ids. + + * src/main/java/de/intevation/gnv/state/StateBase.java: Improved the way of + searching for descriptions in selected values (used in describe document). + + * src/main/java/de/intevation/gnv/state/MeasurementState.java: New state + object to create a describe document which can be used to render a + measurement-parameter-matrix. + + * src/main/java/de/intevation/gnv/state/InputData.java, + src/main/java/de/intevation/gnv/state/DefaultInputData.java: Added a new + method to fetch a description by key. + + * src/main/java/de/intevation/gnv/state/describedata/ExtendedKeyValueData.java: + This class extends DefaultKeyValueDescibeData. It is used by + MeasurementState to create a mapping between measurements and parameters. + Each key/value-pair has an extra attribute storing its parameter value. + 2010-02-25 Ingo Weinzierl <ingo.weinzierl@intevation.de> * doc/conf/products/verticalcrosssection/conf_mesh.xml,
--- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Fri Feb 26 13:53:05 2010 +0000 @@ -142,7 +142,7 @@ <to state="timeseries_depth_height"/> </transition> - <state id="timeseries_depth_height" description="timeseries_depth_height" state="de.intevation.gnv.state.DefaultState"> + <state id="timeseries_depth_height" description="timeseries_depth_height" state="de.intevation.gnv.state.MeasurementState"> <queryID>timeseries_depth_height</queryID> <dataname>measurementid</dataname> <data-multiselect>true</data-multiselect>
--- a/gnv-artifacts/doc/conf/queries.properties Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/queries.properties Fri Feb 26 13:53:05 2010 +0000 @@ -46,7 +46,8 @@ timeseries_depth_height=SELECT DISTINCT \ M.MEASUREMENTID KEY, \ - M.ZLOCATION VALUE \ + M.ZLOCATION VALUE, \ + P.PARAMETERID PARAMETERID \ FROM MEDIAN.MEASUREMENT M, \ MEDIAN.TIMESERIESVALUE TSV, \ MEDIAN.TIMESERIES T, \ @@ -1235,4 +1236,4 @@ layer_data = SELECT ST_ASTEXT(SHAPE) \ FROM ? \ - WHERE ? \ No newline at end of file + WHERE ?
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Fri Feb 26 13:53:05 2010 +0000 @@ -1,11 +1,13 @@ -/** - * - */ package de.intevation.gnv.state; +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; + /** - * @author Tim Englich <tim.englich@intevation.de> - * + * @author Tim Englich (tim.englich@intevation.de) + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ public class DefaultInputData implements InputData { @@ -13,14 +15,16 @@ * */ private static final long serialVersionUID = 4308041648698108066L; - + + private static final Logger logger = Logger.getLogger(DefaultInputData.class); + private final static String VALUE_SEPARATOR = " , "; - protected String name; - protected String value; - protected String[] description; - protected Object object; - + protected String name; + protected String value; + protected Map description; + protected Object object; + /** * Constructor @@ -57,12 +61,42 @@ return object; } + public String getDescription(String key) { + if (description == null) + return null; + + return (String) description.get(key); + } + public String[] getDescription() { + String[] values = splitValue(); + int length = values.length; + + String[] description = new String[length]; + for (int i = 0; i < length; i++) { + description[i] = (String) this.description.get(values[i]); + } + return description; } public void setDescription(String[] description) { - this.description = description; + if (this.description == null) + this.description = new HashMap(); + + String[] values = splitValue(); + + int length = values.length; + int descLength = description.length; + + for (int i = 0; i < length; i++) { + if (i < descLength) { + this.description.put(values[i], description[i]); + } + else { + break; + } + } } /**
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Fri Feb 26 13:53:05 2010 +0000 @@ -21,6 +21,8 @@ public void setDescription(String[] description); + public String getDescription(String key); + public String[] getDescription(); public void concartValue(String value);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MeasurementState.java Fri Feb 26 13:53:05 2010 +0000 @@ -0,0 +1,256 @@ +package de.intevation.gnv.state; + +import de.intevation.artifacts.CallMeta; +import de.intevation.artifactdatabase.XMLUtils; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.geobackend.base.ResultDescriptor; +import de.intevation.gnv.state.describedata.ExtendedKeyValueData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.NamedArrayList; +import de.intevation.gnv.state.describedata.NamedCollection; +import de.intevation.gnv.transition.DefaultTransition; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class MeasurementState +extends DefaultState +{ + private static Logger logger = Logger.getLogger(MeasurementState.class); + + public static final String SQL_KEY_PARAMETERID = "PARAMETERID"; + + + private class ParameterMatrix { + private final Logger logger = + Logger.getLogger(ParameterMatrix.class); + + private List measurements; + private List mDescriptions; + private List parameters; + private boolean[][] values; + + public ParameterMatrix(Collection data, String[] parameter) { + measurements = new ArrayList(data.size()); + mDescriptions = new ArrayList(data.size()); + parameters = new ArrayList(parameter.length); + + values = new boolean[data.size()][parameter.length]; + for (int i = 0; i < data.size(); i++) { + Arrays.fill(values[i], false); + } + + initParameters(parameter); + initMeasurements(data); + } + + private void initMeasurements(Collection data) { + Iterator iter = data.iterator(); + while (iter.hasNext()) { + ExtendedKeyValueData value = (ExtendedKeyValueData) iter.next(); + String key = value.getKey(); + String val = value.getValue(); + String parameter = value.getParameter(); + + int i = measurements.indexOf(key); + int j = parameters.indexOf(parameter); + int tmp = mDescriptions.indexOf(val); + + if (i < 0) { + measurements.add(key); + i = measurements.indexOf(key); + } + + if (j < 0) { + logger.warn("Not a valid parameter: " + parameter); + } + + if (tmp < 0) { + mDescriptions.add(val); + tmp = mDescriptions.indexOf(val); + } + + if (i >= 0 && i < measurements.size() && j >= 0 + && j < parameters.size()) + { + values[i][j] = true; + } + } + } + + private void initParameters(String[] parameter) { + int count = parameter.length; + for (int i = 0; i < count; i++) { + parameters.add(parameter[i]); + } + } + + public int measurementSize() { + if (measurements != null) + return measurements.size(); + + return 0; + } + + public int parameterSize() { + if (parameters != null) + return parameters.size(); + + return 0; + } + + public String getMeasurement(int idx) { + if (idx >= 0 && idx < measurements.size()) + return (String) measurements.get(idx); + + logger.warn("Index is out of bounds: " + idx); + return ""; + } + + public String getParameter(int idx) { + if (idx >= 0 && idx < parameters.size()) { + logger.debug("############### PARAM: " + parameters.get(idx)); + return (String) parameters.get(idx); + } + + logger.warn("Index is out of bounds: " + idx); + return ""; + } + + public String getMDescription(int idx) { + if (mDescriptions != null) { + return (String) mDescriptions.get(idx); + } + + return null; + } + + public boolean isValid(int i, int j) { + if (i < 0 || i > measurements.size() + || j < 0 || j > parameters.size()) + { + logger.warn("Index out of bounds: " + i + "|" + j); + return false; + } + + return values[i][j]; + } + } // End of ParameterMatrix + + + public MeasurementState() { + super(); + } + + @Override + protected NamedCollection<KeyValueDescibeData> extractKVP( + Collection<Result> result, + String keyid, + String valueid + ) { + NamedCollection<KeyValueDescibeData> kvdd = + new NamedArrayList<KeyValueDescibeData>(dataName, result.size()); + + kvdd.setMultiSelect(true); + + int keyPos = -1; + int valPos = -1; + int parPos = -1; + + for (Result res: result) { + if (keyPos < 0 || valPos < 0 || parPos < 0) { + ResultDescriptor rd = res.getResultDescriptor(); + + keyPos = rd.getColumnIndex(keyid); + valPos = rd.getColumnIndex(valueid); + parPos = rd.getColumnIndex(SQL_KEY_PARAMETERID); + } + + kvdd.add(new ExtendedKeyValueData( + res.getString(keyPos), + res.getString(valPos), + getID(), + res.getString(parPos))); + } + + return kvdd; + } + + + @Override + protected void appendToDynamicNode( + XMLUtils.ElementCreator artCreator, + XMLUtils.ElementCreator creator, + Document document, + Node dynamicNode, + CallMeta callMeta, + Object o + ) { + NamedArrayList all = (NamedArrayList) o; + String name = all.getName(); + RessourceFactory factory = RessourceFactory.getInstance(); + + Element matrixNode = creator.create("group"); + Element matrixLabel = creator.create("label"); + matrixLabel.setTextContent(factory.getRessource( + callMeta.getLanguages(), all.getName(), all.getName())); + creator.addAttr(matrixNode, "mode", "matrix"); + matrixNode.appendChild(matrixLabel); + + InputData inputParam = inputData.get("parameterid"); + ParameterMatrix matrix = new ParameterMatrix(all, inputParam.splitValue()); + + int measurements = matrix.measurementSize(); + int parameters = matrix.parameterSize(); + + for (int i = 0; i < measurements; i++) { + Element select = creator.create("select"); + creator.addAttr(select, "label", matrix.getMDescription(i)); + + for (int j = 0; j < parameters; j++) { + Element item = creator.create("item"); + Element label = creator.create("label"); + Element value = creator.create("value"); + + creator.addAttr(item, "ref", name); + creator.addAttr( + item, + "parameter", + inputParam.getDescription(matrix.getParameter(j))); + + if (!matrix.isValid(i, j)) { + creator.addAttr(item, "disabled", "true"); + } + else { + creator.addAttr(item, "disabled", "false"); + } + + label.setTextContent(matrix.getMDescription(i)); + value.setTextContent(matrix.getMeasurement(i)); + + item.appendChild(label); + item.appendChild(value); + select.appendChild(item); + } + + matrixNode.appendChild(select); + } + + dynamicNode.appendChild(matrixNode); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Thu Feb 25 09:11:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Fri Feb 26 13:53:05 2010 +0000 @@ -266,19 +266,29 @@ if (obj instanceof NamedArrayList) { NamedArrayList list = (NamedArrayList) obj; - String[] selected = data.splitValue(); + List selected = Arrays.asList(data.splitValue()); int size = list.size(); - int ssize = selected.length; for (int i = 0; i < size; i++) { KeyValueDescibeData kv = (KeyValueDescibeData) list.get(i); // values are concatinated in InputData, so one InputData object can // contain many input - for (int j = 0; j < ssize; j++) { - if (kv.getKey().equals(selected[j])) { - descs.add(kv.getValue()); + String key = kv.getKey(); + int idx = selected.indexOf(key); + if (idx >= 0) { + descs.add(kv.getValue()); + + // XXX Workarround: I just wanted to remove the element at + // 'idx' from selected, but for any reason this is not + // possible (throws an exception) (iw) + List tmp = new ArrayList(); + for (int j = 0; j < selected.size(); j++) { + if (j != idx) + tmp.add(selected.get(j)); } + + selected = tmp; } } } @@ -709,7 +719,7 @@ itemNode.appendChild(choiceLableNode); Element choiceValueNode = creator.create("value"); - choiceValueNode.setTextContent(dataName); + choiceValueNode.setTextContent(data.getValue()); itemNode.appendChild(choiceValueNode); choiceNode.appendChild(itemNode); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/ExtendedKeyValueData.java Fri Feb 26 13:53:05 2010 +0000 @@ -0,0 +1,27 @@ +package de.intevation.gnv.state.describedata; + +import org.apache.log4j.Logger; + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class ExtendedKeyValueData +extends DefaultKeyValueDescribeData +{ + private static Logger logger = Logger.getLogger(ExtendedKeyValueData.class); + + protected String parameter; + + + public ExtendedKeyValueData( + String key, String value, String state, String parameter) + { + super(key, value, state); + this.parameter = parameter; + } + + public String getParameter() { + return parameter; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: