Search in sources :

Example 1 with IActionSequence

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

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

the class RuntimeContext method validateComponents.

private void validateComponents(final IActionSequence sequence, final IExecutionListener execListener) throws ActionValidationException {
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator it = defList.iterator(); it.hasNext(); ) {
        listItem = it.next();
        if (listItem instanceof IActionSequence) {
            validateComponents((IActionSequence) listItem, execListener);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_VALIDATING_COMPONENT", actionDef.getComponentName()));
            }
            IComponent component = null;
            try {
                component = resolveComponent(actionDef, instanceId, processId, session);
                component.setLoggingLevel(loggingLevel);
                // allow the ActionDefinition to cache the component
                actionDef.setComponent(component);
                paramManager.setCurrentParameters(actionDef);
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable ex) {
                ActionDefinition actionDefinition = new ActionDefinition((Element) actionDef.getNode(), null);
                throw new ActionValidationException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0009_COULD_NOT_CREATE_COMPONENT", // $NON-NLS-1$
                actionDef.getComponentName().trim()), // $NON-NLS-1$
                ex, session.getName(), instanceId, getActionSequence().getSequenceName(), actionDefinition.getDescription(), actionDefinition.getComponentName());
            }
            int validateResult = IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK;
            try {
                validateResult = component.validate();
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable t) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), // $NON-NLS-1$
                t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            if (validateResult != IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            paramManager.addOutputParameters(actionDef);
            // $NON-NLS-1$
            setCurrentComponent("");
            setCurrentActionDef(null);
        }
    }
    if (execListener != null) {
        execListener.validated(this);
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IComponent(org.pentaho.platform.api.engine.IComponent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition)

Example 3 with IActionSequence

use of org.pentaho.platform.api.engine.IActionSequence 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)

Example 4 with IActionSequence

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

the class IsOutputParameterTest method testIsOutputParameter.

/**
 * Assert parameters with is-output-parameter=false don't appear in output
 *
 * @throws XmlParseException
 */
public void testIsOutputParameter() throws XmlParseException {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "services/" + xactionName);
    Document actionSequenceDocument = XmlDom4JHelper.getDocFromString(xactionStr, null);
    IActionSequence actionSequence = SequenceDefinition.ActionSequenceFactory(actionSequenceDocument, "", this, // $NON-NLS-1$
    PentahoSystem.getApplicationContext(), DEBUG);
    Map allParameters = actionSequence.getOutputDefinitions();
    Set<String> outParameters = new HashSet<String>();
    Set<String> nonOutParameters = new HashSet<String>();
    for (Object key : allParameters.keySet()) {
        IActionParameter param = (IActionParameter) allParameters.get(key);
        if (param.isOutputParameter()) {
            outParameters.add(param.getName());
        } else {
            nonOutParameters.add(param.getName());
        }
    }
    Assert.assertEquals("expected 2 outputable parameters in xaction", 2, outParameters.size());
    Assert.assertEquals("expected 1 paramater with is-output-parameter=false", 1, nonOutParameters.size());
    IRuntimeContext runtimeContext = // $NON-NLS-1$
    solutionEngine.execute(// $NON-NLS-1$
    xactionStr, // $NON-NLS-1$
    xactionName, // $NON-NLS-1$
    "simple output test", // $NON-NLS-1$
    false, // $NON-NLS-1$
    true, // $NON-NLS-1$
    null, // $NON-NLS-1$
    false, // $NON-NLS-1$
    new HashMap(), null, null, new SimpleUrlFactory(""), // $NON-NLS-1$
    new ArrayList());
    IParameterManager paramManager = runtimeContext.getParameterManager();
    Assert.assertEquals(outParameters.size(), paramManager.getCurrentOutputNames().size());
    for (Object key : paramManager.getCurrentOutputNames()) {
        Assert.assertTrue("output parameter not found in definition", outParameters.contains(key));
        Assert.assertFalse("non-output parameter in output", nonOutParameters.contains(key));
    }
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) HashMap(java.util.HashMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Example 5 with IActionSequence

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

the class XactionUtil method doParameter.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String doParameter(final RepositoryFile file, IParameterProvider parameterProvider, final IPentahoSession userSession) throws IOException {
    ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper();
    final IActionSequence actionSequence = helper.getActionSequence(file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
    final Document document = DocumentHelper.createDocument();
    try {
        final Element parametersElement = document.addElement("parameters");
        // noinspection unchecked
        final Map<String, IActionParameter> params = actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST);
        for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) {
            final String paramName = entry.getKey();
            final IActionParameter paramDef = entry.getValue();
            final String value = paramDef.getStringValue();
            final Class type;
            // defined as constant (string)
            if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) {
                type = String[].class;
            } else {
                type = String.class;
            }
            final String label = paramDef.getSelectionDisplayName();
            final String[] values;
            if (StringUtils.isEmpty(value)) {
                values = new String[0];
            } else {
                values = new String[] { value };
            }
            createParameterElement(parametersElement, paramName, type, label, "user", "parameters", values);
        }
        createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { file.getPath() });
        createParameterElement(parametersElement, "prompt", String.class, null, "system", "system", new String[] { "yes", "no" });
        createParameterElement(parametersElement, "instance-id", String.class, null, "system", "system", new String[] { parameterProvider.getStringParameter("instance-id", null) });
        // no close, as far as I know tomcat does not like it that much ..
        OutputFormat format = OutputFormat.createCompactFormat();
        format.setSuppressDeclaration(true);
        // $NON-NLS-1$
        format.setEncoding("utf-8");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(outputStream, format);
        writer.write(document);
        writer.flush();
        return outputStream.toString("utf-8");
    } catch (Exception e) {
        logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
        return null;
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) Element(org.dom4j.Element) OutputFormat(org.dom4j.io.OutputFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ServletException(javax.servlet.ServletException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IOException(java.io.IOException) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IActionSequence (org.pentaho.platform.api.engine.IActionSequence)13 List (java.util.List)7 Document (org.dom4j.Document)6 ActionSequenceJCRHelper (org.pentaho.platform.engine.services.ActionSequenceJCRHelper)6 ArrayList (java.util.ArrayList)5 ISolutionActionDefinition (org.pentaho.platform.api.engine.ISolutionActionDefinition)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)3 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)3 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)3 IMimeTypeListener (org.pentaho.platform.api.engine.IMimeTypeListener)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)3 ServletException (javax.servlet.ServletException)2 Element (org.dom4j.Element)2 Node (org.dom4j.Node)2