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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getRootGroup() . 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: TotalItemCountIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSimplifiedRun() throws Exception {
  final MasterReport report = new MasterReport();
  report.addExpression( new EventMonitorFunction() );
  report.addExpression( new TotalItemCountVerifyFunction() );
  report.setDataFactory( new TableDataFactory( "default", new AggregateTestDataTableModel() ) );
  report.setQuery( "default" );
  final RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.clearFields();
  rootGroup.addField( "Continent" );
  rootGroup.setName( "Continent Group" );

  final TotalItemCountFunction f = new TotalItemCountFunction();
  f.setName( "continent-total-gc" );
  f.setGroup( "Continent Group" );
  f.setDependencyLevel( 1 );
  report.addExpression( f );

  final TotalItemCountFunction f2 = new TotalItemCountFunction();
  f2.setName( "total-gc" );
  f2.setDependencyLevel( 1 );
  report.addExpression( f2 );

  DebugReportRunner.execGraphics2D( report );
}
 
Example 2
Source File: ValidateStateIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testExportParameter() {
  final FormulaExpression function = new FormulaExpression();
  function.setName( "out" );
  function.setFormula( "=output // this formula does not even parse!" );

  SubReport subReport = new SubReport();
  subReport.addExportParameter( "out", "out" );
  subReport.addExpression( function );

  MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( report.getQuery(), new DefaultTableModel( 2, 2 ) ) );
  final RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.getHeader().addSubReport( (SubReport) subReport.derive() );
  report.getItemBand().addSubReport( (SubReport) subReport.derive() );

  DebugReportRunner.execGraphics2D( report );

}
 
Example 3
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 4
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 5
Source File: CrosstabPagebreakIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testStandardReport() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }

  final MasterReport report = DebugReportRunner.parseGoldenSampleReport( "Prd-3857-001.prpt" );
  final Group rootGroup = report.getRootGroup();
  assertTrue( rootGroup instanceof CrosstabGroup );

  final CrosstabGroup ct = (CrosstabGroup) rootGroup;
  ct.setPrintColumnTitleHeader( true );
  ct.setPrintDetailsHeader( false );

  // Prints 4 header rows, and 19 data rows (row 0 to row 18)
  List<LogicalPageBox> logicalPageBoxes = DebugReportRunner.layoutPages( report, 0, 1 );
  final LogicalPageBox boxP1 = logicalPageBoxes.get( 0 );
  // ModelPrinter.INSTANCE.print(boxP1);
  final RenderNode[] rowsPage1 = MatchFactory.findElementsByNodeType( boxP1, LayoutNodeTypes.TYPE_BOX_TABLE_ROW );
  assertEquals( 23, rowsPage1.length );

  // Prints 4 header rows and 9 data rows (row 19 to row 27)
  final LogicalPageBox boxP2 = logicalPageBoxes.get( 1 );
  // ModelPrinter.INSTANCE.print(boxP2);
  final RenderNode[] rowsPage2 = MatchFactory.findElementsByNodeType( boxP2, LayoutNodeTypes.TYPE_BOX_TABLE_ROW );
  assertEquals( 13, rowsPage2.length );

}
 
Example 6
Source File: CrosstabPagebreakIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testStandardReport2() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }

  final MasterReport report = DebugReportRunner.parseGoldenSampleReport( "Prd-3857-001.prpt" );
  final Group rootGroup = report.getRootGroup();
  assertTrue( rootGroup instanceof CrosstabGroup );

  final CrosstabGroup ct = (CrosstabGroup) rootGroup;
  ct.setPrintColumnTitleHeader( false );
  ct.setPrintDetailsHeader( false );

  // Prints two header rows, and 21 data rows (row 0 to row 20)
  List<LogicalPageBox> logicalPageBoxes = DebugReportRunner.layoutPages( report, 0, 1 );
  final LogicalPageBox boxP1 = logicalPageBoxes.get( 0 );
  // ModelPrinter.INSTANCE.print(boxP1);
  final RenderNode[] rowsPage1 = MatchFactory.findElementsByNodeType( boxP1, LayoutNodeTypes.TYPE_BOX_TABLE_ROW );
  assertEquals( 23, rowsPage1.length );

  // Prints two header rows and 7 data rows (row 21 to row 27)
  final LogicalPageBox boxP2 = logicalPageBoxes.get( 1 );
  // ModelPrinter.INSTANCE.print(boxP2);
  final RenderNode[] rowsPage2 = MatchFactory.findElementsByNodeType( boxP2, LayoutNodeTypes.TYPE_BOX_TABLE_ROW );
  assertEquals( 9, rowsPage2.length );

}
 
Example 7
Source File: TableToHtmlExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testHtmlExportFull() throws Exception {
  final URL url = getClass().getResource( "Prd-3931.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  final Group rootGroup = report.getRootGroup();
  assertTrue( rootGroup instanceof CrosstabGroup );

  final CrosstabGroup ct = (CrosstabGroup) rootGroup;
  ct.setPrintColumnTitleHeader( true );
  ct.setPrintDetailsHeader( false );

  final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream();
  HtmlReportUtil.createStreamHTML( report, outputStream );

  final String htmlText = new String( outputStream.toByteArray(), "UTF-8" );
  DebugLog.log( htmlText );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2003</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2004</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2005</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Product Line</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Market</td>" ) );
}
 
Example 8
Source File: TableToHtmlExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testHtmlExportFullComplexText() throws Exception {
  final URL url = getClass().getResource( "Prd-3931.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setCompatibilityLevel( null );
  report.getReportConfiguration()
      .setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "true" );

  final Group rootGroup = report.getRootGroup();
  assertTrue( rootGroup instanceof CrosstabGroup );

  final CrosstabGroup ct = (CrosstabGroup) rootGroup;
  ct.setPrintColumnTitleHeader( true );
  ct.setPrintDetailsHeader( false );

  final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream();
  HtmlReportUtil.createStreamHTML( report, outputStream );

  final String htmlText = new String( outputStream.toByteArray(), "UTF-8" );
  DebugLog.log( htmlText );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2003</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2004</td>" ) );
  assertTrue( htmlText.contains( "<td colspan=\"2\" valign=\"top\" class=\"style-1\">2005</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Product Line</td>" ) );
  assertTrue( htmlText.contains( "<td valign=\"top\" class=\"style-3\">Market</td>" ) );
}
 
Example 9
Source File: GroupRowLayoutIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGroupPrinting() throws Exception {
  final MasterReport report = new MasterReport();
  final RelationalGroup rootGroup = (RelationalGroup) report.getRootGroup();
  rootGroup.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_ROW );
  rootGroup.getBody().getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_BLOCK );

  rootGroup.getHeader().setName( "GH" );
  rootGroup.getHeader().getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_CANVAS );
  rootGroup.getHeader().getStyle().setStyleProperty( ElementStyleKeys.USE_MIN_CHUNKWIDTH, Boolean.TRUE );
  rootGroup.getHeader().addElement( createDataItem( "Header" ) );

  report.getNoDataBand().setName( "NDB" );
  report.getNoDataBand().addElement( createDataItem( "No-DataBand" ) );
  report.getNoDataBand().getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 100f );

  rootGroup.getFooter().setName( "GF" );
  rootGroup.getFooter().addElement( createDataItem( "Footer" ) );
  rootGroup.getFooter().getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_CANVAS );
  rootGroup.getFooter().getStyle().setStyleProperty( ElementStyleKeys.USE_MIN_CHUNKWIDTH, Boolean.TRUE );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( report, 0 );

  final RenderNode[] nodes = MatchFactory.matchAll( logicalPageBox, "RowRenderBox > *" );
  assertEquals( "Number of nodes is 3", 3, nodes.length );
  for ( int i = 0; i < nodes.length; i++ ) {
    final RenderNode node = nodes[i];
    assertEquals( "Node: " + node, StrictGeomUtility.toInternalValue( 100 ), node.getWidth() );
  }

  // XmlPageReportUtil.createXml(report, System.out);
}
 
Example 10
Source File: GeneratorTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testCrosstab() throws Exception {
  final GroupDefinition[] groupDefs = new GroupDefinition[ 3 ];
  groupDefs[ 0 ] = new DefaultGroupDefinition( GroupType.RELATIONAL, "group-field1" );
  groupDefs[ 1 ] = new DefaultGroupDefinition( GroupType.CT_ROW, "group-field2" );
  groupDefs[ 2 ] = new DefaultGroupDefinition( GroupType.CT_COLUMN, "group-field3" );

  final DetailFieldDefinition[] detailFields = new DetailFieldDefinition[ 1 ];
  detailFields[ 0 ] = new DefaultDetailFieldDefinition( "detail-field1" );

  final DefaultWizardSpecification wizardSpecification = new DefaultWizardSpecification();
  wizardSpecification.setGroupDefinitions( groupDefs );
  wizardSpecification.setDetailFieldDefinitions( detailFields );

  final MasterReport report = new MasterReport();
  report.setAttribute( AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification );

  final ProcessingContext processingContext = new DefaultProcessingContext();
  final DefaultFlowController flowController = new DefaultFlowController
    ( processingContext, report.getDataSchemaDefinition(), new ReportParameterValues(),
      new NoOpPerformanceMonitorContext() );

  final WizardProcessor processor = new WizardProcessor();
  final MasterReport masterReport = processor.performPreProcessing( report, flowController );

  final int count = masterReport.getGroupCount();
  assertEquals( groupDefs.length + 2, count );
  final RelationalGroup defaultGroup = (RelationalGroup) masterReport.getRootGroup();
  assertEquals( "Default-Group detector", 0, defaultGroup.getFieldsArray().length );
  final SubGroupBody body = (SubGroupBody) defaultGroup.getBody();
  final RelationalGroup group1 = (RelationalGroup) body.getGroup();
  assertEquals( "Rel-Group", "group-field1", group1.getFieldsArray()[ 0 ] );
  final SubGroupBody body1 = (SubGroupBody) group1.getBody();
  final CrosstabGroup ctGroup = (CrosstabGroup) body1.getGroup();
  final CrosstabRowGroupBody body2 = (CrosstabRowGroupBody) ctGroup.getBody();
  final CrosstabRowGroup rowGroup = body2.getGroup();
  assertEquals( "Row-Group", "group-field2", rowGroup.getField() );

  final CrosstabColumnGroupBody body3 = (CrosstabColumnGroupBody) rowGroup.getBody();
  final CrosstabColumnGroup colGroup = body3.getGroup();
  assertEquals( "Col-Group", "group-field3", colGroup.getField() );

}