Search in sources :

Example 1 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter in project pentaho-platform by pentaho.

the class ParameterManager method setCurrentParameters.

public void setCurrentParameters(final ISolutionActionDefinition actionDefinition) {
    currentInputs.clear();
    currentOutputs.clear();
    currentResources.clear();
    if (actionDefinition == null) {
        currentInputs = resetMap(sequenceInputNames, allParams);
        currentResources = resetMap(sequenceResourceNames, allParams);
        for (Iterator it = sequenceOutputDefs.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String outputName = (String) entry.getKey();
            IActionParameter param = (IActionParameter) allParams.get(outputName);
            if (((IActionParameter) entry.getValue()).isOutputParameter()) {
                if (param == null) {
                    currentOutputs.put(outputName, entry.getValue());
                } else {
                    currentOutputs.put(outputName, param);
                }
            }
        }
        return;
    }
    String key;
    Object value;
    for (Iterator it = actionDefinition.getActionInputDefinitions().keySet().iterator(); it.hasNext(); ) {
        key = (String) it.next();
        value = allParams.get(actionDefinition.getMappedInputName(key));
        if (value == null) {
            value = actionDefinition.getActionInputDefinitions().get(key);
            if (!((ActionParameter) value).hasDefaultValue()) {
                // Only use if there is a default value;
                value = null;
            }
        }
        if (value != null) {
            currentInputs.put(key, value);
        }
    }
    // currentOutputs.putAll(actionDefinition.getActionOutputDefinitions());
    // only put output parameters
    Map outParams = actionDefinition.getActionOutputDefinitions();
    for (Object outKey : outParams.keySet()) {
        ActionParameter param = (ActionParameter) outParams.get(outKey);
        if (param.isOutputParameter()) {
            currentOutputs.put(outKey, param);
        }
    }
    // This enables the old behavior - It should eventually be removed
    if (!actionDefinition.hasActionResources()) {
        currentResources.putAll(allResources);
    } else {
        for (Iterator it = actionDefinition.getActionResourceDefinitionNames().iterator(); it.hasNext(); ) {
            key = (String) it.next();
            String key2 = actionDefinition.getMappedResourceName(key);
            value = allResources.get(key2);
            currentResources.put(key, value);
        }
    }
}
Also used : Iterator(java.util.Iterator) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 2 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter in project pentaho-platform by pentaho.

the class RuntimeContext method executeLoop.

private void executeLoop(final IActionParameter loopParm, final IPentahoResultSet loopSet, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async, boolean peekOnly) throws ActionSequenceException {
    // execute the actions
    int loopCount = -1;
    // to the first record. This is to resolve multiple levels of looping on resultset.
    if (loopSet.isScrollable()) {
        loopSet.beforeFirst();
    }
    if (peekOnly && !(loopSet instanceof IPeekable)) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0033_NOT_PEEKABLE"), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
    }
    Object[] row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    Object[][] headerSet = loopSet.getMetaData().getColumnHeaders();
    // TODO handle OLAP result sets
    Object[] headers = headerSet[0];
    while (row != null) {
        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);
        }
        if (loopParm != null) {
            IActionParameter ap;
            for (int columnNo = 0; columnNo < headers.length; columnNo++) {
                String name = headers[columnNo].toString();
                Object value = row[columnNo];
                String type = null;
                if (value instanceof String) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value instanceof Date) {
                    type = IActionParameter.TYPE_DATE;
                } else if ((value instanceof Long) || (value instanceof Integer)) {
                    type = IActionParameter.TYPE_INTEGER;
                } else if ((value instanceof BigDecimal) || (value instanceof Double) || (value instanceof Float)) {
                    type = IActionParameter.TYPE_DECIMAL;
                } else if (value instanceof String[]) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value == null) {
                    // $NON-NLS-1$
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_IS_NULL", name));
                } else {
                    type = IActionParameter.TYPE_OBJECT;
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_NOT_RECOGNIZED", name, // $NON-NLS-1$
                    value.getClass().toString()));
                }
                // TODO make sure any previous loop values are removed
                ap = paramManager.getInput(name);
                if (ap == null) {
                    ap = new ActionParameter(name, type, value, null, null);
                    addInputParameter(name, ap);
                } else {
                    ap.dispose();
                    ap.setValue(value);
                }
            }
        }
        try {
            performActions(sequence, doneListener, execListener, async);
        } catch (ActionSequenceException e) {
            e.setLoopIndex(loopCount);
            throw e;
        }
        row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Date(java.util.Date) BigDecimal(java.math.BigDecimal) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 3 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter in project pentaho-platform by pentaho.

the class ComponentBase method addTempParameterObject.

protected void addTempParameterObject(final String name, final Object paramObject) {
    // $NON-NLS-1$
    String pType = "object";
    IActionParameter actionParameter = new ActionParameter(name, pType, paramObject, null, null);
    addTempParameter(name, actionParameter);
}
Also used : ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 4 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter in project pentaho-platform by pentaho.

the class MessageFormatterTest method formatSuccessMessage.

@Test
public void formatSuccessMessage() throws Exception {
    Set inputNames = new HashSet<String>();
    inputNames.add("Test");
    IActionParameter actionParameter = new ActionParameter("Test", "Test", "<img%20src=\"http://www.pentaho" + ".com/sites/all/themes/pentaho_resp/logo.svg\"%20/>", null, "");
    when(runtimeCtx.getOutputNames()).thenReturn(inputNames);
    doReturn(actionParameter).when(runtimeCtx).getOutputParameter(anyString());
    MessageFormatter mf = new MessageFormatter();
    StringBuffer messageBuffer = new StringBuffer();
    mf.formatSuccessMessage(MessageFormatter.HTML_MIME_TYPE, runtimeCtx, messageBuffer, false);
    assertEquals("<html><head><title>Pentaho BI Platform - Start Action</title><link rel=\"stylesheet\" " + "type=\"text/css\" href=\"/pentaho-style/active/default.css\"></head><body dir=\"LTR\"><table " + "cellspacing=\"10\"><tr><td class=\"portlet-section\" colspan=\"3\">Action Successful<hr " + "size=\"1\"/></td></tr><tr><td class=\"portlet-font\" valign=\"top\">Test=<img%20src=\"http://www" + ".pentaho.com/sites/all/themes/pentaho_resp/logo.svg\"%20/><br/></td></tr></table></body></html>", messageBuffer.toString());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter 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)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)6 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 IPeekable (org.pentaho.commons.connection.IPeekable)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 IParameterManager (org.pentaho.platform.api.engine.IParameterManager)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)1