Search in sources :

Example 11 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet 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 12 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet 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 13 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class JFreeReportParametersComponent method initReportInputs.

private boolean initReportInputs() throws CloneNotSupportedException {
    MasterReport report = getReport();
    if (report == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("JFreeReportParametersComponent.ERROR_0034_NO_REPORT_DEFINITION"));
        return false;
    }
    final boolean privateCopy = getInputBooleanValue(AbstractJFreeReportComponent.REPORTPARAMCOMPONENT_PRIVATEREPORT_OUTPUT, false);
    if (privateCopy && isDefinedOutput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) {
        report = (MasterReport) report.clone();
    }
    // Get input parameters, and set them as properties in the report
    // object.
    final Set paramNames = getInputNames();
    final Iterator it = paramNames.iterator();
    while (it.hasNext()) {
        String paramName = (String) it.next();
        Object paramValue = getInputValue(paramName);
        if ((paramValue == null) || "".equals(paramValue)) {
            // $NON-NLS-1$
            continue;
        }
        if (paramValue instanceof IPentahoResultSet) {
            continue;
        }
        if (paramValue instanceof TableModel) {
            continue;
        }
        if (AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT.equals(paramName)) {
            continue;
        }
        if (AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_DATAINPUT.equals(paramName)) {
            continue;
        }
        if (AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT.equals(paramName)) {
            continue;
        }
        if (paramValue instanceof Object[]) {
            Object[] values = (Object[]) paramValue;
            StringBuffer valuesBuffer = new StringBuffer();
            // TODO support non-string items
            for (int j = 0; j < values.length; j++) {
                if (j == 0) {
                    valuesBuffer.append(values[j].toString());
                } else {
                    valuesBuffer.append(',').append(values[j].toString());
                }
            }
            report.getParameterValues().put(paramName, valuesBuffer.toString());
        // report.setProperty(paramName, valuesBuffer.toString());
        } else {
            report.getParameterValues().put(paramName, paramValue);
        // report.setProperty(paramName, paramValue);
        }
    }
    if (privateCopy && isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) {
        addTempParameterObject(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT, report);
    }
    return true;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) Set(java.util.Set) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Iterator(java.util.Iterator) TableModel(javax.swing.table.TableModel)

Example 14 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class ResultSetCompareComponent method executeAction.

@Override
protected boolean executeAction() throws Throwable {
    ResultSetCompareAction compareAction = (ResultSetCompareAction) getActionDefinition();
    Object obj1 = compareAction.getResultSet1().getValue();
    if (!(obj1 instanceof IPentahoResultSet)) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0004_INPUT_RS1_NOT_RS"));
        return false;
    }
    Object obj2 = compareAction.getResultSet2().getValue();
    if (!(obj2 instanceof IPentahoResultSet)) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("ResultSetCompareComponent.ERROR_0005_INPUT_RS2_NOT_RS"));
        return false;
    }
    IPentahoResultSet rs1 = (IPentahoResultSet) compareAction.getResultSet1().getValue();
    IPentahoResultSet rs2 = (IPentahoResultSet) compareAction.getResultSet2().getValue();
    String tempOutputMismatches = compareAction.getOutputMismatches().getStringValue();
    boolean outputMismatches = false;
    if ((tempOutputMismatches != null) && tempOutputMismatches.trim().toLowerCase().equals("true")) {
        // $NON-NLS-1$
        outputMismatches = true;
    }
    boolean stopOnError = false;
    String tempStopOnError = compareAction.getStopOnError().getStringValue();
    if ((tempStopOnError != null) && tempStopOnError.trim().toLowerCase().equals("true")) {
        // $NON-NLS-1$
        stopOnError = true;
    }
    int compareCol = Integer.parseInt(compareAction.getCompareColumnNum().getStringValue());
    return compareEquals(rs1, rs2, compareCol, outputMismatches, stopOnError);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ResultSetCompareAction(org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)

Example 15 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class IPreparedComponentIT method testIPreparedComponentXQueryShareConnection.

public void testIPreparedComponentXQueryShareConnection() {
    startTest();
    // $NON-NLS-1$
    info("Expected: Successful execution with object available");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_xquery_shareconn.xaction");
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // $NON-NLS-1$
    IActionParameter rtn1 = context.getOutputParameter("prepared_component");
    assertNotNull(rtn1);
    IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
    assertNotNull(preparedComponent1);
    IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null);
    assertTrue(resultset1.getRowCount() >= 1);
    Object val1 = resultset1.getValueAt(0, 0);
    assertNotNull(val1);
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5