Search in sources :

Example 1 with IDataComponent

use of org.pentaho.platform.api.data.IDataComponent 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)

Aggregations

ActionDefinition (org.pentaho.actionsequence.dom.actions.ActionDefinition)1 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 IDataComponent (org.pentaho.platform.api.data.IDataComponent)1 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)1 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)1