Search in sources :

Example 1 with IActionResource

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

the class ActionDelegate method executeAction.

/**
 * Wires up inputs outputs and resources to an Action and executes it.
 */
@Override
protected boolean executeAction() throws Throwable {
    // 
    // Set inputs
    // 
    InputErrorCallback errorCallback = new InputErrorCallback();
    for (IActionInput input : getActionDefinition().getInputs()) {
        Object inputValue = input.getValue();
        if (input instanceof ActionInputConstant) {
            // if the input is coming from the component definition section,
            // do parameter replacement on the string and the result of that
            // is the input value
            inputValue = input.getStringValue(true);
        }
        errorCallback.setValue(inputValue);
        actionHarness.setValue(input.getName(), inputValue, errorCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Set resources
    // 
    ResourceCallback resourceCallback = new ResourceCallback();
    for (IActionResource res : getActionDefinition().getResources()) {
        actionHarness.setValue(res.getName(), res.getInputStream(), resourceCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Provide output stream for the streaming action. We are going to look for all outputs where
    // type = "content", and derive output streams to hand to the IStreamingAction.
    // 
    Map<String, IContentItem> outputContentItems = new HashMap<String, IContentItem>();
    StreamOutputErrorCallback streamingOutputCallback = new StreamOutputErrorCallback();
    OuputStreamGenerator outputStreamGenerator = new OuputStreamGenerator(outputContentItems);
    IActionOutput[] contentOutputs = getActionDefinition().getOutputs(ActionSequenceDocument.CONTENT_TYPE);
    if (contentOutputs.length > 0) {
        for (IActionOutput contentOutput : contentOutputs) {
            outputStreamGenerator.setContentOutput(contentOutput);
            actionHarness.setValue(contentOutput.getName(), outputStreamGenerator, streamingOutputCallback, STREAM_APPENDER_FORMATTER, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
        }
    }
    // 
    if (actionBean instanceof IAction) {
        ((IAction) actionBean).execute();
    }
    // 
    for (IActionOutput output : actionDefintionOutputs) {
        String outputName = output.getName();
        outputName = COMPATIBILITY_FORMATTER.format(outputName);
        // if streaming output, add it to the context and don't try to get it from the Action bean
        if (outputContentItems.containsKey(outputName)) {
            IContentItem contentItem = outputContentItems.get(outputName);
            if (!(contentItem instanceof SimpleContentItem)) {
                // this is a special output for streaming actions and does not require a bean accessor
                output.setValue(contentItem);
            }
        } else if (actionHarness.isReadable(outputName)) {
            Object outputVal = actionHarness.getValue(outputName);
            output.setValue(outputVal);
        } else {
            if (loggingLevel <= ILogger.WARN) {
                warn(// $NON-NLS-1$
                Messages.getInstance().getString(// $NON-NLS-1$
                "ActionDelegate.WARN_OUTPUT_NOT_READABLE", outputName, output.getType(), actionBean.getClass().getSimpleName()));
            }
        }
    }
    return true;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) IActionResource(org.pentaho.actionsequence.dom.IActionResource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 2 with IActionResource

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

the class HQLBaseComponent method getCatalog.

/*
   * Utility function to get the catalog info from hibernate config.
   */
private String getCatalog() {
    IActionResource hibernateConfigRes = ((HQLConnectionAction) getActionDefinition()).getHibernateConfigResource();
    String catalog = null;
    String resAddress = null;
    if (hibernateConfigRes != null) {
        String resName = this.applyInputsToFormat(hibernateConfigRes.getName());
        IActionSequenceResource resource = getResource(resName);
        resAddress = resource.getAddress();
        if (resAddress != null) {
            catalog = this.applyInputsToFormat(resAddress);
        }
    }
    return catalog;
}
Also used : IActionResource(org.pentaho.actionsequence.dom.IActionResource) HQLConnectionAction(org.pentaho.actionsequence.dom.actions.HQLConnectionAction) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Aggregations

IActionResource (org.pentaho.actionsequence.dom.IActionResource)2 HashMap (java.util.HashMap)1 ActionInputConstant (org.pentaho.actionsequence.dom.ActionInputConstant)1 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 HQLConnectionAction (org.pentaho.actionsequence.dom.actions.HQLConnectionAction)1 IAction (org.pentaho.platform.api.action.IAction)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)1