Search in sources :

Example 11 with JFreeReportAction

use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.

the class JFreeReportComponent method getQueryComponentDataFactory.

private PentahoTableDataFactory getQueryComponentDataFactory() throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    PentahoTableDataFactory factory = null;
    String dataComponentName = jFreeReportAction.getDataComponent().getStringValue();
    String origComponentName = jFreeReportAction.getComponentName();
    if (dataComponentName != null) {
        if (JFreeReportAction.SQL_DATA_SOURCE.equalsIgnoreCase(dataComponentName)) {
            dataComponentName = AbstractJFreeReportComponent.DATACOMPONENT_SQLCLASS;
        } else if (JFreeReportAction.MDX_DATA_SOURCE.equalsIgnoreCase(dataComponentName)) {
            dataComponentName = AbstractJFreeReportComponent.DATACOMPONENT_MDXCLASS;
        }
        try {
            // This is a giant hack and a big no, no. Basically we're going to transform the JFreeReportAction into a
            // SQL or MDX lookup action, by changing its component name. Then we create the appropriate component to run the
            // transformed action.
            // All this to support the DB and Query info being embedded in the JFreeReport action. This is definitely
            // deprecated functionality
            // that should not be relied upon. The correct way to do this is to create an SQL or MDX action prior to the
            // JFreeReport
            // action in the action sequence. That action performs the desired query, then pass the results of that query to
            // the JFreeReport
            // action.
            jFreeReportAction.setComponentName(dataComponentName);
            ActionDefinition tmpActionDefinition = ActionFactory.getActionDefinition(jFreeReportAction.getElement(), jFreeReportAction.getActionParameterMgr());
            final Class componentClass = Class.forName(dataComponentName);
            IDataComponent dataComponent = (IDataComponent) componentClass.newInstance();
            dataComponent.setInstanceId(getInstanceId());
            dataComponent.setActionName(getActionName());
            dataComponent.setProcessId(getProcessId());
            dataComponent.setActionDefinition(tmpActionDefinition);
            dataComponent.setComponentDefinition(getComponentDefinition());
            dataComponent.setRuntimeContext(getRuntimeContext());
            dataComponent.setSession(getSession());
            dataComponent.setLoggingLevel(getLoggingLevel());
            dataComponent.setMessages(getMessages());
            // Abort, we cant continue anyway.
            if ((dataComponent.validate() == IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) && dataComponent.init() && (dataComponent.execute() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
                final IPentahoResultSet resultset = dataComponent.getResultSet();
                factory = new PentahoTableDataFactory(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(resultset));
            } else {
                throw new IllegalArgumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "JFreeReport.ERROR_0021_DATA_COMPONENT_FAILED"));
            }
        } catch (ClassNotFoundException e) {
            JFreeReportComponent.logger.error(null, e);
        } catch (InstantiationException e) {
            JFreeReportComponent.logger.error(null, e);
        } catch (IllegalAccessException e) {
            JFreeReportComponent.logger.error(null, e);
        } finally {
            jFreeReportAction.setComponentName(origComponentName);
        }
    }
    return factory;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) IDataComponent(org.pentaho.platform.api.data.IDataComponent) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition)

Example 12 with JFreeReportAction

use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.

the class JFreeReportComponent method getReportFromInputParam.

private MasterReport getReportFromInputParam() throws ResourceException, UnsupportedEncodingException, IOException {
    MasterReport report = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    Object reportDefinition = jFreeReportAction.getReportDefinition();
    if (reportDefinition instanceof ActionInput) {
        String repDef = ((ActionInput) reportDefinition).getStringValue();
        report = createReport(repDef);
    }
    return report;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ActionInput(org.pentaho.actionsequence.dom.ActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput)

Example 13 with JFreeReportAction

use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.

the class JFreeReportComponent method getJarDataFactory.

private PentahoTableDataFactory getJarDataFactory() throws Exception {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    try {
        org.pentaho.actionsequence.dom.IActionResource actionResource = jFreeReportAction.getDataJar().getJar();
        if (actionResource != null) {
            DataSource dataSource = new ActivationHelper.PentahoStreamSourceWrapper(actionResource.getDataSource());
            InputStream in = dataSource.getInputStream();
            try {
                // not being able to read a single char is definitly a big boo ..
                if (in.read() == -1) {
                    // $NON-NLS-1$
                    throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
                } else {
                    final ClassLoader loader = ReportUtils.createJarLoader(getSession(), getResource(actionResource.getName()));
                    if (loader == null) {
                        throw new Exception(Messages.getInstance().getString(// $NON-NLS-1$
                        "JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER"));
                    } else if (!isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT)) {
                        throw new Exception(Messages.getInstance().getErrorString(// $NON-NLS-1$
                        "JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING"));
                    } else {
                        // Get input parameters, and set them as properties in the report
                        // object.
                        final ReportParameterValues reportProperties = new ReportParameterValues();
                        IActionInput[] actionInputs = jFreeReportAction.getInputs();
                        for (IActionInput element : actionInputs) {
                            final Object paramValue = element.getValue();
                            if (paramValue instanceof Object[]) {
                                final Object[] values = (Object[]) paramValue;
                                final StringBuffer valuesBuffer = new StringBuffer();
                                // TODO support non-string items
                                for (int z = 0; z < values.length; z++) {
                                    if (z == 0) {
                                        valuesBuffer.append(values[z].toString());
                                    } else {
                                        valuesBuffer.append(',').append(values[z].toString());
                                    }
                                }
                                reportProperties.put(element.getName(), valuesBuffer.toString());
                            } else {
                                reportProperties.put(element.getName(), paramValue);
                            }
                        }
                        final DataFactory dataFactory = new PentahoDataFactory(loader);
                        final TableModel model = dataFactory.queryData(jFreeReportAction.getDataJar().getDataClass(), new ParameterDataRow(reportProperties));
                        factory = new PentahoTableDataFactory(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model);
                    }
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
            }
        }
    } catch (FileNotFoundException e1) {
        throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0010_REPORT_JAR_MISSING", // $NON-NLS-1$
        jFreeReportAction.getDataJar().toString()));
    }
    return factory;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IActionResource(org.pentaho.actionsequence.dom.IActionResource) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) DataFactory(org.pentaho.reporting.engine.classic.core.DataFactory) ParameterDataRow(org.pentaho.reporting.engine.classic.core.ParameterDataRow) PrintException(javax.print.PrintException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) DataSource(javax.activation.DataSource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) PentahoDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoDataFactory) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues)

Example 14 with JFreeReportAction

use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.

the class JFreeReportComponent method validateAction.

/**
 * We cannot validate the parameters of all components, as the required parameters might not have been created.
 *
 * @return
 */
@Override
public boolean validateAction() {
    boolean result = true;
    if (!(getActionDefinition() instanceof JFreeReportAction)) {
        error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
        getActionDefinition().getElement().asXML()));
        result = false;
    } else {
        validateParametersComponent = new JFreeReportValidateParametersComponent();
        if (initAndValidate(validateParametersComponent) == false) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("JFreeReportComponent.ERROR_0025_COULD_NOT_VALIDATE"));
            result = false;
        }
    }
    return result;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) JFreeReportValidateParametersComponent(org.pentaho.platform.plugin.action.jfreereport.components.JFreeReportValidateParametersComponent)

Aggregations

JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)14 IActionInput (org.pentaho.actionsequence.dom.IActionInput)5 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)4 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)4 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)4 TableModel (javax.swing.table.TableModel)3 IActionResource (org.pentaho.actionsequence.dom.IActionResource)3 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 DataSource (javax.activation.DataSource)2 PrintException (javax.print.PrintException)2 ActionInput (org.pentaho.actionsequence.dom.ActionInput)2 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)2 IContentItem (org.pentaho.platform.api.repository.IContentItem)2 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)2 ReportGenerator (org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator)2 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)2