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

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getItemBand() . 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: 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 2
Source File: CSVExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testExport() throws Exception {
  final MasterReport report = new MasterReport();
  final ItemBand itemBand = report.getItemBand();
  final TextFieldElementFactory cfef = new TextFieldElementFactory();
  cfef.setFieldname( "field" );
  cfef.setMinimumWidth( new Float( 500 ) );
  cfef.setMinimumHeight( new Float( 200 ) );
  itemBand.addElement( cfef.createElement() );

  final DefaultTableModel tableModel = new DefaultTableModel( new String[] { "field" }, 2000 );
  for ( int row = 0; row < tableModel.getRowCount(); row++ ) {
    tableModel.setValueAt( "Value row = " + row, row, 0 );
  }

  report.setDataFactory( new TableDataFactory( "default", tableModel ) );

  DebugReportRunner.createDataCSV( report );
}
 
Example 3
Source File: XMLExportIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testExport() throws Exception {
  final MasterReport report = new MasterReport();
  final ItemBand itemBand = report.getItemBand();
  final TextFieldElementFactory cfef = new TextFieldElementFactory();
  cfef.setFieldname( "field" );
  cfef.setMinimumWidth( new Float( 500 ) );
  cfef.setMinimumHeight( new Float( 200 ) );
  itemBand.addElement( cfef.createElement() );

  final DefaultTableModel tableModel = new DefaultTableModel( new String[] { "field" }, 2000 );
  for ( int row = 0; row < tableModel.getRowCount(); row++ ) {
    tableModel.setValueAt( "Value row = " + row, row, 0 );
  }

  report.setDataFactory( new TableDataFactory( "default", tableModel ) );

  DebugReportRunner.createDataXML( report );
}
 
Example 4
Source File: SimpleBarcodesAPIDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 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 org.pentaho.reporting.engine.classic.demo.util.ReportDefinitionException
 *          if an error occured preventing the report definition.
 */
public MasterReport createReport() throws ReportDefinitionException
{
  final MasterReport report = new MasterReport();

  final BarcodeElementFactory factory = new BarcodeElementFactory();
  factory.setFieldname("value");
  factory.setAbsolutePosition(new Point2D.Float(0, 0));
  // remember that with barcodes we do not have much control over the element size, just make it big enough
  // to be fully printable
  factory.setMinimumSize(new Dimension(300, 50));
  factory.setType(SimpleBarcodesUtility.BARCODE_CODE128);   // code128 accepts every characters
  factory.setBarWidth(new Integer(2));
  factory.setBarHeight(new Integer(30));
  factory.setFontSize(new Integer(10));
  factory.setFontName("SansSerif");


  final ItemBand itemBand = report.getItemBand();
  itemBand.addElement(factory.createElement());

  report.setDataFactory(new TableDataFactory("default", data));
  return report;
}
 
Example 5
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 6
Source File: Prd4625Test.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testChartCollectorActive() throws Exception {
  final URL source = getClass().getResource( "Prd-4625.prpt" );
  final ResourceManager mgr = new ResourceManager();
  mgr.registerDefaults();
  final MasterReport report = (MasterReport) mgr.createDirectly( source, MasterReport.class ).getResource();

  final ItemBand itemBand = report.getItemBand();
  final SubReport subReport = (SubReport) itemBand.getElement( 0 );
  subReport.addExpression( new ValidateChartConfigurationFunction() );
  // the chart is in the report header. We now validate that there is a chart-dataset collector added to the
  // report.

  DebugReportRunner.execGraphics2D( report );
}
 
Example 7
Source File: SimpleStyleResolverTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testStyleInheritance() {
  MasterReport report = new MasterReport();
  final ItemBand itemBand = report.getItemBand();

  report.getStyle().setStyleProperty( TextStyleKeys.FONT, "Dudadu" );

  ResolverStyleSheet styleSheet = new ResolverStyleSheet();
  new SimpleStyleResolver( true ).resolve( itemBand, styleSheet );
  Assert.assertEquals( "Dudadu", styleSheet.getStyleProperty( TextStyleKeys.FONT ) );

}
 
Example 8
Source File: SparklineAPIDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 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 MasterReport report = new MasterReport();
  report.setName("Sparkline Demo");
  final DefaultParameterDefinition paramDef = new DefaultParameterDefinition();
  final PlainParameter plainParameter = new PlainParameter("sparkline-data", Number[].class);
  plainParameter.setDefaultValue(new Number[]
      {new Integer(10), new Integer(5),
          new Integer(6), new Integer(3),
          new Integer(1), new Integer(2),
          new Integer(7), new Integer(9)});
  paramDef.addParameterDefinition(plainParameter);

  report.setParameterDefinition(paramDef);

  // using the field sparkline-data
  final BarSparklineElementFactory elementFactory = new BarSparklineElementFactory();
  elementFactory.setFieldname("sparkline-data");
  elementFactory.setAbsolutePosition(new Point2D.Float(0, 0));
  elementFactory.setMinimumSize(new Dimension(100, 10));
  elementFactory.setColor(Color.black);
  elementFactory.setHighColor(Color.red);
  elementFactory.setLastColor(Color.blue);
  elementFactory.setBackgroundColor(Color.orange);

  final ReportFooter footer = report.getReportFooter();
  footer.addElement(elementFactory.createElement());

  // using a formula
  final BarSparklineElementFactory itemsSparkFactory = new BarSparklineElementFactory();
  itemsSparkFactory.setFormula
      ("={[January]|[February]|[March]|[April]|[May]|[June]|" +
          "[July]|[August]|[September]|[October]|[November]|[December]}");
  itemsSparkFactory.setAbsolutePosition(new Point2D.Float(0, 0));
  itemsSparkFactory.setMinimumSize(new Dimension(100, 10));
  itemsSparkFactory.setHighColor(Color.green);
  itemsSparkFactory.setLastColor(Color.blue);
  //itemsSparkFactory.setBackgroundColor(Color.yellow);
  final ItemBand itemBand = report.getItemBand();
  itemBand.addElement(itemsSparkFactory.createElement());

  itemBand.addElement(HorizontalLineElementFactory.createHorizontalLine
      (15, null, new BasicStroke(5)));

  report.setDataFactory(new TableDataFactory("default", data));
  return report;
}
 
Example 9
Source File: AlignmentRightApiIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void setupItemBand( final MasterReport report ) {
  final Band band = report.getItemBand();
  band.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, new Float( 20 ) );

  final ItemCountFunction icf = new ItemCountFunction();
  icf.setName( "ITEM_COUNT" );

  report.addExpression( icf );

  final TextFieldElementFactory factory2 = new TextFieldElementFactory();
  factory2.setFontName( "Serif" );
  factory2.setFontSize( new Integer( 11 ) );
  factory2.setBold( Boolean.FALSE );

  final NumberFieldElementFactory nf = new NumberFieldElementFactory();
  nf.setName( "ItemNumberTextField" );
  nf.setAbsolutePosition( new Point2D.Double( X1, 7.0 ) );
  nf.setMinimumSize( new FloatDimension( 25.0f, 16.0f ) );
  nf.setVerticalAlignment( ElementAlignment.TOP );
  nf.setFieldname( "ITEM_COUNT" );
  nf.setFormatString( "#0'.'" );
  band.addElement( nf.createElement() );

  factory2.setName( "ItemField" );
  factory2.setAbsolutePosition( new Point2D.Double( X1 + 25.0, 7.0 ) );
  factory2.setMinimumSize( new FloatDimension( C1_WIDTH - 25.0f, 16.0f ) );
  factory2.setDynamicHeight( Boolean.TRUE );
  factory2.setTrimTextContent( Boolean.TRUE );
  factory2.setFieldname( "Item" );
  band.addElement( factory2.createElement() );

  final SurveyScaleExpression iaf1 = new SurveyScaleExpression( 1, 5 );
  iaf1.setName( "Survey Response" );
  iaf1.setField( 0, "Your Response" );
  iaf1.setField( 1, "Average Response" );

  report.addExpression( iaf1 );

  final ContentFieldElementFactory f = new ContentFieldElementFactory();
  f.setFieldname( "Survey Response" );
  f.setMinimumSize( new FloatDimension( C2_WIDTH, 15.0f ) );
  f.setAbsolutePosition( new Point2D.Double( X2, 6.0 ) );
  band.addElement( f.createElement() );

  final NumberFieldElementFactory nfef = new NumberFieldElementFactory();
  nfef.setFontName( "Serif" );
  nfef.setFontSize( new Integer( 11 ) );
  nfef.setName( "F1" );
  nfef.setAbsolutePosition( new Point2D.Double( X3, 7.0 ) );
  nfef.setMinimumSize( new FloatDimension( C3_WIDTH, 16.0f ) );
  nfef.setFieldname( "Your Response" );
  nfef.setFormatString( "0.00" );
  nfef.setHorizontalAlignment( ElementAlignment.CENTER );
  band.addElement( nfef.createElement() );

  nfef.setName( "F2" );
  nfef.setAbsolutePosition( new Point2D.Double( X4, 7.0 ) );
  nfef.setFieldname( "Average Response" );
  band.addElement( nfef.createElement() );
}
 
Example 10
Source File: SurveyScaleAPIDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void setupItemBand(final MasterReport report)
{
  final Band band = report.getItemBand();
  band.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(20));

  final ItemCountFunction icf = new ItemCountFunction();
  icf.setName("ITEM_COUNT");

  report.addExpression(icf);

  final TextFieldElementFactory factory2 = new TextFieldElementFactory();
  factory2.setFontName("Serif");
  factory2.setFontSize(new Integer(11));
  factory2.setBold(Boolean.FALSE);

  final NumberFieldElementFactory nf = new NumberFieldElementFactory();
  nf.setName("ItemNumberTextField");
  nf.setAbsolutePosition(new Point2D.Double(X1, 7.0));
  nf.setMinimumSize(new FloatDimension(25.0f, 16.0f));
  nf.setVerticalAlignment(ElementAlignment.TOP);
  nf.setFieldname("ITEM_COUNT");
  nf.setFormatString("#0'.'");
  band.addElement(nf.createElement());

  factory2.setName("ItemField");
  factory2.setAbsolutePosition(new Point2D.Double(X1 + 25.0, 7.0));
  factory2.setMinimumSize(new FloatDimension(C1_WIDTH - 25.0f, 16.0f));
  factory2.setDynamicHeight(Boolean.TRUE);
  factory2.setTrimTextContent(Boolean.TRUE);
  factory2.setFieldname("Item");
  band.addElement(factory2.createElement());

  final SurveyScaleExpression iaf1 = new SurveyScaleExpression(1, 5);
  iaf1.setName("Survey Response");
  iaf1.setField(0, "Your Response");
  iaf1.setField(1, "Average Response");

  report.addExpression(iaf1);

  final ContentFieldElementFactory f = new ContentFieldElementFactory();
  f.setFieldname("Survey Response");
  f.setMinimumSize(new FloatDimension(C2_WIDTH, 15.0f));
  f.setAbsolutePosition(new Point2D.Double(X2, 6.0));
  band.addElement(f.createElement());

  final NumberFieldElementFactory nfef = new NumberFieldElementFactory();
  nfef.setFontName("Serif");
  nfef.setFontSize(new Integer(11));
  nfef.setName("F1");
  nfef.setAbsolutePosition(new Point2D.Double(X3, 7.0));
  nfef.setMinimumSize(new FloatDimension(C3_WIDTH, 16.0f));
  nfef.setFieldname("Your Response");
  nfef.setFormatString("0.00");
  nfef.setHorizontalAlignment(ElementAlignment.CENTER);
  band.addElement(nfef.createElement());

  nfef.setName("F2");
  nfef.setAbsolutePosition(new Point2D.Double(X4, 7.0));
  nfef.setFieldname("Average Response");
  band.addElement(nfef.createElement());
}
 
Example 11
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();

    // Loading the Table DataFactory.
    DefaultTableModel tableModel = new DefaultTableModel(
      new Object[][] {
        {"Product A", 123},
        {"Product B", 234},
        {"Product C", 345},
        {"Product D", 456}
      },
  	new String[] {"Product", "Cost"});
    TableDataFactory dataFactory = new TableDataFactory();
    dataFactory.addTable("default", tableModel);
    report.setDataFactory(dataFactory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("Product");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("Cost");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 12
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();
  }
}
 
Example 13
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");
    dataFactory.setQuery("default2", "SELECT PRODUCTCODE, QUANTITYORDERED, PRICEEACH FROM ORDERDETAILS WHERE ORDERNUMBER=${ORDERNUMBER}  ORDER BY ORDERLINENUMBER ASC LIMIT 5");
    report.setDataFactory(dataFactory);
    report.setQuery("default");

    // 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);
    numberFactory.setBold(true);
    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);

    // Creating the subreport.
    SubReport subReport = new SubReport();
    subReport.setQuery("default2");
    subReport.addInputParameter("ORDERNUMBER", "ORDERNUMBER");

    // Adding a field to the subreport's details band.
    TextFieldElementFactory textFactory2 = new TextFieldElementFactory();
    textFactory2.setFieldname("PRODUCTCODE");
    textFactory2.setX(101f);
    textFactory2.setY(1f);
    textFactory2.setMinimumWidth(200f);
    textFactory2.setMinimumHeight(20f);
    Element textField2 = textFactory2.createElement();
    subReport.getItemBand().addElement(textField2);

    // Adding a field to the subreport's details band.
    NumberFieldElementFactory numberFactory2 = new NumberFieldElementFactory();
    numberFactory2.setFieldname("QUANTITYORDERED");
    numberFactory2.setX(301f);
    numberFactory2.setY(1f);
    numberFactory2.setMinimumWidth(100f);
    numberFactory2.setMinimumHeight(20f);
    Element numberField2 = numberFactory2.createElement();
    subReport.getItemBand().addElement(numberField2);

    // Adding a field to the subreport's details band.
    NumberFieldElementFactory numberFactory3 = new NumberFieldElementFactory();
    numberFactory3.setFieldname("PRICEEACH");
    numberFactory3.setX(401f);
    numberFactory3.setY(1f);
    numberFactory3.setMinimumWidth(100f);
    numberFactory3.setMinimumHeight(20f);
    Element numberField3 = numberFactory3.createElement();
    subReport.getItemBand().addElement(numberField3);

    // Adding the subreport to the report's details band.
    itemBand.addSubReport(subReport);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 14
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.
    Connection connection = DriverManager.getConnection("jdbc:hsqldb:./resources/sampledata/sampledata", "pentaho_user", "password");
    StaticConnectionProvider provider = new StaticConnectionProvider(connection);

    // Defining the query.
    SQLReportDataFactory dataFactory = new SQLReportDataFactory(provider);
    String sqlQuery = "SELECT PRODUCTNAME, QUANTITYINSTOCK FROM PRODUCTS";
    dataFactory.setQuery("default", sqlQuery);
    report.setDataFactory(dataFactory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("PRODUCTNAME");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("QUANTITYINSTOCK");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 15
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 query.
    SQLReportDataFactory dataFactory = new SQLReportDataFactory(provider);
    String sqlQuery = "SELECT PRODUCTNAME, QUANTITYINSTOCK FROM PRODUCTS";
    dataFactory.setQuery("default", sqlQuery);
    report.setDataFactory(dataFactory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("PRODUCTNAME");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the quantity in stock of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("QUANTITYINSTOCK");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 16
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();

    // Loading Kettle data source.
    KettleTransFromFileProducer producer = new KettleTransFromFileProducer (
      "resources/CSV Input - Reading customer data.ktr",
      "Dummy (do nothing)",
      new FormulaArgument[0], 
      new FormulaParameter[0]);
    KettleDataFactory factory = new KettleDataFactory();
    factory.setQuery("default", producer);
    report.setDataFactory(factory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("name");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("id");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 17
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();

    // Data source provider.
    DriverDataSourceProvider dsProvider = new DriverDataSourceProvider();
    dsProvider.setDriver("org.hsqldb.jdbcDriver");
    dsProvider.setProperty("user", "pentaho_user");
    dsProvider.setProperty("password", "password");
    dsProvider.setUrl("jdbc:hsqldb:./resources/sampledata/sampledata");

    // Mondrian cube provider.
    DefaultCubeFileProvider cubeProvider = new DefaultCubeFileProvider();
    cubeProvider.setMondrianCubeFile("./resources/steelwheels.mondrian.xml");

    // Loading Mondrian data source.
    BandedMDXDataFactory factory = new BandedMDXDataFactory();
    factory.setDataSourceProvider(dsProvider);
    factory.setCubeFileProvider(cubeProvider);
    factory.setQuery("default", "SELECT {[Measures].[Sales]} ON COLUMNS, {Descendants([Time].Children, [Time].[Months])} ON ROWS FROM [SteelWheelsSales]");
    report.setDataFactory(factory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("[Time].[Months]");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("[Measures].[Sales]");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 18
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();

    // Loading MQL data source.
    PmdDataFactory factory = new PmdDataFactory();
    factory.setConnectionProvider(new PmdConnectionProvider());
    factory.setXmiFile("resources/metadata.xmi");
    factory.setDomainId("test");
    factory.setQuery(
      "default",
      "<?xml version='1.0' encoding='UTF-8'?>" + 
      "<mql>" + 
        "<domain_id>test</domain_id>" + 
        "<model_id>BV_ORDERS</model_id>" + 
        "<options>" + 
          "<disable_distinct>false</disable_distinct>" + 
          "<limit>-1</limit>" + 
        "</options>" + 
        "<selections>" + 
          "<selection>" + 
            "<view>CAT_PRODUCTS</view>" + 
            "<column>BC_PRODUCTS_PRODUCTNAME</column>" + 
            "<aggregation>NONE</aggregation>" + 
          "</selection>" + 
          "<selection>" + 
            "<view>CAT_PRODUCTS</view>" + 
            "<column>BC_PRODUCTS_MSRP</column>" + 
            "<aggregation>AVERAGE</aggregation>" + 
          "</selection>" + 
        "</selections>" + 
        "<constraints/>" + 
        "<orders/>" + 
      "</mql>",
      null,
      null);

    report.setDataFactory(factory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("BC_PRODUCTS_PRODUCTNAME");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("BC_PRODUCTS_MSRP");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
Example 19
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();

    // Load report xpath data.
    XPathDataFactory factory = new XPathDataFactory();
    factory.setXqueryDataFile("file:./resources/xpathexample.xml");
    factory.setQuery("default", "/ExampleResultSet/Row", false);
    report.setDataFactory(factory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("NAME");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("SIZE");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

  }
  catch (Exception e) 
  {
      e.printStackTrace();
  }
}
 
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();

    // Loading OLAP data.
    DriverConnectionProvider provider = new DriverConnectionProvider();
    provider.setDriver("mondrian.olap4j.MondrianOlap4jDriver");
    provider.setUrl("jdbc:mondrian: ");
    provider.setProperty("Catalog", "./resources/steelwheels.mondrian.xml");
    provider.setProperty("JdbcUser", "pentaho_user");
    provider.setProperty("JdbcPassword", "password");
    provider.setProperty("Jdbc", "jdbc:hsqldb:./resources/sampledata/sampledata");
    provider.setProperty("JdbcDrivers", "org.hsqldb.jdbcDriver");

    // Creating the factory.
    BandedMDXDataFactory factory = new BandedMDXDataFactory(provider);
    factory.setQuery("default", "SELECT {[Measures].[Sales]} ON COLUMNS, {Descendants([Time].Children, [Time].[Months])} ON ROWS FROM [SteelWheelsSales]");
    report.setDataFactory(factory);

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

    // Adding a text field for the product name, added to the item band.
    TextFieldElementFactory textFactory = new TextFieldElementFactory(); 
    textFactory.setFieldname("[Time].[Months]");
    textFactory.setX(1f);
    textFactory.setY(1f); 
    textFactory.setMinimumWidth(200f);
    textFactory.setMinimumHeight(20f);
    Element nameField = textFactory.createElement(); 
    itemBand.addElement(nameField);

    // Adding a number filed with the total cost of the products.
    NumberFieldElementFactory numberFactory = new NumberFieldElementFactory();
    numberFactory.setFieldname("[Measures].[Sales]");
    numberFactory.setX(201f);
    numberFactory.setY(1f);
    numberFactory.setMinimumWidth(100f);
    numberFactory.setMinimumHeight(20f);
    Element totalCost = numberFactory.createElement();
    itemBand.addElement(totalCost);

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

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