Package org.eclipse.birt.report.engine.api

Examples of org.eclipse.birt.report.engine.api.IRunTask


            TimeZone timeZone, Map parameters, Map displayTexts, Integer maxRows)
            throws RemoteException {
        assert runnable != null;

        // Prepare the run report task.
        IRunTask runTask = null;
        try {
            runTask = BirtContainer.getReportEngine().createRunTask(runnable);
        } catch (Exception e) {
            throwDummyException(e);
        }
        runTask.setLocale(locale);

        com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone(timeZone);
        if (tz != null) {
            runTask.setTimeZone(tz);
        }

        runTask.setParameterValues(parameters);

        // set MaxRows settings
        if (maxRows != null) {
            runTask.setMaxRowsPerQuery(maxRows.intValue());
        }

        // add task into session
        BirtUtility.addTask(request, runTask);

        // Set display Text for select parameters
        if (displayTexts != null)
        {
            Iterator keys = displayTexts.keySet().iterator();
            while (keys.hasNext()) {
                String paramName = DataUtil.getString(keys.next());
                String displayText = DataUtil.getString(displayTexts.get(paramName));
                runTask.setParameterDisplayText(paramName, displayText);
            }
        }

        // set app context
        Map context = BirtUtility.getAppContext(request);
        runTask.setAppContext(context);

        // Run report.
        try {
            runTask.run(documentName);
        } catch (BirtException e) {
            // clear document file
            File doc = new File(documentName);
            if (doc != null) {
                doc.delete();
            }
            throwDummyException(e);
        } finally {
            // Remove task from http session
            BirtUtility.removeTask(request);

            // Append errors
            if (ParameterAccessor.isDesigner()) {
                BirtUtility.error(request, runTask.getErrors());
            }

            runTask.close();

            // check for non-fatal errors
            List<Exception> errors = UtilGenerics.cast(runTask.getErrors());
            if (!errors.isEmpty()) {
                return errors;
            }
        }
        return null;
View Full Code Here


  public static void createPdf() throws EngineException {

    initEngine();

    // Create task to run the report - use the task to execute and run the report,
    IRunTask runTask = engine.createRunTask(runnable);

    // Create rptdocument
    File document = createTempFile(fileFolder);
    runTask.run(document.getAbsolutePath());

    // Open rptdocument
    IReportDocument rptdoc = engine.openReportDocument(document.getAbsolutePath());

    // Create Render Task
    IRenderTask renderTask = engine.createRenderTask(rptdoc);

    PDFRenderOption optionsPDF = new PDFRenderOption();
    optionsPDF.setOutputFileName("D:/Temp/output.pdf");
    optionsPDF.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
    renderTask.setRenderOption(optionsPDF);

    // render
    renderTask.render();

    // render the report and destroy the engine
    // Note - If the program stays resident do not shutdown the Platform or the Engine
//    rptdoc.close();
    renderTask.close();
    runTask.close();
    engine.shutdown();
    Platform.shutdown();
    RegistryProviderFactory.releaseDefault();

    if (document.exists()) {
View Full Code Here

    IReportRunnable runnable = null;

    runnable = engine.openReportDesign(outputReportFile);

    // Create task to run the report - use the task to execute and run the report,
    IRunTask task2 = engine.createRunTask(runnable);

    // Create rptdocument
    task2.run("D:/Temp/TOCTest.rptdocument");

    // Open rptdocument
    IReportDocument rptdoc = engine
        .openReportDocument("D:/Temp/TOCTest.rptdocument");

    // Create Render Task
    IRenderTask rtask = engine.createRenderTask(rptdoc);

    PDFRenderOption optionsPDF = new PDFRenderOption();
    optionsPDF.setOutputFileName("D:/Temp/output.pdf");
    optionsPDF.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
    rtask.setRenderOption(optionsPDF);

    // render
    rtask.render();

    // render the report and destroy the engine
    // Note - If the program stays resident do not shutdown the Platform or
    // the Engine
    task2.close();
    engine.shutdown();
    Platform.shutdown();
    System.out.println("Finished");
  }
View Full Code Here

            TimeZone timeZone, Map parameters, Map displayTexts, Integer maxRows)
            throws RemoteException {
        assert runnable != null;

        // Prepare the run report task.
        IRunTask runTask = null;
        try {
            runTask = BirtContainer.getReportEngine().createRunTask(runnable);
        } catch (Exception e) {
            throwDummyException(e);
        }
        runTask.setLocale(locale);

        com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone(timeZone);
        if (tz != null) {
            runTask.setTimeZone(tz);
        }

        runTask.setParameterValues(parameters);

        // set MaxRows settings
        if (maxRows != null) {
            runTask.setMaxRowsPerQuery(maxRows.intValue());
        }

        // add task into session
        BirtUtility.addTask(request, runTask);

        // Set display Text for select parameters
        if (displayTexts != null)
        {
            Iterator keys = displayTexts.keySet().iterator();
            while (keys.hasNext()) {
                String paramName = DataUtil.getString(keys.next());
                String displayText = DataUtil.getString(displayTexts.get(paramName));
                runTask.setParameterDisplayText(paramName, displayText);
            }
        }

        // set app context
        Map context = BirtUtility.getAppContext(request);
        runTask.setAppContext(context);

        // Run report.
        try {
            runTask.run(documentName);
        } catch (BirtException e) {
            // clear document file
            File doc = new File(documentName);
            if (doc != null) {
                doc.delete();
            }
            throwDummyException(e);
        } finally {
            // Remove task from http session
            BirtUtility.removeTask(request);

            // Append errors
            if (ParameterAccessor.isDesigner()) {
                BirtUtility.error(request, runTask.getErrors());
            }

            runTask.close();

            // check for non-fatal errors
            List<Exception> errors = UtilGenerics.cast(runTask.getErrors());
            if (!errors.isEmpty()) {
                return errors;
            }
        }
        return null;
View Full Code Here

            TimeZone timeZone, Map parameters, Map displayTexts, Integer maxRows)
            throws RemoteException {
        assert runnable != null;

        // Prepare the run report task.
        IRunTask runTask = null;
        try {
            runTask = BirtContainer.getReportEngine().createRunTask(runnable);
        } catch (Exception e) {
            throwDummyException(e);
        }
        runTask.setLocale(locale);

        com.ibm.icu.util.TimeZone tz = BirtUtility.toICUTimeZone(timeZone);
        if (tz != null) {
            runTask.setTimeZone(tz);
        }

        runTask.setParameterValues(parameters);

        // set MaxRows settings
        if (maxRows != null) {
            runTask.setMaxRowsPerQuery(maxRows.intValue());
        }

        // add task into session
        BirtUtility.addTask(request, runTask);

        // Set display Text for select parameters
        if (displayTexts != null)
        {
            Iterator keys = displayTexts.keySet().iterator();
            while (keys.hasNext()) {
                String paramName = DataUtil.getString(keys.next());
                String displayText = DataUtil.getString(displayTexts.get(paramName));
                runTask.setParameterDisplayText(paramName, displayText);
            }
        }

        // set app context
        Map context = BirtUtility.getAppContext(request);
        runTask.setAppContext(context);

        // Run report.
        try {
            runTask.run(documentName);
        } catch (BirtException e) {
            // clear document file
            File doc = new File(documentName);
            if (doc != null) {
                doc.delete();
            }
            throwDummyException(e);
        } finally {
            // Remove task from http session
            BirtUtility.removeTask(request);

            // Append errors
            if (ParameterAccessor.isDesigner()) {
                BirtUtility.error(request, runTask.getErrors());
            }

            runTask.close();

            // check for non-fatal errors
            List<Exception> errors = UtilGenerics.cast(runTask.getErrors());
            if (!errors.isEmpty()) {
                return errors;
            }
        }
        return null;
View Full Code Here

  private void prepareCSVRender (Map reportParams, HttpServletRequest request, IReportRunnable design, String userId, String documentId, IEngUserProfile profile, String kpiUrl, HttpServletResponse response) throws Exception {
    logger.debug("IN");

    //Create task to run the report
    logger.debug("design: " + design.getReportName());
    IRunTask CSVtask = birtReportEngine.createRunTask(design);
     
    //**** Set parameters for the report **** 
     
    CSVtask.setParameterValues(reportParams);
    CSVtask.validateParameters();
    
    //************************************
    
    UUIDGenerator uuidGen  = UUIDGenerator.getInstance();
    UUID uuid_local = uuidGen.generateTimeBasedUUID();
    String executionId = uuid_local.toString();
    executionId = executionId.replaceAll("-", "");
    
    String nameFile = getJRTempDirName(getServletContext(), executionId)+ "csvreport.rptdocument";
    
    Map context = BirtUtility.getAppContext(request);
    CSVtask.setAppContext(context);

    //Run the report and create the rptdocument
    CSVtask.run(nameFile);

    //Open the rptdocument
    IReportDocument rptdoc = birtReportEngine.openReportDocument(nameFile);

    logger.debug(rptdoc.getPageCount());


    //*** Create the data extraction task ****
    IDataExtractionTask iDataExtract = birtReportEngine.createDataExtractionTask(rptdoc);
    ArrayList resultSetList = (ArrayList)iDataExtract.getResultSetList( );
         
      ICSVDataExtractionOption extractionOptions = new CSVDataExtractionOption();
      OutputStream responseOut = response.getOutputStream();

      extractionOptions.setOutputFormat("csv");
      extractionOptions.setSeparator(";");
     
      //flag for exportdata found
      boolean ed_found = false;
     
     
      //check if there is the ExportData element
      for (int j=0; j<resultSetList.size();j++){
     
        //get an item
      IResultSetItem resultItem = (IResultSetItem)resultSetList.get(j);
     
      //get the name of the resultSet
      String dispName = resultItem.getResultSetName();
     
      if (dispName.equalsIgnoreCase("exportdata")){
        logger.debug("Found ExportData Element in report ");
        ed_found = true;
       
        //output directly on the response OutputStream
          extractionOptions.setOutputStream(responseOut);
         
          //Set the HTTP response
        response.setContentType("text/csv");
        response.setHeader("Content-disposition", "inline; filename=reportcsv.csv");
        iDataExtract.selectResultSet( dispName );
        iDataExtract.extract(extractionOptions);
        logger.debug("Extraction successfull "+dispName);
        break;
      }
      }
     
      if (ed_found){
     
        //close the extract
      iDataExtract.close();
   
      //close the task
      CSVtask.close();

      logger.debug("Finished");
      logger.debug("OUT");
      }
     
     
      //ExtractData element not found, search all element to export
    if (!ed_found) {
      //check if there is only a result set and generate one CSV file
      if (resultSetList.size() <= 1){
       
          //output directly on the response OutputStream
          extractionOptions.setOutputStream(responseOut);
       
          //Set the HTTP response
        response.setContentType("text/csv");
        response.setHeader("Content-disposition", "inline; filename=reportcsv.csv");
       
          IResultSetItem resultItem = (IResultSetItem)resultSetList.get(0);
     
          //Set the name of the element you want to retrieve.
        String dispName = resultItem.getResultSetName( );
        iDataExtract.selectResultSet( dispName );
        iDataExtract.extract(extractionOptions);
        logger.debug("Extraction successfull "+dispName);
        }
        else {
          //with more resultSet generate a zip file containing more CSV file
          try {
          //Set the HTTP response
          response.setContentType("application/zip");
          response.setHeader("Content-disposition", "attachment; filename=reportcsv.zip");
         
            //ZipOutputStream directly on the response OutputStream
            ZipOutputStream outZip = new ZipOutputStream(responseOut);
         
            //temporary output buffer that contain a single csv
            OutputStream tempOut = new ByteArrayOutputStream();
         
            //temporary input buffer
            InputStream tempIn;
         
            // Create a buffer for reading the files
            byte[] buf = new byte[1024];
         
            //extracted csv is writed on the temp buffer
            extractionOptions.setOutputStream(tempOut);
         
            //iterate the resultSetList
           for (int i=0; i<resultSetList.size();i++){
         
             //get an item
             IResultSetItem resultItem = (IResultSetItem)resultSetList.get(i);
         
            //Set the name of the element you want to retrieve.
            String dispName = resultItem.getResultSetName( );
            iDataExtract.selectResultSet( dispName );
            iDataExtract.extract(extractionOptions);
            logger.debug("Extraction successfull "+dispName);
          
            // Add ZIP entry to ZIP output stream
            outZip.putNextEntry(new ZipEntry("reportcsv"+i+".csv"));
         
            //convert temp outputStream to InputStream
            tempIn = new ByteArrayInputStream (((ByteArrayOutputStream) tempOut).toByteArray());
         
              // Transfer bytes from the temp buffer to the ZIP file
            int len;
            while ((len = tempIn.read(buf)) > 0) {
              outZip.write(buf, 0, len);
              }
         
            // Complete the entry
            outZip.closeEntry();
            tempIn.close();
         
            //reset the temp output buffer
            ((ByteArrayOutputStream)tempOut).reset();
           }
         //**************************
         
         // Complete the ZIP file
         outZip.close()

          }
          catch (IOException e){
            logger.error("Error while generating csv zip file: " + e);
          }

        }

      //close the extract
      iDataExtract.close();
   
      //close the task
      CSVtask.close();

      logger.debug("Finished");
      logger.debug("OUT");
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.birt.report.engine.api.IRunTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.