Mercurial > dive4elements > gnv-client
changeset 232:3d6d89bcbf42
Added special Data-Selection to the ODV-Exports of TimeSeries on TimeSeriesPoints. issue68
gnv-artifacts/trunk@300 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/ChangeLog Mon Nov 09 08:55:01 2009 +0000 @@ -1,3 +1,24 @@ +2009-11-09 Tim Englich <tim.englich@intevation.de> + + * src/test/ressources/timeseries/timeseries_step_06_out_*.xml: + Added the missing out-Modes to the Testcase and rename it to + the common used way in this TestCases. + * src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java (testTimeSeriesArtifact): + Added the ODV-Export to the Unit-Testcase. + Some Refactoring Work done. + * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (out): + The Method for generating ODV-Export now reads its Data from + the special Method which delivers the adapted Data. + * src/main/java/de/intevation/gnv/transition/TransitionBase.java (generateFilterValuesFromInputData): + Extracted the Generation of the FilterValues for the geo-backend + to use it in several methods. + * src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java (getODVResult): + Added Method for getting the rquired Data for ODV-Exports + * doc/conf/products/timeseries/conf_timeseriespoint.xml: + Added separat QueryID Lookup for ODV-Data-Queryies + * doc/conf/queries.properties: + DB-Queries for ODV-Support TimeSeries on TimeSeriesPoints added. + 2009-11-06 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/exports,
--- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Mon Nov 09 08:55:01 2009 +0000 @@ -98,6 +98,7 @@ <transition id="timeseries_calculate_results" description="timeseries_interval" transition="de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition"> <queryID>timeseries_chart_data</queryID> + <queryID-odv>timeseries_odv_data</queryID-odv> <inputvalues> <inputvalue name="parameterid" type="Integer" multiselect="true"/> <inputvalue name="measurementid" type="Integer" multiselect="true"/>
--- a/gnv-artifacts/doc/conf/queries.properties Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/doc/conf/queries.properties Mon Nov 09 08:55:01 2009 +0000 @@ -82,6 +82,35 @@ tv.TIMESERIESID , \ t.PARAMETERID , \ tv.TIMEVALUE + +timeseries_odv_data = SELECT SI.NAME CRUISE, \ + MEDIAN.TIMESERIESPOINT.NAME STATION, \ + '*' TYPE, \ + ST_ASTEXT(SHAPE), \ + 0 BOTDEPTH, \ + (M.ZLOCATION *-1) DEPTH, \ + TSV.TIMEVALUE, \ + TSV.DATAVALUE, \ + TS.PARAMETERID PARAMETER, \ + TSV.MEASUREMENTID, \ + TSV.TIMESERIESID \ + FROM MEDIAN.TIMESERIESPOINT , \ + MEDIAN.TIMESERIESVALUE TSV, \ + MEDIAN.TIMESERIES TS, \ + MEDIAN.MEASUREMENT M, \ + MEDIAN.SOURCEINFO SI \ + WHERE SI.SOURCEID = M.SOURCEID AND \ + M.FEATUREID = MEDIAN.TIMESERIESPOINT.FEATUREID AND \ + M.MEASUREMENTID = TSV.MEASUREMENTID AND \ + TSV.TIMESERIESID = TS.TIMESERIESID AND \ + TS.PARAMETERID IN ( ? ) AND \ + TSV.MEASUREMENTID IN ( ? ) AND \ + TSV.TIMEVALUE >= ? AND \ + TSV.TIMEVALUE <= ? \ + ORDER BY TSV.MEASUREMENTID , \ + TSV.TIMESERIESID , \ + TS.PARAMETERID , \ + TSV.TIMEVALUE ############################################# ############################################# @@ -685,5 +714,4 @@ FROM MEDIAN.FEATUREAREA \ WHERE (FEATURETYPE = 7 OR FEATURETYPE = 8) AND \ FEATUREID = ? \ - ORDER BY NAME - \ No newline at end of file + ORDER BY NAME \ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Mon Nov 09 08:55:01 2009 +0000 @@ -66,7 +66,7 @@ protected XYSeries createXYSeries(String seriesName, Collection<Result> resultSet, int lUpperCut, int lLowerCut, int pStart, - int pEnd) throws TechnicalChartException { + int pEnd, double maxGap) throws TechnicalChartException { if (sDebug) sLogger.debug("createXYSeries()"); XYSeries series = new XYSeries(seriesName);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Mon Nov 09 08:55:01 2009 +0000 @@ -212,7 +212,7 @@ protected XYSeries createXYSeries(String seriesName, Collection<Result> resultSet, int lUpperCut, int lLowerCut, int pStart, - int pEnd) throws TechnicalChartException { + int pEnd, double maxGap) throws TechnicalChartException { if (sDebug) sLogger.debug("createXYSeries()"); XYSeries series = new XYSeries(seriesName); @@ -262,16 +262,23 @@ int mEnd = 0; Iterator<Result> resultIterator = resultSet.iterator(); + Result firstRow = null, lastRow = null; + + double maxGap; if (resultIterator.hasNext()) { // Row row = new Row(sArrayStrLine); Result row = resultIterator.next(); - + + firstRow = row; + lastRow = row; + break1 = row.getString("GROUP1"); // 2 break2 = row.getString("GROUP2"); // 3 break3 = row.getString("GROUP3"); // 4 int i = 1; while (resultIterator.hasNext()) { row = resultIterator.next(); + if (!break1.equals(row.getString("GROUP1")) || !break2.equals(row.getString("GROUP2")) || !break3.equals(row.getString("GROUP3"))) { @@ -279,8 +286,12 @@ sLogger.debug("Neuer Datensatz " + seriesName + "von Datens�tzen " + mStart + " / " + mEnd); + + maxGap = this.calculateMaxGap(firstRow, lastRow, mEnd-mStart); + xyDataset.addSeries(createXYSeries(seriesName, - resultSet, lUpperCut, lLowerCut, mStart, mEnd)); + resultSet, lUpperCut, lLowerCut, mStart, mEnd,maxGap)); + firstRow = row; mStart = i; break1 = row.getString("GROUP1"); @@ -288,6 +299,7 @@ break3 = row.getString("GROUP3"); // 4 } + lastRow = row; mEnd = i; // mEnd ++; i = i + 1; @@ -296,11 +308,13 @@ String seriesName = this.createSeriesName(parameters, measurements, dates, break1, break2, break3); sLogger.debug("Neuer Datensatz " + seriesName + "von Datens�tzen " + mStart + " / " + mEnd); + + maxGap = this.calculateMaxGap(firstRow, lastRow, mEnd-mStart); xyDataset.addSeries(createXYSeries(seriesName, resultSet, - lUpperCut, lLowerCut, mStart, mEnd)); + lUpperCut, lLowerCut, mStart, mEnd,maxGap)); }else{ xyDataset.addSeries(createXYSeries("", - resultSet, lUpperCut, lLowerCut, mStart, mEnd)); + resultSet, lUpperCut, lLowerCut, mStart, mEnd,9999)); } } catch (Exception e) { sLogger.error(e.getMessage(), e); @@ -308,6 +322,15 @@ } return xyDataset; } + + + protected double calculateMaxGap(Result firstRow, Result lastRow, int numResults){ + + double firstValue = firstRow.getDouble("YORDINATE"); + // TODO Implement me. Hier ist die zentrale Frage wie wir zwischen Netzen und + // anderen Datenquellen unterscheiden. + return 0; + } /** * @param parameters
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Mon Nov 09 08:55:01 2009 +0000 @@ -17,6 +17,9 @@ import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.cache.CacheFactory; 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.transition.exception.TransitionException; /** @@ -40,6 +43,8 @@ * The different Outputmodes which are provided by an OutputTransition */ protected Collection<OutputMode> outputModes = null; + + protected String queryODVID = null; /** * Constructor @@ -63,6 +68,9 @@ public void setup(Node configuration) { log.debug("OutputTransitionBase.setup"); super.setup(configuration); + + this.queryODVID = Config.getStringXPath(configuration,"queryID-odv"); + NodeList outputModeList = Config.getNodeSetXPath(configuration, "outputsModes/outputsMode"); if (outputModeList != null) { @@ -138,6 +146,31 @@ return null; } + protected Collection<Result> getODVResult(String uuid) { + log.debug("OutputTransitionBase.getODVResult"); + // TODO add Caching? I think it's not nessessary + Collection<Result> returnValue = null; + if (this.queryODVID != null){ + try { + String[] filterValues = this.generateFilterValuesFromInputData(); + try { + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance() + .getQueryExecutor(); + returnValue = queryExecutor.executeQuery(this.queryODVID, + filterValues); + } catch (RuntimeException e) { + log.error(e, e); + } + } catch (QueryException e) { + log.error(e, e); + } + }else{ + log.warn("No Query for ODV Data is defined."); + } + return returnValue; + } + protected void removeChartResult(String uuid) { log.debug("OutputTransitionBase.getChartResult"); if (CacheFactory.getInstance().isInitialized()) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Nov 09 08:55:01 2009 +0000 @@ -368,35 +368,7 @@ this.alternativeTransition.advance(uuid, callMeta); }else{ try { - List<String> list = new ArrayList<String>(); - Iterator<String> it = this.inputValueNames.iterator(); - int i = 0; - while (it.hasNext()) { - String value = it.next(); - InputData data = this.inputData.get(value); - if (data != null - && this.inputValues.containsKey(data.getName())) { - int size = this.inputValues.get(data.getName()) - .usedInQueries(); - String type = this.inputValues.get(data.getName()) - .getType(); - String requestValue = data.getValue(); - if (type.equalsIgnoreCase("string")) { - requestValue = this - .prepareInputData4DBQuery(requestValue); - } else if (type.equalsIgnoreCase("date")) { - requestValue = this - .prepareInputData4DateDBQuery(requestValue); - } else if (type.equalsIgnoreCase("coordinate")){ - requestValue = this - .prepareInputData4RegionDBQuery(requestValue); - } - for (int j = 0; j < size; j++) { - list.add(requestValue); - } - } - } - String[] filterValues = list.toArray(new String[0]); + String[] filterValues = this.generateFilterValuesFromInputData(); Collection<Result> result = null; try { if (this.queryID != null) { @@ -415,6 +387,41 @@ } } } + + /** + * @return + */ + protected String[] generateFilterValuesFromInputData() { + List<String> list = new ArrayList<String>(); + Iterator<String> it = this.inputValueNames.iterator(); + while (it.hasNext()) { + String value = it.next(); + InputData data = this.inputData.get(value); + if (data != null + && this.inputValues.containsKey(data.getName())) { + int size = this.inputValues.get(data.getName()) + .usedInQueries(); + String type = this.inputValues.get(data.getName()) + .getType(); + String requestValue = data.getValue(); + if (type.equalsIgnoreCase("string")) { + requestValue = this + .prepareInputData4DBQuery(requestValue); + } else if (type.equalsIgnoreCase("date")) { + requestValue = this + .prepareInputData4DateDBQuery(requestValue); + } else if (type.equalsIgnoreCase("coordinate")){ + requestValue = this + .prepareInputData4RegionDBQuery(requestValue); + } + for (int j = 0; j < size; j++) { + list.add(requestValue); + } + } + } + String[] filterValues = list.toArray(new String[0]); + return filterValues; + } protected String prepareInputData4RegionDBQuery(String value){ return value;
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Nov 09 08:55:01 2009 +0000 @@ -7,8 +7,6 @@ import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; @@ -39,6 +37,9 @@ import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.ChartStyle; import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export.Profile; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.statistics.Statistic; import de.intevation.gnv.statistics.Statistics; @@ -51,11 +52,6 @@ import de.intevation.gnv.transition.describedata.KeyValueDescibeData; import de.intevation.gnv.transition.describedata.NamedCollection; import de.intevation.gnv.transition.exception.TransitionException; - -import de.intevation.gnv.exports.DefaultExport; -import de.intevation.gnv.exports.DefaultProfile; -import de.intevation.gnv.exports.Export.Profile; - import de.intevation.gnv.utils.ArtifactXMLUtilities; @@ -93,6 +89,19 @@ "GROUP2", "GROUP3" }; + + public static final String [] TIMESERIES_ODV_PROFILE_NAMES = { + "CRUISE", + "STATION", + "TYPE", + "BOTDEPTH", + "DEPTH", + "TIMEVALUE", + "DATAVALUE", + "PARAMETER", + "MEASUREMENTID", + "TIMESERIESID" + }; /** * Profile for exporting data to cvs @@ -112,7 +121,7 @@ */ public static final Profile TIMESERIES_ODV_PROFILE = new DefaultProfile( - TIMESERIES_CSV_PROFILE_NAMES, + TIMESERIES_ODV_PROFILE_NAMES, '\t', CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER, @@ -137,8 +146,8 @@ log.debug("TimeSeriesOutputTransition.out"); try { - this.advance(uuid, callMeta); - Collection<Result> chartResult = this.getChartResult(uuid); + this.advance(uuid, callMeta); // TODO This hsould only be done if it is nessessary + if (outputMode.equalsIgnoreCase("chart")) { log.debug("Chart will be generated."); int chartWidth = 600; @@ -170,10 +179,12 @@ chartStyle, chartLables, uuid); } else if (outputMode.equalsIgnoreCase("csv")) { log.debug("CSV-File will be generated."); + Collection<Result> chartResult = this.getChartResult(uuid); this.createCSV(outputStream, chartResult); } else if (outputMode.equalsIgnoreCase("statistics")) { log.debug("Statistics will be generated."); Statistics s = getStatisticsGenerator(); + Collection<Result> chartResult = this.getChartResult(uuid); Collection<Statistic> statistics = s .calculateStatistics(chartResult); Document doc = this.writeStatistics2XML(statistics); @@ -181,7 +192,9 @@ } else if (outputMode.equalsIgnoreCase("odv")) { //TimeSeriesExport export = new TimeSeriesExport(); //export.createODV(outputStream, chartResult); - createODV(outputStream, chartResult); + + Collection<Result> odvResult = this.getODVResult(uuid); + this.createODV(outputStream, odvResult); } } catch (IOException e) { log.error(e, e);
--- a/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Fri Nov 06 11:12:45 2009 +0000 +++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Mon Nov 09 08:55:01 2009 +0000 @@ -92,64 +92,56 @@ // Erster Schritt Document describeDocument = this.readDocument("src/test/ressources/timeseries/timeseries_describe.xml"); - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_01_feed.xml", - "src/test/ressources/timeseries/timeseries_step_01_advance.xml", describeDocument); - - // Zweiter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_02_feed.xml", - "src/test/ressources/timeseries/timeseries_step_02_advance.xml", describeDocument); - - // Dritter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_03_feed.xml", - "src/test/ressources/timeseries/timeseries_step_03_advance.xml", describeDocument); - - // Vierter Schritt - this - .doNextStep( + + int steps = 5; + + for (int i = 1; i <= steps; i++){ + + this.doNextStep( artifact, cc, - "src/test/ressources/timeseries/timeseries_step_04_feed.xml", - "src/test/ressources/timeseries/timeseries_step_04_advance.xml", describeDocument); - - // F�nfter Schritt - this - .doNextStep( - artifact, - cc, - "src/test/ressources/timeseries/timeseries_step_05_feed.xml", - "src/test/ressources/timeseries/timeseries_step_05_advance.xml", describeDocument); - + "src/test/ressources/timeseries/" + + "timeseries_step_0"+i+"_feed.xml", + "src/test/ressources/timeseries/" + + "timeseries_step_0"+i+"_advance.xml", + describeDocument); - Document outputData; - // F�nfter Schritt - outputData = artifact.describe(describeDocument,cc); + } + + Document outputData = artifact.describe(describeDocument,cc); FileOutputStream fos = null; + FileOutputStream fos2 = null; + FileOutputStream fos3 = null; + FileOutputStream fos4 = null; try { - fos = new FileOutputStream( - "src/test/results/timeseriesdiagramm" - + System.currentTimeMillis() + ".png"); - artifact - .feed( - this - .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), - cc); - artifact - .out( - this - .readDocument("src/test/ressources/timeseries/timeseries_step_06_out.xml"), - fos, cc); + fos = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".png"); + fos2 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".xml"); + fos3 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".csv"); + fos4 = new FileOutputStream("src/test/results/timeseries" + + System.currentTimeMillis() + + ".odv"); + + artifact.feed(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), + cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_chart.xml"), + fos, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml"), + fos2, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_csv.xml"), + fos3, cc); + artifact.out(this + .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_odv.xml"), + fos4, cc); } catch (Exception e) { log.error(e, e); fail();
--- a/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out.xml Fri Nov 06 11:12:45 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<art:action xmlns:art="http://www.intevation.de/2009/artifacts"> - <art:type name="out"/> - <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/> - <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/> - <art:out name="chart"> - <art:params> - <!-- out params copied from describe --> - </art:params> - </art:out> -</art:action> -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_chart.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<art:action xmlns:art="http://www.intevation.de/2009/artifacts"> + <art:type name="out"/> + <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/> + <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/> + <art:out name="chart"> + <art:params> + <!-- out params copied from describe --> + </art:params> + </art:out> +</art:action> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_csv.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<art:action xmlns:art="http://www.intevation.de/2009/artifacts"> + <art:type name="out"/> + <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/> + <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/> + <art:out name="csv"> + <art:params> + <!-- out params copied from describe --> + </art:params> + </art:out> +</art:action> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_odv.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<art:action xmlns:art="http://www.intevation.de/2009/artifacts"> + <art:type name="out"/> + <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/> + <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/> + <art:out name="odv"> + <art:params> + <!-- out params copied from describe --> + </art:params> + </art:out> +</art:action> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml Mon Nov 09 08:55:01 2009 +0000 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<art:action xmlns:art="http://www.intevation.de/2009/artifacts"> + <art:type name="out"/> + <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/> + <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/> + <art:out name="statistics"> + <art:params> + <!-- out params copied from describe --> + </art:params> + </art:out> +</art:action> +