Search in sources :

Example 1 with MQLAction

use of org.pentaho.actionsequence.dom.actions.MQLAction 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", IActionSequenceDocument.STRING_TYPE);
    // $NON-NLS-1$
    IActionSequenceInput chartModelJsonInput = actionSequenceDocument.createInput("chart-model-json", IActionSequenceDocument.STRING_TYPE);
    // $NON-NLS-1$
    IActionSequenceInput chartWidthInput = actionSequenceDocument.createInput("chart-width", IActionSequenceDocument.INTEGER_TYPE);
    // $NON-NLS-1$
    chartWidthInput.addSource(IActionSequenceDocument.REQUEST_INPUT_SOURCE, "chart-width");
    // $NON-NLS-1$
    chartWidthInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput chartHeightInput = actionSequenceDocument.createInput("chart-height", IActionSequenceDocument.INTEGER_TYPE);
    // $NON-NLS-1$
    chartHeightInput.addSource(IActionSequenceDocument.REQUEST_INPUT_SOURCE, "chart-height");
    // $NON-NLS-1$
    chartHeightInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput seriesColumnInput = actionSequenceDocument.createInput("series-column", IActionSequenceDocument.STRING_TYPE);
    // $NON-NLS-1$
    seriesColumnInput.setDefaultValue("1");
    // $NON-NLS-1$
    IActionSequenceInput categoryColumnInput = actionSequenceDocument.createInput("category-column", IActionSequenceDocument.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", IActionSequenceDocument.STRING_TYPE);
    // $NON-NLS-1$
    valueColumnInput.setDefaultValue("0");
    // $NON-NLS-1$
    IActionSequenceInput scalingFactorInput = actionSequenceDocument.createInput("scaling-factor", IActionSequenceDocument.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), IActionSequenceDocument.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", IActionSequenceDocument.CONTENT_TYPE);
    // $NON-NLS-1$
    outputStreamOutput.addDestination(IActionSequenceDocument.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), IActionSequenceDocument.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", IActionSequenceDocument.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", IActionSequenceDocument.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 MQLAction

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

the class MQLRelationalDataComponent method executeAction.

@Override
public boolean executeAction() {
    // 
    // For backwards compatibility, call into the new metadata query component
    // 
    MetadataQueryComponent component = new MetadataQueryComponent();
    // setup component
    MQLAction actionDefinition = (MQLAction) getActionDefinition();
    String mql = actionDefinition.getQuery().getStringValue();
    component.setQuery(mql);
    if (actionDefinition.getMaxRows() != ActionInputConstant.NULL_INPUT) {
        component.setMaxRows(actionDefinition.getMaxRows().getIntValue());
    }
    if (actionDefinition.getQueryTimeout() != ActionInputConstant.NULL_INPUT) {
        component.setTimeout(actionDefinition.getQueryTimeout().getIntValue());
    }
    if (actionDefinition.getReadOnly() != ActionInputConstant.NULL_INPUT) {
        component.setReadOnly(actionDefinition.getReadOnly().getBooleanValue());
    }
    // log the sql to info if set
    if (isDefinedInput("logSql")) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$
        component.setLogSql("true".equals(actionDefinition.getInput("logSql").getStringValue()));
    }
    // TODO: We also need to pass in the component definitions
    Set<String> inputNames = getInputNames();
    if (inputNames != null) {
        Map<String, Object> inputMap = new HashMap<String, Object>();
        for (String inputName : inputNames) {
            inputMap.put(ActionDefinitionEncoder.decodeBlankSpaces(inputName), getInputValue(inputName));
        }
        component.setInputs(inputMap);
    }
    boolean success = component.execute();
    if (success) {
        IActionOutput actionOutput = actionDefinition.getOutputResultSet();
        if (actionOutput != null) {
            actionOutput.setValue(component.getResultSet());
        }
    }
    return success;
}
Also used : HashMap(java.util.HashMap) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) MQLAction(org.pentaho.actionsequence.dom.actions.MQLAction)

Aggregations

MQLAction (org.pentaho.actionsequence.dom.actions.MQLAction)2 HashMap (java.util.HashMap)1 ActionSequenceDocument (org.pentaho.actionsequence.dom.ActionSequenceDocument)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)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 ActionDefinition (org.pentaho.actionsequence.dom.actions.ActionDefinition)1