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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#setDataFactory() . 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: ContextMenuUtilityTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testToggleActivationItem() throws Exception {

  final MasterReport masterReport = new MasterReport();
  final CompoundDataFactory compoundDataFactory = new CompoundDataFactory();
  final TableDataFactory tableDataFactory = new TableDataFactory();
  tableDataFactory.addTable( "default", new DefaultTableModel() );
  compoundDataFactory.add( tableDataFactory );
  masterReport.setDataFactory( compoundDataFactory );

  final ReportRenderContext doc = new ReportRenderContext( masterReport );
  final JMenuItem item = new JMenuItem();
  final ReportQueryNode reportQueryNode = new ReportQueryNode( compoundDataFactory, "default", true );

  ContextMenuUtility.toggleActivationItem( doc, reportQueryNode, item );

  Assert.assertTrue( item.isEnabled() );

  final TableDataFactory tableDataFactory2 = new TableDataFactory();
  tableDataFactory2.addTable( "default", new DefaultTableModel() );
  compoundDataFactory.add( tableDataFactory2 );

  ContextMenuUtility.toggleActivationItem( doc, reportQueryNode, item );

  Assert.assertFalse( item.isEnabled() );
}
 
Example 2
Source File: Prd5062Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testTransformationNameEmpty() throws Exception {
  final KettleDataFactory kettleDataFactory = new KettleDataFactory();
  kettleDataFactory.setQuery( "default", new KettleTransFromFileProducer( null, STEP ) );

  MasterReport report = new MasterReport();
  report.setDataFactory( kettleDataFactory );

  MasterReport r2 = ReportWritingUtil.saveAndLoad( report );
  assertTrue( r2.getDataFactory() instanceof KettleDataFactory );
  KettleDataFactory kdf = (KettleDataFactory) r2.getDataFactory();
  KettleTransformationProducer query = kdf.getQuery( "default" );
  assertNotNull( query );
  assertNull( query.getTransformationFile() );
  assertNotNull( query.getStepName() );
}
 
Example 3
Source File: MondrianDataFactoryWriteTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testWriteBanded() throws Exception {
  final BandedMDXDataFactory df = new BandedMDXDataFactory();
  df.setCubeFileProvider( new DefaultCubeFileProvider( "path/to/cube.xml", "test-connection" ) );
  df.setDataSourceProvider( new JndiDataSourceProvider( "dummy" ) );

  df.setGlobalScript( "GlobalScript" );
  df.setGlobalScriptLanguage( "GlobalScriptLanguage" );
  df.setQuery( "QueryName", "QueryText", "ScriptLanguage", "Script" );
  final MasterReport report = new MasterReport();
  report.setDataFactory( df );

  final MasterReport masterReport = postProcess( report );
  final BandedMDXDataFactory dataFactory = (BandedMDXDataFactory) masterReport.getDataFactory();
  assertEquals( "QueryName", dataFactory.getQueryNames()[ 0 ] );
  assertEquals( "QueryText", dataFactory.getQuery( "QueryName" ) );
  assertEquals( "ScriptLanguage", dataFactory.getScriptingLanguage( "QueryName" ) );
  assertEquals( "Script", dataFactory.getScript( "QueryName" ) );
  assertEquals( "GlobalScript", dataFactory.getGlobalScript() );
  assertEquals( "GlobalScriptLanguage", dataFactory.getGlobalScriptLanguage() );
  assertEquals( "test-connection", dataFactory.getCubeFileProvider().getCubeConnectionName() );
  assertEquals( "path/to/cube.xml", dataFactory.getCubeFileProvider().getDesignTimeFile() );
}
 
Example 4
Source File: Prd5041IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDependenciesMultiLevel2() throws ReportProcessingException {
  final MasterReport report = new MasterReport();
  report.setDataFactory( new TableDataFactory( "query", new DefaultTableModel( 2, 2 ) ) );
  report.addExpression( new DependencyFunction( 1, "source" ) );
  report.addExpression( new ForwardExpression( 0, "forward", "source" ) );
  report.addExpression( new ValidateFunction( 0, "validate", "forward" ) );

  DebugReportRunner.createPDF( report );
}
 
Example 5
Source File: MultiPageCountryDataDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = parseReport();
  report.setDataFactory(new TableDataFactory
      ("default", data));
  return report;
}
 
Example 6
Source File: PaddingIT.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.setName( "BorderTest" );

  Element label1 =
      LabelElementFactory.createLabelElement( "Label1", new Rectangle2D.Double( 0, 0, 200, 100 ), Color.RED,
          ElementAlignment.LEFT, new FontDefinition( "Arial", 12 ), "Label1" );

  report.getReportHeader().addElement( label1 );

  label1.getStyle().setStyleProperty( ElementStyleKeys.BACKGROUND_COLOR, new Color( 255, 127, 127, 120 ) );

  Element label2 =
      LabelElementFactory.createLabelElement( "Label2", new Rectangle2D.Double( 0, 110, 200, 100 ), Color.RED,
          ElementAlignment.LEFT, new FontDefinition( "Arial", 12 ), "Label2" );

  report.getReportHeader().addElement( label2 );

  label2.getStyle().setStyleProperty( ElementStyleKeys.BACKGROUND_COLOR, new Color( 255, 127, 127, 120 ) );
  label2.getStyle().setStyleProperty( ElementStyleKeys.PADDING_TOP, new Float( 10 ) );
  label2.getStyle().setStyleProperty( ElementStyleKeys.PADDING_LEFT, new Float( 10 ) );
  label2.getStyle().setStyleProperty( ElementStyleKeys.PADDING_RIGHT, new Float( 10 ) );
  label2.getStyle().setStyleProperty( ElementStyleKeys.PADDING_BOTTOM, new Float( 10 ) );

  Element label3 =
      LabelElementFactory.createLabelElement( "Label3", new Rectangle2D.Double( 210, 0, 200, 100 ), Color.RED,
          ElementAlignment.LEFT, new FontDefinition( "Arial", 12 ), "Label3" );

  report.getReportHeader().addElement( label3 );

  label3.getStyle().setStyleProperty( ElementStyleKeys.BACKGROUND_COLOR, new Color( 255, 127, 127, 120 ) );
  label3.getStyle().setStyleProperty( ElementStyleKeys.PADDING_TOP, new Float( 10 ) );
  label3.getStyle().setStyleProperty( ElementStyleKeys.PADDING_LEFT, new Float( 10 ) );
  label3.getStyle().setStyleProperty( ElementStyleKeys.PADDING_RIGHT, new Float( 10 ) );
  label3.getStyle().setStyleProperty( ElementStyleKeys.PADDING_BOTTOM, new Float( 10 ) );

  report.setDataFactory( new TableDataFactory( "default", new DefaultTableModel( 1, 1 ) ) );
  return report;
}
 
Example 7
Source File: SwingIconsDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  MasterReport report = parseReport();
  report.setDataFactory(new TableDataFactory
      ("default", demoPanel.getData()));
  return report;
}
 
Example 8
Source File: MultiAPIChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  // empty as implementation side effect
  final MasterReport report = new MasterReport();

  final ContentFieldElementFactory factory = new ContentFieldElementFactory();
  factory.setName("drawable-field");
  factory.setAbsolutePosition(new Point2D.Float(7, 7));
  factory.setMinimumSize(new FloatDimension(400, 250));
  factory.setFieldname("Chart");
  report.getItemBand().addElement(factory.createElement());
  report.setDataFactory(new TableDataFactory("default", data));
  return report;
}
 
Example 9
Source File: StraightToPNG.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new demo application.
 *
 * @param filename the output filename.
 * @throws ParseException if the report could not be parsed.
 */
public StraightToPNG(final String filename)
    throws ParseException
{
  final URL in = ObjectUtilities.getResource
      ("org/pentaho/reporting/engine/classic/demo/opensource/opensource.xml", StraightToPNG.class);
  final MasterReport report = parseReport(in);
  final TableModel data = new OpenSourceProjects();
  report.setDataFactory(new TableDataFactory
      ("default", data));
  final long startTime = System.currentTimeMillis();
  savePNG(report, filename);
}
 
Example 10
Source File: AbstractReportProcessorTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testIsQueryLimitReachedForNumberOfRowsGreaterQueryLimit() throws Exception {
  final MasterReport report = new MasterReport();
  final DefaultTableModel model = new DefaultTableModel( 501, 10 );
  report.setDataFactory( new TableDataFactory( "default", model ) );
  report.setQueryLimit( 500 );
  final AbstractReportProcessor reportProcessor = new DummyReportProcessor( report );
  reportProcessor.prepareReportProcessing();
  assertEquals( reportProcessor.isQueryLimitReached(), true );
}
 
Example 11
Source File: GroupsDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = parseReport();
  report.setDataFactory(new TableDataFactory
      ("default", data));
  return report;
}
 
Example 12
Source File: CombinedAdvertisingDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = parseReport();
  report.setDataFactory(new TableDataFactory
      ("default", data));
  return report;
}
 
Example 13
Source File: EventOrderIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testEventOrder() throws Exception {
  final MasterReport report = getReport();
  final DefaultTableModel model = new DefaultTableModel( 2, 1 );
  model.setValueAt( "0-0", 0, 0 );
  model.setValueAt( "0-1", 1, 0 );
  report.setDataFactory( new TableDataFactory( "default", model ) );

  DebugReportRunner.executeAll( report );
}
 
Example 14
Source File: TotalGroupCountIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testGroupCount2() throws Exception {
  final URL url = getClass().getResource( "aggregate-function-test.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setDataFactory( new TableDataFactory( "default", new AggregateTestDataTableModel() ) );

  final RelationalGroup g = report.getGroupByName( "default" );
  if ( g != null ) {
    report.removeGroup( g );
  }
  report.addExpression( new TotalGroupCountVerifyFunction() );

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

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

  DebugReportRunner.execGraphics2D( report );
}
 
Example 15
Source File: EmployeeListingWaqrIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFailure() throws Exception {
  final URL target = EmployeeListingWaqrIT.class.getResource( "EmployeeListing.waqr.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setDataFactory( new TableDataFactory( "default", new DefaultTableModel( 1, 1 ) ) );
  DebugReportRunner.executeAll( report );

}
 
Example 16
Source File: ValidatePageNumbersIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPageSystem() throws Exception {
  if ( DebugReportRunner.isSkipLongRunTest() ) {
    return;
  }
  final URL target = ValidatePageNumbersIT.class.getResource( "validate-page-numbers.xml" );
  final ResourceManager rm = new ResourceManager();
  rm.registerDefaults();
  final Resource directly = rm.createDirectly( target, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();
  report.setDataFactory( new TableDataFactory( "default", new DefaultTableModel( 1, 1 ) ) );
  final TableModel data = new DefaultTableModel( 2000, 1 );
  report.setDataFactory( new TableDataFactory( "default", data ) ); //$NON-NLS-1$;

  DebugReportRunner.executeAll( report );
}
 
Example 17
Source File: CountryReportExtXMLDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = parseReport();
  report.setDataFactory(new TableDataFactory
      ("default", data));
  return report;
}
 
Example 18
Source File: TotalItemMinFunctionIT.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 19
Source File: ExtSubReportDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = parseReport();
  final TableDataFactory tableDataFactory = new TableDataFactory();
  tableDataFactory.addTable("default", new DefaultTableModel());
  tableDataFactory.addTable("fruit", createFruitTableModel());
  tableDataFactory.addTable("color", createColorTableModel());
  report.setDataFactory(tableDataFactory);
  return report;
}
 
Example 20
Source File: NewReportAction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static MasterReport prepareMasterReport() {
  final MasterReport report = new MasterReport();
  report.setAutoSort( Boolean.TRUE );
  report.setDataFactory( new CompoundDataFactory() );
  report.setQuery( null );
  report.setQueryLimitInheritance( Boolean.TRUE );
  report.getRelationalGroup( 0 ).getHeader()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getRelationalGroup( 0 ).getFooter()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getDetailsFooter()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getDetailsHeader()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getNoDataBand()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );
  report.getWatermark()
    .setAttribute( ReportDesignerParserModule.NAMESPACE, ReportDesignerParserModule.HIDE_IN_LAYOUT_GUI_ATTRIBUTE,
      Boolean.TRUE );

  try {
    final MemoryDocumentBundle bundle = (MemoryDocumentBundle) report.getBundle();
    if ( bundle.isEntryExists( TRANSLATIONS_PROPERTIES ) == false ) {
      final String defaultMessage = ActionMessages.getString( "Translations.DefaultContent" );
      final OutputStream outputStream = bundle.createEntry( TRANSLATIONS_PROPERTIES, "text/plain" ); // NON-NLS
      outputStream.write( defaultMessage.getBytes( "ISO-8859-1" ) ); // NON-NLS
      outputStream.close();
      bundle.getWriteableDocumentMetaData()
        .setEntryAttribute( TRANSLATIONS_PROPERTIES, BundleUtilities.STICKY_FLAG, "true" ); // NON-NLS
    }
  } catch ( Exception ex ) {
    // ignore, its not that important ..
    DebugLog.log( "Failed to created default translation entry", ex ); // NON-NLS
  }
  return report;
}