Search in sources :

Example 1 with ActionDefinition

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

the class DefaultChartBeansGenerator method createActionSequenceDocument.

/**
 * Creates an <code>ActionSequenceDocument</code> that will run an MQL query and pipe the results in the ChartBeans
 * <code>ChartComponent</code>.
 *
 * @param parameterNameSet
 *          set of parameter names that appear in the MQL query
 * @return doc
 */
protected ActionSequenceDocument createActionSequenceDocument(final Set<String> parameterNameSet, String contentLinkingTemplate) {
    ActionSequenceDocument actionSequenceDocument = new ActionSequenceDocument();
    // $NON-NLS-1$
    actionSequenceDocument.setTitle("chartbeans_mql.xaction");
    // $NON-NLS-1$
    actionSequenceDocument.setVersion("1");
    // $NON-NLS-1$
    actionSequenceDocument.setLoggingLevel("debug");
    // $NON-NLS-1$
    actionSequenceDocument.setAuthor("Dashboard");
    // $NON-NLS-1$
    actionSequenceDocument.setDescription("Generate a chart through ChartBeans from an MQL statement.");
    actionSequenceDocument.setHelp(// $NON-NLS-1$
    "Pass in an MQL statement that returns a table of three columns. The first column " + // $NON-NLS-1$
    "is the series, the second is the category and the third is the data.");
    // $NON-NLS-1$
    actionSequenceDocument.setHelp("");
    // $NON-NLS-1$
    actionSequenceDocument.setResultType("rule");
    // $NON-NLS-1$
    IActionSequenceInput queryInput = actionSequenceDocument.createInput("query", STRING_TYPE);
    // $NON-NLS-1$
    IActionSequenceInput chartModelJsonInput = actionSequenceDocument.createInput("chart-model-json", STRING_TYPE);
    // $NON-NLS-1$
    IActionSequenceInput chartWidthInput = actionSequenceDocument.createInput("chart-width", INTEGER_TYPE);
    // $NON-NLS-1$
    chartWidthInput.addSource(REQUEST_INPUT_SOURCE, "chart-width");
    // $NON-NLS-1$
    chartWidthInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput chartHeightInput = actionSequenceDocument.createInput("chart-height", INTEGER_TYPE);
    // $NON-NLS-1$
    chartHeightInput.addSource(REQUEST_INPUT_SOURCE, "chart-height");
    // $NON-NLS-1$
    chartHeightInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput seriesColumnInput = actionSequenceDocument.createInput("series-column", STRING_TYPE);
    // $NON-NLS-1$
    seriesColumnInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput categoryColumnInput = actionSequenceDocument.createInput("category-column", STRING_TYPE);
    // set a default value of empty string to avoid an error when rendering pie charts (which don't have a category
    // column
    // $NON-NLS-1$
    categoryColumnInput.setDefaultValue("2");
    // $NON-NLS-1$
    IActionSequenceInput valueColumnInput = actionSequenceDocument.createInput("value-column", STRING_TYPE);
    // $NON-NLS-1$
    valueColumnInput.setDefaultValue("0");
    // $NON-NLS-1$
    IActionSequenceInput scalingFactorInput = actionSequenceDocument.createInput("scaling-factor", STRING_TYPE);
    // add inputs from parameterNameSet; these parameters will appear as placeholders in the query input
    for (String parameterName : parameterNameSet) {
        IActionSequenceInput input = actionSequenceDocument.createInput(ActionDefinitionEncoder.encodeBlankSpaces(parameterName), STRING_TYPE);
        IActionSequenceInputSource[] sources = input.getSources();
        if (sources.length > 0) {
            input.getSources()[0].setName(parameterName);
        } else {
            input.addSource("request", parameterName);
        }
    }
    // $NON-NLS-1$
    IActionSequenceOutput outputStreamOutput = actionSequenceDocument.createOutput("outputstream", CONTENT_TYPE);
    // $NON-NLS-1$
    outputStreamOutput.addDestination(RESPONSE_OUTPUT_DESTINATION, "content");
    MQLAction mqlAction = (MQLAction) actionSequenceDocument.addAction(MQLAction.class);
    // $NON-NLS-1$
    mqlAction.setActionInputValue("query", queryInput);
    // add inputs from parameterNameSet to this action
    for (String parameterName : parameterNameSet) {
        mqlAction.addInput(ActionDefinitionEncoder.encodeBlankSpaces(parameterName), STRING_TYPE);
    }
    // $NON-NLS-1$
    mqlAction.setOutputResultSet("chartdata");
    // $NON-NLS-1$
    mqlAction.setComponentDefinition("live", Boolean.TRUE.toString());
    // $NON-NLS-1$
    mqlAction.setComponentDefinition("display-names", Boolean.FALSE.toString());
    ActionDefinition pojoAction = (ActionDefinition) actionSequenceDocument.addAction(ActionDefinition.class);
    // $NON-NLS-1$
    pojoAction.setComponentName("ChartBeansComponent");
    if (contentLinkingTemplate != null) {
        pojoAction.setComponentDefinition("contentLinkingTemplate", contentLinkingTemplate);
    }
    // $NON-NLS-1$
    pojoAction.setActionInputValue("chart-model-json", chartModelJsonInput);
    // $NON-NLS-1$
    pojoAction.addInput("chartdata", RESULTSET_TYPE);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("chart-width", chartWidthInput);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("chart-height", chartHeightInput);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("series-column", seriesColumnInput);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("category-column", categoryColumnInput);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("value-column", valueColumnInput);
    // $NON-NLS-1$
    pojoAction.setActionInputValue("scaling-factor", scalingFactorInput);
    // $NON-NLS-1$
    pojoAction.addOutput("outputstream", CONTENT_TYPE);
    return actionSequenceDocument;
}
Also used : IActionSequenceOutput(org.pentaho.actionsequence.dom.IActionSequenceOutput) IActionSequenceInput(org.pentaho.actionsequence.dom.IActionSequenceInput) IActionSequenceInputSource(org.pentaho.actionsequence.dom.IActionSequenceInputSource) MQLAction(org.pentaho.actionsequence.dom.actions.MQLAction) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition) IActionSequenceDocument(org.pentaho.actionsequence.dom.IActionSequenceDocument) ActionSequenceDocument(org.pentaho.actionsequence.dom.ActionSequenceDocument)

Example 2 with ActionDefinition

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

the class RuntimeContext method validateComponents.

private void validateComponents(final IActionSequence sequence, final IExecutionListener execListener) throws ActionValidationException {
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator it = defList.iterator(); it.hasNext(); ) {
        listItem = it.next();
        if (listItem instanceof IActionSequence) {
            validateComponents((IActionSequence) listItem, execListener);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_VALIDATING_COMPONENT", actionDef.getComponentName()));
            }
            IComponent component = null;
            try {
                component = resolveComponent(actionDef, instanceId, processId, session);
                component.setLoggingLevel(loggingLevel);
                // allow the ActionDefinition to cache the component
                actionDef.setComponent(component);
                paramManager.setCurrentParameters(actionDef);
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable ex) {
                ActionDefinition actionDefinition = new ActionDefinition((Element) actionDef.getNode(), null);
                throw new ActionValidationException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0009_COULD_NOT_CREATE_COMPONENT", // $NON-NLS-1$
                actionDef.getComponentName().trim()), // $NON-NLS-1$
                ex, session.getName(), instanceId, getActionSequence().getSequenceName(), actionDefinition.getDescription(), actionDefinition.getComponentName());
            }
            int validateResult = IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK;
            try {
                validateResult = component.validate();
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable t) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), // $NON-NLS-1$
                t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            if (validateResult != IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            paramManager.addOutputParameters(actionDef);
            // $NON-NLS-1$
            setCurrentComponent("");
            setCurrentActionDef(null);
        }
    }
    if (execListener != null) {
        execListener.validated(this);
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IComponent(org.pentaho.platform.api.engine.IComponent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition)

Example 3 with ActionDefinition

use of org.pentaho.actionsequence.dom.actions.ActionDefinition 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)3 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ActionSequenceDocument (org.pentaho.actionsequence.dom.ActionSequenceDocument)1 IActionSequenceDocument (org.pentaho.actionsequence.dom.IActionSequenceDocument)1 IActionSequenceInput (org.pentaho.actionsequence.dom.IActionSequenceInput)1 IActionSequenceInputSource (org.pentaho.actionsequence.dom.IActionSequenceInputSource)1 IActionSequenceOutput (org.pentaho.actionsequence.dom.IActionSequenceOutput)1 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)1 MQLAction (org.pentaho.actionsequence.dom.actions.MQLAction)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 IDataComponent (org.pentaho.platform.api.data.IDataComponent)1 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IComponent (org.pentaho.platform.api.engine.IComponent)1 ISolutionActionDefinition (org.pentaho.platform.api.engine.ISolutionActionDefinition)1 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)1 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)1