@Test public void testCreateParentFolder() { String filename = getTestDirectory() + "/" + "testfile.csv"; MasterReport report = Mockito.mock( MasterReport.class ); ModifiableConfiguration conf = Mockito.spy( new DefaultConfiguration() ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.csv.FileName", filename ); conf.setConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.gui.csv.CreateParentFolder", "true" ); Mockito.doReturn(conf).when(report).getConfiguration(); File file = null; File directory; try { file = new File( filename ).getCanonicalFile(); directory = file.getParentFile(); if ( directory != null ) { if ( directory.exists() == true ) { directory.delete(); } } Assert.assertFalse( directory.exists() ); CSVTableExportTask task = new CSVTableExportTask( report, null, null ); task.run(); } catch (Exception e1) { e1.printStackTrace(); } directory = file.getParentFile(); Assert.assertTrue( directory != null ); Assert.assertTrue( directory.exists() ); file.delete(); directory.delete(); }
public void run() { OutputStream out = null; final File file = new File( fileName ); try { if ( createParentFolder ) { final File directory = file.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { CSVTableExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportProcessor reportProcessor; ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor( out ); reportProcessor = new StreamReportProcessor( report, target ); } else { reportProcessor = new FastCsvExportProcessor( report, out ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_COMPLETE" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { CSVTableExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { CSVTableExportTask.logger.error( "Exporting failed .", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "CSVTableExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { CSVTableExportTask.logger.error( "Unable to close the output stream.", e ); } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } }
CSVTableExportTask implements Runnable { public void run() { OutputStream out = null; final File file = new File( fileName ); try { if ( createParentFolder ) { final File directory = file.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { CSVTableExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportProcessor reportProcessor; ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor( out ); reportProcessor = new StreamReportProcessor( report, target ); } else { reportProcessor = new FastCsvExportProcessor( report, out ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_COMPLETE" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { CSVTableExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { CSVTableExportTask.logger.error( "Exporting failed .", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "CSVTableExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { CSVTableExportTask.logger.error( "Unable to close the output stream.", e ); } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } } }
CSVTableExportTask implements Runnable { public void run() { OutputStream out = null; final File file = new File( fileName ); try { if ( createParentFolder ) { final File directory = file.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { CSVTableExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportProcessor reportProcessor; ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor( out ); reportProcessor = new StreamReportProcessor( report, target ); } else { reportProcessor = new FastCsvExportProcessor( report, out ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_COMPLETE" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { CSVTableExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { CSVTableExportTask.logger.error( "Exporting failed .", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "CSVTableExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { CSVTableExportTask.logger.error( "Unable to close the output stream.", e ); } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } } CSVTableExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); }
CSVTableExportTask implements Runnable { public void run() { OutputStream out = null; final File file = new File( fileName ); try { if ( createParentFolder ) { final File directory = file.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { CSVTableExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportProcessor reportProcessor; ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor( out ); reportProcessor = new StreamReportProcessor( report, target ); } else { reportProcessor = new FastCsvExportProcessor( report, out ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_COMPLETE" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { CSVTableExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { CSVTableExportTask.logger.error( "Exporting failed .", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "CSVTableExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { CSVTableExportTask.logger.error( "Unable to close the output stream.", e ); } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } } CSVTableExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); void run(); }
CSVTableExportTask implements Runnable { public void run() { OutputStream out = null; final File file = new File( fileName ); try { if ( createParentFolder ) { final File directory = file.getAbsoluteFile().getParentFile(); if ( directory != null ) { if ( directory.exists() == false ) { if ( directory.mkdirs() == false ) { CSVTableExportTask.logger.warn( "Can't create directories. Hoping and praying now.." ); } } } } out = new BufferedOutputStream( new FileOutputStream( file ) ); ReportProcessor reportProcessor; ReportStructureValidator validator = new ReportStructureValidator(); if ( validator.isValidForFastProcessing( report ) == false ) { final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor( out ); reportProcessor = new StreamReportProcessor( report, target ); } else { reportProcessor = new FastCsvExportProcessor( report, out ); } if ( progressDialog != null ) { progressDialog.setModal( false ); progressDialog.setVisible( true ); reportProcessor.addReportProgressListener( progressDialog ); } reportProcessor.processReport(); out.close(); out = null; if ( progressDialog != null ) { reportProcessor.removeReportProgressListener( progressDialog ); } if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_COMPLETE" ), null ); } } catch ( ReportInterruptedException re ) { if ( statusListener != null ) { statusListener.setStatus( StatusType.INFORMATION, messages.getString( "CSVTableExportTask.USER_TASK_ABORTED" ), null ); } try { out.close(); out = null; if ( file.delete() == false ) { CSVTableExportTask.logger.warn( "Unable to delete incomplete export:" + file ); } } catch ( SecurityException se ) { } catch ( IOException ioe ) { } } catch ( Exception re ) { CSVTableExportTask.logger.error( "Exporting failed .", re ); if ( statusListener != null ) { statusListener.setStatus( StatusType.ERROR, messages.getString( "CSVTableExportTask.USER_TASK_FAILED" ), re ); } } finally { try { if ( out != null ) { out.close(); } } catch ( Exception e ) { CSVTableExportTask.logger.error( "Unable to close the output stream.", e ); } if ( progressDialog != null ) { progressDialog.setVisible( false ); } } } CSVTableExportTask( final MasterReport report, final ReportProgressDialog dialog,
      final SwingGuiContext swingGuiContext ); void run();  }