Search in sources :

Example 6 with IActionSequence

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

the class InputFormComponent method getXmlContent.

/*
   * (non-Javadoc)
   * 
   * @see org.pentaho.core.ui.component.BaseUIComponent#getXmlContent()
   */
@Override
public Document getXmlContent() {
    ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(getSession());
    IActionSequence actionSequence = actionHelper.getActionSequence(ActionInfo.buildSolutionPath(solution, path, actionName), getLoggingLevel(), RepositoryFilePermission.READ);
    if (actionSequence == null) {
        // TODO log this
        // $NON-NLS-1$
        error(Messages.getInstance().getString("InputForm.ERROR_0004_ACTION_NOT_FOUND") + solution + path + actionName);
        return null;
    }
    List actions = actionSequence.getActionDefinitionsAndSequences();
    ISolutionActionDefinition action = (ISolutionActionDefinition) actions.get(0);
    Node node = action.getComponentSection();
    if (node == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("InputForm.ERROR_0005_INBOX_DEFINITION_MISSING") + solution + path + actionName);
        return null;
    }
    if (templateName == null) {
        // see if the template is specified in the action document
        // $NON-NLS-1$
        Node templateNode = node.selectSingleNode("//template");
        if (templateNode != null) {
            templateName = templateNode.getText();
        }
        if (templateName == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("InputForm.ERROR_0006_TEMPLATE_NOT_SPECIFIED"));
            return null;
        }
    }
    // $NON-NLS-1$
    Node xFormNode = node.selectSingleNode("//xForm");
    try {
        String actionTitle = actionSequence.getTitle();
        if (actionTitle != null) {
            // $NON-NLS-1$
            setXslProperty("title", actionTitle);
        }
        String description = actionSequence.getDescription();
        if (description != null) {
            // $NON-NLS-1$
            setXslProperty("description", description);
        }
        String xFormHtml = XForm.transformSnippet(xFormNode, getSession(), new SolutionURIResolver());
        if (xFormHtml == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getString("InputForm.ERROR_0007_INBOX_DEFINITION_INVALID") + solution + path + actionName);
            return null;
        }
        Document document = DocumentHelper.parseText(xFormHtml);
        // $NON-NLS-1$
        Node xFormHtmlNode = document.selectSingleNode("//xForm");
        // $NON-NLS-1$
        setXslProperty("xForm", xFormHtmlNode.asXML());
        if ((stylesheetName != null) && !"".equals(stylesheetName)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            setXslProperty("css", stylesheetName);
        }
        // $NON-NLS-1$
        setXsl("text/html", templateName);
        return document;
    } catch (Exception e) {
        return null;
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) Node(org.dom4j.Node) List(java.util.List) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Example 7 with IActionSequence

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

the class SolutionEngine method createActionSequenceFromXml.

private IActionSequence createActionSequenceFromXml(final String actionDef) {
    try {
        Document actionSequenceDocument = XmlDom4JHelper.getDocFromString(actionDef, null);
        if (actionSequenceDocument == null) {
            return null;
        }
        IActionSequence actionSequence = SequenceDefinition.ActionSequenceFactory(actionSequenceDocument, "", this, // $NON-NLS-1$
        PentahoSystem.getApplicationContext(), loggingLevel);
        return (actionSequence);
    } catch (Exception e) {
    // ignore
    }
    return null;
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) Document(org.dom4j.Document) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException)

Example 8 with IActionSequence

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

the class SolutionEngine method executeInternal.

@SuppressWarnings({ "unchecked" })
protected IRuntimeContext executeInternal(final String sequencePath, final String processId, final boolean async, final boolean instanceEnds, final Map parameterProviderMap, final String actionSequenceXML) {
    long start = System.currentTimeMillis();
    parameterProviders.putAll(parameterProviderMap);
    parameterProviders.put(PentahoSystem.SCOPE_GLOBAL, PentahoSystem.getGlobalParameters());
    // load the solution action document
    if (debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("SolutionEngine.DEBUG_LOADING_ACTION_DEFINITION"));
    }
    IActionSequence actionSequence = null;
    if (actionSequenceXML != null) {
        actionSequence = createActionSequenceFromXml(actionSequenceXML);
    } else {
        actionSequence = createActionSequence(sequencePath);
    }
    if (actionSequence == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"));
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        long end = System.currentTimeMillis();
        AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"), ((float) (end - start) / 1000), // $NON-NLS-1$
        this);
        return runtime;
    }
    runtime.setActionSequence(actionSequence);
    if (parameterXsl != null) {
        runtime.setParameterXsl(parameterXsl);
    }
    if (forcePrompt) {
        runtime.setPromptStatus(IRuntimeContext.PROMPT_WAITING);
    } else {
        runtime.setPromptStatus(IRuntimeContext.PROMPT_NO);
    }
    boolean validating = true;
    try {
        runtime.validateSequence(FilenameUtils.getName(sequencePath), execListener);
        validating = false;
        runtime.executeSequence(doneListener, execListener, async);
        if (instanceEnds) {
            long end = System.currentTimeMillis();
            AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_END, runtime.getInstanceId(), "", ((float) (end - start) / 1000), // $NON-NLS-1$
            this);
        }
        status = runtime.getStatus();
    } catch (ActionSequenceException ex) {
        String errorMsg = null;
        status = validating ? IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL : IRuntimeContext.RUNTIME_STATUS_FAILURE;
        // This next line is a bit of a workaround, to make up for a deficiency in the SolutionEngine api.
        // What would be nice is to have the exception that is being caught here actually be thrown out of this
        // method. However, the ISolutionEngine interface that this class implements doesn't allow exceptions to be
        // thrown from this method. Since we can't change the signature of public API's with a minor release we need
        // a
        // workaround. We've created an new error method in PentahoMessenger that takes the exception and stuffs it
        // in
        // the messages list maintained within PentahoMessenger. Callers of this method that want to know if an
        // ActionSequenceException occurred should first call getStatus(). If the status does not
        // indicate success then call getMessages() and check if there is an exception in the list of messages.
        error(ex);
        long end = System.currentTimeMillis();
        AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), errorMsg, ((float) (end - start) / 1000), // $NON-NLS-1$
        this);
    }
    return runtime;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) IActionSequence(org.pentaho.platform.api.engine.IActionSequence)

Example 9 with IActionSequence

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

the class SolutionEngineInteractivityService method doGet.

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    PentahoSystem.systemEntryPoint();
    try {
        IPentahoSession userSession = getPentahoSession(request);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // $NON-NLS-1$
        String solutionName = request.getParameter("solution");
        // $NON-NLS-1$
        String actionPath = request.getParameter("path");
        // $NON-NLS-1$
        String actionName = request.getParameter("action");
        IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
        String fileName = null;
        if (actionSequence != null) {
            String title = actionSequence.getTitle();
            if ((title != null) && (title.length() > 0)) {
                fileName = title;
            } else {
                String sequenceName = actionSequence.getSequenceName();
                if ((sequenceName != null) && (sequenceName.length() > 0)) {
                    fileName = sequenceName;
                } else {
                    List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
                    int i = 0;
                    boolean done = false;
                    while ((actionDefinitionsList.size() > i) && !done) {
                        IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
                        String componentName = actionDefinition.getComponentName();
                        if ((componentName != null) && (componentName.length() > 0)) {
                            fileName = componentName;
                            done = true;
                        } else {
                            i++;
                        }
                    }
                }
            }
        }
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
        outputHandler.setSession(userSession);
        IMimeTypeListener listener = new HttpMimeTypeListener(request, response);
        listener.setName(fileName);
        outputHandler.setMimeTypeListener(listener);
        SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + // $NON-NLS-1$
        "SolutionEngineInteractivityService?");
        IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
        setupOutputHandler(outputHandler, requestParameters);
        HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
        handleActionRequest(request, response, outputHandler, requestHandler, requestParameters, outputStream, null);
    } finally {
        PentahoSystem.systemExitPoint();
    }
}
Also used : IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) List(java.util.List) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Example 10 with IActionSequence

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

the class HttpWebService method doParameter.

private void doParameter(final String solutionName, final String actionPath, final String actionName, final IParameterProvider parameterProvider, final OutputStream outputStream, final IPentahoSession userSession, final HttpServletResponse response) throws IOException {
    final IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
    if (actionSequence == null) {
        logger.debug(Messages.getInstance().getString("HttpWebService.ERROR_0002_NOTFOUND", solutionName, actionPath, actionName));
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    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);
        }
        // built in parameters: solution, path, action, prompt, instance-id
        createParameterElement(parametersElement, "solution", String.class, null, "system", "system", new String[] { solutionName });
        createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { actionPath });
        createParameterElement(parametersElement, "action", String.class, null, "system", "system", new String[] { actionName });
        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) });
    } catch (Exception e) {
        logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    // no close, as far as I know tomcat does not like it that much ..
    final XMLWriter writer = new XMLWriter(outputStream, OutputFormat.createPrettyPrint());
    writer.write(document);
    writer.flush();
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) HashMap(java.util.HashMap) Map(java.util.Map)

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