Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Problem defining DataFactory from Java Application

  1. #1
    Join Date
    Sep 2016
    Posts
    16

    Default Problem defining DataFactory from Java Application

    Hi.
    No one knows a solution to launch a report from java passing parameters and operate the pop consulting them ??

    I'm making a Java application that calls a report created in Pentaho RD.
    The report created has as parameters a drop-down list of options that is read from the database. When one of the possible options is chosen, the report shows the related data.
    The connection to the database is a proper driver jdbc "generic database"
    From Pentaho Rd everything is working properly.
    I developed the Java application with Eclipse Neon and I can generate executable jar and everything works properly.

    Name:  Captura1.PNG
Views: 171
Size:  17.5 KB

    The problem arises when trying to define a new Datafactory report from the java application.
    I need to change the path of the database when I released the report and did not take the default defined in the PRPT.

    Name:  Captura2.PNG
Views: 158
Size:  4.6 KB

    When I set any parameter of Datafactory (eg SampleDriverConnectionProvider.setDriver ....), launching the report, the query to get the parameters gives error: "The specified query is not executable here."

    Name:  Captura3.jpg
Views: 156
Size:  21.3 KB

    Name:  Captura4.jpg
Views: 159
Size:  11.1 KB

    To remove this error I define the parameters of the dataset report the Display Type option blank, then the report runs but I must indicate the parameter manually instead of take it from a dropdown list.

    Name:  Captura5.PNG
Views: 161
Size:  7.3 KB

    I think I need to define a parameter to pass the new DataFactory, but took days searching and can't find any solution.

    I have tried to define a data source jndi but Pentaho RD with this data source does not load the driver while the jdbc "generic database" works correctly.

    I made the code from the examples shown in the book "embedding_pentaho_repoting_engine".

    Could someone tell me what I should add in the DataFactory to the drop-down list of parameters work?

    Thank you so much.


    The code for the Java Application:

    import java.util.HashMap;
    import java.util.Map;

    import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
    import org.pentaho.reporting.engine.classic.core.DataFactory;
    import org.pentaho.reporting.engine.classic.core.MasterReport;
    import org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewDialog;
    import org.pentaho.reporting.engine.classic.core.wizard.RelationalAutoGeneratorPreProcessor;
    import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.ConnectionProvider;
    import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.DriverConnectionProvider;
    import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SQLReportDataFactory;
    import org.pentaho.reporting.libraries.resourceloader.Resource;
    import org.pentaho.reporting.libraries.resourceloader.ResourceException;
    import org.pentaho.reporting.libraries.resourceloader.ResourceManager;


    public class Grafico {


    /**
    * @param args
    */
    public static void main(String[] args) {
    // initialize the Reporting Engine

    ClassicEngineBoot.getInstance().start();

    // Get the complete report definition (the report definition with the data factory and
    // parameters already applied)
    Grafico sample = new Grafico();
    final MasterReport report = sample.getCompleteReportDefinition();

    // Generate the swing preview dialog
    final PreviewDialog dialog = new PreviewDialog();
    dialog.setReportJob(report);
    dialog.setSize(500, 500);
    dialog.setModal(true);
    dialog.setVisible(true);
    System.exit(0);
    }

    public MasterReport getCompleteReportDefinition() {
    final MasterReport report = getReportDefinition();

    // Add any parameters to the report
    final Map<String, Object> reportParameters = getReportParameters();
    if (null != reportParameters) {
    for (String key : reportParameters.keySet()) {
    report.getParameterValues().put(key, reportParameters.get(key));
    }
    }

    // Set the data factory for the report
    final DataFactory dataFactory = getDataFactory();
    if (dataFactory != null) {
    report.setDataFactory(dataFactory);
    }

    //report.setQuery(Query_Propio);
    report.addPreProcessor(new RelationalAutoGeneratorPreProcessor());

    // Return the completed report
    return report;
    }


    public MasterReport getReportDefinition()
    {
    try
    {

    final ResourceManager resourceManager = new ResourceManager();
    final Resource directly = resourceManager.createDirectly("F:/PENTAHO/FILES/CONT4/Art_Tarifas.prpt", MasterReport.class);
    // final Resource directly = resourceManager.createDirectly("F:/PENTAHO/FILES/CONT4/Sample1.prpt", MasterReport.class);
    return (MasterReport) directly.getResource();
    }
    catch (ResourceException e)
    {
    e.printStackTrace();
    }
    return null;
    }


    private Map<String, Object> getReportParameters() {
    final Map<String, Object> parameters = new HashMap<String, Object>();

    return null;

    //parameters.put("Tarifa", "LIBROS");
    //return parameters;
    }

    /**
    * Returns the data factory which will be used to generate the data used during report generation. In this example,
    * we will return null since the data factory has been defined in the report definition.
    *
    * @return the data factory used with the report generator
    */
    private DataFactory getDataFactory() {

    return null;

    If any of these options active the report fails in the query for the list of parameter options

    //final DriverConnectionProvider sampleDriverConnectionProvider = new DriverConnectionProvider();

    //sampleDriverConnectionProvider.setDriver("bd4.jdbc.XDriver");
    //sampleDriverConnectionProvider.setUrl("jdbc:bd4://127.0.0.1:4000/0/GEST_2016_1");
    //sampleDriverConnectionProvider.setProperty("user", "OPEN");
    //sampleDriverConnectionProvider.setProperty("password", "");
    //return dataFactory;

    }
    }
    Last edited by Clientescop; 10-08-2016 at 07:02 AM.

  2. #2
    Join Date
    Sep 2016
    Posts
    16

    Default

    Hi.

    For if it may help someone.

    I solved this problem by using the function "init (DataRow)" in the Global Data Source Scripting section. Both the main report and subreports.
    I leave an example.
    Greetings.

    function init(dataRow)
    {
    var s_DBdef = "jdbc:bd4://127.0.0.1:4002/GEST_2016_60";
    var s_selectedDB = dataRow.get("Database");
    if (s_selectedDB != null ) var databaseUrl = s_selectedDB;
    else var databaseUrl = s_DBdef;

    var s_USdef="DBA";
    var s_selectedUS = dataRow.get("Usu");
    if (s_selectedUS != null) var databaseUsu = s_selectedUS;
    else var databaseUsu = s_USdef;

    var s_PWSdef="SQL";
    var s_selectedPW = dataRow.get("Pwd");
    if (s_selectedPW != null) var databasePwd = s_selectedPW;
    else var databasePwd = s_PWSdef;

    dataFactory.getConnectionProvider().setUrl(databaseUrl);
    dataFactory.getConnectionProvider().setProperty("user", databaseUsu);
    dataFactory.getConnectionProvider().setProperty("password", databasePwd);
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.