# HG changeset patch # User Tim Englich # Date 1260261543 0 # Node ID e964a3d8f7bcbed93458880f9fac3dd8a8a17d0f # Parent e37930705daa180ed8af772af15fefe02313a167 Some Refactoring work done. Moved Transition to State gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/ChangeLog Tue Dec 08 08:39:03 2009 +0000 @@ -1,3 +1,39 @@ +2009-12-08 Tim Englich + + * doc/conf/products/*.xml: + Switched all Package and Classnames to the new Names. + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: + Switched Imports from de.intevation.gnv.transition to de.intevation.gnv.state + and renamed all Mebers and local Variables from *transition* to *state* + * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java: + Changed the Class for the loggeer from TimeseriesoutputTransition + to ArtifactXMLUtilities because it was wrong. + * src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java, + src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java, + src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java, + src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java, + src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java, + src/main/java/de/intevation/gnv/statistics/Statistics.java, + src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java, + src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java, + src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java, + src/main/java/de/intevation/gnv/exports/Export.java, + src/main/java/de/intevation/gnv/exports/DefaultExport.java, + src/main/java/de/intevation/gnv/exports/DefaultDataCollector.java, + src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java, + src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java, + src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChartFactory.java, + src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java, + src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java, + src/main/java/de/intevation/gnv/chart/HorizontalCrossSectionChartFactory.java, + src/main/java/de/intevation/gnv/chart/ChartFactory.java, + src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java: + Changed import from de.intevation.gnv.transition.* to de.intevation.gnv.state.* + according to refactoring Work in the Transitionsmodel. + * de.intevation.gnv.transition.* + Moved to de.intevation.gnv.state.* + and renamed all Mebers, local Variables, and Methodsignatures from *transition* to *state* + 2009-12-07 Ingo Weinzierl * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java: diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,103 +1,103 @@ - - + + area_filter areaid false true - - horizontalcrosssection_subarea - horizontalcrosssection_mesh_without_geom - + + horizontalcrosssection_subarea + horizontalcrosssection_mesh_without_geom + - + - + subarea_filter subareaid false - - horizontalcrosssection_mesh - + + horizontalcrosssection_mesh + - + - + verticalprofile_mesh meshid false - - horizontalcrosssection_meshpoint_depth - + + horizontalcrosssection_meshpoint_depth + - + - + verticalprofile_mesh_with_area meshid false - - horizontalcrosssection_meshpoint_depth - + + horizontalcrosssection_meshpoint_depth + - + - + horizontalcrosssection_meshpoint_depth depthid false - - horizontalcrosssection_meshpoint_parameter - + + horizontalcrosssection_meshpoint_parameter + - + - + verticalprofile_mesh_parameter parameterid false - - horizontalcrosssection_mesh_date - + + horizontalcrosssection_mesh_date + - + - + horizontalcrosssection_mesh_date dateid false - - horizontalcrosssection_mesh_calculate_results - + + horizontalcrosssection_mesh_calculate_results + @@ -105,9 +105,9 @@ - + - + horizontalcrosssection_mesh_data horizontalcrosssection_mesh_odv_data @@ -134,7 +134,7 @@ - + - + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,59 +1,59 @@ - - + + area_filter areaid false true - - horizontalprofile_instantaneouspoint_subarea - horizontalprofile_instantaneouspoint_vehicle_without_geom - + + horizontalprofile_instantaneouspoint_subarea + horizontalprofile_instantaneouspoint_vehicle_without_geom + - + - + subarea_filter subareaid false - - horizontalprofile_instantaneouspoint_vehicle - + + horizontalprofile_instantaneouspoint_vehicle + - + - + horizontalprofile_instantaneouspoint_vehicle_with_area vehicleid false - - horizontalprofile_instantaneouspoint_cruise_with_area - + + horizontalprofile_instantaneouspoint_cruise_with_area + - - + + horizontalprofile_instantaneouspoint_cruise_with_area cruiseid false - - horizontalprofile_instantaneouspoint_track_with_area - + + horizontalprofile_instantaneouspoint_track_with_area + @@ -61,85 +61,85 @@ - - + + horizontalprofile_instantaneouspoint_track_with_area trackid false - - horizontalprofile_instantaneouspoint_surveyinfo - Eisklimatologie + + horizontalprofile_instantaneouspoint_surveyinfo + Eisklimatologie - + - + horizontalprofile_instantaneouspoint_vehicle vehicleid false - - horizontalprofile_instantaneouspoint_cruise - + + horizontalprofile_instantaneouspoint_cruise + - + - + horizontalprofile_instantaneouspoint_cruise cruiseid false - - horizontalprofile_instantaneouspoint_track - + + horizontalprofile_instantaneouspoint_track + - - + + horizontalprofile_instantaneouspoint_track trackid false - - horizontalprofile_instantaneouspoint_surveyinfo - Eisklimatologie + + horizontalprofile_instantaneouspoint_surveyinfo + Eisklimatologie - - + + horizontalprofile_instantaneouspoint_surveyinfo surveyid false - - horizontalprofile_instantaneouspoint_parameter - + + horizontalprofile_instantaneouspoint_parameter + - - + + horizontalprofile_instantaneouspoint_parameter parameterid true - - horizontalprofile_instantaneouspoint_depth - + + horizontalprofile_instantaneouspoint_depth + @@ -147,14 +147,14 @@ - - + + horizontalprofile_instantaneouspoint_depth measurementid true - - horizontalprofile_instantaneouspoint_calculate_results - + + horizontalprofile_instantaneouspoint_calculate_results + @@ -163,8 +163,8 @@ - - + + horizontalprofile_instantaneouspoint_chart_data horizontalprofile_instantaneouspoint_odv_data @@ -193,6 +193,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,112 +1,112 @@ - - + + area_filter areaid false true - - horizontalprofile_mesh_subarea - horizontalprofile_mesh_without_geom - + + horizontalprofile_mesh_subarea + horizontalprofile_mesh_without_geom + - - + + subarea_filter subareaid false - - horizontalprofile_mesh - + + horizontalprofile_mesh + - + - + verticalprofile_mesh meshid false - - horizontalprofile_mesh_coordinate - + + horizontalprofile_mesh_coordinate + - + - + verticalprofile_mesh_with_area meshid false - - horizontalprofile_mesh_coordinate - + + horizontalprofile_mesh_coordinate + - + - + mesh_coordinate false - - horizontalprofile_mesh_point - + + horizontalprofile_mesh_point + - + - + verticalprofile_mesh_point mesh_point false - - horizontalprofile_mesh_axis - + + horizontalprofile_mesh_axis + - - + + axisid false - - horizontalprofile_meshpoint_parameter - + + horizontalprofile_meshpoint_parameter + - - + + verticalprofile_mesh_parameter parameterid true - - horizontalprofile_meshpoint_depth - + + horizontalprofile_meshpoint_depth + @@ -114,16 +114,16 @@ - + - + horizontalprofile_meshpoint_depth depthid true - - horizontalprofile_mesh_date - + + horizontalprofile_mesh_date + @@ -132,15 +132,15 @@ - + - + verticalprofile_mesh_date dateid true - - horizontalprofile_mesh_calculate_results - + + horizontalprofile_mesh_calculate_results + @@ -150,9 +150,9 @@ - + - + horizontalprofile_mesh_chart_data horizontalprofile_mesh_odv_data @@ -182,6 +182,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,115 +1,115 @@ - - + + area_filter areaid false true - - timeseries_mesh_subarea - timeseries_mesh_without_geom - + + timeseries_mesh_subarea + timeseries_mesh_without_geom + - - + + subarea_filter subareaid false - - timeseries_mesh - + + timeseries_mesh + - + - + verticalprofile_mesh meshid false - - timeseries_mesh_coordinate - + + timeseries_mesh_coordinate + - + - + verticalprofile_mesh_with_area meshid false - - timeseries_mesh_coordinate - + + timeseries_mesh_coordinate + - + - + mesh_coordinate false - - timeseries_meshpoint - + + timeseries_meshpoint + - + - + timeseries_meshpoint mesh_point false - - timeseries_meshpoint_depth - + + timeseries_meshpoint_depth + - + - + timeseries_meshpoint_depth depthid true - - timeseries_meshpoint_parameter - + + timeseries_meshpoint_parameter + - + - + timeseries_mesh_parameter parameterid true - - timeseries_meshpoint_interval - + + timeseries_meshpoint_interval + @@ -117,15 +117,15 @@ - + - + timeseries_mesh_interval timeinterval false - - timeseries_meshpoint_calculate_results - + + timeseries_meshpoint_calculate_results + @@ -135,9 +135,9 @@ - + - + timeseries_mesh_chart_data timeseries_mesh_odv_data @@ -167,7 +167,7 @@ - + - + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Dec 08 08:39:03 2009 +0000 @@ -7,25 +7,25 @@ * Statistics * CSV * ODV --> - + - + InputValues in the next state-Step from each state it + is only possible to move to those states which are Configured + in the rechablestates-Tag --> - - + area_filter - @@ -42,29 +42,29 @@ + using this state. --> false + this state. --> true - - - timeseries_subarea - timeseries_without_geom - + timeseries_subarea + timeseries_without_geom + @@ -72,15 +72,15 @@ - + - + subarea_filter subareaid false - - timeseries_timeseriespoint - + + timeseries_timeseriespoint + @@ -88,73 +88,73 @@ - + - + timeseries_timeseriespoint featureid false - - timeseries_parameter - + + timeseries_parameter + - + - + timeseries_timeseriespoint_with_area featureid false - - timeseries_parameter - + + timeseries_parameter + - + - + timeseries_parameter parameterid true - - timeseries_depth_height - + + timeseries_depth_height + - + - + timeseries_depth_height measurementid true - - timeseries_interval - + + timeseries_interval + - + - + timeseries_interval timeinterval false - - timeseries_calculate_results - + + timeseries_calculate_results + @@ -162,12 +162,12 @@ - + - - + timeseries_chart_data timeseries_odv_data @@ -193,7 +193,7 @@ - + - + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,112 +1,112 @@ - - + + area_filter areaid false true - - verticalcrosssection_mesh_subarea - verticalcrosssection_mesh_without_geom - + + verticalcrosssection_mesh_subarea + verticalcrosssection_mesh_without_geom + - - + + subarea_filter subareaid false - - verticalcrosssection_mesh - + + verticalcrosssection_mesh + - + - + verticalprofile_mesh meshid false - - verticalcrosssection_mesh_coordinate - + + verticalcrosssection_mesh_coordinate + - + - + verticalprofile_mesh_with_area meshid false - - verticalcrosssection_mesh_coordinate - + + verticalcrosssection_mesh_coordinate + - + - + mesh_coordinate false - - verticalcrosssection_mesh_point - + + verticalcrosssection_mesh_point + - + - + verticalprofile_mesh_point mesh_point false - - verticalcrosssection_mesh_axis - + + verticalcrosssection_mesh_axis + - - + + axisid false - - verticalcrosssection_mesh_parameter - + + verticalcrosssection_mesh_parameter + - - + + verticalprofile_mesh_parameter parameterid false - - verticalcrosssection_mesh_date - + + verticalcrosssection_mesh_date + @@ -114,16 +114,16 @@ - + - + verticalcrosssection_mesh_date dateid false - - verticalcrosssection_mesh_calculate_results - + + verticalcrosssection_mesh_calculate_results + @@ -132,9 +132,9 @@ - + - + verticalcrosssection_mesh_chart_data verticalcrosssection_mesh_odv_data @@ -161,6 +161,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,54 +1,54 @@ - - + + verticalprofile_instantaneouspoint_series seriesid false - - verticalprofile_instantaneouspoint_point - + + verticalprofile_instantaneouspoint_point + - - + + verticalprofile_instantaneouspoint_point instantaneouspoint_point false - - verticalprofile_instantaneouspoint_parameter - + + verticalprofile_instantaneouspoint_parameter + - - + + verticalprofile_instantaneouspoint_parameter parameterid true - - verticalprofile_instantaneouspoint_minmaxdepth - + + verticalprofile_instantaneouspoint_minmaxdepth + - - + + verticalprofile_instantaneouspoint_minmaxdepth depthrange true - - verticalprofile_instantaneouspoint_calculate_results - + + verticalprofile_instantaneouspoint_calculate_results + @@ -57,8 +57,8 @@ - - + + verticalprofile_instantaneouspoint_chart_data verticalprofile_instantaneouspoint_odv_data @@ -87,6 +87,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,115 +1,115 @@ - - + + area_filter areaid false true - - verticalprofile_mesh_subarea - verticalprofile_mesh_without_geom - + + verticalprofile_mesh_subarea + verticalprofile_mesh_without_geom + - - + + subarea_filter subareaid false - - verticalprofile_mesh - + + verticalprofile_mesh + - + - + verticalprofile_mesh meshid false - - verticalprofile_mesh_coordinate - + + verticalprofile_mesh_coordinate + - + - + verticalprofile_mesh_with_area meshid false - - verticalprofile_mesh_coordinate - + + verticalprofile_mesh_coordinate + - + - + mesh_coordinate false - - verticalprofile_mesh_point - + + verticalprofile_mesh_point + - + - + verticalprofile_mesh_point mesh_point false - - verticalprofile_mesh_mindepth - + + verticalprofile_mesh_mindepth + - + - + verticalprofile_mesh_mindepth mindepthid false - - verticalprofile_mesh_maxdepth - + + verticalprofile_mesh_maxdepth + - + - + verticalprofile_mesh_maxdepth maxdepthid false - - verticalprofile_meshpoint_parameter - + + verticalprofile_meshpoint_parameter + @@ -117,14 +117,14 @@ - - + + verticalprofile_mesh_parameter parameterid true - - verticalprofile_mesh_date - + + verticalprofile_mesh_date + @@ -133,15 +133,15 @@ - + - + verticalprofile_mesh_date dateid true - - verticalprofile_mesh_calculate_results - + + verticalprofile_mesh_calculate_results + @@ -151,9 +151,9 @@ - + - + verticalprofile_mesh_chart_data verticalprofile_mesh_odv_data @@ -183,6 +183,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Dec 08 08:39:03 2009 +0000 @@ -1,102 +1,102 @@ - - + + area_filter areaid false true - - verticalprofile_subarea - verticalprofile_without_geom - + + verticalprofile_subarea + verticalprofile_without_geom + - + - + subarea_filter subareaid false - - verticalprofile_timeseriespoint - + + verticalprofile_timeseriespoint + - + - + verticalprofile_point featureid false - - verticalprofile_parameter - + + verticalprofile_parameter + - + - + timeseries_timeseriespoint_with_area featureid false - - verticalprofile_parameter - + + verticalprofile_parameter + - + - + verticalprofile_parameter parameterid true - - verticalprofile_date - + + verticalprofile_date + - + - + verticalprofile_date dateid true - - verticalprofile_minmaxdepth - + + verticalprofile_minmaxdepth + - + - + verticalprofile_minmaxdepth depthrange true - - verticalprofile_calculate_results - + + verticalprofile_calculate_results + @@ -105,9 +105,9 @@ - + - + verticalprofile_chart_data verticalprofile_odv_data @@ -136,6 +136,6 @@ - - + + diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Dec 08 08:39:03 2009 +0000 @@ -26,14 +26,14 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.context.GNVArtifactContext; -import de.intevation.gnv.transition.DefaultInputData; -import de.intevation.gnv.transition.InputData; -import de.intevation.gnv.transition.InputValue; -import de.intevation.gnv.transition.OutputMode; -import de.intevation.gnv.transition.OutputTransition; -import de.intevation.gnv.transition.Transition; -import de.intevation.gnv.transition.TransitionFactory; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.DefaultInputData; +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.InputValue; +import de.intevation.gnv.state.OutputMode; +import de.intevation.gnv.state.OutputState; +import de.intevation.gnv.state.State; +import de.intevation.gnv.state.StateFactory; +import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.utils.ArtifactXMLUtilities; /** @@ -63,14 +63,14 @@ + "']"; /** - * The current Transition + * The current State */ - protected Transition current = null; + protected State current = null; /** - * The Transitions that can be used + * The States that can be used */ - protected Map transitions = null; + protected Map states = null; /** * The Name of the Artifact @@ -96,12 +96,12 @@ Document result = XMLUtils.newDocument(); try { if (this.current != null) { - String transitionName = this.readTransitionName(target); - log.debug("Transitionsname: " + transitionName); - if (this.current.isTransitionReachable(transitionName)) { + String stateName = this.readStateName(target); + log.debug("Statename: " + stateName); + if (this.current.isStateReachable(stateName)) { try { - Transition nextStep = this.transitions - .get(transitionName); + State nextStep = this.states + .get(stateName); // 1.Ergebnisse Berechnen this.current.advance(super.identifier, context.getMeta()); // 2. Ergebnisse Übergeben @@ -116,7 +116,7 @@ result = new ArtifactXMLUtilities() .createSuccessReport("Advance success", XMLUtils.newDocument()); - } catch (TransitionException e) { + } catch (StateException e) { log.error(e, e); result = new ArtifactXMLUtilities() .createExceptionReport(e @@ -130,7 +130,7 @@ msg, XMLUtils.newDocument()); } } else { - String msg = "Kein Transitionsschritt aktiviert."; + String msg = "Kein State aktiviert."; log.error(msg); result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); @@ -151,7 +151,7 @@ result = new ArtifactXMLUtilities() .createSuccessReport("Initialize success", XMLUtils.newDocument()); - } catch (TransitionException e) { + } catch (StateException e) { log.error(e,e); result = new ArtifactXMLUtilities().createExceptionReport(e .getLocalizedMessage(), XMLUtils.newDocument()); @@ -159,7 +159,7 @@ return result; } - protected String readTransitionName(Document document) { + protected String readStateName(Document document) { String returnValue = Config.getStringXPath(document, "action/target/@name"); return returnValue; @@ -205,12 +205,12 @@ XMLUtils.newDocument()); } } else { - String msg = "No Transition instantiated"; + String msg = "No State instantiated"; log.warn(msg); result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); } - } catch (TransitionException e) { + } catch (StateException e) { log.error(e, e); result = new ArtifactXMLUtilities().createExceptionReport(e .getLocalizedMessage(), XMLUtils.newDocument()); @@ -238,17 +238,17 @@ Document doc = gnvContext.getConfig(); Node artifactNode = this.getConfigurationFragment(doc); - NodeList transitionList = Config.getNodeSetXPath(artifactNode, - "transitions/transition"); - this.transitions = new HashMap(transitionList + NodeList stateList = Config.getNodeSetXPath(artifactNode, + "states/state"); + this.states = new HashMap(stateList .getLength()); - for (int i = 0; i < transitionList.getLength(); i++) { - Transition tmpTransition = TransitionFactory.getInstance() - .createTransition(transitionList.item(i)); - if (tmpTransition != null) { - this.transitions.put(tmpTransition.getID(), tmpTransition); + for (int i = 0; i < stateList.getLength(); i++) { + State tmpState = StateFactory.getInstance() + .createState(stateList.item(i)); + if (tmpState != null) { + this.states.put(tmpState.getID(), tmpState); if (this.current == null) { - this.current = tmpTransition; + this.current = tmpState; } } } @@ -308,7 +308,7 @@ Element stateNode = xmlUtilities.createArtifactElement(document, "reachable-states"); if (this.current != null) { - Iterator states = this.current.reachableTransitions() + Iterator states = this.current.reachableStates() .iterator(); while (states.hasNext()) { String value = states.next(); @@ -316,7 +316,7 @@ document, "state"); currentNode.setAttribute("name", value); log.debug("Reachable State: " + value); - currentNode.setAttribute("description", transitions.get(value) + currentNode.setAttribute("description", this.states.get(value) .getDescription()); stateNode.appendChild(currentNode); } @@ -368,8 +368,8 @@ log.debug("GNVArtifactBase.createOutputs"); Element outputsNode = xmlUtilities.createArtifactElement(document, "outputs"); - if (this.current instanceof OutputTransition) { - Collection outputModes = ((OutputTransition) this.current) + if (this.current instanceof OutputState) { + Collection outputModes = ((OutputState) this.current) .getOutputModes(); if (outputModes != null) { Iterator it = outputModes.iterator(); @@ -457,13 +457,13 @@ log.debug("TGNVArtifactBase.out"); try { - if (current != null && current instanceof OutputTransition) { - ((OutputTransition) current) + if (current != null && current instanceof OutputState) { + ((OutputState) current) .out(format, this.parseInputData( format, "/action/out/params/input"), outputStream, super.identifier, context.getMeta()); } - } catch (TransitionException e) { + } catch (StateException e) { log.error(e, e); throw new IOException(e.getMessage()); } diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java Tue Dec 08 08:39:03 2009 +0000 @@ -29,8 +29,8 @@ import de.intevation.gnv.artifacts.fis.product.DefaultProduct; import de.intevation.gnv.artifacts.fis.product.Product; import de.intevation.gnv.artifacts.ressource.RessourceFactory; -import de.intevation.gnv.transition.DefaultInputData; -import de.intevation.gnv.transition.InputData; +import de.intevation.gnv.state.DefaultInputData; +import de.intevation.gnv.state.InputData; import de.intevation.gnv.utils.ArtifactFactoryUtilities; import de.intevation.gnv.utils.ArtifactXMLUtilities; diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/DefaultProduct.java Tue Dec 08 08:39:03 2009 +0000 @@ -6,7 +6,7 @@ import java.util.Collection; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.gnv.transition.InputData; +import de.intevation.gnv.state.InputData; /** * @author Tim Englich @@ -14,6 +14,11 @@ */ public class DefaultProduct implements Product { + /** + * The UID of this Class + */ + private static final long serialVersionUID = 6473812725442092770L; + private String name = null; private Collection parameter = null; diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/product/Product.java Tue Dec 08 08:39:03 2009 +0000 @@ -7,7 +7,7 @@ import java.util.Collection; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.gnv.transition.InputData; +import de.intevation.gnv.state.InputData; /** * @author Tim Englich diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Tue Dec 08 08:39:03 2009 +0000 @@ -23,7 +23,7 @@ import org.jfree.data.general.Series; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -44,8 +44,8 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.timeseries.gap.TimeGap; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** * The class ChartFactory fulfills the following purposes: diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalCrossSectionChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalCrossSectionChartFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalCrossSectionChartFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -24,7 +24,7 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** * diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/HorizontalProfileChartFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -27,7 +27,7 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.utils.DistanceCalculator; /** diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Tue Dec 08 08:39:03 2009 +0000 @@ -23,7 +23,7 @@ import org.jfree.data.time.TimeSeriesCollection; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.timeseries.gap.TimeGap; diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChartFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalCrossSectionChartFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -24,7 +24,7 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** * diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChart.java Tue Dec 08 08:39:03 2009 +0000 @@ -9,7 +9,6 @@ import org.jfree.chart.ChartTheme; import org.jfree.chart.axis.Axis; -import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; @@ -17,7 +16,7 @@ import org.jfree.data.xy.XYSeriesCollection; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -41,7 +41,7 @@ import de.intevation.gnv.chart.exception.TechnicalChartException; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** * diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultDataCollector.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultDataCollector.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultDataCollector.java Tue Dec 08 08:39:03 2009 +0000 @@ -7,7 +7,7 @@ import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.exception.StateException; /** @@ -31,7 +31,7 @@ } public String[] getData(Result result) - throws TransitionException { + throws StateException { if (rd == null) init(result); diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultExport.java Tue Dec 08 08:39:03 2009 +0000 @@ -12,11 +12,9 @@ import java.io.OutputStreamWriter; import java.io.OutputStream; -import de.intevation.gnv.exports.Export.Profile; - import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.exception.StateException; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) @@ -38,7 +36,7 @@ Collection result, CSVWriter writer ) - throws TransitionException { + throws StateException { log.debug("create content for export."); Iterator it = result.iterator(); @@ -61,13 +59,13 @@ throws IOException, UnsupportedEncodingException, - TransitionException + StateException { if (result == null) { String msg = "No data given for generation of " + profile.getType() + " file."; log.error(msg); - throw new TransitionException(msg); + throw new StateException(msg); } CSVWriter writer = new CSVWriter( diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/exports/Export.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/Export.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/Export.java Tue Dec 08 08:39:03 2009 +0000 @@ -7,7 +7,7 @@ import java.io.UnsupportedEncodingException; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.exception.StateException; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) @@ -27,7 +27,7 @@ public interface DataCollector { String[] getData(Result result) - throws TransitionException; + throws StateException; } public void create( @@ -35,6 +35,6 @@ OutputStream outputStream, Collection result ) - throws IOException, UnsupportedEncodingException, TransitionException; + throws IOException, UnsupportedEncodingException, StateException; } diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ShapeDataCollector.java Tue Dec 08 08:39:03 2009 +0000 @@ -7,7 +7,7 @@ import com.vividsolutions.jts.geom.Point; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.exception.StateException; /** @@ -25,7 +25,7 @@ } public String[] getData(Result result) - throws TransitionException { + throws StateException { if (rd == null) init(result); @@ -50,7 +50,7 @@ } catch (ParseException pe) { log.error(pe, pe); - throw new TransitionException( + throw new StateException( "Error occured while parsing a Point from WKT."); } } diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/SimpleOdvDataCollector.java Tue Dec 08 08:39:03 2009 +0000 @@ -10,7 +10,7 @@ import com.vividsolutions.jts.geom.Point; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.state.exception.StateException; /** * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) @@ -31,7 +31,7 @@ } public String[] getData(Result result) - throws TransitionException + throws StateException { if (rd == null) init(result); @@ -62,12 +62,12 @@ } catch (ParseException pe) { log.error(pe, pe); - throw new TransitionException( + throw new StateException( "Error occured while parsing source data."); } catch (java.text.ParseException pe) { log.error(pe, pe); - throw new TransitionException( + throw new StateException( "Error occured while parsing source data."); } } diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/CoordinateSelectionState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,138 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.log4j.Logger; + +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.ParseException; +import com.vividsolutions.jts.io.WKTReader; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; +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.utils.InputValidator; +import de.intevation.gnv.utils.exception.ValidationException; + +/** + * @author Tim Englich + * + */ +public class CoordinateSelectionState extends StateBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(CoordinateSelectionState.class); + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 6318923553625195063L; + + /** + * Constructor + */ + public CoordinateSelectionState() { + super(); + } + + @Override + protected void purifyResult(Collection result, String uuid) { + log.debug("CoordinateSelectionState.purifyResult"); + Collection describeData = this.getDescibeData(uuid); + if (describeData == null) { + describeData = new ArrayList(); + } + NamedCollection keyValueDescibeData = this + .extractKVP(result, "FEATUREID", "SHAPE"); + describeData.add(keyValueDescibeData); + this.setDescibeData(uuid, describeData); + } + + @Override + protected String prepareInputData4RegionDBQuery(String value) { + log.debug("CoordinateSelectionState.prepareInputData4RegionDBQuery"); + double distance=0.; + String returnValue = null; + try { + Point center = new InputValidator().getPointValue(value); + String meshIDValue = super.inputData.get("meshid").getValue(); + int segments = 97; + int meshid = new Integer(meshIDValue); + if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. + distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte + }else if (meshid == 1 || meshid == 4){ + distance = 0.03; //Kuestenmodell 1 nm + }else if (meshid == 2 || meshid == 321){ + distance = 0.3; //SST Karten ca 20km + }else if (meshid == 641){ + distance = 0.3; //Eisdaten Klima + } + returnValue = center.buffer(distance,segments).toText(); + } catch (NumberFormatException e) { + log.error(e,e); + } catch (ValidationException e) { + log.error(e,e); + } + return returnValue; + + } + + /** + * @see de.intevation.gnv.state.StateBase#extractKVP(java.util.Collection, java.lang.String, java.lang.String) + */ + @Override + protected NamedCollection extractKVP( + Collection result, + String keyid, + String valueid) { + Iterator rit = result.iterator(); + NamedCollection keyValueDescibeData = new NamedArrayList( + this.dataName, result.size()); + keyValueDescibeData.setMultiSelect(this.dataMultiSelect); + String prevKey = null; + while (rit.hasNext()) { + Result resultValue = rit.next(); + String key = resultValue.getString(keyid); + if(prevKey == null || !prevKey.equals(key)){ // müssen wir so machen, da die sde kein select distinct auf layern zulässt. + String geomString = this.convert2DisplayCoordinate(resultValue.getString(valueid)); + String value = geomString; + if (resultValue.getResultDescriptor().getColumnIndex("VALUE") > 0){ + value = resultValue.getString("VALUE") + " - "+value; + } + + + keyValueDescibeData.add(new DefaultKeyValueDescribeData(key,value )); + } + prevKey = key; + } + return keyValueDescibeData; + } + + protected String convert2DisplayCoordinate(String wkt){ + String formattedCoordinate = null; + try { + Point p = (Point)new WKTReader().read(wkt); + double lat = p.getY(); + double lon =p.getX(); + String nord="N"; + String ost="E"; + if (lat <0 ){nord="S"; lat=-lat;} + if (lon <0 ){ost="W"; lon=-lon;} + formattedCoordinate = String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'", + (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); + } catch (ParseException e) { + log.error(e,e); + } + + return formattedCoordinate; + } +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,56 @@ +/** + * + */ +package de.intevation.gnv.state; + +/** + * @author Tim Englich + * + */ +public class DefaultInputData implements InputData { + + /** + * + */ + private static final long serialVersionUID = 4308041648698108066L; + private String name = null; + private String value = null; + + /** + * Constructor + */ + public DefaultInputData(String name, String value) { + this.name = name; + this.value = value; + } + + /** + * @see de.intevation.gnv.state.InputData#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.state.InputData#getValue() + */ + public String getValue() { + return this.value; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.name + "==> " + this.value; + } + + /** + * @see de.intevation.gnv.state.InputData#concartValue(java.lang.String) + */ + public void concartValue(String value) { + this.value = this.value + " , " + value; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputValue.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,78 @@ +/** + * + */ +package de.intevation.gnv.state; + +/** + * @author Tim Englich + * + */ +public class DefaultInputValue implements InputValue { + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -8518824299166180986L; + private String name = null; + private String type = null; + private boolean multiselect = false; + private int usedInQueries = 1; + private String defaultValue = "N/N"; + + public DefaultInputValue(String name, String type, String defaultValue, + boolean multiselect) { + this(name, type, multiselect, 1); + this.defaultValue = defaultValue; + + } + + /** + * Constructor + */ + public DefaultInputValue(String name, String type, boolean multiselect, + int usedInQueries) { + this.name = name; + this.type = type; + this.multiselect = multiselect; + this.usedInQueries = usedInQueries; + } + + /** + * @see de.intevation.gnv.state.InputValue#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.state.InputValue#getType() + */ + public String getType() { + return this.type; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "InputValue " + this.name + " ==> " + this.type + + "==> multiselect: " + this.multiselect; + } + + /** + * @see de.intevation.gnv.state.InputValue#isMultiselect() + */ + public boolean isMultiselect() { + return this.multiselect; + } + + public int usedInQueries() { + return this.usedInQueries; + } + + public String getDefaultValue() { + return this.defaultValue; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultOutputMode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultOutputMode.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,76 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.Collection; + +/** + * @author Tim Englich + * + */ +public class DefaultOutputMode implements OutputMode { + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -6459085460904827056L; + private String name = null; + private String description = null; + private String mimeType = null; + private Collection inputParameters = null; + + /** + * Constructor + * + * @param name + * @param description + * @param mimeType + */ + public DefaultOutputMode(String name, String description, String mimeType, + Collection inputParameters) { + super(); + this.name = name; + this.description = description; + this.mimeType = mimeType; + this.inputParameters = inputParameters; + } + + /** + * @see de.intevation.gnv.state.OutputMode#getDescription() + */ + public String getDescription() { + return this.description; + } + + /** + * @see de.intevation.gnv.state.OutputMode#getMimeType() + */ + public String getMimeType() { + return this.mimeType; + } + + /** + * @see de.intevation.gnv.state.OutputMode#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Name: " + this.name + " ; Description: " + this.description + + " ; Mime-Type: " + this.mimeType; + } + + /** + * @see de.intevation.gnv.state.OutputMode#getInputParameters() + */ + public Collection getInputParameters() { + return this.inputParameters; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,23 @@ +/** + * + */ +package de.intevation.gnv.state; + +/** + * @author Tim Englich + * + */ +public class DefaultState extends StateBase { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 8934030362091576766L; + + /** + * Constructor + */ + public DefaultState() { + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,19 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.Serializable; + +/** + * @author Tim Englich + * + */ +public interface InputData extends Serializable { + + public String getName(); + + public String getValue(); + + public void concartValue(String value); +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/InputValue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/InputValue.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,24 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.Serializable; + +/** + * @author Tim Englich + * + */ +public interface InputValue extends Serializable { + + public String getName(); + + public String getType(); + + public String getDefaultValue(); + + public boolean isMultiselect(); + + public int usedInQueries(); + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,62 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.ArrayList; +import java.util.Collection; + +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; + +/** + * @author Tim Englich + * + */ +public class MinMaxState extends StateBase { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = -3525903792105187408L; + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(MinMaxState.class); + + /** + * Constructor + */ + public MinMaxState() { + super(); + } + + /** + * @see de.intevation.gnv.state.StateBase#purifyResult(java.util.Collection, + * java.lang.String) + */ + @Override + protected void purifyResult(Collection result, String uuid) { + log.debug("MinMaxState.purifyResult"); + Collection describeData = this.getDescibeData(uuid); + if (describeData == null) { + describeData = new ArrayList(); + } + if (result != null && result.size() == 1) { + + Result value = result.iterator().next(); + DescribeData values = new DefaultMinMaxDescribeData(this.dataName, + value.getObject("MIN"), + value.getObject("MAX")); + log.debug(values.toString()); + describeData.add(values); + } else { + log.warn("Result cannot be handled as MinMax Resultset"); + } + this.setDescibeData(uuid, describeData); + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputMode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputMode.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,22 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.Serializable; +import java.util.Collection; + +/** + * @author Tim Englich + * + */ +public interface OutputMode extends Serializable { + + public String getName(); + + public String getDescription(); + + public String getMimeType(); + + public Collection getInputParameters(); +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,38 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.OutputStream; +import java.util.Collection; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.CallMeta; +import de.intevation.gnv.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public interface OutputState extends State { + + /** + * Returns the Rendered Result of an State. + * + * @param outputMode + * The Mode that should be produces (Chart, Map, ...) + * @return The Bytecode of the Result + * @throws StateException + */ + public void out(Document format, Collection inputData, + OutputStream outputStream, String uuid, CallMeta callMeta) + throws StateException; + + /** + * Delivers the provided OutputModes of an State + * + * @return the provided OutputModes of an State + */ + public Collection getOutputModes(); +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,273 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Locale; + + +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.artifacts.CallMeta; +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.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public abstract class OutputStateBase extends StateBase implements + OutputState { + + /** + * The UID of this Class + */ + private static final long serialVersionUID = -1718732895737303823L; + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(OutputStateBase.class); + + /** + * The different Outputmodes which are provided by an OutputState + */ + protected Collection outputModes = null; + + protected String queryODVID = null; + + /** + * Constructor + */ + public OutputStateBase() { + super(); + } + + /** + * @see de.intevation.gnv.state.OutputState#getOutputModes() + */ + public Collection getOutputModes() { + log.debug("OutputStateBase.getOutputModes"); + return this.outputModes; + } + + /** + * @see de.intevation.gnv.state.StateBase#setup(org.w3c.dom.Node) + */ + @Override + public void setup(Node configuration) { + log.debug("OutputStateBase.setup"); + super.setup(configuration); + + this.queryODVID = Config.getStringXPath(configuration,"queryID-odv"); + + NodeList outputModeList = Config.getNodeSetXPath(configuration, + "outputsModes/outputsMode"); + if (outputModeList != null) { + log.debug(outputModeList.getLength() + " were found."); + this.outputModes = new ArrayList(outputModeList + .getLength()); + for (int i = 0; i < outputModeList.getLength(); i++) { + Element currentNode = (Element)outputModeList.item(i); + String name = currentNode.getAttribute("name"); + String description =currentNode.getAttribute("description"); + String mimeType = currentNode.getAttribute("mime-type"); + NodeList inputValuesList = Config.getNodeSetXPath(currentNode, + "parameters/inputvalue"); + Collection inputParameters = null; + if (inputValuesList != null) { + inputParameters = new ArrayList(inputValuesList + .getLength()); + for (int j = 0; j < inputValuesList.getLength(); j++) { + Element currentInputValuesNode = (Element)inputValuesList.item(j); + String inputValueName = currentInputValuesNode.getAttribute("name"); + String inputValueType = currentInputValuesNode.getAttribute("type"); + String defaultValue =currentInputValuesNode.getAttribute("value"); + boolean isMultiselect = false; + InputValue inputValue = new DefaultInputValue( + inputValueName, inputValueType, defaultValue, + isMultiselect); + inputParameters.add(inputValue); + } + } + + OutputMode outputMode = new DefaultOutputMode(name, + description, mimeType, inputParameters); + log.debug(outputMode.toString()); + this.outputModes.add(outputMode); + + } + } + } + + /** + * @see de.intevation.gnv.state.StateBase#advance() + */ + @Override + public void advance(String uuid, CallMeta callMeta) + throws StateException { + } + + @Override + public void initialize(String uuid, CallMeta callMeta) + throws StateException { + } + + public void out(Document format, Collection inputData, + OutputStream outputStream, String uuid, CallMeta callMeta) + throws StateException { + } + + /** + * @see de.intevation.gnv.state.OutputState#out(java.lang.String, + * java.util.Collection, java.io.OutputStream) + */ + public void out(String outputMode, Collection inputData, + OutputStream outputStream) throws StateException { + } + + /** + * @return + */ + protected Collection getChartResult(String uuid) { + log.debug("OutputStateBase.getChartResult"); + Collection result = null; + if (CacheFactory.getInstance().isInitialized()) { + String key = uuid + super.getID(); + log.debug("Hash for Queryelements: " + key); + net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); + if (value != null) { + result = (Collection) (value.getObjectValue()); + }else{ + result = this.getData(this.queryID); + if (CacheFactory.getInstance().isInitialized()) { + CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); + } + + } + } + return result; + } + + protected Object getChartFromCache(String uuid) { + log.debug("Fetch chart [" + uuid + "] from cache"); + CacheFactory cacheFactory = CacheFactory.getInstance(); + if (cacheFactory.isInitialized()) { + String key = "chart_" + uuid + super.getID(); + net.sf.ehcache.Element object = cacheFactory.getCache().get(key); + + if (object != null) { + return object.getObjectValue(); + } + } + return null; + } + + protected Collection getODVResult(String uuid) { + log.debug("OutputStateBase.getODVResult"); + // TODO add Caching? I think it's not nessessary + Collection returnValue = null; + if (this.queryODVID != null){ + returnValue = this.getData(this.queryODVID); + }else{ + log.warn("No Query for ODV Data is defined."); + } + return returnValue; + } + + /** + * @param returnValue + * @return + */ + private Collection getData(String queryID) { + log.debug("OutputStateBase.getData"); + Collection returnValue = null; + try { + String[] filterValues = this.generateFilterValuesFromInputData(); + try { + QueryExecutor queryExecutor = QueryExecutorFactory + .getInstance() + .getQueryExecutor(); + returnValue = queryExecutor.executeQuery(queryID,filterValues); + } catch (RuntimeException e) { + log.error(e, e); + } + } catch (QueryException e) { + log.error(e, e); + } + return returnValue; + } + + protected void removeChartResult(String uuid) { + log.debug("OutputStateBase.getChartResult"); + if (CacheFactory.getInstance().isInitialized()) { + String key = uuid + super.getID(); + log.debug("Hash for Queryelements: " + key); + net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); + if (value != null) { + CacheFactory.getInstance().getCache().remove(key); + } + } + } + + protected void removeChart(String uuid) { + log.debug("OutputStateBase.removeChart from cache"); + + CacheFactory cacheFactory = CacheFactory.getInstance(); + if (cacheFactory.isInitialized()) { + String key = "chart_" + uuid + super.getID(); + net.sf.ehcache.Element object = cacheFactory.getCache().get(key); + if (object != null) + cacheFactory.getCache().remove(key); + } + } + + protected void purifyChart(Object chart, String uuid) { + log.debug("Prufify chart [" + uuid + "]"); + CacheFactory cacheFactory = CacheFactory.getInstance(); + if (cacheFactory.isInitialized()) { + String key = "chart_" + uuid + getID(); + cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart)); + } + } + + /** + * @see de.intevation.gnv.state.StateBase#putInputData(java.util.Collection, java.lang.String) + */ + @Override + public void putInputData(Collection inputData, + String uuid) + throws StateException { + log.debug("OutputStateBase.putInputData"); + this.removeChartResult(uuid); + this.removeChart(uuid); + super.putInputData(inputData, uuid); + } + + public void out(String outputMode, Collection inputData, + OutputStream outputStream, String uuid, CallMeta callMeta) + throws StateException { + } + + + protected String getMessage(Locale locale, String key, String value) { + return RessourceFactory.getInstance().getRessource( + locale, + key, + value + ); + } +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,59 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.DefaultSingleValueDescribeData; + +/** + * @author Tim Englich + * + */ +public class SingleInputState extends StateBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(SingleInputState.class); + + /** + * + */ + private static final long serialVersionUID = -6169497306324917318L; + + /** + * Constructor + */ + public SingleInputState() { + } + + /** + * @see de.intevation.gnv.state.StateBase#purifyResult(java.util.Collection, + * java.lang.String) + */ + @Override + protected void purifyResult(Collection result, String uuid) { + log.debug("SingleInputState.purifyResult"); + Collection describeData = this.getDescibeData(uuid); + if (describeData == null) { + describeData = new ArrayList(); + } + String value = null; + if (result != null && result.size() == 1) { + Result tmpItem = result.iterator().next(); + value = tmpItem.getObject("MAX").toString(); + } else { + value = ""; + } + + describeData.add(new DefaultSingleValueDescribeData(this.dataName,value)); + this.setDescibeData(uuid, describeData); + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,51 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.io.Serializable; +import java.util.Collection; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import de.intevation.artifacts.CallMeta; +import de.intevation.gnv.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public interface State extends Serializable { + + public void setup(Node configuration); + + public Collection reachableStates(); + + public boolean isStateReachable(String stateID); + + public String getID(); + + public String getDescription(); + + public void describe(Document document, Node rootNode, + CallMeta callMeta, String uuid); + + public void setParent(State state); + + public State getParent(); + + public Collection getRequiredInputValues(); + + public void putInputData(Collection inputData, + String uuid)throws StateException; + + public Collection getInputData() throws StateException; + + public void advance(String uuid, CallMeta callMeta) + throws StateException; + public void initialize(String uuid, CallMeta callMeta) + throws StateException; + + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,788 @@ +/** + * + */ +package de.intevation.gnv.state; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +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.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.ArtifactXMLUtilities; +import de.intevation.gnv.utils.InputValidator; + +/** + * @author Tim Englich + * + */ +public abstract class StateBase implements State { + + + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 2411169179001645426L; + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + + private final static String MINVALUEFIELDNAME = "minvalue"; + private final static String MAXVALUEFIELDNAME = "maxvalue"; + + private final static String NODATASELECTIONKEY = "n/n"; + + private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; + + private String id = null; + + private String description = null; + + protected String dataName = null; + + protected boolean dataMultiSelect = false; + + protected boolean dataNoSelect = false; + + protected String queryID = null; + + private Collection reachableStates = null; + + protected Collection inputValueNames = null; + + private Map inputValues = null; + + private State parent = null; + + protected Map inputData = null; + + + /** + * Constructor + */ + public StateBase() { + super(); + } + + /** + * @see de.intevation.gnv.state.State#getID() + */ + public String getID() { + return this.id; + } + + /** + * @see de.intevation.gnv.state.State#getDescription() + */ + public String getDescription() { + return this.description; + } + + /** + * @see de.intevation.gnv.state.State#reachableStates() + */ + public Collection reachableStates() { + + if (this.couldAlternativeStateUsed()){ + Iterator it = this.reachableStates.iterator(); + String transValue = null; + while (it.hasNext()){ + transValue = it.next(); + } + Collection returnValue = new ArrayList(1); + returnValue.add(transValue); + return returnValue; + }else{ + return this.reachableStates; + } + + } + + /** + * @return + */ + private boolean couldAlternativeStateUsed() { + // TODO das muss hier noch etwas freier gestaltet werden. + String key = this.dataName; + boolean returnValue=this.inputData != null && + this.inputData.containsKey(key) && + this.inputData.get(key).getValue(). + equals(NODATASELECTIONKEY); + return returnValue; + } + + /** + * @see de.intevation.gnv.state.State#getRequiredInputValues() + */ + public Collection getRequiredInputValues() { + return this.inputValues.values(); + } + + /** + * @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"); + + log.info("State-ID = " + this.id); + NodeList nodes = Config.getNodeSetXPath(configuration, + "reachablestates/state"); + this.reachableStates = new ArrayList(nodes.getLength()); + for (int i = 0; i < nodes.getLength(); i++) { + String reachableState = nodes.item(i).getTextContent(); + log.info("ReachableState ==> " + reachableState); + this.reachableStates.add(reachableState); + + } + + NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, + "inputvalues/inputvalue"); + this.inputValues = new HashMap(inputValuesNodes + .getLength()); + this.inputValueNames = new ArrayList(inputValuesNodes + .getLength()); + for (int i = 0; i < inputValuesNodes.getLength(); i++) { + Element inputValueNode = (Element)inputValuesNodes.item(i); + String usedinQueryValue = inputValueNode.getAttribute("usedinquery"); + int usedinQuery = 1; + if (usedinQueryValue != null) { + try { + usedinQuery = Integer.parseInt(usedinQueryValue); + } catch (NumberFormatException e) { + log + .warn("Used in Query Value cannot be transformed into a Number"); + } + } + InputValue inputValue = new DefaultInputValue(inputValueNode.getAttribute("name"), + inputValueNode.getAttribute("type"), + Boolean.parseBoolean(inputValueNode. + getAttribute("multiselect")), usedinQuery); + log.debug(inputValue.toString()); + this.inputValues.put(inputValue.getName(), inputValue); + this.inputValueNames.add(inputValue.getName()); + } + + this.queryID = Config.getStringXPath(configuration, "queryID"); + log.info("QueryID ==> " + this.queryID); + + this.dataName = Config.getStringXPath(configuration, "dataname"); + + String dataMultiSelectValue = Config.getStringXPath(configuration, + "data-multiselect"); + if (dataMultiSelectValue != null) { + this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); + } + + String dataNoSelectValue =Config.getStringXPath(configuration, + "data-noselect"); + if (dataNoSelectValue != null) { + this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue); + } + + } + + /** + * @see de.intevation.gnv.state.State#getParent() + */ + public State getParent() { + return this.parent; + } + + /** + * @see de.intevation.gnv.state.State#setParent(de.intevation.gnv.state.State) + */ + public void setParent(State state) { + 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"); + 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.setSelection(tmpItem, uuid); + 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"); + } + } + + private String getInputValue4ID(Collection inputData, String inputName){ + Iterator it = inputData.iterator(); + while (it.hasNext()) { + InputData tmpItem = it.next(); + if (tmpItem.getName().equals(inputName)){ + return tmpItem.getValue(); + } + } + return null; + } + + private void setSelection(InputData inputData, String uuid) { + log.debug("StateBase.setSelection"); + + Object o = this.getDescribeData(inputData.getName(),uuid); + if (o != null) { + if (o instanceof Collection) { + Collection values = (Collection) o; + + String value = inputData.getValue(); + String[] selectedValues = value.split(","); + Set selectedItems = new HashSet( + selectedValues.length); + for (int i = 0; i < selectedValues.length; i++) { + selectedItems.add(selectedValues[i].trim()); + } + // Selektion umsetzen + Iterator it = values.iterator(); + while (it.hasNext()) { + KeyValueDescibeData data = it.next(); + String key = "" + data.getKey(); + boolean selected = selectedItems.contains(key); + data.setSelected(selected); + } + } else if (o instanceof MinMaxDescribeData) { + MinMaxDescribeData data = (MinMaxDescribeData) o; + if (inputData.getName().equals(MINVALUEFIELDNAME)) { + data.setMinValue(inputData.getValue()); + } + if (inputData.getName().equals(MAXVALUEFIELDNAME)) { + data.setMaxValue(inputData.getValue()); + } + } else if (o instanceof SingleValueDescribeData) { + ((SingleValueDescribeData)o).setValue(inputData.getValue()); + } + } + } + + private Object getDescribeData(String name, String uuid) { + log.debug("StateBase.getDescribeData"); + Collection descibeData = this.getDescibeData(uuid); + if (descibeData != null) { + Iterator it = descibeData.iterator(); + while (it.hasNext()) { + Object o = it.next(); + if (o instanceof NamedCollection) { + if (name.equals(((NamedCollection) o).getName())) { + return o; + } + } else if (o instanceof MinMaxDescribeData) { + if (name.equals(((MinMaxDescribeData) o).getMinName())) { + return o; + } + if (name.equals(((MinMaxDescribeData) o).getMaxName())) { + return o; + } + }else if (o instanceof SingleValueDescribeData) { + if (name.equals(((SingleValueDescribeData)o).getName())){ + return o; + } + } + } + } + return null; + + } + + /** + * @see de.intevation.gnv.state.State#isStateReachable(java.lang.String) + */ + public boolean isStateReachable(String stateID) { + log.debug("StateBase.isStateReachable"); + boolean returnValue = false; + Iterator states = reachableStates.iterator(); + while (states.hasNext()) { + if (states.next().equals(stateID)) { + log.debug("State " + stateID + " wird unterstützt."); + returnValue = true; + break; + } + } + return returnValue; + } + + /** + * @see de.intevation.gnv.state.State#advance(java.lang.String, + * de.intevation.artifacts.CallMeta) + */ + public void advance(String uuid, CallMeta callMeta) + throws StateException { + } + + public void initialize(String uuid, CallMeta callMeta) + 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) { + log.error(e, e); + throw new StateException(e); + } + } + + /** + * @return + */ + protected String[] generateFilterValuesFromInputData() { + List list = new ArrayList(); + Iterator 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; + } + + private String prepareInputData4DateDBQuery(String value) { + log.debug("StateBase.prepareInputData4DateDBQuery"); + if (value != null) { + String[] values = value.split(","); + String newValue = ""; + for (int i = 0; i < values.length; i++) { + if (newValue.length() > 0) { + newValue = newValue + " , "; + } + // TODO JUST HACK FIND A BETTER RESOLUTION + newValue = newValue + "to_date('" + values[i].trim() + + "', 'YYYY.MM.DD HH24:MI:SS')"; + } + return newValue; + } + + return value; + } + + private String prepareInputData4DBQuery(String value) { + log.debug("StateBase.prepareInputData4DBQuery"); + if (value != null) { + String[] values = value.split(","); + String newValue = ""; + for (int i = 0; i < values.length; i++) { + if (newValue.length() > 0) { + newValue = newValue + " , "; + } + newValue = newValue + "'" + values[i].trim() + "'"; + } + return newValue; + } + + return value; + + } + + /** + * @param result + */ + protected void purifyResult(Collection result, String uuid) { + log.debug("StateBase.purifyResult"); + Collection describeData = this.getDescibeData(uuid); + if (describeData == null) { + describeData = new ArrayList(); + } + NamedCollection keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); + describeData.add(keyValueDescibeData); + this.setDescibeData(uuid, describeData); + } + + /** + * @param result + * @return + */ + protected NamedCollection extractKVP(Collection result, + String keyid, + 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, + "No Selection")); + } + boolean initialized = false; + int keyPos= 0; + int valuePos = 1; + String previousKey = null; + while (rit.hasNext()) { + Result resultValue = rit.next(); + if (!initialized){ + keyPos = resultValue.getResultDescriptor().getColumnIndex(keyid); + valuePos = resultValue.getResultDescriptor().getColumnIndex(valueid); + if (valuePos < 0){ + valuePos = 1; + } + initialized = true; + } + String tmpKey = resultValue.getString(keyPos); + // TODO: HACK da die ARCSDE kein DISTINCT auf räumlichen Anfragen unterstützt. + if (previousKey == null || !tmpKey.equals(previousKey)){ + previousKey = tmpKey; + keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos))); + } + } + return keyValueDescibeData; + } + + /** + * @see de.intevation.gnv.state.State#describe(org.w3c.dom.Document, + * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, + * java.lang.String) + */ + public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { + log.debug("StateBase.describe"); + Collection descibeData = this.getDescibeData(uuid); + if (descibeData != null) { + ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); + Iterator it = descibeData.iterator(); + Node staticNode = xmlutilities.createArtifactElement(document, + "static"); + Node dynamic = xmlutilities.createArtifactElement(document, + "dynamic"); + rootNode.appendChild(staticNode); + rootNode.appendChild(dynamic); + while (it.hasNext()) { + + Object o = it.next(); + if (o instanceof Collection) { + String name = null; + boolean multiselect = false; + if (o instanceof NamedCollection) { + NamedCollection nc = ((NamedCollection) o); + name = nc.getName(); + multiselect = nc.isMultiSelect(); + } else { + Object[] names = this.inputValueNames.toArray(); + name = names[names.length - 1].toString(); + } + + Element selectNode = xmlutilities.createXFormElement( + document, multiselect ? "select" : "select1"); + selectNode.setAttribute("ref", name); + + Element lableNode = xmlutilities.createXFormElement( + document, "label"); + lableNode.setTextContent(RessourceFactory.getInstance() + .getRessource(callMeta.getLanguages(), name, name)); + Element choiceNode = xmlutilities.createXFormElement( + document, "choices"); + + Collection values = (Collection) o; + Iterator resultIt = values.iterator(); + while (resultIt.hasNext()) { + KeyValueDescibeData result = resultIt.next(); + Element itemNode = xmlutilities.createXFormElement( + document, "item"); + + if (result.isSelected()) { + itemNode.setAttribute("selected", "true"); + } + + Element choiceLableNode = xmlutilities + .createXFormElement(document, "label"); + choiceLableNode.setTextContent(result.getValue()); + itemNode.appendChild(choiceLableNode); + + Element choicValueNode = xmlutilities + .createXFormElement(document, "value"); + choicValueNode.setTextContent("" + result.getKey()); + itemNode.appendChild(choicValueNode); + choiceNode.appendChild(itemNode); + } + selectNode.appendChild(lableNode); + selectNode.appendChild(choiceNode); + + if (!it.hasNext() && this.dataName != null) { + dynamic.appendChild(selectNode); + } else { + staticNode.appendChild(selectNode); + } + + } else if (o instanceof MinMaxDescribeData) { + MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; + Object min = minMaxDescibeData.getMinValue(); + Object max = minMaxDescibeData.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 = xmlutilities.createXFormElement( + document, "group"); + groupNode.setAttribute("ref", minMaxDescibeData.getName()); + Element groupNodeLableNode = xmlutilities + .createXFormElement(document, "label"); + groupNodeLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), + minMaxDescibeData.getName(), + minMaxDescibeData.getName())); + groupNode.appendChild(groupNodeLableNode); + + Element inputMinNode = xmlutilities.createXFormElement( + document, "input"); + inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); + Element inputMinLableNode = xmlutilities + .createXFormElement(document, "label"); + inputMinLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MINVALUEFIELDNAME, + MINVALUEFIELDNAME)); + inputMinNode.appendChild(inputMinLableNode); + + Element inputMinValueNode = xmlutilities + .createXFormElement(document, "value"); + inputMinValueNode.setTextContent(min.toString()); + inputMinNode.appendChild(inputMinValueNode); + + Element inputMaxNode = xmlutilities.createXFormElement( + document, "input"); + inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); + Element inputMaxLableNode = xmlutilities + .createXFormElement(document, "label"); + inputMaxLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MAXVALUEFIELDNAME, + MAXVALUEFIELDNAME)); + inputMaxNode.appendChild(inputMaxLableNode); + + Element inputMaxValueNode = xmlutilities + .createXFormElement(document, "value"); + inputMaxValueNode.setTextContent(max.toString()); + inputMaxNode.appendChild(inputMaxValueNode); + + groupNode.appendChild(inputMinNode); + groupNode.appendChild(inputMaxNode); + + if (!it.hasNext() && this.dataName != null) { + dynamic.appendChild(groupNode); + } else { + staticNode.appendChild(groupNode); + } + } else if (o instanceof SingleValueDescribeData) { + + SingleValueDescribeData svdb = (SingleValueDescribeData) o; + + Element groupNode = xmlutilities.createXFormElement( + document, "group"); + groupNode.setAttribute("ref", svdb.getName()); + Element groupNodeLableNode = xmlutilities + .createXFormElement(document, "label"); + groupNodeLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), + svdb.getName(), + svdb.getName())); + groupNode.appendChild(groupNodeLableNode); + + Element inputNode = xmlutilities.createXFormElement( + document, "input"); + inputNode.setAttribute("ref", svdb.getName()); + + Element inputLableNode = xmlutilities.createXFormElement( + document, "label"); + inputLableNode.setTextContent(""); + inputNode.appendChild(inputLableNode); + + Element inputValueNode = xmlutilities.createXFormElement( + document, "value"); + inputValueNode.setTextContent(svdb.getValue()); + inputNode.appendChild(inputValueNode); + + groupNode.appendChild(inputNode); + if (!it.hasNext() && this.dataName != null) { + dynamic.appendChild(groupNode); + } else { + staticNode.appendChild(groupNode); + } + } + + } + } + } + + /** + * @see de.intevation.gnv.state.State#getDescibeData() + */ + protected Collection 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 (Collection) (value.getObjectValue()); + } + } + return null; + } + + /** + * @see de.intevation.gnv.state.State#getDescibeData() + */ + protected void setDescibeData(String uuid, Collection 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)); + } + } + + /** + * @see de.intevation.gnv.state.State#getInputData() + */ + public Collection getInputData() throws StateException { + return this.inputData != null ? this.inputData.values() : null; + } +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/StateFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateFactory.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,55 @@ +/** + * + */ +package de.intevation.gnv.state; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; + +import de.intevation.gnv.artifacts.GNVArtifactBase; + +/** + * @author Tim Englich + * + */ +public class StateFactory { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + + private static StateFactory instance = null; + + /** + * Constructor + */ + public StateFactory() { + super(); + } + + public static StateFactory getInstance() { + if (instance == null) { + instance = new StateFactory(); + } + return instance; + } + + public State createState(Node configuration) { + log.debug("StateFactory.createState"); + State state = null; + try { + String classname = ((org.w3c.dom.Element)configuration).getAttribute("state"); + state = (State) (Class.forName(classname).newInstance()); + state.setup(configuration); + } catch (InstantiationException e) { + log.error(e, e); + } catch (IllegalAccessException e) { + log.error(e, e); + } catch (ClassNotFoundException e) { + log.error(e, e); + } + return state; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultKeyValueDescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,57 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +/** + * @author Tim Englich + * + */ +public class DefaultKeyValueDescribeData implements KeyValueDescibeData { + + /** + * + */ + private static final long serialVersionUID = -924469415242703108L; + + private String key; + + private String value = null; + + private boolean selected = false; + + public DefaultKeyValueDescribeData(String key, String value) { + super(); + this.key = key; + this.value = value; + } + + /** + * @see de.intevation.gnv.state.describedata.KeyValueDescibeData#getKey() + */ + public String getKey() { + return this.key; + } + + /** + * @see de.intevation.gnv.state.describedata.KeyValueDescibeData#getValue() + */ + public String getValue() { + return this.value; + } + + /** + * @see de.intevation.gnv.state.describedata.KeyValueDescibeData#isSelected() + */ + public boolean isSelected() { + return this.selected; + } + + /** + * @see de.intevation.gnv.state.describedata.KeyValueDescibeData#setSelected(boolean) + */ + public void setSelected(boolean selected) { + this.selected = selected; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultMinMaxDescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,92 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +/** + * @author Tim Englich + * + */ +public class DefaultMinMaxDescribeData implements MinMaxDescribeData { + + /** + * + */ + private static final long serialVersionUID = -2917176219029052295L; + + private Object minValue = null; + + private Object maxValue = null; + + private String name = null; + + private final static String minName = "minvalue"; + + private final static String maxName = "maxvalue"; + + /** + * Constructor + */ + public DefaultMinMaxDescribeData(String name, Object minValue, Object maxValue) { + super(); + this.name = name; + this.minValue = minValue; + this.maxValue = maxValue; + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#getMaxValue() + */ + public Object getMaxValue() { + return this.maxValue; + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#getMinValue() + */ + public Object getMinValue() { + return this.minValue; + } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "MIN: " + this.minValue.toString() + " ; MAX: " + + this.maxValue.toString(); + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#getName() + */ + public String getMinName() { + return minName; + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#getMaxName() + */ + public String getMaxName() { + return maxName; + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#setMaxValue(java.lang.Object) + */ + public void setMaxValue(Object maxValue) { + this.maxValue = maxValue; + } + + /** + * @see de.intevation.gnv.state.describedata.MinMaxDescribeData#setMinValue(java.lang.Object) + */ + public void setMinValue(Object minValue) { + this.minValue = minValue; + } + + public String getName() { + return this.name; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DefaultSingleValueDescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,51 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +/** + * @author Tim Englich + * + */ +public class DefaultSingleValueDescribeData implements SingleValueDescribeData { + + /** + * + */ + private static final long serialVersionUID = 3580176842483316917L; + + private String name = null; + + private String value = null; + + /** + * Constructor + * + * @param name + * @param value + */ + public DefaultSingleValueDescribeData(String name, String value) { + super(); + this.name = name; + this.value = value; + } + + /** + * @see de.intevation.gnv.state.describedata.SingleValueDescribeData#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.state.describedata.SingleValueDescribeData#getValue() + */ + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/DescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,16 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +import java.io.Serializable; + +/** + * Markerinterface + * + * @author Tim Englich + * + */ +public interface DescribeData extends Serializable { + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/KeyValueDescibeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,22 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +import java.io.Serializable; + +/** + * @author Tim Englich + * + */ +public interface KeyValueDescibeData extends Serializable { + + public String getKey(); + + public String getValue(); + + public boolean isSelected(); + + public void setSelected(boolean selected); + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/MinMaxDescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,26 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +/** + * @author Tim Englich + * + */ +public interface MinMaxDescribeData extends DescribeData { + + public Object getMinValue(); + + public Object getMaxValue(); + + public void setMinValue(Object minValue); + + public void setMaxValue(Object maxValue); + + public String getName(); + + public String getMinName(); + + public String getMaxName(); + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/NamedArrayList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/NamedArrayList.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,71 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Tim Englich + * + */ +public class NamedArrayList extends ArrayList implements + NamedCollection { + /** + * + */ + private static final long serialVersionUID = 8172229594749676354L; + + private String name = null; + + private boolean multiSelect = false; + + /** + * Constructor + */ + public NamedArrayList(String name) { + this.name = name; + } + + /** + * Constructor + * + * @param initialCapacity + */ + public NamedArrayList(String name, int initialCapacity) { + super(initialCapacity); + this.name = name; + } + + /** + * Constructor + * + * @param c + */ + public NamedArrayList(String name, Collection c) { + super(c); + this.name = name; + } + + /** + * @see de.intevation.gnv.state.describedata.NamedCollection#getName() + */ + public String getName() { + return this.name; + } + + /** + * @see de.intevation.gnv.state.describedata.NamedCollection#isMultiSelect() + */ + public boolean isMultiSelect() { + return multiSelect; + } + + /** + * @see de.intevation.gnv.state.describedata.NamedCollection#setMultiSelect(boolean) + */ + public void setMultiSelect(boolean multiSelect) { + this.multiSelect = multiSelect; + } +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/NamedCollection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/NamedCollection.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,19 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +import java.util.Collection; + +/** + * @author Tim Englich + * + */ +public interface NamedCollection extends Collection { + + public String getName(); + + public boolean isMultiSelect(); + + public void setMultiSelect(boolean multiSelect); +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/describedata/SingleValueDescribeData.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,17 @@ +/** + * + */ +package de.intevation.gnv.state.describedata; + +/** + * @author Tim Englich + * + */ +public interface SingleValueDescribeData extends DescribeData { + + public String getName(); + + public String getValue(); + + public void setValue(String value); +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/exception/StateException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/exception/StateException.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,52 @@ +/** + * + */ +package de.intevation.gnv.state.exception; + +/** + * @author Tim Englich + * + */ +public class StateException extends Exception { + + /** + * The UID of the Class + */ + private static final long serialVersionUID = -1635921702746050244L; + + /** + * Constructor + */ + public StateException() { + super(); + } + + /** + * Constructor + * + * @param message + */ + public StateException(String message) { + super(message); + } + + /** + * Constructor + * + * @param cause + */ + public StateException(Throwable cause) { + super(cause); + } + + /** + * Constructor + * + * @param message + * @param cause + */ + public StateException(String message, Throwable cause) { + super(message, cause); + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,285 @@ +/** + * + */ +package de.intevation.gnv.state.profile.horizontal; + +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.WKTReader; +import com.vividsolutions.jts.io.ParseException; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.HorizontalProfileChart; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; +import de.intevation.gnv.statistics.HorizontalProfileStatistics; +import de.intevation.gnv.statistics.Statistics; + +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.ShapeDataCollector; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export.Profile; + +/** + * @author Tim Englich + * + */ +public class HorizontalProfileOutputState extends + TimeSeriesOutputState { + /** + * The UID of this class + */ + private static final long serialVersionUID = 4401516087492028840L; + + private static Logger log = Logger + .getLogger(HorizontalProfileOutputState.class); + + public static final String DATE_FORMAT = "yyyy.MM.dd HH:mm:ss"; + + public static final String [] CHART_TITLE_META = { + "CRUISE", + "DEPTH", + "SHAPE" + }; + + + public static final String [] CHART_TITLE_META_RESSOURCES = { + "cruiseid", + "depth", + "coordinate" + }; + + public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { + "SHAPE", + "YORDINATE", + "GROUP1", + "GROUP2", + "GROUP3" + }; + + public static final Profile TIMESERIES_CSV_PROFILE = + new DefaultProfile( + null, + ',', + '"', + '"', + "CSV", + "ISO-8859-1"); + + /** + * Constructor + */ + public HorizontalProfileOutputState() { + super(); + super.domainLable = "Distance [km]"; + } + + + @Override + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get horizontalprofile chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + chart = new HorizontalProfileChart( + chartLables, + createStyle(), + parameters, + measurements, + dates, + result, + null, + locale, + linesVisible, + shapesVisible + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + + return chart; + } + + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return new HorizontalProfileStatistics(); + } + + @Override + protected void createCSV(OutputStream outputStream, + Collection chartResult) + throws UnsupportedEncodingException, + IOException, + StateException { + + log.debug("createCSV for HorizontalProfileOutputState."); + DefaultExport export = new DefaultExport( + new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES)); + + export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); + } + + + protected String createChartTitle(Locale locale, String uuid) { + String fisName = getFisName(locale); + log.debug("created title for horizontal profile chart: " + fisName); + + return fisName; + } + + + protected String createChartSubtitle(Locale locale, String uuid) { + log.debug("create chart subtitle."); + String subtitle = createTimePeriod(locale, uuid); + + // ODV results contain meta information about cruise, station and so on + Collection results = getODVResult(uuid); + if (results != null) { + Iterator iter = results.iterator(); + Result result = iter.hasNext() ? (Result) iter.next() : null; + + subtitle += subtitle.length() != 0 ? "\n" : ""; + subtitle += createMetaChartSubtitle(locale, result); + } + + return subtitle; + } + + + protected String createMetaChartSubtitle(Locale locale, Result result) { + log.debug("Fetch meta information and put it into subtitle."); + if (result == null) + return ""; + + StringBuilder meta = new StringBuilder(); + WKTReader wktReader = new WKTReader(); + + + for (int i = 0; i < CHART_TITLE_META.length; i++) { + String qry = CHART_TITLE_META[i]; + + if (qry.equals("SHAPE")) { + try { + Point p = (Point) wktReader.read(result.getString(qry)); + + meta.append(getMessage(locale,"coordinate","coordinate")); + meta.append(": "); + + log.debug( + "Add " + qry + " to meta information of subtitle: " + + p.toString() + ); + meta.append(p.getX() + ", " + p.getY()); + } + catch (ParseException pe) { + log.warn("Error while parsing point.", pe); + } + } + else { + log.debug( + "Add " + qry + " to meta information of subtitle: " + + result.getString(qry) + ); + meta.append(getMessage( + locale, + CHART_TITLE_META_RESSOURCES[i], + CHART_TITLE_META_RESSOURCES[i] + )); + meta.append(": "); + meta.append(result.getString(qry)); + } + + if (i != CHART_TITLE_META.length-1) + meta.append("\n"); + } + + log.debug("Meta title for chart: " + meta.toString()); + return meta.toString(); + } + + + protected String createTimePeriod(Locale locale, String uuid) { + log.debug("create time period for chart subtitle."); + String subTitle = null; + Date startDate = null; + Date endDate = null; + + Collection dates = getDates(uuid); + if (dates == null) { + log.debug("No time period for subtitle."); + return ""; + } + + SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); + KeyValueDescibeData data = null; + + Iterator iter = dates.iterator(); + while (iter.hasNext()) { + try { + data = (KeyValueDescibeData)iter.next(); + + if (!data.isSelected()) + continue; + + Date current = format.parse(data.getValue()); + long time = current.getTime(); + + if (startDate == null) { + startDate = current; + endDate = current; + } + else if (time < startDate.getTime()) { + startDate = current; + } + else if (time > endDate.getTime()) { + endDate = current; + } + } + catch (java.text.ParseException pe) { + log.warn("Error while parsing date: " + data.getValue(), pe); + } + } + + subTitle = format.format(startDate) + " - " + format.format(endDate); + log.debug("created title for horizontal profile chart: " + subTitle); + + return subTitle; + } +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/NorthSouthEastWestState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,67 @@ +/** + * + */ +package de.intevation.gnv.state.profile.horizontal; + +import java.util.ArrayList; +import java.util.Collection; + +import de.intevation.artifacts.CallMeta; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.StateBase; +import de.intevation.gnv.state.describedata.DefaultKeyValueDescribeData; +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.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public class NorthSouthEastWestState extends StateBase { + + + /** + * The UID of this Class + */ + private static final long serialVersionUID = -7989531326553305293L; + + /** + * Constructor + */ + public NorthSouthEastWestState() { + } + + /** + * @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, CallMeta callMeta) + throws StateException { + Collection describeData = this.getDescibeData(uuid); + if (describeData == null) { + describeData = new ArrayList(); + } + NamedCollection keyValueDescibeData = new NamedArrayList( + this.dataName, 2); + keyValueDescibeData.setMultiSelect(super.dataMultiSelect); + keyValueDescibeData.add(new DefaultKeyValueDescribeData("IPOSITION", + RessourceFactory.getInstance().getRessource( + callMeta.getLanguages(), "iposition", "iposition"))); + keyValueDescibeData.add(new DefaultKeyValueDescribeData("JPOSITION", + RessourceFactory.getInstance().getRessource( + callMeta.getLanguages(), "jposition", "jposition"))); + describeData.add(keyValueDescibeData); + } + + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,143 @@ +/** + * + */ +package de.intevation.gnv.state.profile.horizontalcrosssection; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import au.com.bytecode.opencsv.CSVWriter; +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; +import de.intevation.gnv.statistics.Statistics; + +/** + * @author Tim Englich + * + */ +public class HorizontalCrossSectionMeshOutputState + extends TimeSeriesOutputState { + + private static Logger log = Logger + .getLogger(HorizontalCrossSectionMeshOutputState.class); + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 3233620652465061860L; + + /** + * Constructor + */ + public HorizontalCrossSectionMeshOutputState() { + super(); + super.domainLable = "Latitude [m]"; + } + + @Override + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get horizontalcrosssection chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + + log.warn("This sort of chart is not implemented yet."); + /* TODO Implement a special chart for this sort of charts. + chart = new HorizontalProfileChart( + chartLables, + chartTheme, + parameters, + measurements, + result, + dates, + locale + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + */ + + return chart; + } + + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return null; //Statistiken werden nicht für diesen Out-Typ unterstützt. + } + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, + * java.util.Collection) + */ + @Override + protected void createCSV(OutputStream outputStream, + Collection chartResult) + throws UnsupportedEncodingException, + IOException, + StateException { + if (chartResult != null) { + try { + CSVWriter writer = new CSVWriter(new OutputStreamWriter( + outputStream, "ISO-8859-1"), ','); + // USE THIS ENCODING BECAUSE OF + // PROBLEMS WITH EXCEL AND UTF-8 + Iterator it = chartResult.iterator(); + while (it.hasNext()) { + Result result = it.next(); + int i = 0; + String[] entries = new String[5]; + entries[i++] = result.getString("SHAPE"); + entries[i++] = result.getString("YORDINATE"); + entries[i++] = result.getString("IPOSITION"); + entries[i++] = result.getString("JPOSITION"); + entries[i++] = result.getString("KPOSITION"); + writer.writeNext(entries); + } + writer.close(); + } catch (Exception e) { + log.error(e,e); + throw new StateException( + "Exception occured while parsing an Point from WKT."); + } + } else { + log.error("No Data given for generating an CSV-File."); + throw new StateException( + "No Data given for generating an CSV-File."); + } + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,100 @@ +/** + * + */ +package de.intevation.gnv.state.profile.vertical; + +import java.util.Collection; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.VerticalProfileChart; +import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; +import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.statistics.VerticalProfileStatistics; + +/** + * @author Tim Englich + * + */ +public class VerticalProfileOutputState extends TimeSeriesOutputState { + /** + * The UID of this class + */ + private static final long serialVersionUID = 4401516087492028840L; + + private static Logger log = Logger + .getLogger(TimeSeriesOutputState.class); + + /** + * Constructor + */ + public VerticalProfileOutputState() { + super(); + super.domainLable = "Depth [m]"; + } + + + @Override + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get verticalprofile chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + chart = new VerticalProfileChart( + chartLables, + this.createStyle(), + parameters, + measurements, + dates, + result, + null, + locale, + linesVisible, + shapesVisible + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + + return chart; + } + + + protected String createChartSubtitle(Locale locale, String uuid) { + return getSelectedFeatureName(uuid); + } + + + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return new VerticalProfileStatistics(); + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,177 @@ +/** + * + */ +package de.intevation.gnv.state.profile.verticalcrosssection; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import org.apache.log4j.Logger; + +import au.com.bytecode.opencsv.CSVWriter; + +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.ParseException; +import com.vividsolutions.jts.io.WKTReader; + +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.ChartStyle; +import de.intevation.gnv.chart.VerticalCrossSectionChartFactory; +import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; +import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.statistics.VerticalProfileStatistics; + +/** + * @author Tim Englich + * + */ +public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { + + private static Logger log = Logger + .getLogger(VerticalCrossSectionOutputState.class); + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 3233620652465061860L; + + /** + * Constructor + */ + public VerticalCrossSectionOutputState() { + super(); + super.domainLable = "Depth [m]"; + } + + @Override + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get verticalcrosssection chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + + log.warn("This sort of chart is not implemented yet."); + /* TODO Implement a special chart for this sort of charts. + chart = new VerticalProfileChart( + chartLables, + chartTheme, + parameters, + measurements, + result, + dates, + locale + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + */ + + return chart; + } + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createChart(java.io.OutputStream, + * java.util.Collection, java.util.Collection, java.lang.String, + * de.intevation.gnv.chart.ChartStyle, + * de.intevation.gnv.chart.ChartLabels) + */ + /* + @Override + protected void createChart(OutputStream outputStream, + Collection parameters, + Collection measurements, + Collection dates, + ChartStyle chartStyle, ChartLabels chartLables, + String uuid) throws IOException, + TechnicalChartException { + new VerticalCrossSectionChartFactory().createProfileChart(chartLables, + chartStyle, parameters, measurements, dates, outputStream, this + .getChartResult(uuid)); + } + */ + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() + */ + @Override + protected Statistics getStatisticsGenerator() { + return new VerticalProfileStatistics(); + } + + /** + * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) + */ + @Override + protected void createCSV(OutputStream outputStream, + Collection chartResult) + throws UnsupportedEncodingException, + IOException, + StateException { + if (chartResult != null) { + try { + CSVWriter writer = new CSVWriter(new OutputStreamWriter( + outputStream, "ISO-8859-1"), ','); + // USE THIS ENCODING BECAUSE OF + // PROBLEMS WITH EXCEL AND UTF-8 + Iterator it = chartResult.iterator(); + WKTReader wktReader = new WKTReader(); + while (it.hasNext()) { + Result result = it.next(); + int i = 0; + String[] entries = new String[9]; + Point p = (Point)wktReader.read(result.getString("SHAPE")); + entries[i++] = ""+p.getX(); + entries[i++] = ""+p.getY(); + entries[i++] = result.getString("Z"); + entries[i++] = result.getString("YORDINATE"); + entries[i++] = result.getString("GROUP1"); + entries[i++] = result.getString("GROUP2"); + entries[i++] = result.getString("IPOSITION"); + entries[i++] = result.getString("JPOSITION"); + entries[i++] = result.getString("KPOSITION"); + writer.writeNext(entries); + } + writer.close(); + } catch (ParseException e) { + log.error(e,e); + throw new StateException( + "Exception occured while parsing an Point from WKT."); + } + } else { + log.error("No Data given for generating an CSV-File."); + throw new StateException( + "No Data given for generating an CSV-File."); + } + } + +} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java Tue Dec 08 08:39:03 2009 +0000 @@ -0,0 +1,835 @@ +/** + * + */ +package de.intevation.gnv.state.timeseries; + +import java.io.IOException; +import java.io.File; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Vector; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +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 org.jfree.chart.ChartTheme; + +import au.com.bytecode.opencsv.CSVWriter; +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; +import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.PreferredLocale; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.chart.Chart; +import de.intevation.gnv.chart.ChartLabels; +import de.intevation.gnv.chart.TimeSeriesChart; +import de.intevation.gnv.chart.XMLChartTheme; +import de.intevation.gnv.chart.exception.TechnicalChartException; +import de.intevation.gnv.exports.ChartExportHelper; +import de.intevation.gnv.exports.DefaultExport; +import de.intevation.gnv.exports.DefaultDataCollector; +import de.intevation.gnv.exports.SimpleOdvDataCollector; +import de.intevation.gnv.exports.DefaultProfile; +import de.intevation.gnv.exports.Export.Profile; +import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.OutputStateBase; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.NamedCollection; +import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.statistics.Statistic; +import de.intevation.gnv.statistics.StatisticSet; +import de.intevation.gnv.statistics.Statistics; +import de.intevation.gnv.statistics.TimeseriesStatistics; +import de.intevation.gnv.statistics.exception.StatisticsException; +import de.intevation.gnv.timeseries.gap.DefaultTimeGap; +import de.intevation.gnv.timeseries.gap.TimeGap; +import de.intevation.gnv.utils.ArtifactXMLUtilities; + + +/** + * @author Tim Englich + * + */ +public class TimeSeriesOutputState extends OutputStateBase { + + protected static final boolean CACHE_CHART = + Boolean.parseBoolean(System.getProperty("cache.chart", "false")); + + protected static final boolean PDF_FORMAT_LANDSCAPE = + Boolean.parseBoolean(System.getProperty("export.pdf.landscape","true")); + + protected static final String[] IMG_EXPORT_FORMAT = { + "PNG", "JPEG", "GIF" + }; + + /** + * The UID of this Class + */ + private static final long serialVersionUID = 4178407570503098858L; + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger + .getLogger(TimeSeriesOutputState.class); + + private static List timeGapDefinitions = null; + + protected String domainLable = "Zeit [UTC]"; + + protected String featureValuesName = "featureid"; + protected String parameterValuesName = "parameterid"; + protected String measuremenValueName = "measurementid"; + protected String dateValueName = "dateid"; + + public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { + "XORDINATE", + "YORDINATE", + "GROUP1", + "GROUP2", + "GROUP3" + }; + + public static final String [] TIMESERIES_ODV_PROFILE_NAMES = { + "CRUISE", + "STATION", + "TYPE", + "SHAPE", + "BOTDEPTH", + "DEPTH", + "TIMEVALUE", + "DATAVALUE", + "PARAMETER" + }; + + + public static final String [] ODV_COLUMN_HEADER = { + "Cruise", + "Station", + "Type", + "Longitude [deegrees_east]", + "Latitude [deegrees_north]", + "Bot. Depth [m]", + "Depth [m]", + "Date/Time", + "Value", + "Parameterid" + }; + + /** + * Profile for exporting data to cvs + */ + public static final Profile TIMESERIES_CSV_PROFILE = + new DefaultProfile( + null, + ',', + '"', + '"', + "CSV", + "ISO-8859-1"); + + /** + * Profile for exporting data to odv + * TODO Change TIMESERIES_PROFILE_NAMES, which belong to CSV exports + */ + public static final Profile TIMESERIES_ODV_PROFILE = + new DefaultProfile( + ODV_COLUMN_HEADER, + '\t', + CSVWriter.NO_QUOTE_CHARACTER, + CSVWriter.NO_ESCAPE_CHARACTER, + "ODV", + "ISO-8859-1"); + + /** + * Constructor + */ + public TimeSeriesOutputState() { + super(); + } + + /** + * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, + * java.util.Collection, java.io.OutputStream, java.lang.String, + * de.intevation.artifacts.CallMeta) + */ + public void out( + Document format, + Collection inputData, + OutputStream outputStream, + String uuid, + CallMeta callMeta + ) throws StateException + { + log.debug("TimeSeriesOutputTransition.out"); + + String outputMode = Config.getStringXPath( + format, + "action/out/@name" + ); + String mimeType = Config.getStringXPath( + format, + "action/out/mime-type/@value" + ); + + try { + if (outputMode.equalsIgnoreCase("chart")) { + log.debug("Chart will be generated."); + int chartWidth = 600; + int chartHeight = 400; + try { + if (inputData != null) { + Iterator it = inputData.iterator(); + while (it.hasNext()) { + InputData ip = it.next(); + if (ip.getName().equalsIgnoreCase("width")) { + chartWidth = Integer.parseInt(ip.getValue()); + } else if (ip.getName().equalsIgnoreCase("height")) { + chartHeight = Integer.parseInt(ip.getValue()); + } + } + } + } catch (NumberFormatException e) { + log.error(e, e); + throw new StateException(e); + } + + PreferredLocale[] locales = callMeta.getLanguages(); + Locale[] serverLocales = + RessourceFactory.getInstance().getLocales(); + Locale locale = + callMeta.getPreferredLocale(serverLocales); + + log.debug( + "Best locale - regarding intersection of server and " + + "browser locales - is " + locale.toString() + ); + + Collection parameters = this.getCleanedParameters(uuid); + Collection measurements = this.getMeasurements(uuid); + Collection dates = this.getDates(uuid); + + ChartLabels chartLables = new ChartLabels( + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable + ); + + String exportFormat = getExportFormat(mimeType); + + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + + this.createChart( + outputStream, + parameters, + measurements, + dates, + chartLables, + uuid, + exportFormat, + locale, + chartWidth, + chartHeight, + linesVisible, + shapesVisible + ); + } + else if (outputMode.equalsIgnoreCase("pdf")) { + log.debug("Output mode == pdf"); + + Locale[] serverLocales = + RessourceFactory.getInstance().getLocales(); + Locale locale = + callMeta.getPreferredLocale(serverLocales); + + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + + log.debug( + "Best locale - regarding intersection of server and " + + "browser locales - is " + locale.toString() + ); + + createPDF( + outputStream, + getCleanedParameters(uuid), + getMeasurements(uuid), + getDates(uuid), + new ChartLabels( + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable), + uuid, + "A4", + true, + locale, + linesVisible, + shapesVisible + ); + } + else if (outputMode.equalsIgnoreCase("svg")) { + log.debug("Output mode == svg"); + int width = 600; + int height = 400; + + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + + Locale[] serverLocales = + RessourceFactory.getInstance().getLocales(); + Locale locale = + callMeta.getPreferredLocale(serverLocales); + + log.debug( + "Best locale - regarding intersection of server and " + + "browser locales - is " + locale.toString() + ); + + createSVG( + outputStream, + getCleanedParameters(uuid), + getMeasurements(uuid), + getDates(uuid), + new ChartLabels( + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable + ), + uuid, + locale, + width, + height, + linesVisible, + shapesVisible + ); + } + else if (outputMode.equalsIgnoreCase("csv")) { + log.debug("CSV-File will be generated."); + Collection chartResult = this.getChartResult(uuid); + this.createCSV(outputStream, chartResult); + } else if (outputMode.equalsIgnoreCase("statistics")) { + log.debug("Statistics will be generated."); + Statistics s = getStatisticsGenerator(); + Collection chartResult = this.getChartResult(uuid); + Collection parameters = + this.getParameters(uuid); + Collection measurements = + this.getMeasurements(uuid); + Collection dates = + this.getDates(uuid); + Collection statistics = + s.calculateStatistics(chartResult, + parameters, + measurements, + dates); + Document doc = this.writeStatistics2XML(statistics); + this.writeDocument2OutputStream(doc, outputStream); + } else if (outputMode.equalsIgnoreCase("odv")) { + + Collection odvResult = this.getODVResult(uuid); + this.createODV(outputStream, odvResult); + } + } catch (IOException e) { + log.error(e, e); + throw new StateException(e); + } catch (TechnicalChartException e) { + log.error(e, e); + throw new StateException(e); + } catch (StatisticsException e) { + log.error(e, e); + throw new StateException(e); + } + } + + + protected String getExportFormat(String mime) { + for(int i = 0; i < IMG_EXPORT_FORMAT.length; i++) { + if (mime.trim().toUpperCase().indexOf(IMG_EXPORT_FORMAT[i]) > 0) + return IMG_EXPORT_FORMAT[i]; + } + + // no format found relating to mimeType, default export as PNG + return IMG_EXPORT_FORMAT[0]; + } + + + protected Collection getCleanedParameters(Collection parameters) { + Iterator iter = parameters.iterator(); + Collection parameter = new Vector(parameters); + while (iter.hasNext()) { + KeyValueDescibeData data = (KeyValueDescibeData)iter.next(); + if (!data.isSelected()) + parameter.remove(data); + } + + return parameter; + } + + + protected Collection getCleanedParameters(String uuid) { + return getCleanedParameters(getParameters(uuid)); + } + + + /** + * @param outputStream + * @param chartResult + * @throws UnsupportedEncodingException + * @throws IOException + * @throws StateException + */ + protected void createCSV(OutputStream outputStream, + Collection chartResult) + throws UnsupportedEncodingException, + IOException, + StateException { + DefaultExport export = new DefaultExport(new DefaultDataCollector( + TIMESERIES_CSV_PROFILE_NAMES)); + + export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); + } + + /** + * TODO Result is not used at the moment. Change result with correct data. + */ + protected void createODV(OutputStream outputStream, Collection result) + throws IOException, StateException { + + DefaultExport export = new DefaultExport(new SimpleOdvDataCollector( + TIMESERIES_ODV_PROFILE_NAMES)); + + if (result == null) + log.error("#################### RESULT == NULL #################"); + export.create(TIMESERIES_ODV_PROFILE, outputStream, result); + } + + /** + * @return + */ + protected Statistics getStatisticsGenerator() { + Statistics s = new TimeseriesStatistics(); + return s; + } + + protected void writeDocument2OutputStream(Document document, OutputStream os) { + + try { + TransformerFactory transformerFactory = TransformerFactory + .newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(document); + StreamResult result = new StreamResult(os); + transformer.transform(source, result); + } catch (TransformerConfigurationException e) { + log.error(e, e); + } catch (TransformerFactoryConfigurationError e) { + log.error(e, e); + } catch (TransformerException e) { + log.error(e, e); + } + } + + protected Document writeStatistics2XML( Collection statistic) { + ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); + Document doc = XMLUtils.newDocument(); + if (statistic != null) { + Node statisticResults = xmlUtilities.createArtifactElement(doc, + "statistics"); + doc.appendChild(statisticResults); + Iterator it = statistic.iterator(); + while (it.hasNext()) { + StatisticSet set = it.next(); + Element setElement = xmlUtilities.createArtifactElement(doc, + "statistic"); + setElement.setAttribute("name", set.getName()); + + Iterator sit = set.getStatistics().iterator(); + while (sit.hasNext()){ + Statistic s = sit.next(); + Element result = xmlUtilities.createArtifactElement(doc, + "statistic-value"); + result.setAttribute("name", s.getKey()); + result.setAttribute("value", s.getStringValue()); + setElement.appendChild(result); + } + statisticResults.appendChild(setElement); + } + + } + return doc; + } + + + protected String getSelectedFeatureName(String uuid) { + Collection values = getCollection(featureValuesName, uuid); + + if (values != null) { + Iterator it = values.iterator(); + + while (it.hasNext()) { + KeyValueDescibeData data = (KeyValueDescibeData) it.next(); + + if (data.isSelected()) { + return data.getValue(); + } + } + } + return null; + } + + + /** + * @param outputStream + * @param parameters + * @param measurements + * @param timeSeriesName + * @param chartStyle + * @param chartLables + * @throws IOException + * @throws TechnicalChartException + */ + protected void createChart( + OutputStream outputStream, + Collection parameters, + Collection measurements, + Collection dates, + ChartLabels chartLables, + String uuid, + String exportFormat, + Locale locale, + int width, + int height, + boolean linesVisible, + boolean shapesVisible + ) + throws IOException, TechnicalChartException + { + log.debug("Create chart."); + Chart chart = getChart( + chartLables, + parameters, + measurements, + dates, + getChartResult(uuid), + locale, // Locale + uuid, + linesVisible, + shapesVisible + ); + + if (chart == null) { + log.error("Could not initialize chart."); + return; + } + + log.debug( + "export chart as " + exportFormat + + " in " + width + "x" + height + ); + + ChartExportHelper.exportImage( + outputStream, + chart.generateChart(), + exportFormat, + width, + height + ); + } + + + protected void createPDF( + OutputStream outputStream, + Collection parameters, + Collection measurements, + Collection dates, + ChartLabels chartLables, + String uuid, + String exportFormat, + boolean landscape, + Locale locale, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = getChart( + chartLables, + parameters, + measurements, + dates, + getChartResult(uuid), + locale, + uuid, + linesVisible, + shapesVisible + ); + + if (chart == null) { + log.error("Could not initialize chart."); + return; + } + + ChartExportHelper.exportPDF( + outputStream, + chart.generateChart(), + "A4", + PDF_FORMAT_LANDSCAPE, + 50F, 50F, 50F, 50F + ); + + try { + OutputStream toFile = new FileOutputStream("/vol1/home/iweinzierl/tmp/test.svg"); + ChartExportHelper.exportSVG( + toFile, + chart.generateChart(), + null, + 600, 400 + ); + toFile.flush(); + toFile.close(); + } + catch(Exception e) { log.debug("ERROR WHLILE TEST."); } + } + + + protected void createSVG( + OutputStream outputStream, + Collection parameters, + Collection measurements, + Collection dates, + ChartLabels chartLables, + String uuid, + Locale locale, + int width, + int height, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = getChart( + chartLables, + parameters, + measurements, + dates, + getChartResult(uuid), + locale, + uuid, + linesVisible, + shapesVisible + ); + + if (chart == null) { + log.error("Could not initialize chart."); + return; + } + + ChartExportHelper.exportSVG( + outputStream, + chart.generateChart(), + null, + 600, 400 + ); + + log.debug("svg export finished."); + } + + + protected Chart getChart( + ChartLabels chartLables, + Collection parameters, + Collection measurements, + Collection dates, + Collection result, + Locale locale, + String uuid, + boolean linesVisible, + boolean shapesVisible + ) { + Chart chart = null; + + if (CACHE_CHART) { + log.info("Try to get timeseries chart from cache."); + chart = (Chart) getChartFromCache(uuid); + } + + if (chart != null) + return chart; + + log.info("Chart not in cache yet."); + chart = new TimeSeriesChart( + chartLables, + createStyle(), + parameters, + measurements, + dates, + result, + timeGapDefinitions, + locale, + linesVisible, + shapesVisible + ); + chart.generateChart(); + + if (CACHE_CHART) { + log.info("Put chart into cache."); + purifyChart(chart, uuid); + } + + return chart; + } + + protected ChartTheme createStyle() { + XMLChartTheme theme = null; + + Document template = Config.getChartTemplate(); + String name = Config.getStringXPath( + template, + "theme/name/@value" + ); + + theme = new XMLChartTheme(name); + theme.applyXMLConfiguration(template); + + return theme; + } + + + protected String createChartTitle(Locale locale, String uuid) { + return getFisName(locale); + + } + + + protected String createChartSubtitle(Locale locale, String uuid) { + return getSelectedFeatureName(uuid); + } + + + protected String getFisName(Locale locale) { + String returnValue = ""; + InputData input = inputData.get("fisname"); + + if (input != null) { + String value = input.getValue(); + + returnValue = RessourceFactory.getInstance().getRessource( + locale, + value, + value + ); + } + return returnValue; + } + + + protected Collection getParameters(String uuid) { + return this.getCollection(parameterValuesName, uuid); + } + + protected Collection getMeasurements(String uuid) { + return this.getCollection(measuremenValueName, uuid); + } + protected Collection getDates(String uuid) { + return this.getCollection(dateValueName,uuid); + } + + @Override + public void setup(Node configuration) { + super.setup(configuration); + String featureNameValue = Config.getStringXPath(configuration, + "value-names/value-name[@name='feature']/@value"); + if (featureNameValue != null) { + this.featureValuesName = featureNameValue; + } + String parameterNameValue = Config.getStringXPath(configuration, + "value-names/value-name[@name='parameter']/@value"); + if (parameterNameValue != null) { + this.parameterValuesName = parameterNameValue; + } + String measurementNameValue = Config.getStringXPath(configuration, + "value-names/value-name[@name='measurement']/@value"); + if (measurementNameValue != null) { + this.measuremenValueName = measurementNameValue; + } + + String dateNameValue = Config.getStringXPath(configuration, + "value-names/value-name[@name='date']/@value"); + if (dateNameValue != null) { + this.dateValueName = dateNameValue; + } + if (timeGapDefinitions == null){ + Element gapDefinition = (Element)Config.getNodeXPath(configuration, + "time-gap-definition"); + synchronized (this.getClass()) { + if (gapDefinition != null){ + String link = gapDefinition.getAttribute("xlink:href"); + if (link != null ){ + String absolutFileName = Config.replaceConfigDir(link); + gapDefinition = (Element)new ArtifactXMLUtilities(). + readConfiguration(absolutFileName); + } + + NodeList gapDefinitions = Config.getNodeSetXPath(gapDefinition, + "/time-gaps/time-gap"); + if (gapDefinition != null){ + timeGapDefinitions = new ArrayList(gapDefinitions. + getLength()); + for (int i = 0; i < gapDefinitions.getLength(); i++){ + Element gapNode = (Element)gapDefinitions.item(i); + String unit = gapNode.getAttribute("unit"); + int key = Integer.parseInt(gapNode.getAttribute("key")); + int value = Integer.parseInt(gapNode.getAttribute("gap")); + log.info("Add new Timegap: "+key+" "+value+" "+ unit); + timeGapDefinitions.add(new DefaultTimeGap(unit, + key, + value)); + } + } + + } + } + } + } + + /** + * @param collectionName + * @return + */ + protected Collection getCollection( + String collectionName, + String uuid) { + Iterator it = this.getDescibeData(uuid).iterator(); + while (it.hasNext()) { + + Object o = it.next(); + + if (o instanceof NamedCollection) { + NamedCollection nc = (NamedCollection) o; + if (nc.getName().equals(collectionName)) { + return nc; + } + } + } + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/HorizontalProfileStatistics.java Tue Dec 08 08:39:03 2009 +0000 @@ -13,7 +13,7 @@ import com.vividsolutions.jts.io.WKTReader; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.utils.DistanceCalculator; /** diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/Statistics.java Tue Dec 08 08:39:03 2009 +0000 @@ -18,8 +18,8 @@ import java.util.Collection; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.statistics.exception.StatisticsException; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** * The interface Statistics fulfills the following purposes: diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/TimeseriesStatistics.java Tue Dec 08 08:39:03 2009 +0000 @@ -25,8 +25,8 @@ import org.apache.log4j.Logger; import de.intevation.gnv.geobackend.base.Result; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.statistics.exception.StatisticsException; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** * The class TimeseriesStatistics fulfills the following purposes: diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/statistics/VerticalProfileStatistics.java Tue Dec 08 08:39:03 2009 +0000 @@ -7,7 +7,7 @@ import java.util.Collection; import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; +import de.intevation.gnv.state.describedata.KeyValueDescibeData; /** * @author Tim Englich diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/CoordinateSelectionTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.log4j.Logger; - -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; - -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; -import de.intevation.gnv.transition.describedata.NamedArrayList; -import de.intevation.gnv.transition.describedata.NamedCollection; -import de.intevation.gnv.utils.InputValidator; -import de.intevation.gnv.utils.exception.ValidationException; - -/** - * @author Tim Englich - * - */ -public class CoordinateSelectionTransition extends TransitionBase { - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(CoordinateSelectionTransition.class); - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 6318923553625195063L; - - /** - * Constructor - */ - public CoordinateSelectionTransition() { - super(); - } - - @Override - protected void purifyResult(Collection result, String uuid) { - log.debug("CoordinateSelectionTransition.purifyResult"); - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = this - .extractKVP(result, "FEATUREID", "SHAPE"); - describeData.add(keyValueDescibeData); - this.setDescibeData(uuid, describeData); - } - - @Override - protected String prepareInputData4RegionDBQuery(String value) { - log.debug("CoordinateSelectionTransition.prepareInputData4RegionDBQuery"); - double distance=0.; - String returnValue = null; - try { - Point center = new InputValidator().getPointValue(value); - String meshIDValue = super.inputData.get("meshid").getValue(); - int segments = 97; - int meshid = new Integer(meshIDValue); - if (meshid == 3 || meshid == 5){ // TODO nicht hier festbrennen. - distance = 0.15; //nord-ostsee 6nm // 97 Stützpunkte - }else if (meshid == 1 || meshid == 4){ - distance = 0.03; //Kuestenmodell 1 nm - }else if (meshid == 2 || meshid == 321){ - distance = 0.3; //SST Karten ca 20km - }else if (meshid == 641){ - distance = 0.3; //Eisdaten Klima - } - returnValue = center.buffer(distance,segments).toText(); - } catch (NumberFormatException e) { - log.error(e,e); - } catch (ValidationException e) { - log.error(e,e); - } - return returnValue; - - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#extractKVP(java.util.Collection, java.lang.String, java.lang.String) - */ - @Override - protected NamedCollection extractKVP( - Collection result, - String keyid, - String valueid) { - Iterator rit = result.iterator(); - NamedCollection keyValueDescibeData = new NamedArrayList( - this.dataName, result.size()); - keyValueDescibeData.setMultiSelect(this.dataMultiSelect); - String prevKey = null; - while (rit.hasNext()) { - Result resultValue = rit.next(); - String key = resultValue.getString(keyid); - if(prevKey == null || !prevKey.equals(key)){ // müssen wir so machen, da die sde kein select distinct auf layern zulässt. - String geomString = this.convert2DisplayCoordinate(resultValue.getString(valueid)); - String value = geomString; - if (resultValue.getResultDescriptor().getColumnIndex("VALUE") > 0){ - value = resultValue.getString("VALUE") + " - "+value; - } - - - keyValueDescibeData.add(new DefaultKeyValueDescribeData(key,value )); - } - prevKey = key; - } - return keyValueDescibeData; - } - - protected String convert2DisplayCoordinate(String wkt){ - String formattedCoordinate = null; - try { - Point p = (Point)new WKTReader().read(wkt); - double lat = p.getY(); - double lon =p.getX(); - String nord="N"; - String ost="E"; - if (lat <0 ){nord="S"; lat=-lat;} - if (lon <0 ){ost="W"; lon=-lon;} - formattedCoordinate = String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'", - (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon))); - } catch (ParseException e) { - log.error(e,e); - } - - return formattedCoordinate; - } -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -/** - * @author Tim Englich - * - */ -public class DefaultInputData implements InputData { - - /** - * - */ - private static final long serialVersionUID = 4308041648698108066L; - private String name = null; - private String value = null; - - /** - * Constructor - */ - public DefaultInputData(String name, String value) { - this.name = name; - this.value = value; - } - - /** - * @see de.intevation.gnv.transition.InputData#getName() - */ - public String getName() { - return this.name; - } - - /** - * @see de.intevation.gnv.transition.InputData#getValue() - */ - public String getValue() { - return this.value; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return this.name + "==> " + this.value; - } - - /** - * @see de.intevation.gnv.transition.InputData#concartValue(java.lang.String) - */ - public void concartValue(String value) { - this.value = this.value + " , " + value; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputValue.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputValue.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -/** - * @author Tim Englich - * - */ -public class DefaultInputValue implements InputValue { - - /** - * The UID of this Class. - */ - private static final long serialVersionUID = -8518824299166180986L; - private String name = null; - private String type = null; - private boolean multiselect = false; - private int usedInQueries = 1; - private String defaultValue = "N/N"; - - public DefaultInputValue(String name, String type, String defaultValue, - boolean multiselect) { - this(name, type, multiselect, 1); - this.defaultValue = defaultValue; - - } - - /** - * Constructor - */ - public DefaultInputValue(String name, String type, boolean multiselect, - int usedInQueries) { - this.name = name; - this.type = type; - this.multiselect = multiselect; - this.usedInQueries = usedInQueries; - } - - /** - * @see de.intevation.gnv.transition.InputValue#getName() - */ - public String getName() { - return this.name; - } - - /** - * @see de.intevation.gnv.transition.InputValue#getType() - */ - public String getType() { - return this.type; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "InputValue " + this.name + " ==> " + this.type - + "==> multiselect: " + this.multiselect; - } - - /** - * @see de.intevation.gnv.transition.InputValue#isMultiselect() - */ - public boolean isMultiselect() { - return this.multiselect; - } - - public int usedInQueries() { - return this.usedInQueries; - } - - public String getDefaultValue() { - return this.defaultValue; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultOutputMode.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultOutputMode.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.util.Collection; - -/** - * @author Tim Englich - * - */ -public class DefaultOutputMode implements OutputMode { - - /** - * The UID of this Class. - */ - private static final long serialVersionUID = -6459085460904827056L; - private String name = null; - private String description = null; - private String mimeType = null; - private Collection inputParameters = null; - - /** - * Constructor - * - * @param name - * @param description - * @param mimeType - */ - public DefaultOutputMode(String name, String description, String mimeType, - Collection inputParameters) { - super(); - this.name = name; - this.description = description; - this.mimeType = mimeType; - this.inputParameters = inputParameters; - } - - /** - * @see de.intevation.gnv.transition.OutputMode#getDescription() - */ - public String getDescription() { - return this.description; - } - - /** - * @see de.intevation.gnv.transition.OutputMode#getMimeType() - */ - public String getMimeType() { - return this.mimeType; - } - - /** - * @see de.intevation.gnv.transition.OutputMode#getName() - */ - public String getName() { - return this.name; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "Name: " + this.name + " ; Description: " + this.description - + " ; Mime-Type: " + this.mimeType; - } - - /** - * @see de.intevation.gnv.transition.OutputMode#getInputParameters() - */ - public Collection getInputParameters() { - return this.inputParameters; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -/** - * @author Tim Englich - * - */ -public class DefaultTransition extends TransitionBase { - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 8934030362091576766L; - - /** - * Constructor - */ - public DefaultTransition() { - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.Serializable; - -/** - * @author Tim Englich - * - */ -public interface InputData extends Serializable { - - public String getName(); - - public String getValue(); - - public void concartValue(String value); -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputValue.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputValue.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.Serializable; - -/** - * @author Tim Englich - * - */ -public interface InputValue extends Serializable { - - public String getName(); - - public String getType(); - - public String getDefaultValue(); - - public boolean isMultiselect(); - - public int usedInQueries(); - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.util.ArrayList; -import java.util.Collection; - -import org.apache.log4j.Logger; - -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.DefaultMinMaxDescribeData; -import de.intevation.gnv.transition.describedata.DescribeData; - -/** - * @author Tim Englich - * - */ -public class MinMaxTransition extends TransitionBase { - - /** - * The UID of this Class - */ - private static final long serialVersionUID = -3525903792105187408L; - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(MinMaxTransition.class); - - /** - * Constructor - */ - public MinMaxTransition() { - super(); - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, - * java.lang.String) - */ - @Override - protected void purifyResult(Collection result, String uuid) { - log.debug("MinMaxTransition.purifyResult"); - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - if (result != null && result.size() == 1) { - - Result value = result.iterator().next(); - DescribeData values = new DefaultMinMaxDescribeData(this.dataName, - value.getObject("MIN"), - value.getObject("MAX")); - log.debug(values.toString()); - describeData.add(values); - } else { - log.warn("Result cannot be handled as MinMax Resultset"); - } - this.setDescibeData(uuid, describeData); - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputMode.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputMode.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.Serializable; -import java.util.Collection; - -/** - * @author Tim Englich - * - */ -public interface OutputMode extends Serializable { - - public String getName(); - - public String getDescription(); - - public String getMimeType(); - - public Collection getInputParameters(); -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.OutputStream; -import java.util.Collection; - -import org.w3c.dom.Document; - -import de.intevation.artifacts.CallMeta; -import de.intevation.gnv.transition.exception.TransitionException; - -/** - * @author Tim Englich - * - */ -public interface OutputTransition extends Transition { - - /** - * Returns the Rendered Result of an Transition. - * - * @param outputMode - * The Mode that should be produces (Chart, Map, ...) - * @return The Bytecode of the Result - * @throws TransitionException - */ - public void out(Document format, Collection inputData, - OutputStream outputStream, String uuid, CallMeta callMeta) - throws TransitionException; - - /** - * Delivers the provided OutputModes of an Transition - * - * @return the provided OutputModes of an Transition - */ - public Collection getOutputModes(); -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,273 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Locale; - - -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.artifacts.CallMeta; -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.transition.exception.TransitionException; - -/** - * @author Tim Englich - * - */ -public abstract class OutputTransitionBase extends TransitionBase implements - OutputTransition { - - /** - * The UID of this Class - */ - private static final long serialVersionUID = -1718732895737303823L; - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(OutputTransitionBase.class); - - /** - * The different Outputmodes which are provided by an OutputTransition - */ - protected Collection outputModes = null; - - protected String queryODVID = null; - - /** - * Constructor - */ - public OutputTransitionBase() { - super(); - } - - /** - * @see de.intevation.gnv.transition.OutputTransition#getOutputModes() - */ - public Collection getOutputModes() { - log.debug("OutputTransitionBase.getOutputModes"); - return this.outputModes; - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#setup(org.w3c.dom.Node) - */ - @Override - 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) { - log.debug(outputModeList.getLength() + " were found."); - this.outputModes = new ArrayList(outputModeList - .getLength()); - for (int i = 0; i < outputModeList.getLength(); i++) { - Element currentNode = (Element)outputModeList.item(i); - String name = currentNode.getAttribute("name"); - String description =currentNode.getAttribute("description"); - String mimeType = currentNode.getAttribute("mime-type"); - NodeList inputValuesList = Config.getNodeSetXPath(currentNode, - "parameters/inputvalue"); - Collection inputParameters = null; - if (inputValuesList != null) { - inputParameters = new ArrayList(inputValuesList - .getLength()); - for (int j = 0; j < inputValuesList.getLength(); j++) { - Element currentInputValuesNode = (Element)inputValuesList.item(j); - String inputValueName = currentInputValuesNode.getAttribute("name"); - String inputValueType = currentInputValuesNode.getAttribute("type"); - String defaultValue =currentInputValuesNode.getAttribute("value"); - boolean isMultiselect = false; - InputValue inputValue = new DefaultInputValue( - inputValueName, inputValueType, defaultValue, - isMultiselect); - inputParameters.add(inputValue); - } - } - - OutputMode outputMode = new DefaultOutputMode(name, - description, mimeType, inputParameters); - log.debug(outputMode.toString()); - this.outputModes.add(outputMode); - - } - } - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#advance() - */ - @Override - public void advance(String uuid, CallMeta callMeta) - throws TransitionException { - } - - @Override - public void initialize(String uuid, CallMeta callMeta) - throws TransitionException { - } - - public void out(Document format, Collection inputData, - OutputStream outputStream, String uuid, CallMeta callMeta) - throws TransitionException { - } - - /** - * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, - * java.util.Collection, java.io.OutputStream) - */ - public void out(String outputMode, Collection inputData, - OutputStream outputStream) throws TransitionException { - } - - /** - * @return - */ - protected Collection getChartResult(String uuid) { - log.debug("OutputTransitionBase.getChartResult"); - Collection result = null; - if (CacheFactory.getInstance().isInitialized()) { - String key = uuid + super.getID(); - log.debug("Hash for Queryelements: " + key); - net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); - if (value != null) { - result = (Collection) (value.getObjectValue()); - }else{ - result = this.getData(this.queryID); - if (CacheFactory.getInstance().isInitialized()) { - CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); - } - - } - } - return result; - } - - protected Object getChartFromCache(String uuid) { - log.debug("Fetch chart [" + uuid + "] from cache"); - CacheFactory cacheFactory = CacheFactory.getInstance(); - if (cacheFactory.isInitialized()) { - String key = "chart_" + uuid + super.getID(); - net.sf.ehcache.Element object = cacheFactory.getCache().get(key); - - if (object != null) { - return object.getObjectValue(); - } - } - return null; - } - - protected Collection getODVResult(String uuid) { - log.debug("OutputTransitionBase.getODVResult"); - // TODO add Caching? I think it's not nessessary - Collection returnValue = null; - if (this.queryODVID != null){ - returnValue = this.getData(this.queryODVID); - }else{ - log.warn("No Query for ODV Data is defined."); - } - return returnValue; - } - - /** - * @param returnValue - * @return - */ - private Collection getData(String queryID) { - log.debug("OutputTransitionBase.getData"); - Collection returnValue = null; - try { - String[] filterValues = this.generateFilterValuesFromInputData(); - try { - QueryExecutor queryExecutor = QueryExecutorFactory - .getInstance() - .getQueryExecutor(); - returnValue = queryExecutor.executeQuery(queryID,filterValues); - } catch (RuntimeException e) { - log.error(e, e); - } - } catch (QueryException e) { - log.error(e, e); - } - return returnValue; - } - - protected void removeChartResult(String uuid) { - log.debug("OutputTransitionBase.getChartResult"); - if (CacheFactory.getInstance().isInitialized()) { - String key = uuid + super.getID(); - log.debug("Hash for Queryelements: " + key); - net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); - if (value != null) { - CacheFactory.getInstance().getCache().remove(key); - } - } - } - - protected void removeChart(String uuid) { - log.debug("OutputTransitionBase.removeChart from cache"); - - CacheFactory cacheFactory = CacheFactory.getInstance(); - if (cacheFactory.isInitialized()) { - String key = "chart_" + uuid + super.getID(); - net.sf.ehcache.Element object = cacheFactory.getCache().get(key); - if (object != null) - cacheFactory.getCache().remove(key); - } - } - - protected void purifyChart(Object chart, String uuid) { - log.debug("Prufify chart [" + uuid + "]"); - CacheFactory cacheFactory = CacheFactory.getInstance(); - if (cacheFactory.isInitialized()) { - String key = "chart_" + uuid + getID(); - cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart)); - } - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#putInputData(java.util.Collection, java.lang.String) - */ - @Override - public void putInputData(Collection inputData, - String uuid) - throws TransitionException { - log.debug("OutputTransitionBase.putInputData"); - this.removeChartResult(uuid); - this.removeChart(uuid); - super.putInputData(inputData, uuid); - } - - public void out(String outputMode, Collection inputData, - OutputStream outputStream, String uuid, CallMeta callMeta) - throws TransitionException { - } - - - protected String getMessage(Locale locale, String key, String value) { - return RessourceFactory.getInstance().getRessource( - locale, - key, - value - ); - } -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/SingleInputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/SingleInputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.util.ArrayList; -import java.util.Collection; - -import org.apache.log4j.Logger; - -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.describedata.DefaultSingleValueDescribeData; - -/** - * @author Tim Englich - * - */ -public class SingleInputTransition extends TransitionBase { - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(SingleInputTransition.class); - - /** - * - */ - private static final long serialVersionUID = -6169497306324917318L; - - /** - * Constructor - */ - public SingleInputTransition() { - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, - * java.lang.String) - */ - @Override - protected void purifyResult(Collection result, String uuid) { - log.debug("SingleInputTransition.purifyResult"); - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - String value = null; - if (result != null && result.size() == 1) { - Result tmpItem = result.iterator().next(); - value = tmpItem.getObject("MAX").toString(); - } else { - value = ""; - } - - describeData.add(new DefaultSingleValueDescribeData(this.dataName,value)); - this.setDescibeData(uuid, describeData); - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.io.Serializable; -import java.util.Collection; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import de.intevation.artifacts.CallMeta; -import de.intevation.gnv.transition.exception.TransitionException; - -/** - * @author Tim Englich - * - */ -public interface Transition extends Serializable { - - public void setup(Node configuration); - - public Collection reachableTransitions(); - - public boolean isTransitionReachable(String transitionID); - - public String getID(); - - public String getDescription(); - - public void describe(Document document, Node rootNode, - CallMeta callMeta, String uuid); - - public void setParent(Transition transition); - - public Transition getParent(); - - public Collection getRequiredInputValues(); - - public void putInputData(Collection inputData, - String uuid)throws TransitionException; - - public Collection getInputData() throws TransitionException; - - public void advance(String uuid, CallMeta callMeta) - throws TransitionException; - public void initialize(String uuid, CallMeta callMeta) - throws TransitionException; - - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,789 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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.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.transition.describedata.DefaultKeyValueDescribeData; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; -import de.intevation.gnv.transition.describedata.MinMaxDescribeData; -import de.intevation.gnv.transition.describedata.NamedArrayList; -import de.intevation.gnv.transition.describedata.NamedCollection; -import de.intevation.gnv.transition.describedata.SingleValueDescribeData; -import de.intevation.gnv.transition.exception.TransitionException; -import de.intevation.gnv.utils.ArtifactXMLUtilities; -import de.intevation.gnv.utils.InputValidator; - -/** - * @author Tim Englich - * - */ -public abstract class TransitionBase implements Transition { - - - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 2411169179001645426L; - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(GNVArtifactBase.class); - - private final static String MINVALUEFIELDNAME = "minvalue"; - private final static String MAXVALUEFIELDNAME = "maxvalue"; - - private final static String NODATASELECTIONKEY = "n/n"; - - private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; - - private String id = null; - - private String description = null; - - protected String dataName = null; - - protected boolean dataMultiSelect = false; - - protected boolean dataNoSelect = false; - - protected String queryID = null; - - private Collection reachableTransitions = null; - - protected Collection inputValueNames = null; - - private Map inputValues = null; - - private Transition parent = null; - - protected Map inputData = null; - - - /** - * Constructor - */ - public TransitionBase() { - super(); - } - - /** - * @see de.intevation.gnv.transition.Transition#getID() - */ - public String getID() { - return this.id; - } - - /** - * @see de.intevation.gnv.transition.Transition#getDescription() - */ - public String getDescription() { - return this.description; - } - - /** - * @see de.intevation.gnv.transition.Transition#reachableTransitions() - */ - public Collection reachableTransitions() { - - if (this.couldAlternativeTransitionUsed()){ - Iterator it = this.reachableTransitions.iterator(); - String transValue = null; - while (it.hasNext()){ - transValue = it.next(); - } - Collection returnValue = new ArrayList(1); - returnValue.add(transValue); - return returnValue; - }else{ - return this.reachableTransitions; - } - - } - - /** - * @return - */ - private boolean couldAlternativeTransitionUsed() { - // TODO das muss hier noch etwas freier gestaltet werden. - String key = this.dataName; - boolean returnValue= /*this.alternativeTransition != null &&*/ - this.inputData != null && - this.inputData.containsKey(key) && - this.inputData.get(key).getValue(). - equals(NODATASELECTIONKEY); - return returnValue; - } - - /** - * @see de.intevation.gnv.transition.Transition#getRequiredInputValues() - */ - public Collection getRequiredInputValues() { - return this.inputValues.values(); - } - - /** - * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node) - */ - public void setup(Node configuration) { - log.debug("TransitionBase.setup"); - this.id = ((Element)configuration).getAttribute("id"); - this.description = ((Element)configuration).getAttribute("description"); - - log.info("Transition-ID = " + this.id); - NodeList nodes = Config.getNodeSetXPath(configuration, - "reachableTransitions/transition"); - this.reachableTransitions = new ArrayList(nodes.getLength()); - for (int i = 0; i < nodes.getLength(); i++) { - String reachableTransition = nodes.item(i).getTextContent(); - log.info("ReachableTransition ==> " + reachableTransition); - this.reachableTransitions.add(reachableTransition); - - } - - NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, - "inputvalues/inputvalue"); - this.inputValues = new HashMap(inputValuesNodes - .getLength()); - this.inputValueNames = new ArrayList(inputValuesNodes - .getLength()); - for (int i = 0; i < inputValuesNodes.getLength(); i++) { - Element inputValueNode = (Element)inputValuesNodes.item(i); - String usedinQueryValue = inputValueNode.getAttribute("usedinquery"); - int usedinQuery = 1; - if (usedinQueryValue != null) { - try { - usedinQuery = Integer.parseInt(usedinQueryValue); - } catch (NumberFormatException e) { - log - .warn("Used in Query Value cannot be transformed into a Number"); - } - } - InputValue inputValue = new DefaultInputValue(inputValueNode.getAttribute("name"), - inputValueNode.getAttribute("type"), - Boolean.parseBoolean(inputValueNode. - getAttribute("multiselect")), usedinQuery); - log.debug(inputValue.toString()); - this.inputValues.put(inputValue.getName(), inputValue); - this.inputValueNames.add(inputValue.getName()); - } - - this.queryID = Config.getStringXPath(configuration, "queryID"); - log.info("QueryID ==> " + this.queryID); - - this.dataName = Config.getStringXPath(configuration, "dataname"); - - String dataMultiSelectValue = Config.getStringXPath(configuration, - "data-multiselect"); - if (dataMultiSelectValue != null) { - this.dataMultiSelect = Boolean.parseBoolean(dataMultiSelectValue); - } - - String dataNoSelectValue =Config.getStringXPath(configuration, - "data-noselect"); - if (dataNoSelectValue != null) { - this. dataNoSelect = Boolean.parseBoolean(dataNoSelectValue); - } - - } - - /** - * @see de.intevation.gnv.transition.Transition#getParent() - */ - public Transition getParent() { - return this.parent; - } - - /** - * @see de.intevation.gnv.transition.Transition#setParent(de.intevation.gnv.transition.Transition) - */ - public void setParent(Transition transition) { - this.parent = transition; - } - - /** - * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection) - */ - public void putInputData(Collection inputData, String uuid) - throws TransitionException { - log.debug("TransitionBase.putInputData"); - 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 TransitionException(errMsg); - } - - valid = iv.isInputValid(minValue, - maxValue, - inputValue.getType()); - if (!valid){ - String errMsg = "MaxValue-Input is less than MinValue-Input "; - log.warn(errMsg); - throw new TransitionException(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 TransitionException(errMsg); - } - - valid = iv.isInputValid(minValue, - maxValue, - inputValue.getType()); - if (!valid){ - String errMsg = "MaxValue-Input is less than MinValue-Input "; - log.warn(errMsg); - throw new TransitionException(errMsg); - } - } - this.setSelection(tmpItem, uuid); - 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 TransitionException(errMsg); - } - - } else { - String errMsg = "No Inputvalue given for Inputdata " - + tmpItem.getName(); - log.warn(errMsg + "Value will be ignored"); - - } - } - } else { - log.warn("No Inputdata given"); - } - } - - private String getInputValue4ID(Collection inputData, String inputName){ - Iterator it = inputData.iterator(); - while (it.hasNext()) { - InputData tmpItem = it.next(); - if (tmpItem.getName().equals(inputName)){ - return tmpItem.getValue(); - } - } - return null; - } - - private void setSelection(InputData inputData, String uuid) { - log.debug("TransitionBase.setSelection"); - - Object o = this.getDescribeData(inputData.getName(),uuid); - if (o != null) { - if (o instanceof Collection) { - Collection values = (Collection) o; - - String value = inputData.getValue(); - String[] selectedValues = value.split(","); - Set selectedItems = new HashSet( - selectedValues.length); - for (int i = 0; i < selectedValues.length; i++) { - selectedItems.add(selectedValues[i].trim()); - } - // Selektion umsetzen - Iterator it = values.iterator(); - while (it.hasNext()) { - KeyValueDescibeData data = it.next(); - String key = "" + data.getKey(); - boolean selected = selectedItems.contains(key); - data.setSelected(selected); - } - } else if (o instanceof MinMaxDescribeData) { - MinMaxDescribeData data = (MinMaxDescribeData) o; - if (inputData.getName().equals(MINVALUEFIELDNAME)) { - data.setMinValue(inputData.getValue()); - } - if (inputData.getName().equals(MAXVALUEFIELDNAME)) { - data.setMaxValue(inputData.getValue()); - } - } else if (o instanceof SingleValueDescribeData) { - ((SingleValueDescribeData)o).setValue(inputData.getValue()); - } - } - } - - private Object getDescribeData(String name, String uuid) { - log.debug("TransitionBase.getDescribeData"); - Collection descibeData = this.getDescibeData(uuid); - if (descibeData != null) { - Iterator it = descibeData.iterator(); - while (it.hasNext()) { - Object o = it.next(); - if (o instanceof NamedCollection) { - if (name.equals(((NamedCollection) o).getName())) { - return o; - } - } else if (o instanceof MinMaxDescribeData) { - if (name.equals(((MinMaxDescribeData) o).getMinName())) { - return o; - } - if (name.equals(((MinMaxDescribeData) o).getMaxName())) { - return o; - } - }else if (o instanceof SingleValueDescribeData) { - if (name.equals(((SingleValueDescribeData)o).getName())){ - return o; - } - } - } - } - return null; - - } - - /** - * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String) - */ - public boolean isTransitionReachable(String transitionID) { - log.debug("TransitionBase.isTransitionReachable"); - boolean returnValue = false; - Iterator transitions = reachableTransitions.iterator(); - while (transitions.hasNext()) { - if (transitions.next().equals(transitionID)) { - log.debug("Transition " + transitionID + " wird unterstützt."); - returnValue = true; - break; - } - } - return returnValue; - } - - /** - * @see de.intevation.gnv.transition.Transition#advance(java.lang.String, - * de.intevation.artifacts.CallMeta) - */ - public void advance(String uuid, CallMeta callMeta) - throws TransitionException { - } - - public void initialize(String uuid, CallMeta callMeta) - throws TransitionException { - log.debug("TransitionBase.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) { - log.error(e, e); - throw new TransitionException(e); - } - } - - /** - * @return - */ - protected String[] generateFilterValuesFromInputData() { - List list = new ArrayList(); - Iterator 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; - } - - private String prepareInputData4DateDBQuery(String value) { - log.debug("TransitionBase.prepareInputData4DateDBQuery"); - if (value != null) { - String[] values = value.split(","); - String newValue = ""; - for (int i = 0; i < values.length; i++) { - if (newValue.length() > 0) { - newValue = newValue + " , "; - } - // TODO JUST HACK FIND A BETTER RESOLUTION - newValue = newValue + "to_date('" + values[i].trim() - + "', 'YYYY.MM.DD HH24:MI:SS')"; - } - return newValue; - } - - return value; - } - - private String prepareInputData4DBQuery(String value) { - log.debug("TransitionBase.prepareInputData4DBQuery"); - if (value != null) { - String[] values = value.split(","); - String newValue = ""; - for (int i = 0; i < values.length; i++) { - if (newValue.length() > 0) { - newValue = newValue + " , "; - } - newValue = newValue + "'" + values[i].trim() + "'"; - } - return newValue; - } - - return value; - - } - - /** - * @param result - */ - protected void purifyResult(Collection result, String uuid) { - log.debug("TransitionBase.purifyResult"); - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = extractKVP(result, "KEY", "VALUE"); - describeData.add(keyValueDescibeData); - this.setDescibeData(uuid, describeData); - } - - /** - * @param result - * @return - */ - protected NamedCollection extractKVP(Collection result, - String keyid, - 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, - "No Selection")); - } - boolean initialized = false; - int keyPos= 0; - int valuePos = 1; - String previousKey = null; - while (rit.hasNext()) { - Result resultValue = rit.next(); - if (!initialized){ - keyPos = resultValue.getResultDescriptor().getColumnIndex(keyid); - valuePos = resultValue.getResultDescriptor().getColumnIndex(valueid); - if (valuePos < 0){ - valuePos = 1; - } - initialized = true; - } - String tmpKey = resultValue.getString(keyPos); - // TODO: HACK da die ARCSDE kein DISTINCT auf räumlichen Anfragen unterstützt. - if (previousKey == null || !tmpKey.equals(previousKey)){ - previousKey = tmpKey; - keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos))); - } - } - return keyValueDescibeData; - } - - /** - * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, - * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, - * java.lang.String) - */ - public void describe(Document document, Node rootNode, CallMeta callMeta,String uuid) { - log.debug("TransitionBase.describe"); - Collection descibeData = this.getDescibeData(uuid); - if (descibeData != null) { - ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); - Iterator it = descibeData.iterator(); - Node staticNode = xmlutilities.createArtifactElement(document, - "static"); - Node dynamic = xmlutilities.createArtifactElement(document, - "dynamic"); - rootNode.appendChild(staticNode); - rootNode.appendChild(dynamic); - while (it.hasNext()) { - - Object o = it.next(); - if (o instanceof Collection) { - String name = null; - boolean multiselect = false; - if (o instanceof NamedCollection) { - NamedCollection nc = ((NamedCollection) o); - name = nc.getName(); - multiselect = nc.isMultiSelect(); - } else { - Object[] names = this.inputValueNames.toArray(); - name = names[names.length - 1].toString(); - } - - Element selectNode = xmlutilities.createXFormElement( - document, multiselect ? "select" : "select1"); - selectNode.setAttribute("ref", name); - - Element lableNode = xmlutilities.createXFormElement( - document, "label"); - lableNode.setTextContent(RessourceFactory.getInstance() - .getRessource(callMeta.getLanguages(), name, name)); - Element choiceNode = xmlutilities.createXFormElement( - document, "choices"); - - Collection values = (Collection) o; - Iterator resultIt = values.iterator(); - while (resultIt.hasNext()) { - KeyValueDescibeData result = resultIt.next(); - Element itemNode = xmlutilities.createXFormElement( - document, "item"); - - if (result.isSelected()) { - itemNode.setAttribute("selected", "true"); - } - - Element choiceLableNode = xmlutilities - .createXFormElement(document, "label"); - choiceLableNode.setTextContent(result.getValue()); - itemNode.appendChild(choiceLableNode); - - Element choicValueNode = xmlutilities - .createXFormElement(document, "value"); - choicValueNode.setTextContent("" + result.getKey()); - itemNode.appendChild(choicValueNode); - choiceNode.appendChild(itemNode); - } - selectNode.appendChild(lableNode); - selectNode.appendChild(choiceNode); - - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(selectNode); - } else { - staticNode.appendChild(selectNode); - } - - } else if (o instanceof MinMaxDescribeData) { - MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; - Object min = minMaxDescibeData.getMinValue(); - Object max = minMaxDescibeData.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 = xmlutilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", minMaxDescibeData.getName()); - Element groupNodeLableNode = xmlutilities - .createXFormElement(document, "label"); - groupNodeLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), - minMaxDescibeData.getName(), - minMaxDescibeData.getName())); - groupNode.appendChild(groupNodeLableNode); - - Element inputMinNode = xmlutilities.createXFormElement( - document, "input"); - inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); - Element inputMinLableNode = xmlutilities - .createXFormElement(document, "label"); - inputMinLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), MINVALUEFIELDNAME, - MINVALUEFIELDNAME)); - inputMinNode.appendChild(inputMinLableNode); - - Element inputMinValueNode = xmlutilities - .createXFormElement(document, "value"); - inputMinValueNode.setTextContent(min.toString()); - inputMinNode.appendChild(inputMinValueNode); - - Element inputMaxNode = xmlutilities.createXFormElement( - document, "input"); - inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); - Element inputMaxLableNode = xmlutilities - .createXFormElement(document, "label"); - inputMaxLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), MAXVALUEFIELDNAME, - MAXVALUEFIELDNAME)); - inputMaxNode.appendChild(inputMaxLableNode); - - Element inputMaxValueNode = xmlutilities - .createXFormElement(document, "value"); - inputMaxValueNode.setTextContent(max.toString()); - inputMaxNode.appendChild(inputMaxValueNode); - - groupNode.appendChild(inputMinNode); - groupNode.appendChild(inputMaxNode); - - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(groupNode); - } else { - staticNode.appendChild(groupNode); - } - } else if (o instanceof SingleValueDescribeData) { - - SingleValueDescribeData svdb = (SingleValueDescribeData) o; - - Element groupNode = xmlutilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", svdb.getName()); - Element groupNodeLableNode = xmlutilities - .createXFormElement(document, "label"); - groupNodeLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), - svdb.getName(), - svdb.getName())); - groupNode.appendChild(groupNodeLableNode); - - Element inputNode = xmlutilities.createXFormElement( - document, "input"); - inputNode.setAttribute("ref", svdb.getName()); - - Element inputLableNode = xmlutilities.createXFormElement( - document, "label"); - inputLableNode.setTextContent(""); - inputNode.appendChild(inputLableNode); - - Element inputValueNode = xmlutilities.createXFormElement( - document, "value"); - inputValueNode.setTextContent(svdb.getValue()); - inputNode.appendChild(inputValueNode); - - groupNode.appendChild(inputNode); - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(groupNode); - } else { - staticNode.appendChild(groupNode); - } - } - - } - } - } - - /** - * @see de.intevation.gnv.transition.Transition#getDescibeData() - */ - protected Collection 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 (Collection) (value.getObjectValue()); - } - } - return null; - } - - /** - * @see de.intevation.gnv.transition.Transition#getDescibeData() - */ - protected void setDescibeData(String uuid, Collection 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)); - } - } - - /** - * @see de.intevation.gnv.transition.Transition#getInputData() - */ - public Collection getInputData() throws TransitionException { - return this.inputData != null ? this.inputData.values() : null; - } -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionFactory.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition; - -import org.apache.log4j.Logger; -import org.w3c.dom.Node; - -import de.intevation.gnv.artifacts.GNVArtifactBase; - -/** - * @author Tim Englich - * - */ -public class TransitionFactory { - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger.getLogger(GNVArtifactBase.class); - - private static TransitionFactory instance = null; - - /** - * Constructor - */ - public TransitionFactory() { - super(); - } - - public static TransitionFactory getInstance() { - if (instance == null) { - instance = new TransitionFactory(); - } - return instance; - } - - public Transition createTransition(Node configuration) { - log.debug("TransitionFactory.createTransition"); - Transition transition = null; - try { - String classname = ((org.w3c.dom.Element)configuration).getAttribute("transition"); - transition = (Transition) (Class.forName(classname).newInstance()); - transition.setup(configuration); - } catch (InstantiationException e) { - log.error(e, e); - } catch (IllegalAccessException e) { - log.error(e, e); - } catch (ClassNotFoundException e) { - log.error(e, e); - } - return transition; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultKeyValueDescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultKeyValueDescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -/** - * @author Tim Englich - * - */ -public class DefaultKeyValueDescribeData implements KeyValueDescibeData { - - /** - * - */ - private static final long serialVersionUID = -924469415242703108L; - - private String key; - - private String value = null; - - private boolean selected = false; - - public DefaultKeyValueDescribeData(String key, String value) { - super(); - this.key = key; - this.value = value; - } - - /** - * @see de.intevation.gnv.transition.describedata.KeyValueDescibeData#getKey() - */ - public String getKey() { - return this.key; - } - - /** - * @see de.intevation.gnv.transition.describedata.KeyValueDescibeData#getValue() - */ - public String getValue() { - return this.value; - } - - /** - * @see de.intevation.gnv.transition.describedata.KeyValueDescibeData#isSelected() - */ - public boolean isSelected() { - return this.selected; - } - - /** - * @see de.intevation.gnv.transition.describedata.KeyValueDescibeData#setSelected(boolean) - */ - public void setSelected(boolean selected) { - this.selected = selected; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultMinMaxDescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultMinMaxDescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -/** - * @author Tim Englich - * - */ -public class DefaultMinMaxDescribeData implements MinMaxDescribeData { - - /** - * - */ - private static final long serialVersionUID = -2917176219029052295L; - - private Object minValue = null; - - private Object maxValue = null; - - private String name = null; - - private final static String minName = "minvalue"; - - private final static String maxName = "maxvalue"; - - /** - * Constructor - */ - public DefaultMinMaxDescribeData(String name, Object minValue, Object maxValue) { - super(); - this.name = name; - this.minValue = minValue; - this.maxValue = maxValue; - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getMaxValue() - */ - public Object getMaxValue() { - return this.maxValue; - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getMinValue() - */ - public Object getMinValue() { - return this.minValue; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "MIN: " + this.minValue.toString() + " ; MAX: " - + this.maxValue.toString(); - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getName() - */ - public String getMinName() { - return minName; - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#getMaxName() - */ - public String getMaxName() { - return maxName; - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#setMaxValue(java.lang.Object) - */ - public void setMaxValue(Object maxValue) { - this.maxValue = maxValue; - } - - /** - * @see de.intevation.gnv.transition.describedata.MinMaxDescribeData#setMinValue(java.lang.Object) - */ - public void setMinValue(Object minValue) { - this.minValue = minValue; - } - - public String getName() { - return this.name; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultSingleValueDescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DefaultSingleValueDescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -/** - * @author Tim Englich - * - */ -public class DefaultSingleValueDescribeData implements SingleValueDescribeData { - - /** - * - */ - private static final long serialVersionUID = 3580176842483316917L; - - private String name = null; - - private String value = null; - - /** - * Constructor - * - * @param name - * @param value - */ - public DefaultSingleValueDescribeData(String name, String value) { - super(); - this.name = name; - this.value = value; - } - - /** - * @see de.intevation.gnv.transition.describedata.SingleValueDescribeData#getName() - */ - public String getName() { - return this.name; - } - - /** - * @see de.intevation.gnv.transition.describedata.SingleValueDescribeData#getValue() - */ - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/DescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -import java.io.Serializable; - -/** - * Markerinterface - * - * @author Tim Englich - * - */ -public interface DescribeData extends Serializable { - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/KeyValueDescibeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/KeyValueDescibeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -import java.io.Serializable; - -/** - * @author Tim Englich - * - */ -public interface KeyValueDescibeData extends Serializable { - - public String getKey(); - - public String getValue(); - - public boolean isSelected(); - - public void setSelected(boolean selected); - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/MinMaxDescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/MinMaxDescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -/** - * @author Tim Englich - * - */ -public interface MinMaxDescribeData extends DescribeData { - - public Object getMinValue(); - - public Object getMaxValue(); - - public void setMinValue(Object minValue); - - public void setMaxValue(Object maxValue); - - public String getName(); - - public String getMinName(); - - public String getMaxName(); - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/NamedArrayList.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/NamedArrayList.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * @author Tim Englich - * - */ -public class NamedArrayList extends ArrayList implements - NamedCollection { - /** - * - */ - private static final long serialVersionUID = 8172229594749676354L; - - private String name = null; - - private boolean multiSelect = false; - - /** - * Constructor - */ - public NamedArrayList(String name) { - this.name = name; - } - - /** - * Constructor - * - * @param initialCapacity - */ - public NamedArrayList(String name, int initialCapacity) { - super(initialCapacity); - this.name = name; - } - - /** - * Constructor - * - * @param c - */ - public NamedArrayList(String name, Collection c) { - super(c); - this.name = name; - } - - /** - * @see de.intevation.gnv.transition.describedata.NamedCollection#getName() - */ - public String getName() { - return this.name; - } - - /** - * @see de.intevation.gnv.transition.describedata.NamedCollection#isMultiSelect() - */ - public boolean isMultiSelect() { - return multiSelect; - } - - /** - * @see de.intevation.gnv.transition.describedata.NamedCollection#setMultiSelect(boolean) - */ - public void setMultiSelect(boolean multiSelect) { - this.multiSelect = multiSelect; - } -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/NamedCollection.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/NamedCollection.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -import java.util.Collection; - -/** - * @author Tim Englich - * - */ -public interface NamedCollection extends Collection { - - public String getName(); - - public boolean isMultiSelect(); - - public void setMultiSelect(boolean multiSelect); -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/SingleValueDescribeData.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/describedata/SingleValueDescribeData.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.describedata; - -/** - * @author Tim Englich - * - */ -public interface SingleValueDescribeData extends DescribeData { - - public String getName(); - - public String getValue(); - - public void setValue(String value); -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/exception/TransitionException.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/exception/TransitionException.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.exception; - -/** - * @author Tim Englich - * - */ -public class TransitionException extends Exception { - - /** - * The UID of the Class - */ - private static final long serialVersionUID = -1635921702746050244L; - - /** - * Constructor - */ - public TransitionException() { - super(); - } - - /** - * Constructor - * - * @param message - */ - public TransitionException(String message) { - super(message); - } - - /** - * Constructor - * - * @param cause - */ - public TransitionException(Throwable cause) { - super(cause); - } - - /** - * Constructor - * - * @param message - * @param cause - */ - public TransitionException(String message, Throwable cause) { - super(message, cause); - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,285 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.profile.horizontal; - -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.io.WKTReader; -import com.vividsolutions.jts.io.ParseException; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.Locale; - -import org.apache.log4j.Logger; - -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.chart.HorizontalProfileChart; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.statistics.HorizontalProfileStatistics; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.transition.exception.TransitionException; -import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; - -import de.intevation.gnv.exports.DefaultExport; -import de.intevation.gnv.exports.ShapeDataCollector; -import de.intevation.gnv.exports.DefaultProfile; -import de.intevation.gnv.exports.Export.Profile; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; - -/** - * @author Tim Englich - * - */ -public class HorizontalProfileOutputTransition extends - TimeSeriesOutputTransition { - /** - * The UID of this class - */ - private static final long serialVersionUID = 4401516087492028840L; - - private static Logger log = Logger - .getLogger(HorizontalProfileOutputTransition.class); - - public static final String DATE_FORMAT = "yyyy.MM.dd HH:mm:ss"; - - public static final String [] CHART_TITLE_META = { - "CRUISE", - "DEPTH", - "SHAPE" - }; - - - public static final String [] CHART_TITLE_META_RESSOURCES = { - "cruiseid", - "depth", - "coordinate" - }; - - public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { - "SHAPE", - "YORDINATE", - "GROUP1", - "GROUP2", - "GROUP3" - }; - - public static final Profile TIMESERIES_CSV_PROFILE = - new DefaultProfile( - null, - ',', - '"', - '"', - "CSV", - "ISO-8859-1"); - - /** - * Constructor - */ - public HorizontalProfileOutputTransition() { - super(); - super.domainLable = "Distance [km]"; - } - - - @Override - protected Chart getChart( - ChartLabels chartLables, - Collection parameters, - Collection measurements, - Collection dates, - Collection result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = null; - - if (CACHE_CHART) { - log.info("Try to get horizontalprofile chart from cache."); - chart = (Chart) getChartFromCache(uuid); - } - - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - chart = new HorizontalProfileChart( - chartLables, - createStyle(), - parameters, - measurements, - dates, - result, - null, - locale, - linesVisible, - shapesVisible - ); - chart.generateChart(); - - if (CACHE_CHART) { - log.info("Put chart into cache."); - purifyChart(chart, uuid); - } - - return chart; - } - - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() - */ - @Override - protected Statistics getStatisticsGenerator() { - return new HorizontalProfileStatistics(); - } - - @Override - protected void createCSV(OutputStream outputStream, - Collection chartResult) - throws UnsupportedEncodingException, - IOException, - TransitionException { - - log.debug("createCSV for HorizontalProfileOutputTransition."); - DefaultExport export = new DefaultExport( - new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES)); - - export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); - } - - - protected String createChartTitle(Locale locale, String uuid) { - String fisName = getFisName(locale); - log.debug("created title for horizontal profile chart: " + fisName); - - return fisName; - } - - - protected String createChartSubtitle(Locale locale, String uuid) { - log.debug("create chart subtitle."); - String subtitle = createTimePeriod(locale, uuid); - - // ODV results contain meta information about cruise, station and so on - Collection results = getODVResult(uuid); - if (results != null) { - Iterator iter = results.iterator(); - Result result = iter.hasNext() ? (Result) iter.next() : null; - - subtitle += subtitle.length() != 0 ? "\n" : ""; - subtitle += createMetaChartSubtitle(locale, result); - } - - return subtitle; - } - - - protected String createMetaChartSubtitle(Locale locale, Result result) { - log.debug("Fetch meta information and put it into subtitle."); - if (result == null) - return ""; - - StringBuilder meta = new StringBuilder(); - WKTReader wktReader = new WKTReader(); - - - for (int i = 0; i < CHART_TITLE_META.length; i++) { - String qry = CHART_TITLE_META[i]; - - if (qry.equals("SHAPE")) { - try { - Point p = (Point) wktReader.read(result.getString(qry)); - - meta.append(getMessage(locale,"coordinate","coordinate")); - meta.append(": "); - - log.debug( - "Add " + qry + " to meta information of subtitle: " - + p.toString() - ); - meta.append(p.getX() + ", " + p.getY()); - } - catch (ParseException pe) { - log.warn("Error while parsing point.", pe); - } - } - else { - log.debug( - "Add " + qry + " to meta information of subtitle: " - + result.getString(qry) - ); - meta.append(getMessage( - locale, - CHART_TITLE_META_RESSOURCES[i], - CHART_TITLE_META_RESSOURCES[i] - )); - meta.append(": "); - meta.append(result.getString(qry)); - } - - if (i != CHART_TITLE_META.length-1) - meta.append("\n"); - } - - log.debug("Meta title for chart: " + meta.toString()); - return meta.toString(); - } - - - protected String createTimePeriod(Locale locale, String uuid) { - log.debug("create time period for chart subtitle."); - String subTitle = null; - Date startDate = null; - Date endDate = null; - - Collection dates = getDates(uuid); - if (dates == null) { - log.debug("No time period for subtitle."); - return ""; - } - - SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); - KeyValueDescibeData data = null; - - Iterator iter = dates.iterator(); - while (iter.hasNext()) { - try { - data = (KeyValueDescibeData)iter.next(); - - if (!data.isSelected()) - continue; - - Date current = format.parse(data.getValue()); - long time = current.getTime(); - - if (startDate == null) { - startDate = current; - endDate = current; - } - else if (time < startDate.getTime()) { - startDate = current; - } - else if (time > endDate.getTime()) { - endDate = current; - } - } - catch (java.text.ParseException pe) { - log.warn("Error while parsing date: " + data.getValue(), pe); - } - } - - subTitle = format.format(startDate) + " - " + format.format(endDate); - log.debug("created title for horizontal profile chart: " + subTitle); - - return subTitle; - } -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/NorthSouthEastWestTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/NorthSouthEastWestTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.profile.horizontal; - -import java.util.ArrayList; -import java.util.Collection; - -import de.intevation.artifacts.CallMeta; -import de.intevation.gnv.artifacts.ressource.RessourceFactory; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.transition.TransitionBase; -import de.intevation.gnv.transition.describedata.DefaultKeyValueDescribeData; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; -import de.intevation.gnv.transition.describedata.NamedArrayList; -import de.intevation.gnv.transition.describedata.NamedCollection; -import de.intevation.gnv.transition.exception.TransitionException; - -/** - * @author Tim Englich - * - */ -public class NorthSouthEastWestTransition extends TransitionBase { - - - /** - * The UID of this Class - */ - private static final long serialVersionUID = -7989531326553305293L; - - /** - * Constructor - */ - public NorthSouthEastWestTransition() { - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, java.lang.String) - */ - @Override - protected void purifyResult(Collection result, String uuid) { - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#initialize(java.lang.String, de.intevation.artifacts.CallMeta) - */ - @Override - public void initialize(String uuid, CallMeta callMeta) - throws TransitionException { - Collection describeData = this.getDescibeData(uuid); - if (describeData == null) { - describeData = new ArrayList(); - } - NamedCollection keyValueDescibeData = new NamedArrayList( - this.dataName, 2); - keyValueDescibeData.setMultiSelect(super.dataMultiSelect); - keyValueDescibeData.add(new DefaultKeyValueDescribeData("IPOSITION", - RessourceFactory.getInstance().getRessource( - callMeta.getLanguages(), "iposition", "iposition"))); - keyValueDescibeData.add(new DefaultKeyValueDescribeData("JPOSITION", - RessourceFactory.getInstance().getRessource( - callMeta.getLanguages(), "jposition", "jposition"))); - describeData.add(keyValueDescibeData); - } - - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.profile.horizontalcrosssection; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Locale; - -import org.apache.log4j.Logger; - -import au.com.bytecode.opencsv.CSVWriter; -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.transition.exception.TransitionException; -import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; - -/** - * @author Tim Englich - * - */ -public class HorizontalCrossSectionMeshOutputTransition - extends TimeSeriesOutputTransition { - - private static Logger log = Logger - .getLogger(HorizontalCrossSectionMeshOutputTransition.class); - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 3233620652465061860L; - - /** - * Constructor - */ - public HorizontalCrossSectionMeshOutputTransition() { - super(); - super.domainLable = "Latitude [m]"; - } - - @Override - protected Chart getChart( - ChartLabels chartLables, - Collection parameters, - Collection measurements, - Collection dates, - Collection result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = null; - - if (CACHE_CHART) { - log.info("Try to get horizontalcrosssection chart from cache."); - chart = (Chart) getChartFromCache(uuid); - } - - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - - log.warn("This sort of chart is not implemented yet."); - /* TODO Implement a special chart for this sort of charts. - chart = new HorizontalProfileChart( - chartLables, - chartTheme, - parameters, - measurements, - result, - dates, - locale - ); - chart.generateChart(); - - if (CACHE_CHART) { - log.info("Put chart into cache."); - purifyChart(chart, uuid); - } - */ - - return chart; - } - - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() - */ - @Override - protected Statistics getStatisticsGenerator() { - return null; //Statistiken werden nicht für diesen Out-Typ unterstützt. - } - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#createCSV(java.io.OutputStream, - * java.util.Collection) - */ - @Override - protected void createCSV(OutputStream outputStream, - Collection chartResult) - throws UnsupportedEncodingException, - IOException, - TransitionException { - if (chartResult != null) { - try { - CSVWriter writer = new CSVWriter(new OutputStreamWriter( - outputStream, "ISO-8859-1"), ','); - // USE THIS ENCODING BECAUSE OF - // PROBLEMS WITH EXCEL AND UTF-8 - Iterator it = chartResult.iterator(); - while (it.hasNext()) { - Result result = it.next(); - int i = 0; - String[] entries = new String[5]; - entries[i++] = result.getString("SHAPE"); - entries[i++] = result.getString("YORDINATE"); - entries[i++] = result.getString("IPOSITION"); - entries[i++] = result.getString("JPOSITION"); - entries[i++] = result.getString("KPOSITION"); - writer.writeNext(entries); - } - writer.close(); - } catch (Exception e) { - log.error(e,e); - throw new TransitionException( - "Exception occured while parsing an Point from WKT."); - } - } else { - log.error("No Data given for generating an CSV-File."); - throw new TransitionException( - "No Data given for generating an CSV-File."); - } - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.profile.vertical; - -import java.util.Collection; -import java.util.Locale; - -import org.apache.log4j.Logger; - -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.chart.VerticalProfileChart; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.statistics.VerticalProfileStatistics; -import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; - -/** - * @author Tim Englich - * - */ -public class VerticalProfileOutputTransition extends TimeSeriesOutputTransition { - /** - * The UID of this class - */ - private static final long serialVersionUID = 4401516087492028840L; - - private static Logger log = Logger - .getLogger(TimeSeriesOutputTransition.class); - - /** - * Constructor - */ - public VerticalProfileOutputTransition() { - super(); - super.domainLable = "Depth [m]"; - } - - - @Override - protected Chart getChart( - ChartLabels chartLables, - Collection parameters, - Collection measurements, - Collection dates, - Collection result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = null; - - if (CACHE_CHART) { - log.info("Try to get verticalprofile chart from cache."); - chart = (Chart) getChartFromCache(uuid); - } - - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - chart = new VerticalProfileChart( - chartLables, - this.createStyle(), - parameters, - measurements, - dates, - result, - null, - locale, - linesVisible, - shapesVisible - ); - chart.generateChart(); - - if (CACHE_CHART) { - log.info("Put chart into cache."); - purifyChart(chart, uuid); - } - - return chart; - } - - - protected String createChartSubtitle(Locale locale, String uuid) { - return getSelectedFeatureName(uuid); - } - - - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() - */ - @Override - protected Statistics getStatisticsGenerator() { - return new VerticalProfileStatistics(); - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/verticalcrosssection/VerticalCrossSectionOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/verticalcrosssection/VerticalCrossSectionOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.profile.verticalcrosssection; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Locale; - -import org.apache.log4j.Logger; - -import au.com.bytecode.opencsv.CSVWriter; - -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; - -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.chart.ChartStyle; -import de.intevation.gnv.chart.VerticalCrossSectionChartFactory; -import de.intevation.gnv.chart.exception.TechnicalChartException; -import de.intevation.gnv.geobackend.base.Result; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.statistics.VerticalProfileStatistics; -import de.intevation.gnv.transition.describedata.KeyValueDescibeData; -import de.intevation.gnv.transition.exception.TransitionException; -import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; - -/** - * @author Tim Englich - * - */ -public class VerticalCrossSectionOutputTransition extends TimeSeriesOutputTransition { - - private static Logger log = Logger - .getLogger(VerticalCrossSectionOutputTransition.class); - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 3233620652465061860L; - - /** - * Constructor - */ - public VerticalCrossSectionOutputTransition() { - super(); - super.domainLable = "Depth [m]"; - } - - @Override - protected Chart getChart( - ChartLabels chartLables, - Collection parameters, - Collection measurements, - Collection dates, - Collection result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = null; - - if (CACHE_CHART) { - log.info("Try to get verticalcrosssection chart from cache."); - chart = (Chart) getChartFromCache(uuid); - } - - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - - log.warn("This sort of chart is not implemented yet."); - /* TODO Implement a special chart for this sort of charts. - chart = new VerticalProfileChart( - chartLables, - chartTheme, - parameters, - measurements, - result, - dates, - locale - ); - chart.generateChart(); - - if (CACHE_CHART) { - log.info("Put chart into cache."); - purifyChart(chart, uuid); - } - */ - - return chart; - } - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#createChart(java.io.OutputStream, - * java.util.Collection, java.util.Collection, java.lang.String, - * de.intevation.gnv.chart.ChartStyle, - * de.intevation.gnv.chart.ChartLabels) - */ - /* - @Override - protected void createChart(OutputStream outputStream, - Collection parameters, - Collection measurements, - Collection dates, - ChartStyle chartStyle, ChartLabels chartLables, - String uuid) throws IOException, - TechnicalChartException { - new VerticalCrossSectionChartFactory().createProfileChart(chartLables, - chartStyle, parameters, measurements, dates, outputStream, this - .getChartResult(uuid)); - } - */ - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() - */ - @Override - protected Statistics getStatisticsGenerator() { - return new VerticalProfileStatistics(); - } - - /** - * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#createCSV(java.io.OutputStream, java.util.Collection) - */ - @Override - protected void createCSV(OutputStream outputStream, - Collection chartResult) - throws UnsupportedEncodingException, - IOException, - TransitionException { - if (chartResult != null) { - try { - CSVWriter writer = new CSVWriter(new OutputStreamWriter( - outputStream, "ISO-8859-1"), ','); - // USE THIS ENCODING BECAUSE OF - // PROBLEMS WITH EXCEL AND UTF-8 - Iterator it = chartResult.iterator(); - WKTReader wktReader = new WKTReader(); - while (it.hasNext()) { - Result result = it.next(); - int i = 0; - String[] entries = new String[8]; - Point p = (Point)wktReader.read(result.getString("SHAPE")); - entries[i++] = ""+p.getX(); - entries[i++] = ""+p.getY(); - entries[i++] = result.getString("YORDINATE"); - entries[i++] = result.getString("GROUP1"); - entries[i++] = result.getString("GROUP2"); - entries[i++] = result.getString("IPOSITION"); - entries[i++] = result.getString("JPOSITION"); - entries[i++] = result.getString("KPOSITION"); - writer.writeNext(entries); - } - writer.close(); - } catch (ParseException e) { - log.error(e,e); - throw new TransitionException( - "Exception occured while parsing an Point from WKT."); - } - } else { - log.error("No Data given for generating an CSV-File."); - throw new TransitionException( - "No Data given for generating an CSV-File."); - } - } - -} diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Dec 07 17:03:24 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,835 +0,0 @@ -/** - * - */ -package de.intevation.gnv.transition.timeseries; - -import java.io.IOException; -import java.io.File; -import java.io.OutputStream; -import java.io.FileOutputStream; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Vector; - -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -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 org.jfree.chart.ChartTheme; - -import au.com.bytecode.opencsv.CSVWriter; -import de.intevation.artifactdatabase.Config; -import de.intevation.artifactdatabase.XMLUtils; -import de.intevation.artifacts.CallMeta; -import de.intevation.artifacts.PreferredLocale; -import de.intevation.gnv.artifacts.ressource.RessourceFactory; -import de.intevation.gnv.chart.Chart; -import de.intevation.gnv.chart.ChartLabels; -import de.intevation.gnv.chart.TimeSeriesChart; -import de.intevation.gnv.chart.XMLChartTheme; -import de.intevation.gnv.chart.exception.TechnicalChartException; -import de.intevation.gnv.exports.ChartExportHelper; -import de.intevation.gnv.exports.DefaultExport; -import de.intevation.gnv.exports.DefaultDataCollector; -import de.intevation.gnv.exports.SimpleOdvDataCollector; -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.StatisticSet; -import de.intevation.gnv.statistics.Statistics; -import de.intevation.gnv.statistics.TimeseriesStatistics; -import de.intevation.gnv.statistics.exception.StatisticsException; -import de.intevation.gnv.timeseries.gap.DefaultTimeGap; -import de.intevation.gnv.timeseries.gap.TimeGap; -import de.intevation.gnv.transition.InputData; -import de.intevation.gnv.transition.OutputTransitionBase; -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.utils.ArtifactXMLUtilities; - - -/** - * @author Tim Englich - * - */ -public class TimeSeriesOutputTransition extends OutputTransitionBase { - - protected static final boolean CACHE_CHART = - Boolean.parseBoolean(System.getProperty("cache.chart", "false")); - - protected static final boolean PDF_FORMAT_LANDSCAPE = - Boolean.parseBoolean(System.getProperty("export.pdf.landscape","true")); - - protected static final String[] IMG_EXPORT_FORMAT = { - "PNG", "JPEG", "GIF" - }; - - /** - * The UID of this Class - */ - private static final long serialVersionUID = 4178407570503098858L; - - /** - * the logger, used to log exceptions and additonaly information - */ - private static Logger log = Logger - .getLogger(TimeSeriesOutputTransition.class); - - private static List timeGapDefinitions = null; - - protected String domainLable = "Zeit [UTC]"; - - protected String featureValuesName = "featureid"; - protected String parameterValuesName = "parameterid"; - protected String measuremenValueName = "measurementid"; - protected String dateValueName = "dateid"; - - public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { - "XORDINATE", - "YORDINATE", - "GROUP1", - "GROUP2", - "GROUP3" - }; - - public static final String [] TIMESERIES_ODV_PROFILE_NAMES = { - "CRUISE", - "STATION", - "TYPE", - "SHAPE", - "BOTDEPTH", - "DEPTH", - "TIMEVALUE", - "DATAVALUE", - "PARAMETER" - }; - - - public static final String [] ODV_COLUMN_HEADER = { - "Cruise", - "Station", - "Type", - "Longitude [deegrees_east]", - "Latitude [deegrees_north]", - "Bot. Depth [m]", - "Depth [m]", - "Date/Time", - "Value", - "Parameterid" - }; - - /** - * Profile for exporting data to cvs - */ - public static final Profile TIMESERIES_CSV_PROFILE = - new DefaultProfile( - null, - ',', - '"', - '"', - "CSV", - "ISO-8859-1"); - - /** - * Profile for exporting data to odv - * TODO Change TIMESERIES_PROFILE_NAMES, which belong to CSV exports - */ - public static final Profile TIMESERIES_ODV_PROFILE = - new DefaultProfile( - ODV_COLUMN_HEADER, - '\t', - CSVWriter.NO_QUOTE_CHARACTER, - CSVWriter.NO_ESCAPE_CHARACTER, - "ODV", - "ISO-8859-1"); - - /** - * Constructor - */ - public TimeSeriesOutputTransition() { - super(); - } - - /** - * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, - * java.util.Collection, java.io.OutputStream, java.lang.String, - * de.intevation.artifacts.CallMeta) - */ - public void out( - Document format, - Collection inputData, - OutputStream outputStream, - String uuid, - CallMeta callMeta - ) throws TransitionException - { - log.debug("TimeSeriesOutputTransition.out"); - - String outputMode = Config.getStringXPath( - format, - "action/out/@name" - ); - String mimeType = Config.getStringXPath( - format, - "action/out/mime-type/@value" - ); - - try { - if (outputMode.equalsIgnoreCase("chart")) { - log.debug("Chart will be generated."); - int chartWidth = 600; - int chartHeight = 400; - try { - if (inputData != null) { - Iterator it = inputData.iterator(); - while (it.hasNext()) { - InputData ip = it.next(); - if (ip.getName().equalsIgnoreCase("width")) { - chartWidth = Integer.parseInt(ip.getValue()); - } else if (ip.getName().equalsIgnoreCase("height")) { - chartHeight = Integer.parseInt(ip.getValue()); - } - } - } - } catch (NumberFormatException e) { - log.error(e, e); - throw new TransitionException(e); - } - - PreferredLocale[] locales = callMeta.getLanguages(); - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - Collection parameters = this.getCleanedParameters(uuid); - Collection measurements = this.getMeasurements(uuid); - Collection dates = this.getDates(uuid); - - ChartLabels chartLables = new ChartLabels( - createChartTitle(locale, uuid), - createChartSubtitle(locale, uuid), - domainLable - ); - - String exportFormat = getExportFormat(mimeType); - - // TODO Remove this and parse input data - boolean linesVisible = true; - boolean shapesVisible = true; - - this.createChart( - outputStream, - parameters, - measurements, - dates, - chartLables, - uuid, - exportFormat, - locale, - chartWidth, - chartHeight, - linesVisible, - shapesVisible - ); - } - else if (outputMode.equalsIgnoreCase("pdf")) { - log.debug("Output mode == pdf"); - - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - // TODO Remove this and parse input data - boolean linesVisible = true; - boolean shapesVisible = true; - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - createPDF( - outputStream, - getCleanedParameters(uuid), - getMeasurements(uuid), - getDates(uuid), - new ChartLabels( - createChartTitle(locale, uuid), - createChartSubtitle(locale, uuid), - domainLable), - uuid, - "A4", - true, - locale, - linesVisible, - shapesVisible - ); - } - else if (outputMode.equalsIgnoreCase("svg")) { - log.debug("Output mode == svg"); - int width = 600; - int height = 400; - - // TODO Remove this and parse input data - boolean linesVisible = true; - boolean shapesVisible = true; - - Locale[] serverLocales = - RessourceFactory.getInstance().getLocales(); - Locale locale = - callMeta.getPreferredLocale(serverLocales); - - log.debug( - "Best locale - regarding intersection of server and " + - "browser locales - is " + locale.toString() - ); - - createSVG( - outputStream, - getCleanedParameters(uuid), - getMeasurements(uuid), - getDates(uuid), - new ChartLabels( - createChartTitle(locale, uuid), - createChartSubtitle(locale, uuid), - domainLable - ), - uuid, - locale, - width, - height, - linesVisible, - shapesVisible - ); - } - else if (outputMode.equalsIgnoreCase("csv")) { - log.debug("CSV-File will be generated."); - Collection chartResult = this.getChartResult(uuid); - this.createCSV(outputStream, chartResult); - } else if (outputMode.equalsIgnoreCase("statistics")) { - log.debug("Statistics will be generated."); - Statistics s = getStatisticsGenerator(); - Collection chartResult = this.getChartResult(uuid); - Collection parameters = - this.getParameters(uuid); - Collection measurements = - this.getMeasurements(uuid); - Collection dates = - this.getDates(uuid); - Collection statistics = - s.calculateStatistics(chartResult, - parameters, - measurements, - dates); - Document doc = this.writeStatistics2XML(statistics); - this.writeDocument2OutputStream(doc, outputStream); - } else if (outputMode.equalsIgnoreCase("odv")) { - - Collection odvResult = this.getODVResult(uuid); - this.createODV(outputStream, odvResult); - } - } catch (IOException e) { - log.error(e, e); - throw new TransitionException(e); - } catch (TechnicalChartException e) { - log.error(e, e); - throw new TransitionException(e); - } catch (StatisticsException e) { - log.error(e, e); - throw new TransitionException(e); - } - } - - - protected String getExportFormat(String mime) { - for(int i = 0; i < IMG_EXPORT_FORMAT.length; i++) { - if (mime.trim().toUpperCase().indexOf(IMG_EXPORT_FORMAT[i]) > 0) - return IMG_EXPORT_FORMAT[i]; - } - - // no format found relating to mimeType, default export as PNG - return IMG_EXPORT_FORMAT[0]; - } - - - protected Collection getCleanedParameters(Collection parameters) { - Iterator iter = parameters.iterator(); - Collection parameter = new Vector(parameters); - while (iter.hasNext()) { - KeyValueDescibeData data = (KeyValueDescibeData)iter.next(); - if (!data.isSelected()) - parameter.remove(data); - } - - return parameter; - } - - - protected Collection getCleanedParameters(String uuid) { - return getCleanedParameters(getParameters(uuid)); - } - - - /** - * @param outputStream - * @param chartResult - * @throws UnsupportedEncodingException - * @throws IOException - * @throws TransitionException - */ - protected void createCSV(OutputStream outputStream, - Collection chartResult) - throws UnsupportedEncodingException, - IOException, - TransitionException { - DefaultExport export = new DefaultExport(new DefaultDataCollector( - TIMESERIES_CSV_PROFILE_NAMES)); - - export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); - } - - /** - * TODO Result is not used at the moment. Change result with correct data. - */ - protected void createODV(OutputStream outputStream, Collection result) - throws IOException, TransitionException { - - DefaultExport export = new DefaultExport(new SimpleOdvDataCollector( - TIMESERIES_ODV_PROFILE_NAMES)); - - if (result == null) - log.error("#################### RESULT == NULL #################"); - export.create(TIMESERIES_ODV_PROFILE, outputStream, result); - } - - /** - * @return - */ - protected Statistics getStatisticsGenerator() { - Statistics s = new TimeseriesStatistics(); - return s; - } - - protected void writeDocument2OutputStream(Document document, OutputStream os) { - - try { - TransformerFactory transformerFactory = TransformerFactory - .newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - DOMSource source = new DOMSource(document); - StreamResult result = new StreamResult(os); - transformer.transform(source, result); - } catch (TransformerConfigurationException e) { - log.error(e, e); - } catch (TransformerFactoryConfigurationError e) { - log.error(e, e); - } catch (TransformerException e) { - log.error(e, e); - } - } - - protected Document writeStatistics2XML( Collection statistic) { - ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); - Document doc = XMLUtils.newDocument(); - if (statistic != null) { - Node statisticResults = xmlUtilities.createArtifactElement(doc, - "statistics"); - doc.appendChild(statisticResults); - Iterator it = statistic.iterator(); - while (it.hasNext()) { - StatisticSet set = it.next(); - Element setElement = xmlUtilities.createArtifactElement(doc, - "statistic"); - setElement.setAttribute("name", set.getName()); - - Iterator sit = set.getStatistics().iterator(); - while (sit.hasNext()){ - Statistic s = sit.next(); - Element result = xmlUtilities.createArtifactElement(doc, - "statistic-value"); - result.setAttribute("name", s.getKey()); - result.setAttribute("value", s.getStringValue()); - setElement.appendChild(result); - } - statisticResults.appendChild(setElement); - } - - } - return doc; - } - - - protected String getSelectedFeatureName(String uuid) { - Collection values = getCollection(featureValuesName, uuid); - - if (values != null) { - Iterator it = values.iterator(); - - while (it.hasNext()) { - KeyValueDescibeData data = (KeyValueDescibeData) it.next(); - - if (data.isSelected()) { - return data.getValue(); - } - } - } - return null; - } - - - /** - * @param outputStream - * @param parameters - * @param measurements - * @param timeSeriesName - * @param chartStyle - * @param chartLables - * @throws IOException - * @throws TechnicalChartException - */ - protected void createChart( - OutputStream outputStream, - Collection parameters, - Collection measurements, - Collection dates, - ChartLabels chartLables, - String uuid, - String exportFormat, - Locale locale, - int width, - int height, - boolean linesVisible, - boolean shapesVisible - ) - throws IOException, TechnicalChartException - { - log.debug("Create chart."); - Chart chart = getChart( - chartLables, - parameters, - measurements, - dates, - getChartResult(uuid), - locale, // Locale - uuid, - linesVisible, - shapesVisible - ); - - if (chart == null) { - log.error("Could not initialize chart."); - return; - } - - log.debug( - "export chart as " + exportFormat + - " in " + width + "x" + height - ); - - ChartExportHelper.exportImage( - outputStream, - chart.generateChart(), - exportFormat, - width, - height - ); - } - - - protected void createPDF( - OutputStream outputStream, - Collection parameters, - Collection measurements, - Collection dates, - ChartLabels chartLables, - String uuid, - String exportFormat, - boolean landscape, - Locale locale, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = getChart( - chartLables, - parameters, - measurements, - dates, - getChartResult(uuid), - locale, - uuid, - linesVisible, - shapesVisible - ); - - if (chart == null) { - log.error("Could not initialize chart."); - return; - } - - ChartExportHelper.exportPDF( - outputStream, - chart.generateChart(), - "A4", - PDF_FORMAT_LANDSCAPE, - 50F, 50F, 50F, 50F - ); - - try { - OutputStream toFile = new FileOutputStream("/vol1/home/iweinzierl/tmp/test.svg"); - ChartExportHelper.exportSVG( - toFile, - chart.generateChart(), - null, - 600, 400 - ); - toFile.flush(); - toFile.close(); - } - catch(Exception e) { log.debug("ERROR WHLILE TEST."); } - } - - - protected void createSVG( - OutputStream outputStream, - Collection parameters, - Collection measurements, - Collection dates, - ChartLabels chartLables, - String uuid, - Locale locale, - int width, - int height, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = getChart( - chartLables, - parameters, - measurements, - dates, - getChartResult(uuid), - locale, - uuid, - linesVisible, - shapesVisible - ); - - if (chart == null) { - log.error("Could not initialize chart."); - return; - } - - ChartExportHelper.exportSVG( - outputStream, - chart.generateChart(), - null, - 600, 400 - ); - - log.debug("svg export finished."); - } - - - protected Chart getChart( - ChartLabels chartLables, - Collection parameters, - Collection measurements, - Collection dates, - Collection result, - Locale locale, - String uuid, - boolean linesVisible, - boolean shapesVisible - ) { - Chart chart = null; - - if (CACHE_CHART) { - log.info("Try to get timeseries chart from cache."); - chart = (Chart) getChartFromCache(uuid); - } - - if (chart != null) - return chart; - - log.info("Chart not in cache yet."); - chart = new TimeSeriesChart( - chartLables, - createStyle(), - parameters, - measurements, - dates, - result, - timeGapDefinitions, - locale, - linesVisible, - shapesVisible - ); - chart.generateChart(); - - if (CACHE_CHART) { - log.info("Put chart into cache."); - purifyChart(chart, uuid); - } - - return chart; - } - - protected ChartTheme createStyle() { - XMLChartTheme theme = null; - - Document template = Config.getChartTemplate(); - String name = Config.getStringXPath( - template, - "theme/name/@value" - ); - - theme = new XMLChartTheme(name); - theme.applyXMLConfiguration(template); - - return theme; - } - - - protected String createChartTitle(Locale locale, String uuid) { - return getFisName(locale); - - } - - - protected String createChartSubtitle(Locale locale, String uuid) { - return getSelectedFeatureName(uuid); - } - - - protected String getFisName(Locale locale) { - String returnValue = ""; - InputData input = inputData.get("fisname"); - - if (input != null) { - String value = input.getValue(); - - returnValue = RessourceFactory.getInstance().getRessource( - locale, - value, - value - ); - } - return returnValue; - } - - - protected Collection getParameters(String uuid) { - return this.getCollection(parameterValuesName, uuid); - } - - protected Collection getMeasurements(String uuid) { - return this.getCollection(measuremenValueName, uuid); - } - protected Collection getDates(String uuid) { - return this.getCollection(dateValueName,uuid); - } - - @Override - public void setup(Node configuration) { - super.setup(configuration); - String featureNameValue = Config.getStringXPath(configuration, - "value-names/value-name[@name='feature']/@value"); - if (featureNameValue != null) { - this.featureValuesName = featureNameValue; - } - String parameterNameValue = Config.getStringXPath(configuration, - "value-names/value-name[@name='parameter']/@value"); - if (parameterNameValue != null) { - this.parameterValuesName = parameterNameValue; - } - String measurementNameValue = Config.getStringXPath(configuration, - "value-names/value-name[@name='measurement']/@value"); - if (measurementNameValue != null) { - this.measuremenValueName = measurementNameValue; - } - - String dateNameValue = Config.getStringXPath(configuration, - "value-names/value-name[@name='date']/@value"); - if (dateNameValue != null) { - this.dateValueName = dateNameValue; - } - if (timeGapDefinitions == null){ - Element gapDefinition = (Element)Config.getNodeXPath(configuration, - "time-gap-definition"); - synchronized (this.getClass()) { - if (gapDefinition != null){ - String link = gapDefinition.getAttribute("xlink:href"); - if (link != null ){ - String absolutFileName = Config.replaceConfigDir(link); - gapDefinition = (Element)new ArtifactXMLUtilities(). - readConfiguration(absolutFileName); - } - - NodeList gapDefinitions = Config.getNodeSetXPath(gapDefinition, - "/time-gaps/time-gap"); - if (gapDefinition != null){ - timeGapDefinitions = new ArrayList(gapDefinitions. - getLength()); - for (int i = 0; i < gapDefinitions.getLength(); i++){ - Element gapNode = (Element)gapDefinitions.item(i); - String unit = gapNode.getAttribute("unit"); - int key = Integer.parseInt(gapNode.getAttribute("key")); - int value = Integer.parseInt(gapNode.getAttribute("gap")); - log.info("Add new Timegap: "+key+" "+value+" "+ unit); - timeGapDefinitions.add(new DefaultTimeGap(unit, - key, - value)); - } - } - - } - } - } - } - - /** - * @param collectionName - * @return - */ - protected Collection getCollection( - String collectionName, - String uuid) { - Iterator it = this.getDescibeData(uuid).iterator(); - while (it.hasNext()) { - - Object o = it.next(); - - if (o instanceof NamedCollection) { - NamedCollection nc = (NamedCollection) o; - if (nc.getName().equals(collectionName)) { - return nc; - } - } - } - return null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Tue Dec 08 08:39:03 2009 +0000 @@ -28,7 +28,6 @@ import org.xml.sax.SAXException; import de.intevation.artifacts.ArtifactNamespaceContext; -import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; /** * @author Tim Englich @@ -44,7 +43,7 @@ * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger - .getLogger(TimeSeriesOutputTransition.class); + .getLogger(ArtifactXMLUtilities.class); public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; public static final String XFORM_PREFIX = "xform"; diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_10_feed.xml --- a/gnv-artifacts/src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_10_feed.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/horizontalProfile_mesh/horizontalprofile_step_10_feed.xml Tue Dec 08 08:39:03 2009 +0000 @@ -4,7 +4,7 @@ - - + + \ No newline at end of file diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_08_feed.xml --- a/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_08_feed.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/timeseries_mesh/timeseries_step_08_feed.xml Tue Dec 08 08:39:03 2009 +0000 @@ -4,7 +4,7 @@ - - + + \ No newline at end of file diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_feed.xml --- a/gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_feed.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_feed.xml Tue Dec 08 08:39:03 2009 +0000 @@ -4,6 +4,6 @@ - + \ No newline at end of file diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_feed.xml --- a/gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_feed.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_feed.xml Tue Dec 08 08:39:03 2009 +0000 @@ -4,6 +4,6 @@ - + \ No newline at end of file diff -r e37930705daa -r e964a3d8f7bc gnv-artifacts/src/test/ressources/verticalprofile_mesh/verticalprofile_step_10_feed.xml --- a/gnv-artifacts/src/test/ressources/verticalprofile_mesh/verticalprofile_step_10_feed.xml Mon Dec 07 17:03:24 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/verticalprofile_mesh/verticalprofile_step_10_feed.xml Tue Dec 08 08:39:03 2009 +0000 @@ -4,7 +4,7 @@ - - + + \ No newline at end of file