Search in sources :

Example 1 with ActionParameterSource

use of org.pentaho.platform.engine.services.actionsequence.ActionParameterSource in project pentaho-platform by pentaho.

the class RuntimeContext method getOutputContentItem.

public IContentItem getOutputContentItem(final String outputName, final String mimeType) {
    IContentItem contentItem = null;
    IActionParameter parameter = (IActionParameter) actionSequence.getOutputDefinitions().get(outputName);
    if (parameter == null) {
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    } else {
        List destinationsList = parameter.getVariables();
        Iterator destinationsIterator = destinationsList.iterator();
        if (destinationsList.size() > 1) {
            contentItem = new MultiContentItem();
        }
        while (destinationsIterator.hasNext()) {
            ActionParameterSource destination = (ActionParameterSource) destinationsIterator.next();
            String objectName = destination.getSourceName();
            String contentName = destination.getValue();
            contentName = TemplateUtil.applyTemplate(contentName, this);
            outputHandler.setSession(session);
            IContentItem tmpContentItem = outputHandler.getOutputContentItem(objectName, contentName, instanceId, mimeType);
            addOutputContentItem(tmpContentItem);
            if (contentItem instanceof MultiContentItem) {
                ((MultiContentItem) contentItem).addContentItem(tmpContentItem);
            } else {
                contentItem = tmpContentItem;
                break;
            }
        }
    }
    return contentItem;
}
Also used : ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) MultiContentItem(org.pentaho.platform.engine.core.output.MultiContentItem) IContentItem(org.pentaho.platform.api.repository.IContentItem) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 2 with ActionParameterSource

use of org.pentaho.platform.engine.services.actionsequence.ActionParameterSource in project pentaho-platform by pentaho.

the class SolutionEngineInteractivityService method handleActionRequest.

protected void handleActionRequest(final HttpServletRequest request, final HttpServletResponse response, final HttpOutputHandler outputHandler, final HttpServletRequestHandler requestHandler, IParameterProvider requestParameters, ByteArrayOutputStream outputStream, final IContentItem contentItem) throws ServletException, IOException {
    IRuntimeContext runtime = null;
    try {
        DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.newDocument();
        Element root = document.createElement("action_sequence_info");
        document.appendChild(root);
        requestHandler.setCreateFeedbackParameterCallback(new ICreateFeedbackParameterCallback() {

            public void createFeedbackParameter(IRuntimeContext runtimeContext, String fieldName, String displayName, String hint, Object defaultValues, List values, Map dispNames, String displayStyle, boolean optional, boolean visible) {
                Element parameterElement = document.createElement("parameter");
                parameterElement.setAttribute("name", fieldName);
                parameterElement.setAttribute("display-name", displayName);
                parameterElement.setAttribute("display-style", displayStyle);
                parameterElement.setAttribute("hint", "" + hint);
                parameterElement.setAttribute("optional", "" + optional);
                parameterElement.setAttribute("visible", "" + visible);
                try {
                    IActionParameter actionParameter = runtimeContext.getInputParameter(fieldName);
                    if (actionParameter != null) {
                        List variables = actionParameter.getVariables();
                        for (int i = 0; variables != null && i < variables.size(); i++) {
                            Object var = variables.get(i);
                            if (var instanceof ActionParameterSource) {
                                String sourceName = ((ActionParameterSource) var).getSourceName();
                                String sourceValue = ((ActionParameterSource) var).getValue();
                                parameterElement.setAttribute("source-name", "" + sourceName);
                                parameterElement.setAttribute("source-value", "" + sourceValue);
                            } else {
                                System.out.println(var);
                            }
                        }
                    }
                } catch (Exception npe) {
                // ignore
                }
                root.appendChild(parameterElement);
                if (values != null) {
                    Element valuesElement = document.createElement("values");
                    for (Object value : values) {
                        Element valueElement = document.createElement("value");
                        valueElement.setAttribute("value", "" + value);
                        if (dispNames != null && dispNames.containsKey(value)) {
                            valueElement.setAttribute("display-name", "" + dispNames.get(value));
                        }
                        valuesElement.appendChild(valueElement);
                    }
                    parameterElement.appendChild(valuesElement);
                }
                if (defaultValues != null) {
                    Element valuesElement = document.createElement("selected-values");
                    if (defaultValues instanceof List) {
                        for (Object value : (List) defaultValues) {
                            Element valueElement = document.createElement("value");
                            valueElement.setAttribute("value", "" + value);
                            valuesElement.appendChild(valueElement);
                        }
                    } else {
                        Element valueElement = document.createElement("value");
                        valueElement.setAttribute("value", "" + defaultValues);
                        valuesElement.appendChild(valueElement);
                    }
                    parameterElement.appendChild(valuesElement);
                }
            }
        });
        runtime = requestHandler.handleActionRequest(0, 0);
        root.setAttribute("is-prompt-pending", "" + runtime.isPromptPending());
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new StringWriter());
        TransformerFactory.newInstance().newTransformer().transform(source, result);
        String theXML = result.getWriter().toString();
        response.setContentType("text/xml");
        response.getOutputStream().write(theXML.getBytes());
        response.getOutputStream().close();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    } catch (TransformerFactoryConfigurationError e) {
        e.printStackTrace();
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
    if (contentItem != null) {
        contentItem.closeOutputStream();
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ICreateFeedbackParameterCallback(org.pentaho.platform.api.engine.ICreateFeedbackParameterCallback) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) ServletException(javax.servlet.ServletException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashMap(java.util.HashMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) TransformerException(javax.xml.transform.TransformerException)

Example 3 with ActionParameterSource

use of org.pentaho.platform.engine.services.actionsequence.ActionParameterSource 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 4 with ActionParameterSource

use of org.pentaho.platform.engine.services.actionsequence.ActionParameterSource in project pentaho-platform by pentaho.

the class RuntimeContext method resolveParameters.

private void resolveParameters() throws UnresolvedParameterException {
    Set inputNames = getInputNames();
    Iterator inputNamesIterator = inputNames.iterator();
    IActionParameter actionParameter;
    List variables;
    Iterator variablesIterator;
    ActionParameterSource variable;
    String sourceName;
    String sourceValue;
    Object variableValue = null;
    IParameterProvider parameterProvider;
    while (inputNamesIterator.hasNext()) {
        variableValue = null;
        String inputName = (String) inputNamesIterator.next();
        actionParameter = paramManager.getCurrentInput(inputName);
        if (actionParameter == null) {
            throw new UnresolvedParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0031_INPUT_NOT_FOUND", // $NON-NLS-1$
            inputName), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
        }
        variables = actionParameter.getVariables();
        variablesIterator = variables.iterator();
        while (variablesIterator.hasNext()) {
            variable = (ActionParameterSource) variablesIterator.next();
            sourceName = variable.getSourceName();
            sourceValue = variable.getValue();
            variableValue = null;
            // e.g. runtme.parent
            if ("runtime".equals(sourceName)) {
                // $NON-NLS-1$
                // first check the standard variables
                variableValue = getStringParameter(sourceValue, null);
                if (variableValue == null) {
                    // now check the runtime data
                    variableValue = runtimeData.getStringProperty(sourceValue, null);
                }
                if (variableValue != null) {
                    break;
                }
            } else {
                parameterProvider = (IParameterProvider) parameterProviders.get(sourceName);
                if (parameterProvider == null) {
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_REQUESTED_PARAMETER_SOURCE_NOT_AVAILABLE", sourceName, // $NON-NLS-1$
                    inputName));
                } else {
                    variableValue = parameterProvider.getParameter(sourceValue);
                    if (variableValue != null) {
                        break;
                    }
                }
            }
        }
        if (variableValue == null) {
            if (actionParameter.getValue() != null) {
                if (actionParameter.hasDefaultValue()) {
                    if (PentahoSystem.trace) {
                        // $NON-NLS-1$
                        trace(Messages.getInstance().getString("RuntimeContext.TRACE_USING_DEFAULT_PARAMETER_VALUE", inputName));
                    }
                } else {
                    if (PentahoSystem.trace) {
                        trace(Messages.getInstance().getString(// $NON-NLS-1$
                        "RuntimeContext.TRACE_INFO_USING_CURRENT_PARAMETER_VALUE" + inputName));
                    }
                }
            } else if ("content".equals(actionParameter.getType())) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                variableValue = "";
            }
        } else {
            actionParameter.setValue(variableValue);
        }
    }
// while
}
Also used : UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) Set(java.util.Set) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)4 ActionParameterSource (org.pentaho.platform.engine.services.actionsequence.ActionParameterSource)4 Iterator (java.util.Iterator)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ServletException (javax.servlet.ServletException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)1