Search in sources :

Example 1 with IConditionalExecution

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

the class RuntimeContext method performActions.

private void performActions(final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    IConditionalExecution conditional = sequence.getConditionalExecution();
    if (conditional != null) {
        try {
            if (!conditional.shouldExecute(paramManager.getAllParameters(), RuntimeContext.logger)) {
                // audit(MessageTypes.ACTION_SEQUENCE_EXECUTE_CONDITIONAL, MessageTypes.NOT_EXECUTED, "", 0); //$NON-NLS-1$ //$NON-NLS-2$
                if (RuntimeContext.debug) {
                    // $NON-NLS-1$
                    this.debug(Messages.getInstance().getString("RuntimeContext.INFO_ACTION_NOT_EXECUTED"));
                }
                status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
                return;
            }
        } catch (Exception ex) {
            // $NON-NLS-1$
            currentComponent = "";
            status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
            throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "RuntimeContext.ERROR_0032_CONDITIONAL_EXECUTION_FAILED"), // $NON-NLS-1$
            ex, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
        }
    }
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator actIt = defList.iterator(); actIt.hasNext(); ) {
        listItem = actIt.next();
        if (listItem instanceof IActionSequence) {
            executeSequence((IActionSequence) listItem, doneListener, execListener, async);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            currentComponent = actionDef.getComponentName();
            paramManager.setCurrentParameters(actionDef);
            try {
                executeAction(actionDef, parameterProviders, doneListener, execListener, async);
                paramManager.addOutputParameters(actionDef);
            } catch (ActionSequenceException ex) {
                // $NON-NLS-1$
                currentComponent = "";
                status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
                throw ex;
            }
        }
        if (promptStatus == IRuntimeContext.PROMPT_NOW) {
            break;
        }
        // $NON-NLS-1$
        currentComponent = "";
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) IConditionalExecution(org.pentaho.platform.api.engine.IConditionalExecution) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) 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 2 with IConditionalExecution

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

the class SequenceDefinition method parseConditionalExecution.

static IConditionalExecution parseConditionalExecution(final Node actionRootNode, final ILogger logger, final String nodePath) {
    try {
        Node condition = actionRootNode.selectSingleNode(nodePath);
        if (condition == null) {
            return null;
        }
        String script = condition.getText();
        IConditionalExecution ce = PentahoSystem.get(IConditionalExecution.class, null);
        ce.setScript(script);
        return ce;
    } catch (Exception ex) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"), ex);
    }
    return null;
}
Also used : IConditionalExecution(org.pentaho.platform.api.engine.IConditionalExecution) Node(org.dom4j.Node)

Example 3 with IConditionalExecution

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

the class SequenceDefinition method getNextLoopGroup.

private static IActionSequence getNextLoopGroup(final ISequenceDefinition seqDef, final Node actionsNode, final String solutionPath, final ILogger logger, final int loggingLevel) {
    // $NON-NLS-1$
    String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode);
    // $NON-NLS-1$ //$NON-NLS-2$
    boolean loopUsingPeek = "true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@peek-only", actionsNode));
    Node actionDefinitionNode;
    ActionDefinition actionDefinition;
    List actionDefinitionList = new ArrayList();
    // $NON-NLS-1$
    List nodeList = actionsNode.selectNodes("*");
    Iterator actionDefinitionNodes = nodeList.iterator();
    while (actionDefinitionNodes.hasNext()) {
        actionDefinitionNode = (Node) actionDefinitionNodes.next();
        if (actionDefinitionNode.getName().equals("actions")) {
            // $NON-NLS-1$
            actionDefinitionList.add(SequenceDefinition.getNextLoopGroup(seqDef, actionDefinitionNode, solutionPath, logger, loggingLevel));
        } else if (actionDefinitionNode.getName().equals("action-definition")) {
            // $NON-NLS-1$
            actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
            actionDefinition.setLoggingLevel(loggingLevel);
            actionDefinitionList.add(actionDefinition);
        }
    }
    // action sequences with 0 actions are valid, see: JIRA PLATFORM-837
    IConditionalExecution conditionalExecution = // $NON-NLS-1$
    SequenceDefinition.parseConditionalExecution(actionsNode, logger, "condition");
    ActionSequence sequence = new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek);
    sequence.setConditionalExecution(conditionalExecution);
    return sequence;
}
Also used : IConditionalExecution(org.pentaho.platform.api.engine.IConditionalExecution) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) Node(org.dom4j.Node) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition)

Aggregations

IConditionalExecution (org.pentaho.platform.api.engine.IConditionalExecution)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Node (org.dom4j.Node)2 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)2 ISolutionActionDefinition (org.pentaho.platform.api.engine.ISolutionActionDefinition)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)1 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)1 ActionSequencePromptException (org.pentaho.platform.api.engine.ActionSequencePromptException)1 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)1 InvalidParameterException (org.pentaho.platform.api.engine.InvalidParameterException)1 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)1 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)1 XmlParseException (org.pentaho.platform.api.util.XmlParseException)1