Search in sources :

Example 1 with PentahoTableModel

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel in project pentaho-platform by pentaho.

the class JFreeReportComponent method getInputParamDataFactory.

private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    ActionInput reportDataParam = (ActionInput) jFreeReportAction.getData();
    Object dataObject = reportDataParam != null ? reportDataParam.getValue() : null;
    if ((dataObject instanceof IPentahoResultSet) || (dataObject instanceof TableModel)) {
        factory = new PentahoTableDataFactory();
        if (dataObject instanceof IPentahoResultSet) {
            IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
            if (resultset.isScrollable()) {
                resultset.beforeFirst();
            } else {
                // $NON-NLS-1$
                debug("ResultSet is not scrollable. Copying into memory");
                IPentahoResultSet memSet = resultset.memoryCopy();
                resultset.close();
                resultset = memSet;
            }
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(resultset));
        } else if (dataObject instanceof TableModel) {
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, (TableModel) dataObject);
        }
        IActionInput[] subreportQueries = jFreeReportAction.getSubreportQueryParams();
        for (IActionInput element : subreportQueries) {
            dataObject = element.getValue();
            if (dataObject instanceof IPreparedComponent) {
                factory.addPreparedComponent(element.getName(), (IPreparedComponent) dataObject);
            } else if (dataObject instanceof IPentahoResultSet) {
                final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
                resultset.beforeFirst();
                factory.addTable(element.getName(), new PentahoTableModel(resultset));
            } else if (dataObject instanceof TableModel) {
                factory.addTable(element.getName(), (TableModel) dataObject);
            }
        }
    }
    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) ActionInput(org.pentaho.actionsequence.dom.ActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionInput(org.pentaho.actionsequence.dom.IActionInput) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 2 with PentahoTableModel

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel in project pentaho-platform by pentaho.

the class ReportWizardSpecComponent method getDataFactory.

@Override
protected PentahoTableDataFactory getDataFactory() throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
    PentahoTableDataFactory factory = null;
    if (reportSpec != null) {
        if (!isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY) || "true".equals(getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY))) {
            // $NON-NLS-1$
            IPentahoResultSet pentahoResultSet = getResultSet(getReportSpec());
            factory = new PentahoTableDataFactory();
            pentahoResultSet.beforeFirst();
            factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(pentahoResultSet));
        } else {
            factory = super.getDataFactory();
        }
    } else {
        factory = super.getDataFactory();
    }
    return factory;
}
Also used : PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)

Example 3 with PentahoTableModel

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel in project pentaho-platform by pentaho.

the class JFreeReportDataComponent method getInputParamDataFactory.

@SuppressWarnings("unused")
private PentahoTableDataFactory getInputParamDataFactory() {
    PentahoTableDataFactory factory = null;
    if (isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT) || isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT)) {
        factory = new PentahoTableDataFactory();
        final Iterator iter = getInputNames().iterator();
        while (iter.hasNext()) {
            String name = (String) iter.next();
            final Object dataObject = getInputValue(name);
            // if input name is "data", rename to "default" which is the name that jfreereport is expecting.
            if (name.equals(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT)) {
                name = AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT;
            }
            if (dataObject instanceof IPreparedComponent) {
                final IPreparedComponent comp = (IPreparedComponent) dataObject;
                factory.addPreparedComponent(name, comp);
            } else if (dataObject instanceof IPentahoResultSet) {
                final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
                resultset.beforeFirst();
                factory.addTable(name, new PentahoTableModel(resultset));
            } else if (dataObject instanceof TableModel) {
                final TableModel model = (TableModel) dataObject;
                factory.addTable(name, model);
            }
        }
    }
    return factory;
}
Also used : PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) Iterator(java.util.Iterator) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) TableModel(javax.swing.table.TableModel)

Example 4 with PentahoTableModel

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel in project pentaho-platform by pentaho.

the class JFreeReportDataComponent method getQueryComponentDataFactory.

@SuppressWarnings("unused")
private PentahoTableDataFactory getQueryComponentDataFactory() throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception {
    PentahoTableDataFactory factory = null;
    dataComponent = null;
    final Node sourceNode = getComponentDefinition().selectSingleNode(AbstractJFreeReportComponent.DATACOMPONENT_SOURCE);
    if (sourceNode != null) {
        String dataComponentClass = sourceNode.getText();
        if (AbstractJFreeReportComponent.DATACOMPONENT_SQLSOURCE.equalsIgnoreCase(dataComponentClass)) {
            dataComponentClass = AbstractJFreeReportComponent.DATACOMPONENT_SQLCLASS;
        } else if (AbstractJFreeReportComponent.DATACOMPONENT_MDXSOURCE.equalsIgnoreCase(dataComponentClass)) {
            dataComponentClass = AbstractJFreeReportComponent.DATACOMPONENT_MDXCLASS;
        }
        if (dataComponentClass != null) {
            try {
                final Class componentClass = Class.forName(dataComponentClass);
                dataComponent = (IDataComponent) componentClass.newInstance();
                dataComponent.setInstanceId(getInstanceId());
                dataComponent.setActionName(getActionName());
                dataComponent.setProcessId(getProcessId());
                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) {
            // ignore
            } catch (InstantiationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return factory;
}
Also used : PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) PentahoTableDataFactory(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory) Node(org.dom4j.Node)

Example 5 with PentahoTableModel

use of org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel 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

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)5 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)5 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)5 TableModel (javax.swing.table.TableModel)2 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)2 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)2 Iterator (java.util.Iterator)1 Node (org.dom4j.Node)1 ActionInput (org.pentaho.actionsequence.dom.ActionInput)1 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 ActionDefinition (org.pentaho.actionsequence.dom.actions.ActionDefinition)1 IDataComponent (org.pentaho.platform.api.data.IDataComponent)1