Search in sources :

Example 36 with IActionParameter

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

the class RuntimeContext method getInputParameterStringValue.

public String getInputParameterStringValue(final String name) {
    String value = null;
    IActionParameter actionParameter = paramManager.getCurrentInput(name);
    if (actionParameter == null) {
        // TODO need to know from the action definition if this is ok or not
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0019_INVALID_INPUT_REQUEST", name, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    } else {
        value = actionParameter.getStringValue();
    }
    return value;
}
Also used : IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 37 with IActionParameter

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

the class ParameterManager method getReturnParameters.

/**
 * Returns a mapping of output parameters and the value and destination.
 *
 * @param actionSequence
 *          The Action Sequence definition to use
 *
 * @return a map with the param name as the key and a ReturnParameter containing the data.
 */
public Map getReturnParameters() {
    ListOrderedMap returnMap = new ListOrderedMap();
    // Iterate for each output defined
    for (Iterator it = sequenceOutputDefs.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();
        String outputName = (String) entry.getKey();
        IActionParameter outputParam = (IActionParameter) entry.getValue();
        if (!outputParam.isOutputParameter()) {
            continue;
        }
        // The output Action Parameter objects do not have values - they are just the definition
        // Pull the value from allParams
        IActionParameter inputParam = (IActionParameter) allParams.get(outputName);
        if (inputParam == null) {
            returnMap.put(outputParam.getName(), null);
        } else {
            for (Iterator varIt = outputParam.getVariables().iterator(); varIt.hasNext(); ) {
                ActionParameterSource src = (ActionParameterSource) varIt.next();
                returnMap.put(outputParam.getName(), new ReturnParameter(src.getSourceName(), src.getValue(), inputParam.getValue()));
            }
        }
    }
    return (returnMap);
}
Also used : ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Iterator(java.util.Iterator) ListOrderedMap(org.apache.commons.collections.map.ListOrderedMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 38 with IActionParameter

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

the class ParameterManager method addOutputParameters.

public boolean addOutputParameters(final ISolutionActionDefinition actionDefinition) {
    String key;
    for (Iterator it = actionDefinition.getActionOutputDefinitions().keySet().iterator(); it.hasNext(); ) {
        key = (String) it.next();
        IActionParameter outputParam = (IActionParameter) currentOutputs.get(key);
        key = actionDefinition.getMappedOutputName(key);
        // If we already have a parameter with this name, set the value and reuse the definition.
        IActionParameter param = (IActionParameter) allParams.get(key);
        if (param != null) {
            if (param != outputParam) {
                // This is a trap for catching temp params that didn't get deleted at the end
                // of
                // the last loop
                param.dispose();
                param.setValue(outputParam.getValue());
            }
        } else {
            addToAllInputs(key, outputParam);
        }
    }
    return (true);
}
Also used : Iterator(java.util.Iterator) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 39 with IActionParameter

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

the class RuntimeContext method getOutputItem.

public IContentItem getOutputItem(final String outputName, final String mimeType, final String extension) {
    // TODO support content output versions in the action definition
    IActionParameter outputParameter = getOutputParameter(outputName);
    if (outputParameter == null) {
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
        actionSequence.getSequenceName()));
        return null;
    }
    // $NON-NLS-1$
    String filePath = "~/workspace/" + FilenameUtils.getBaseName(getSolutionPath()) + extension;
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String contentName = "contentrepo:" + filePath;
    if (!IActionParameter.TYPE_CONTENT.equals(outputParameter.getType())) {
        // $NON-NLS-1$
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0023_INVALID_OUTPUT_STREAM", outputName));
        return null;
    }
    try {
        IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
        if (output != null) {
            // TODO get this info
            output.setInstanceId(instanceId);
            output.setSolutionPath(filePath);
            output.setMimeType(mimeType);
            output.setSession(session);
            IContentItem contentItem = output.getFileOutputContentItem();
            setOutputValue(outputName, contentItem);
            return contentItem;
        }
    } catch (Exception e) {
    // ignored
    }
    return null;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IOException(java.io.IOException)

Example 40 with IActionParameter

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

the class RuntimeContext method setOutputValue.

public void setOutputValue(final String name, final Object output) {
    IActionParameter actionParameter = paramManager.getCurrentOutput(name);
    if (actionParameter == null) {
        throw new InvalidParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", name, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    }
    actionParameter.setValue(output);
    if (output instanceof String) {
        runtimeData.setStringProperty(name, (String) output);
    } else if (output instanceof Date) {
        runtimeData.setDateProperty(name, (Date) output);
    } else if (output instanceof Long) {
        runtimeData.setLongProperty(name, (Long) output);
    } else if (output instanceof List) {
        runtimeData.setListProperty(name, (List) output);
    } else if (output instanceof Map) {
        runtimeData.setMapProperty(name, (Map) output);
    } else if (output instanceof IContentItem) {
        runtimeData.setStringProperty(name, ((IContentItem) output).getPath());
    }
}
Also used : InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) IContentItem(org.pentaho.platform.api.repository.IContentItem) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

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