Search in sources :

Example 41 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class RuntimeContext method resolveParameters.

private void resolveParameters() throws UnresolvedParameterException {
    Set inputNames = getInputNames();
    Iterator inputNamesIterator = inputNames.iterator();
    IActionParameter actionParameter;
    List variables;
    Iterator variablesIterator;
    ActionParameterSource variable;
    String sourceName;
    String sourceValue;
    Object variableValue = null;
    IParameterProvider parameterProvider;
    while (inputNamesIterator.hasNext()) {
        variableValue = null;
        String inputName = (String) inputNamesIterator.next();
        actionParameter = paramManager.getCurrentInput(inputName);
        if (actionParameter == null) {
            throw new UnresolvedParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0031_INPUT_NOT_FOUND", // $NON-NLS-1$
            inputName), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
        }
        variables = actionParameter.getVariables();
        variablesIterator = variables.iterator();
        while (variablesIterator.hasNext()) {
            variable = (ActionParameterSource) variablesIterator.next();
            sourceName = variable.getSourceName();
            sourceValue = variable.getValue();
            variableValue = null;
            // e.g. runtme.parent
            if ("runtime".equals(sourceName)) {
                // $NON-NLS-1$
                // first check the standard variables
                variableValue = getStringParameter(sourceValue, null);
                if (variableValue == null) {
                    // now check the runtime data
                    variableValue = runtimeData.getStringProperty(sourceValue, null);
                }
                if (variableValue != null) {
                    break;
                }
            } else {
                parameterProvider = (IParameterProvider) parameterProviders.get(sourceName);
                if (parameterProvider == null) {
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_REQUESTED_PARAMETER_SOURCE_NOT_AVAILABLE", sourceName, // $NON-NLS-1$
                    inputName));
                } else {
                    variableValue = parameterProvider.getParameter(sourceValue);
                    if (variableValue != null) {
                        break;
                    }
                }
            }
        }
        if (variableValue == null) {
            if (actionParameter.getValue() != null) {
                if (actionParameter.hasDefaultValue()) {
                    if (PentahoSystem.trace) {
                        // $NON-NLS-1$
                        trace(Messages.getInstance().getString("RuntimeContext.TRACE_USING_DEFAULT_PARAMETER_VALUE", inputName));
                    }
                } else {
                    if (PentahoSystem.trace) {
                        trace(Messages.getInstance().getString(// $NON-NLS-1$
                        "RuntimeContext.TRACE_INFO_USING_CURRENT_PARAMETER_VALUE" + inputName));
                    }
                }
            } else if ("content".equals(actionParameter.getType())) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                variableValue = "";
            }
        } else {
            actionParameter.setValue(variableValue);
        }
    }
// while
}
Also used : UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) Set(java.util.Set) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 42 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class RuntimeContext method executeLoop.

private void executeLoop(final IActionParameter loopParm, final List loopList, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    // execute the actions
    int loopCount = -1;
    for (Iterator it = loopList.iterator(); it.hasNext(); ) {
        loopCount++;
        if (RuntimeContext.debug) {
            debug(Messages.getInstance().getString("RuntimeContext.DEBUG_EXECUTING_ACTION", // $NON-NLS-1$
            Integer.toString(loopCount)));
        }
        if (execListener != null) {
            execListener.loop(this, loopCount);
        }
        Object loopVar = it.next();
        if (loopParm != null) {
            IActionParameter ap;
            if (loopVar instanceof Map) {
                // $NON-NLS-1$
                ap = new ActionParameter(loopParm.getName(), "property-map", loopVar, null, null);
            } else {
                // $NON-NLS-1$
                ap = new ActionParameter(loopParm.getName(), "string", loopVar, null, null);
            }
            addInputParameter(loopParm.getName(), ap);
        }
        try {
            performActions(sequence, doneListener, execListener, async);
        } catch (ActionSequenceException e) {
            e.setLoopIndex(loopCount);
            throw e;
        }
        if (promptStatus == IRuntimeContext.PROMPT_NOW) {
            return;
        }
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) Iterator(java.util.Iterator) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class ActionFilterDefinition method getResultSet.

/**
 * If the <data-output> element is present in the xml file, its text specifies the name of the output parameter
 * in the runtime context containing the result set.
 *
 * However, the <data-output> element is not required. If this element is not in the xml file, then the first
 * parameter in the runtime context's output of type "resultset" contains the result set.
 */
@Override
protected IPentahoResultSet getResultSet(final Map parameterProviders) {
    // create an instance of the solution engine to execute the specified
    // action
    // TODO we need to ensure that this data is cached (not live) so that we
    // can validate selections
    // $NON-NLS-1$
    String solution = XmlDom4JHelper.getNodeText("data-solution", node);
    // $NON-NLS-1$
    String actionPath = XmlDom4JHelper.getNodeText("data-path", node);
    // $NON-NLS-1$
    String actionName = XmlDom4JHelper.getNodeText("data-action", node);
    // $NON-NLS-1$
    String listSource = XmlDom4JHelper.getNodeText("data-output", node);
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(session);
    OutputStream outputStream = null;
    SimpleOutputHandler outputHandler = null;
    outputHandler = new SimpleOutputHandler(outputStream, false);
    ArrayList messages = new ArrayList();
    String processId = this.getClass().getName();
    String instanceId = null;
    IRuntimeContext context = null;
    try {
        String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
        context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, null, messages);
        if (listSource != null) {
            if (context.getOutputNames().contains(listSource)) {
                IActionParameter output = context.getOutputParameter(listSource);
                IPentahoResultSet results = output.getValueAsResultSet();
                if (results != null) {
                    results = results.memoryCopy();
                }
                return results;
            } else {
                // this is an error
                return null;
            }
        } else {
            // return the first list that we find...
            Iterator it = context.getOutputNames().iterator();
            while (it.hasNext()) {
                IActionParameter output = (IActionParameter) it.next();
                if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
                    IPentahoResultSet results = output.getValueAsResultSet();
                    if (results != null) {
                        results = results.memoryCopy();
                    }
                    return results;
                }
            }
        }
        return null;
    } finally {
        if (context != null) {
            context.dispose();
        }
    }
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 44 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class AbstractChartComponent method getActionData.

/**
 * Gets a IPentahoResultSet from the action output
 *
 * @return IPentahoResultSet
 */
public IPentahoResultSet getActionData() {
    // create an instance of the solution engine to execute the specified
    // action
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(getSession());
    HashMap parameterProviders = getParameterProviders();
    OutputStream outputStream = null;
    SimpleOutputHandler outputHandler = null;
    outputHandler = new SimpleOutputHandler(outputStream, false);
    ArrayList messages = new ArrayList();
    String processId = this.getClass().getName();
    context = // $NON-NLS-1$ //$NON-NLS-2$
    solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
    actionPath, // $NON-NLS-1$ //$NON-NLS-2$
    processId, // $NON-NLS-1$ //$NON-NLS-2$
    false, // $NON-NLS-1$ //$NON-NLS-2$
    true, // $NON-NLS-1$ //$NON-NLS-2$
    instanceId, // $NON-NLS-1$ //$NON-NLS-2$
    false, parameterProviders, outputHandler, null, urlFactory, messages);
    if (context == null) {
        // this went badly wrong
        return null;
    }
    if (actionOutput != null) {
        if (context.getOutputNames().contains(actionOutput)) {
            IActionParameter output = context.getOutputParameter(actionOutput);
            IPentahoResultSet results = output.getValueAsResultSet();
            if (results != null) {
                results = results.memoryCopy();
            }
            return results;
        } else {
            // this is an error
            return null;
        }
    } else {
        for (Object objAp : context.getOutputNames()) {
            IActionParameter output = (IActionParameter) objAp;
            if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
                IPentahoResultSet results = output.getValueAsResultSet();
                if (results != null) {
                    results = results.memoryCopy();
                }
                return results;
            }
        }
    }
    return null;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 45 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class SequenceDefinition method getInputDefinitionsForParameterProvider.

public Map getInputDefinitionsForParameterProvider(final String parameterProviderName) {
    Map rtnMap = new ListOrderedMap();
    Map paramList = getInputDefinitions();
    for (Iterator it = paramList.values().iterator(); it.hasNext(); ) {
        IActionParameter actionParameter = (IActionParameter) it.next();
        List vars = actionParameter.getVariables();
        for (int i = 0; i < vars.size(); i++) {
            ActionParameterSource source = (ActionParameterSource) (vars.get(i));
            if (source.getSourceName().equals(parameterProviderName)) {
                rtnMap.put(source.getValue(), actionParameter);
            }
        }
    }
    return (rtnMap);
}
Also used : ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)68 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 Iterator (java.util.Iterator)19 Map (java.util.Map)14 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)14 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)13 List (java.util.List)9 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)9 Set (java.util.Set)8 IContentItem (org.pentaho.platform.api.repository.IContentItem)8 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)6 Test (org.junit.Test)6 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)6 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)6 Document (org.dom4j.Document)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4