Java Code Examples for org.pentaho.reporting.engine.classic.core.MasterReport#setQuery()

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#setQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TotalPageFunctionsIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private MasterReport createRelationalReport( final TableModel tableModel, final Class aggFun ) {
  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( new PageSize( 800, 300 ) ) );
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );

  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );
  final RelationalReportBuilder builder = new RelationalReportBuilder( dataSchemaModel );
  builder.addGroup( ROW_DIMENSION_A );
  builder.addGroup( ROW_DIMENSION_B );
  builder.addDetails( VALUE, aggFun, VALUE_BACKGROUND );
  builder.addDetails( "row-a-sum", null, ROWA_BACKGROUND );
  builder.addDetails( "#row-a-sum", null, ROWA_VALIDATE_BACKGROUND );
  builder.addDetails( "row-b-sum", null, ROWB_BACKGROUND );
  builder.addDetails( "#row-b-sum", null, ROWB_VALIDATE_BACKGROUND );
  builder.addDetails( "no-group", null, ROWC_BACKGROUND );
  builder.addDetails( "#no-group", null, ROWC_VALIDATE_BACKGROUND );

  report.setRootGroup( builder.create() );

  return report;
}
 
Example 2
Source File: Pre497IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testBug() throws ReportProcessingException {
  synchronized ( Pre497IT.class ) {
    querytracker = new HashSet();

    final MasterReport report = new MasterReport();
    report.setDataFactory( new TrackingStaticDataFactory() );
    report.setQuery( "org.pentaho.reporting.engine.classic.core.bugs.Pre497IT#createMasterReport" );
    report.addExpression( new RandomValueExpression( "MR" ) );

    final SubReport sreport = new SubReport();
    sreport.setQuery( SUBREPORT_QUERY );
    sreport.addInputParameter( "A", "PA" );
    sreport.addExpression( new RandomValueExpression( "SR" ) );
    report.getItemBand().addSubReport( sreport );

    DebugReportRunner.createPDF( report );

    querytracker = null;
  }
}
 
Example 3
Source File: ExpressionTestBase.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected MasterReport createCrosstabReport( final TableModel tableModel ) {
  Expression dummy = create( "dummy", null, null );
  if ( dummy instanceof AggregationFunction == false ) {
    return null;
  }

  AggregationFunction function = (AggregationFunction) dummy;

  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( PageSize.A3, PageFormat.LANDSCAPE, new Insets( 0, 0, 0, 0 ) ) );
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final ContextAwareDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final CrosstabBuilder builder = new CrosstabBuilder( dataSchemaModel );
  builder.addRowDimension( ROW_DIMENSION_A );
  builder.addRowDimension( ROW_DIMENSION_B );
  builder.addColumnDimension( COLUMN_DIMENSION_A );
  builder.addColumnDimension( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, function.getClass() );
  report.setRootGroup( builder.create() );
  return report;
}
 
Example 4
Source File: PagebreakIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRunSimpleReport() throws Exception {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", new DefaultTableModel( 10, 1 ) ) );
  report.setQuery( "query" );

  final Band table = TableTestUtil.createTable( 1, 1, 6, true );
  table.setName( "table" );
  report.getReportHeader().addElement( table );
  report.getReportHeader().setLayout( "block" );

  List<LogicalPageBox> pages = DebugReportRunner.layoutPages( report, 0, 1, 2 );
  assertPageValid( pages, 0 );
  assertPageValid( pages, 1 );
  assertPageValid( pages, 2 );
}
 
Example 5
Source File: Prd3133IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private MasterReport createReport() {
  final TypedTableModel model = new TypedTableModel();
  model.addColumn( "key", String.class );
  model.addColumn( "value", Integer.class );
  for ( int i = 0; i < 1000; i += 1 ) {
    model.addRow( new Object[] { "K1", Integer.valueOf( 1 ) } );
  }

  final PageItemSumFunction itemSumFunction = new PageItemSumFunction();
  itemSumFunction.setField( "value" );
  itemSumFunction.setName( "fn" );

  final MasterReport report = new MasterReport();
  report.setQuery( "test" );
  report.setDataFactory( new TableDataFactory( report.getQuery(), model ) );
  report.addExpression( itemSumFunction );
  final ItemBand itemBand = report.getItemBand();
  itemBand.addElement( createNumberElement( 0, "value", "I1" ) );
  itemBand.addElement( createNumberElement( 100, "fn", "I2" ) );

  final PageFooter pageFooter = report.getPageFooter();
  pageFooter.addElement( createNumberElement( 0, "value", "P1" ) );
  pageFooter.addElement( createNumberElement( 100, "fn", "P2" ) );
  return report;
}
 
Example 6
Source File: CrosstabMultiFactDataIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testDiagonalReportProcessing() throws ReportProcessingException {
  final TypedTableModel model = createTestData();

  final MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new TableDataFactory( "default", model ) );
  report.setRootGroup( createCrosstab() );
  report.addExpression( new ValidateExpression() );

  // DebugReportRunner.execGraphics2D(report);

  PrintReportProcessor rp = new PrintReportProcessor( report );
  final int nop = rp.getNumberOfPages();
  for ( int page = 0; page < nop; page += 1 ) {
    final PhysicalPageDrawable pageDrawable = (PhysicalPageDrawable) rp.getPageDrawable( page );
    LogicalPageBox logicalPageBox = pageDrawable.getPageDrawable().getLogicalPageBox();
    // ModelPrinter.print(logicalPageBox);
  }
}
 
Example 7
Source File: PagebreakIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRowWithPrePostPad() throws Exception {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", new DefaultTableModel( 10, 1 ) ) );
  report.setQuery( "query" );

  final Band table = TableTestUtil.createTable( 1, 1, 6, true );
  table.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 200f );
  table.setName( "table" );
  report.getReportHeader().addElement( TableTestUtil.createDataItem( "Pre-Padding", 100, 10 ) );
  report.getReportHeader().addElement( table );
  report.getReportHeader().addElement( TableTestUtil.createDataItem( "Post-Padding", 100, 10 ) );
  report.getReportHeader().setLayout( "row" );

  PdfReportUtil.createPDF( report, "test-output/PRD-3857-output-row.pdf" );
  List<LogicalPageBox> pages = DebugReportRunner.layoutPages( report, 0, 1, 2 );

  assertPageValid( pages, 0 );
  assertPageValid( pages, 1 );
  assertPageValid( pages, 2 );
  // assertPageValid(report, 3);
  // assertPageValid(report, 4);
}
 
Example 8
Source File: CrosstabIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testEmptyCrosstab() throws Exception {
  final MasterReport report = new MasterReport();
  report.setRootGroup( new CrosstabGroup() );
  report.setQuery( "default" );
  report.setDataFactory( new TableDataFactory( "default", new DefaultTableModel( 1, 1 ) ) );
  DebugReportRunner.executeAll( report );
}
 
Example 9
Source File: ItemMaxFunctionIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private MasterReport createReport( final TableModel tableModel ) {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final CrosstabBuilder builder = new CrosstabBuilder( dataSchemaModel );
  builder.addRowDimension( "Row-Dimension-A" );
  builder.addRowDimension( ROW_DIMENSION_B );
  builder.addColumnDimension( COLUMN_DIMENSION_A );
  builder.addColumnDimension( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, null );
  report.setRootGroup( builder.create() );
  return report;
}
 
Example 10
Source File: TotalGroupSumFunctionIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private MasterReport createReport( final TableModel tableModel ) {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", tableModel ) );
  report.setQuery( "query" );
  final DesignTimeDataSchemaModel dataSchemaModel = new DesignTimeDataSchemaModel( report );

  final CrosstabBuilder builder = new CrosstabBuilder( dataSchemaModel );
  builder.addRowDimension( "Row-Dimension-A" );
  builder.addRowDimension( ROW_DIMENSION_B );
  builder.addColumnDimension( COLUMN_DIMENSION_A );
  builder.addColumnDimension( COLUMN_DIMENSION_B );
  builder.addDetails( VALUE, null );
  report.setRootGroup( builder.create() );
  return report;
}
 
Example 11
Source File: Sample4.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private MasterReport createReportDefinition() {
  // Create a report using the autogenerated fields
  final MasterReport report = new MasterReport();
  report.addPreProcessor( new RelationalAutoGeneratorPreProcessor() );
  // Add the data factory to the report
  report.setDataFactory( new TableDataFactory( "Sample4Query", new Sample4TableModel() ) );
  report.setQuery( "Sample4Query" );

  // return
  return report;
}
 
Example 12
Source File: CrosstabDataIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testInvalidReportProcessing() throws Exception {
  final TypedTableModel model = new TypedTableModel();
  model.addRow();
  model.addRow();
  model.addRow();

  final MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new TableDataFactory( "default", model ) );
  report.setRootGroup( createCrosstab() );
  report.addExpression( new ValidateExpression( false ) );

  DebugReportRunner.layoutPage( report, 0 );
}
 
Example 13
Source File: Prd5180IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private MasterReport createReport() {
  MasterReport report = new MasterReport();
  report.setQuery( "query" );
  report.setDataFactory( new TableDataFactory( report.getQuery(), createData() ) );

  ItemBand itemBand = report.getItemBand();
  itemBand.setLayout( BandStyleKeys.LAYOUT_ROW );
  itemBand.addElement( createField( "f1", 100, 20 ) );
  itemBand.addElement( createField( "f2", 100, 20 ) );
  itemBand.addElement( createField( "f3", 100, 20 ) );
  return report;
}
 
Example 14
Source File: SortingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCrosstabSorting() {
  List<SortConstraint> sc = new ArrayList<SortConstraint>();
  sc.add( new SortConstraint( "A", true ) );
  sc.add( new SortConstraint( "B", true ) );

  MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new ValidateDataFactory( "default", new DefaultTableModel( 10, 10 ), sc ) );
  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.AUTOSORT, true );
  RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.setFields( Arrays.asList( "A", "B" ) );

  int i = DebugReportRunner.execGraphics2D( report );
}
 
Example 15
Source File: SortingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRunSorting() {
  List<SortConstraint> sc = new ArrayList<SortConstraint>();
  sc.add( new SortConstraint( "A", true ) );
  sc.add( new SortConstraint( "B", true ) );

  MasterReport report = new MasterReport();
  report.setQuery( "default" );
  report.setDataFactory( new ValidateDataFactory( "default", new DefaultTableModel( 10, 10 ), sc ) );
  report.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.AUTOSORT, true );
  RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.setFields( Arrays.asList( "A", "B" ) );

  int i = DebugReportRunner.execGraphics2D( report );
}
 
Example 16
Source File: AutoTableAPIDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the report. For XML reports, this will most likely call the ReportGenerator, while API reports may use this
 * function to build and return a new, fully initialized report object.
 *
 * @return the fully initialized JFreeReport object.
 * @throws ReportDefinitionException if an error occured preventing the report definition.
 */
public MasterReport createReport() throws ReportDefinitionException
{
  final DriverConnectionProvider drc = new DriverConnectionProvider();
  drc.setDriver("org.hsqldb.jdbcDriver");
  drc.setUrl("jdbc:hsqldb:./sql/sampledata");
  drc.setProperty("user", "sa");
  drc.setProperty("password", "");
  final SQLReportDataFactory sqlDataFactory = new SQLReportDataFactory(drc);
  sqlDataFactory.setQuery("default", "      SELECT\n" +
      "           QUADRANT_ACTUALS.REGION,\n" +
      "           QUADRANT_ACTUALS.DEPARTMENT,\n" +
      "           QUADRANT_ACTUALS.POSITIONTITLE,\n" +
      "           QUADRANT_ACTUALS.ACTUAL,\n" +
      "           QUADRANT_ACTUALS.BUDGET,\n" +
      "           QUADRANT_ACTUALS.VARIANCE\n" +
      "      FROM\n" +
      "           QUADRANT_ACTUALS\n" +
      "      ORDER BY\n" +
      "          REGION, DEPARTMENT, POSITIONTITLE", null, null);

  final MasterReport report = new MasterReport();
  report.setDataFactory(sqlDataFactory);
  report.setQuery("default");
  report.addPreProcessor(new RelationalAutoGeneratorPreProcessor());
  return report;
}
 
Example 17
Source File: KeepTogetherIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testReport() throws Exception {
  final TypedTableModel model = new TypedTableModel();
  model.addColumn( "g0", String.class );
  model.addColumn( "g1", String.class );
  model.addColumn( "value", String.class );
  model.addRow( "a", "1", "row-0" );
  model.addRow( "a", "2", "row-1" );
  model.addRow( "b", "1", "row-2" );
  model.addRow( "b", "2", "row-3" );
  model.addRow( "b", "2", "row-4" );
  model.addRow( "b", "2", "row-4" );
  model.addRow( "b", "2", "row-5" );
  model.addRow( "b", "3", "row-6" );
  model.addRow( "a", "1", "row-7" );
  model.addRow( "b", "1", "row-8" );
  model.addRow( "b", "2", "row-9" );

  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( new PageSize( 500, 100 ) ) );
  report.addGroup( new RelationalGroup() );
  report.setDataFactory( new TableDataFactory( "query", model ) );
  report.setQuery( "query" );

  final RelationalGroup group0 = (RelationalGroup) report.getGroup( 0 );
  group0.setName( "outer-group" );
  group0.addField( "g0" );
  group0.getHeader().addElement( createDataItem( "outer-header-field", 100, 20 ) );
  group0.getFooter().addElement( createDataItem( "outer-footer-field", 100, 20 ) );
  final RelationalGroup group1 = (RelationalGroup) report.getGroup( 1 );
  group1.setName( "inner-group" );
  group1.addField( "g1" );
  group1.getHeader().addElement( createDataItem( "inner-header-field", 100, 20 ) );
  group1.getFooter().addElement( createDataItem( "inner-footer-field", 100, 20 ) );
  report.getItemBand().addElement( createFieldItem( "detail-field", 100, 20 ) );
  report.getItemBand().getParentSection().getStyle().setStyleProperty( ElementStyleKeys.AVOID_PAGEBREAK_INSIDE,
      Boolean.TRUE );
  group1.getStyle().setStyleProperty( ElementStyleKeys.AVOID_PAGEBREAK_INSIDE, Boolean.TRUE );

  // PdfReportUtil.createPDF(report, "/tmp/WidowTest.pdf");
  List<LogicalPageBox> pages = DebugReportRunner.layoutPages( report, 0, 1, 2, 3, 4, 5, 6, 7 );

  final LogicalPageBox page1 = pages.get( 0 );
  assertElementExists( "outer-header-field", page1 );
  assertElementExists( "inner-footer-field", page1 );
  assertElementExists( "row-0", page1 );
  assertElementExists( "inner-header-field", page1 );

  final LogicalPageBox page2 = pages.get( 1 );
  assertElementExists( "inner-header-field", page2 );
  assertElementExists( "row-1", page2 );
  assertElementExists( "inner-footer-field", page2 );
  assertElementExists( "outer-footer-field", page2 );
  assertElementExists( "outer-header-field", page2 );

  final LogicalPageBox page3 = pages.get( 2 );
  assertElementExists( "inner-header-field", page3 );
  assertElementExists( "row-2", page3 );
  assertElementExists( "inner-footer-field", page3 );
  assertElementDoesNotExist( "row-3", page3 );

  final LogicalPageBox page4 = pages.get( 3 );
  assertElementExists( "inner-header-field", page4 );
  assertElementExists( "row-5", page4 );
  assertElementDoesNotExist( "row-6", page4 );

  final LogicalPageBox page5 = pages.get( 4 );
  assertElementExists( "inner-header-field", page5 );
  assertElementExists( "row-6", page5 );
  assertElementDoesNotExist( "row-7", page5 );

  final LogicalPageBox page6 = pages.get( 5 );
  assertElementExists( "inner-header-field", page6 );
  assertElementExists( "row-7", page6 );
  assertElementDoesNotExist( "row-8", page6 );

  final LogicalPageBox page7 = pages.get( 6 );
  assertElementExists( "inner-header-field", page7 );
  assertElementExists( "row-8", page7 );
  assertElementDoesNotExist( "row-9", page7 );

  final LogicalPageBox page8 = pages.get( 7 );
  assertElementExists( "inner-header-field", page8 );
  assertElementExists( "row-9", page8 );
  assertElementExists( "inner-footer-field", page8 );
  assertElementExists( "outer-footer-field", page8 );

  // BundleWriter.writeReportToZipFile(report, "/tmp/Prd-2087-Keep-Together-0.prpt");
}
 
Example 18
Source File: OrphanIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testInvalidReport2() throws Exception {
  final TypedTableModel model = new TypedTableModel();
  model.addColumn( "g0", String.class );
  model.addColumn( "g1", String.class );
  model.addColumn( "value", String.class );
  model.addRow( "a", "1", "row-0" );
  model.addRow( "a", "1", "row-1" );
  model.addRow( "a", "1", "row-2" );
  model.addRow( "a", "2", "row-3" );
  model.addRow( "b", "1", "row-4" );
  model.addRow( "b", "2", "row-5" );
  model.addRow( "b", "2", "row-6" );
  model.addRow( "b", "2", "row-7" );
  model.addRow( "b", "3", "row-8" );
  model.addRow( "b", "3", "row-9" );
  model.addRow( "b", "3", "row-10" );
  model.addRow( "b", "3", "row-11" );
  model.addRow( "b", "3", "row-12" );
  model.addRow( "a", "1", "row-13" );
  model.addRow( "b", "1", "row-14" );
  model.addRow( "b", "2", "row-15" );

  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( new PageSize( 500, 100 ) ) );
  report.addGroup( new RelationalGroup() );
  report.setDataFactory( new TableDataFactory( "query", model ) );
  report.setQuery( "query" );

  final RelationalGroup group0 = (RelationalGroup) report.getGroup( 0 );
  group0.setName( "outer-group" );
  group0.addField( "g0" );
  group0.getHeader().addElement( createDataItem( "outer-header-field", 100, 20 ) );
  group0.getFooter().addElement( createDataItem( "outer-footer-field", 100, 20 ) );
  group0.getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 2 );

  final RelationalGroup group1 = (RelationalGroup) report.getGroup( 1 );
  group1.setName( "inner-group" );
  group1.addField( "g1" );
  group1.getHeader().addElement( createDataItem( "inner-header-field", 100, 20 ) );
  group1.getFooter().addElement( createDataItem( "inner-footer-field", 100, 20 ) );
  report.getItemBand().addElement( createFieldItem( "detail-field", 100, 20 ) );
  report.getItemBand().getParentSection().getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 200 );
  group1.getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 2 );

  // PdfReportUtil.createPDF(report, "/tmp/OrphanTest2.pdf");
  // BundleWriter.writeReportToZipFile(report, "/tmp/Prd-2087-Orphan-2.prpt");
  DebugReportRunner.createPDF( report );

  // ModelPrinter.INSTANCE.print(DebugReportRunner.layoutPage(report, 4));
  // ModelPrinter.INSTANCE.print(DebugReportRunner.layoutPage(report, 5));
}
 
Example 19
Source File: OrphanIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testReport() throws ReportProcessingException, IOException, ContentIOException, BundleWriterException {
  final TypedTableModel model = new TypedTableModel();
  model.addColumn( "g0", String.class );
  model.addColumn( "g1", String.class );
  model.addColumn( "value", String.class );
  model.addRow( "a", "1", "row-0" );
  model.addRow( "a", "2", "row-1" );
  model.addRow( "b", "1", "row-2" );
  model.addRow( "b", "2", "row-3" );
  model.addRow( "b", "2", "row-4" );
  model.addRow( "b", "2", "row-5" );
  model.addRow( "b", "3", "row-6" );
  model.addRow( "a", "1", "row-7" );
  model.addRow( "b", "1", "row-8" );
  model.addRow( "b", "2", "row-9" );

  final MasterReport report = new MasterReport();
  report.setPageDefinition( new SimplePageDefinition( new PageSize( 500, 100 ) ) );
  report.addGroup( new RelationalGroup() );
  report.setDataFactory( new TableDataFactory( "query", model ) );
  report.setQuery( "query" );

  final RelationalGroup group0 = (RelationalGroup) report.getGroup( 0 );
  group0.setName( "outer-group" );
  group0.addField( "g0" );
  group0.getHeader().addElement( createDataItem( "outer-header-field", 100, 20 ) );
  group0.getFooter().addElement( createDataItem( "outer-footer-field", 100, 20 ) );
  group0.getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 2 );

  final RelationalGroup group1 = (RelationalGroup) report.getGroup( 1 );
  group1.setName( "inner-group" );
  group1.addField( "g1" );
  group1.getHeader().addElement( createDataItem( "inner-header-field", 100, 20 ) );
  group1.getFooter().addElement( createDataItem( "inner-footer-field", 100, 20 ) );
  report.getItemBand().addElement( createDataItem( "detail-field", 100, 20 ) );
  report.getItemBand().getParentSection().getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 2 );
  group1.getStyle().setStyleProperty( ElementStyleKeys.ORPHANS, 2 );

  // BundleWriter.writeReportToZipFile(report, "/tmp/Prd-2087-Orphan-0.prpt");
  DebugReportRunner.createPDF( report );
  // PdfReportUtil.createPDF(report, "/tmp/OrphanTest.pdf");
}
 
Example 20
Source File: PentahoServlet.java    From pentaho-8-reporting-for-java-developers with Apache License 2.0 4 votes vote down vote up
@Override
public void doPost(
  HttpServletRequest request, 
  HttpServletResponse response)
  throws ServletException, IOException 
{

  try {

    // Declaring a report.
    MasterReport report = new MasterReport();

    // Defining the connection provider.
    DriverConnectionProvider provider = new DriverConnectionProvider();
    provider.setDriver("org.hsqldb.jdbcDriver");
    provider.setProperty("user", "pentaho_user");
    provider.setProperty("password", "password");
    provider.setUrl("jdbc:hsqldb:./resources/sampledata/sampledata");

    // Defining the queries.
    SQLReportDataFactory dataFactory = new SQLReportDataFactory(provider);
    dataFactory.setQuery("default", "SELECT ORDERNUMBER, ORDERDATE FROM ORDERS LIMIT 10");
    report.setDataFactory(dataFactory);
    report.setQuery("default");

    // Getting the Report header to host the elements.
    ReportHeader reportHeader = report.getReportHeader();

    // Defining the default locale.
    Locale locale = new Locale("es");
    // Locale locale = new Locale("en");
    Locale.setDefault(locale);

    // Adding a resource label to the report header band.
    ResourceLabelElementFactory labelFactory = new ResourceLabelElementFactory();
    labelFactory.setResourceKey("ORDERNUMBER");
    labelFactory.setResourceBase("my-first-reporting-project");
    labelFactory.setBold(true);
    labelFactory.setX(1f);
    labelFactory.setY(1f);
    labelFactory.setMinimumWidth(100f);
    labelFactory.setMinimumHeight(20f);
    labelFactory.setBold(true);
    Element labelField = labelFactory.createElement();
    reportHeader.addElement(labelField);
    
    // Adding a resource label to the report header band.
    ResourceLabelElementFactory label2Factory = new ResourceLabelElementFactory();
    label2Factory.setResourceKey("ORDERDATE");
    label2Factory.setResourceBase("my-first-reporting-project");
    label2Factory.setBold(true);
    label2Factory.setX(101f);
    label2Factory.setY(1f);
    label2Factory.setMinimumWidth(200f);
    label2Factory.setMinimumHeight(20f);
    label2Factory.setBold(true);
    Element label2Field = label2Factory.createElement();
    reportHeader.addElement(label2Field);

    // Getting the item band to host the elements.
    ItemBand itemBand = report.getItemBand();

    // Adding a field to the details band.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("ORDERNUMBER");
    numberFactory.setX(1f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element numberField = numberFactory.createElement();
    itemBand.addElement(numberField);

    // Adding a field to the details band.
    DateFieldElementFactory dateFactory = new DateFieldElementFactory();
    dateFactory.setFieldname("ORDERDATE");
    dateFactory.setX(101f);
    dateFactory.setY(1f);
    dateFactory.setMinimumWidth(200f);
    dateFactory.setMinimumHeight(20f);
    Element dateField = dateFactory.createElement();
    itemBand.addElement(dateField);

    // Conversion to PDF and rendering.
    response.setContentType("application/pdf");
    PdfReportUtil.createPDF(report, response.getOutputStream());

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}