Search in sources :

Example 1 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput 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 IActionInput

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

the class JFreeReportComponent method initReportInputs.

private boolean initReportInputs(final MasterReport report) throws CloneNotSupportedException {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    // Get input parameters, and set them as properties in the report
    // object.
    IActionInput[] actionInputs = jFreeReportAction.getInputs();
    for (IActionInput element : actionInputs) {
        String paramName = element.getName();
        Object paramValue = element.getValue();
        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;
        }
        /*
       * WG: Commenting out because this change (SVN: 44880) breaks bi-developers / reporting / subreport.xaction we'll
       * need to revisit this when reving to the 4.0 reporting engine.
       * 
       * final ParameterDefinitionEntry[] parameterDefinitions =
       * report.getParameterDefinition().getParameterDefinitions(); boolean foundParameter = false; for (int j = 0; j <
       * parameterDefinitions.length; j++) { final ParameterDefinitionEntry definition = parameterDefinitions[j]; if
       * (paramName.equals(definition.getName())) { foundParameter = true; break; } } if (foundParameter == false) { if
       * (report.getParameterDefinition() instanceof ModifiableReportParameterDefinition) { final
       * ModifiableReportParameterDefinition parameterDefinition = (ModifiableReportParameterDefinition)
       * report.getParameterDefinition(); parameterDefinition.addParameterDefinition(new PlainParameter(paramName)); } }
       */
        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);
        }
    }
    return true;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IActionInput(org.pentaho.actionsequence.dom.IActionInput) TableModel(javax.swing.table.TableModel) PentahoTableModel(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)

Example 3 with IActionInput

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

the class JFreeReportComponent method initReportParams.

private int initReportParams() {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    int result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PASSED;
    // $NON-NLS-1$
    final String defaultValue = "";
    IActionInput[] actionInputs = jFreeReportAction.getInputs();
    for (IActionInput element : actionInputs) {
        Object paramValue = element.getValue();
        String inputName = element.getName();
        if (// $NON-NLS-1$
        (paramValue == null) || ("".equals(paramValue))) {
            IActionParameter paramParameter = getInputParameter(inputName);
            if (paramParameter.getPromptStatus() == IActionParameter.PROMPT_PENDING) {
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PROMPT_PENDING;
                continue;
            }
            if (isParameterUIAvailable()) {
                // The parameter value was not provided, and we are allowed
                // to
                // create user interface forms
                // $NON-NLS-1$
                createFeedbackParameter(inputName, inputName, "", defaultValue, true);
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PROMPT_PENDING;
            } else {
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_FAILED;
            }
        }
    }
    return result;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 4 with IActionInput

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

the class UtilityComponent method executeFormatAction.

private boolean executeFormatAction(final FormatMsgAction formatMsgAction) {
    boolean result = true;
    String formatString = formatMsgAction.getFormatString().getStringValue();
    IActionOutput actionOutput = formatMsgAction.getOutputString();
    IActionInput[] msgInputs = formatMsgAction.getMsgInputs();
    ArrayList formatArgs = new ArrayList();
    for (IActionInput element : msgInputs) {
        formatArgs.add(element.getStringValue());
    }
    try {
        MessageFormat mf = new MessageFormat(formatString);
        String theResult = mf.format(formatArgs.toArray());
        if (actionOutput != null) {
            actionOutput.setValue(theResult);
        }
    } catch (Exception ex) {
        result = false;
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) MessageFormat(java.text.MessageFormat) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) ArrayList(java.util.ArrayList)

Example 5 with IActionInput

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

the class ActionDelegate method executeAction.

/**
 * Wires up inputs outputs and resources to an Action and executes it.
 */
@Override
protected boolean executeAction() throws Throwable {
    // 
    // Set inputs
    // 
    InputErrorCallback errorCallback = new InputErrorCallback();
    for (IActionInput input : getActionDefinition().getInputs()) {
        Object inputValue = input.getValue();
        if (input instanceof ActionInputConstant) {
            // if the input is coming from the component definition section,
            // do parameter replacement on the string and the result of that
            // is the input value
            inputValue = input.getStringValue(true);
        }
        errorCallback.setValue(inputValue);
        actionHarness.setValue(input.getName(), inputValue, errorCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Set resources
    // 
    ResourceCallback resourceCallback = new ResourceCallback();
    for (IActionResource res : getActionDefinition().getResources()) {
        actionHarness.setValue(res.getName(), res.getInputStream(), resourceCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Provide output stream for the streaming action. We are going to look for all outputs where
    // type = "content", and derive output streams to hand to the IStreamingAction.
    // 
    Map<String, IContentItem> outputContentItems = new HashMap<String, IContentItem>();
    StreamOutputErrorCallback streamingOutputCallback = new StreamOutputErrorCallback();
    OuputStreamGenerator outputStreamGenerator = new OuputStreamGenerator(outputContentItems);
    IActionOutput[] contentOutputs = getActionDefinition().getOutputs(ActionSequenceDocument.CONTENT_TYPE);
    if (contentOutputs.length > 0) {
        for (IActionOutput contentOutput : contentOutputs) {
            outputStreamGenerator.setContentOutput(contentOutput);
            actionHarness.setValue(contentOutput.getName(), outputStreamGenerator, streamingOutputCallback, STREAM_APPENDER_FORMATTER, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
        }
    }
    // 
    if (actionBean instanceof IAction) {
        ((IAction) actionBean).execute();
    }
    // 
    for (IActionOutput output : actionDefintionOutputs) {
        String outputName = output.getName();
        outputName = COMPATIBILITY_FORMATTER.format(outputName);
        // if streaming output, add it to the context and don't try to get it from the Action bean
        if (outputContentItems.containsKey(outputName)) {
            IContentItem contentItem = outputContentItems.get(outputName);
            if (!(contentItem instanceof SimpleContentItem)) {
                // this is a special output for streaming actions and does not require a bean accessor
                output.setValue(contentItem);
            }
        } else if (actionHarness.isReadable(outputName)) {
            Object outputVal = actionHarness.getValue(outputName);
            output.setValue(outputVal);
        } else {
            if (loggingLevel <= ILogger.WARN) {
                warn(// $NON-NLS-1$
                Messages.getInstance().getString(// $NON-NLS-1$
                "ActionDelegate.WARN_OUTPUT_NOT_READABLE", outputName, output.getType(), actionBean.getClass().getSimpleName()));
            }
        }
    }
    return true;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) IActionResource(org.pentaho.actionsequence.dom.IActionResource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Aggregations

IActionInput (org.pentaho.actionsequence.dom.IActionInput)15 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)5 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)4 TableModel (javax.swing.table.TableModel)3 IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)3 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)3 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ActionInput (org.pentaho.actionsequence.dom.ActionInput)2 IActionResource (org.pentaho.actionsequence.dom.IActionResource)2 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)2 SqlConnectionAction (org.pentaho.actionsequence.dom.actions.SqlConnectionAction)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1