Search in sources :

Example 11 with IActionParameter

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

the class ResultSetExportComponentIT method testRSExportComponent.

public void testRSExportComponent() {
    startTest();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/rules/ResultSetExportTest.xaction");
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // $NON-NLS-1$
    IActionParameter rtn = context.getOutputParameter("EXPORTRESULT");
    // $NON-NLS-1$
    assertNotNull("Result is null", rtn);
    // Check that the data, Eastern, is in the result set
    String content = rtn.getStringValue();
    // $NON-NLS-1$
    assertNotNull("Exported content is null", content);
    // $NON-NLS-1$
    int containsEastern = content.indexOf("Eastern");
    // $NON-NLS-1$
    assertEquals("ResultSet export does not contain 'Eastern'", Math.max(containsEastern, -1), containsEastern);
    finishTest();
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 12 with IActionParameter

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

the class ResultsetCompareIT method testRSCompareNotOK1.

public void testRSCompareNotOK1() {
    startTest();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/rules/ResultSetCompareTest_error1.xaction");
    // $NON-NLS-1$
    IActionParameter rtn = context.getOutputParameter("COMPARERESULT");
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    assertNotNull(rtn);
    String compareResult = rtn.getStringValue();
    // $NON-NLS-1$
    assertEquals(compareResult, "Eastern");
    finishTest();
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 13 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter 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 14 with IActionParameter

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

the class RuntimeContext method getOutputContentItem.

public IContentItem getOutputContentItem(final String outputName, final String mimeType) {
    IContentItem contentItem = null;
    IActionParameter parameter = (IActionParameter) actionSequence.getOutputDefinitions().get(outputName);
    if (parameter == null) {
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    } else {
        List destinationsList = parameter.getVariables();
        Iterator destinationsIterator = destinationsList.iterator();
        if (destinationsList.size() > 1) {
            contentItem = new MultiContentItem();
        }
        while (destinationsIterator.hasNext()) {
            ActionParameterSource destination = (ActionParameterSource) destinationsIterator.next();
            String objectName = destination.getSourceName();
            String contentName = destination.getValue();
            contentName = TemplateUtil.applyTemplate(contentName, this);
            outputHandler.setSession(session);
            IContentItem tmpContentItem = outputHandler.getOutputContentItem(objectName, contentName, instanceId, mimeType);
            addOutputContentItem(tmpContentItem);
            if (contentItem instanceof MultiContentItem) {
                ((MultiContentItem) contentItem).addContentItem(tmpContentItem);
            } else {
                contentItem = tmpContentItem;
                break;
            }
        }
    }
    return contentItem;
}
Also used : ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) MultiContentItem(org.pentaho.platform.engine.core.output.MultiContentItem) IContentItem(org.pentaho.platform.api.repository.IContentItem) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 15 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 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)

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