- Timestamp:
- 08/18/11 12:39:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/web/src/com/ether/ControllerPlot.java
r129 r130 8 8 import org.apache.commons.logging.LogFactory; 9 9 import org.jetbrains.annotations.NotNull; 10 import org.jetbrains.annotations.Nullable; 10 11 import org.springframework.context.ApplicationContext; 11 12 import org.springframework.web.context.support.WebApplicationContextUtils; … … 19 20 import java.awt.image.BufferedImage; 20 21 import java.io.IOException; 21 import java.text.ParseException; 22 import java.util.ArrayList; 23 import java.util.Calendar; 22 24 import java.util.Date; 23 25 import java.util.List; … … 57 59 throws ServletException 58 60 { 61 boolean flagException = false; 62 59 63 try 60 64 { 65 //Parameters 61 66 final Integer plateformId = Integer.valueOf( request.getParameter( "plateformId" ) ); 62 67 final Integer parameterId = Integer.valueOf( request.getParameter( "parameterId" ) ); 68 final String title = request.getParameter( "title" ); 69 final String axeType = request.getParameter( "axeType" ); 70 63 71 final String dateBegin = request.getParameter( "dateBegin" ); 64 72 final String dateEnd = request.getParameter( "dateEnd" ); 65 final String pofBegin = "2009-07-13 13:00"; 66 final String pofEnd = "2009-07-14 14:00"; 67 final Date formatedDateBegin = DateHelper.parseDate( pofBegin, DateHelper.ENGLISH_DATE_PATTERN ); 68 final Date formatedDateEnd = DateHelper.parseDate( pofEnd, DateHelper.ENGLISH_DATE_PATTERN ); 73 final Calendar calendar = Calendar.getInstance(); 74 final Date formatedDateBegin; 75 final Date formatedDateEnd; 76 try 77 { 78 calendar.setTimeInMillis( Long.valueOf( dateBegin ) ); 79 formatedDateBegin = calendar.getTime(); 80 calendar.setTimeInMillis( Long.valueOf( dateEnd ) ); 81 formatedDateEnd = calendar.getTime(); 82 } 83 catch( Exception e ) 84 { 85 createErrorPane( response, request, WebException.WebCode.INVALID_DATE.toString(), e ); 86 flagException = true; 87 throw new ServletException( WebException.WebCode.INVALID_DATE.toString(), e ); 88 } 69 89 90 // Create plot 70 91 //** ******************************************************************** **// 71 92 // TODO : replace List<Data> by List<value> and List<double> 72 93 //** ******************************************************************** **// 73 final List<Pair<Double, Date>> values = _etherService.getValuesByPlateformByParameterByPeriod( plateformId, parameterId, formatedDateBegin, formatedDateEnd ); 94 // final List<Pair<Double, Date>> values = _etherService.getValuesByPlateformByParameterByPeriod( plateformId, parameterId, formatedDateBegin, formatedDateEnd ); 95 final List<Pair<Double, Date>> values = new ArrayList<Pair<Double, Date>>(); 96 final Pair<Double, Date> p1 = new Pair<Double, Date>( Double.valueOf( 23 ), new Date() ); 97 final Pair<Double, Date> p2 = new Pair<Double, Date>( Double.valueOf( 24 ), new Date() ); 98 final Pair<Double, Date> p3 = new Pair<Double, Date>( Double.valueOf( 25 ), new Date() ); 99 final Pair<Double, Date> p4 = new Pair<Double, Date>( Double.valueOf( 26 ), new Date() ); 100 values.add( p1 ); 101 values.add( p2 ); 102 values.add( p3 ); 103 values.add( p4 ); 74 104 final double[] dataArray = extractDoubles( values ); 75 105 final Date[] dateValues = extractDates( values ); … … 88 118 89 119 final MegapoliPlot megapoliPlot = new MegapoliPlot(); 90 megapoliPlot.setTitle( "Mobilis LIDAR");120 megapoliPlot.setTitle( title ); 91 121 megapoliPlot.setData( data ); 92 122 93 final BufferedImage bufferedImage = _etherPlotService.createJPane( megapoliPlot, Context.getLocale( request ) ); 94 123 final BufferedImage bufferedImage = _etherPlotService.createMainPane( megapoliPlot, Context.getLocale( request ) ); 95 124 ImageIO.write( bufferedImage, "png", response.getOutputStream() ); 96 125 } 97 catch( IOException e)126 catch( Exception e1 ) 98 127 { 99 throw new ServletException( "Error : no possibity to write image in response", e ); 128 try 129 { 130 if( !flagException ) 131 createErrorPane( response, request, "", e1 ); 132 } 133 catch( Exception e2 ) 134 { 135 throw new ServletException( "Error : no possibity to write image in response", e2 ); 136 } 100 137 } 101 catch( ServiceException e ) 102 { 103 throw new ServletException( "Error : no possibility to extract data from base", e ); 104 } 105 catch( ParseException e ) 106 { 107 throw new ServletException( "Error : invalid dates, no parsing available", e ); 108 } 138 } 139 140 private void createErrorPane( final HttpServletResponse response, final HttpServletRequest request, @NotNull final String mainError, @NotNull final Exception e ) 141 throws IOException 142 { 143 final BufferedImage errorImage = _etherPlotService.createErrorPane( mainError, e.toString(), Context.getLocale( request ) ); 144 ImageIO.write( errorImage, "png", response.getOutputStream() ); 109 145 } 110 146 … … 137 173 private static final Log LOGGER = LogFactory.getLog( ControllerPlot.class ); 138 174 139 // Dimensions of the jPanes140 private static final int MAIN_WIDTH = 1000;141 private static final int MAIN_HEIGHT = 1000;142 143 175 private EtherService _etherService; 144 176 private EtherPlotService _etherPlotService;
Note: See TracChangeset
for help on using the changeset viewer.