Search in sources :

Example 21 with IPentahoRequestContext

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

the class ChartHelper method doChart.

/**
 * doChart generates the images and html necessary to render various charts within a web page.
 *
 * @param actionPath
 *          full path including the name of the action sequence or resource
 * @param parameterProvider
 *          the collection of parameters to customize the chart
 * @param outputStream
 *          the output string buffer for the content
 * @param userSession
 *          the user session object
 * @param messages
 *          a collection to store error and logging messages
 * @param logger
 *          logging object
 *
 * @return true if successful
 */
@Deprecated
public static boolean doChart(final String actionPath, final IParameterProvider parameterProvider, final StringBuffer outputStream, final IPentahoSession userSession, final ArrayList messages, ILogger logger) {
    deprecateWarning();
    boolean result = true;
    String content = null;
    StringBuffer messageBuffer = new StringBuffer();
    if (logger == null) {
        // No logger? The usersession extends ILogger, use it for logging
        logger = userSession;
    }
    // Retrieve all parameters from parameter provider
    // $NON-NLS-1$
    String outerParams = parameterProvider.getStringParameter("outer-params", null);
    // $NON-NLS-1$
    String innerParam = parameterProvider.getStringParameter("inner-param", null);
    // $NON-NLS-1$
    String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null);
    // $NON-NLS-1$
    String imageUrl = parameterProvider.getStringParameter("image-url", null);
    // Very likely null; allow API users to continue to pass the dial value via parameters
    // $NON-NLS-1$
    String dialValue = parameterProvider.getStringParameter("value", null);
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    if (imageUrl == null) {
        // $NON-NLS-1$
        imageUrl = requestContext.getContextPath();
    }
    if (urlDrillTemplate == null) {
        // $NON-NLS-1$
        urlDrillTemplate = "";
    }
    // $NON-NLS-1$
    int width = (int) parameterProvider.getLongParameter("image-width", 150);
    // $NON-NLS-1$
    int height = (int) parameterProvider.getLongParameter("image-height", 150);
    SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate);
    // Determine the type of chart we are building; these values can come from the chart xml definition, or
    // from the parameter provider. Try the parameter provider first, for performance reasons.
    String chartTypeStr = parameterProvider.getStringParameter(ChartDefinition.TYPE_NODE_NAME, null);
    String datasetType = ChartDefinition.CATEGORY_DATASET_STR;
    if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) {
        try {
            // attempt to get the chart type and possibly data type from the xml doc
            ActionSequenceJCRHelper jcrHelper = new ActionSequenceJCRHelper(userSession);
            Document chartDefinition = jcrHelper.getSolutionDocument(actionPath, RepositoryFilePermission.READ);
            // $NON-NLS-1$
            Node chartAttributes = chartDefinition.selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME);
            chartTypeStr = chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME).getText();
            Node datasetTypeNode = chartAttributes.selectSingleNode(ChartDefinition.DATASET_TYPE_NODE_NAME);
            if (datasetTypeNode != null) {
                datasetType = datasetTypeNode.getText();
            }
        } catch (Exception e) {
            logger.error(Messages.getInstance().getErrorString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), // $NON-NLS-1$
            e);
            PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", Messages.getInstance().getString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), messages, // $NON-NLS-1$ //$NON-NLS-2$
            messageBuffer);
            content = messageBuffer.toString();
            result = false;
        }
    }
    // Check again - do we have a chart type now? If not, bail out, we have no idea what to try to generate
    if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE"));
        PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", Messages.getInstance().getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE"), messages, // $NON-NLS-1$ //$NON-NLS-2$
        messageBuffer);
        content = messageBuffer.toString();
        result = false;
    }
    if (!result) {
        outputStream.append(content);
        return result;
    }
    int chartType = JFreeChartEngine.getChartType(chartTypeStr);
    AbstractJFreeChartComponent chartComponent = null;
    try {
        // Some charts are determined by the dataset that is passed in; check these first...
        if (datasetType.equalsIgnoreCase(ChartDefinition.TIME_SERIES_COLLECTION_STR)) {
            chartComponent = new TimeSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages);
        } else if (datasetType.equalsIgnoreCase(ChartDefinition.XY_SERIES_COLLECTION_STR)) {
            chartComponent = new XYSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages);
        } else if (datasetType.equalsIgnoreCase(ChartDefinition.XYZ_SERIES_COLLECTION_STR)) {
            chartComponent = new XYZSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages);
        }
        // Didn't find a dataset, so try to create the component based on chart type.
        if (chartComponent == null) {
            switch(chartType) {
                case JFreeChartEngine.BAR_CHART_TYPE:
                case JFreeChartEngine.AREA_CHART_TYPE:
                case JFreeChartEngine.BAR_LINE_CHART_TYPE:
                case JFreeChartEngine.LINE_CHART_TYPE:
                case JFreeChartEngine.DIFFERENCE_CHART_TYPE:
                case JFreeChartEngine.DOT_CHART_TYPE:
                case JFreeChartEngine.STEP_AREA_CHART_TYPE:
                case JFreeChartEngine.STEP_CHART_TYPE:
                case JFreeChartEngine.PIE_GRID_CHART_TYPE:
                    chartComponent = new CategoryDatasetChartComponent(chartType, actionPath, width, height, urlFactory, messages);
                    break;
                case JFreeChartEngine.PIE_CHART_TYPE:
                    chartComponent = new PieDatasetChartComponent(chartType, actionPath, width, height, urlFactory, messages);
                    break;
                case JFreeChartEngine.DIAL_CHART_TYPE:
                    chartComponent = new DialChartComponent(chartType, actionPath, width, height, urlFactory, messages);
                    if (dialValue != null) {
                        Number numericDialValue = DataUtilities.toNumber(dialValue, LocaleHelper.getCurrencyFormat(), LocaleHelper.getNumberFormat());
                        ((DialChartComponent) chartComponent).setValue(numericDialValue.doubleValue());
                    }
                    break;
                case JFreeChartEngine.BUBBLE_CHART_TYPE:
                    chartComponent = new XYZSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages);
                    break;
                case JFreeChartEngine.UNDEFINED_CHART_TYPE:
                default:
                    // Unsupported chart type, bail out
                    logger.error(Messages.getInstance().getString("ChartHelper.ERROR_0003_INVALID_CHART_TYPE", chartTypeStr, // $NON-NLS-1$
                    Integer.toString(chartType)));
                    PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getInstance().getString(// $NON-NLS-1$ //$NON-NLS-2$
                    "ChartHelper.ERROR_0003_INVALID_CHART_TYPE", chartTypeStr, Integer.toString(chartType)), messages, messageBuffer);
                    content = messageBuffer.toString();
                    result = false;
            }
        }
        if (result && (chartComponent != null)) {
            try {
                chartComponent.setLoggingLevel(logger.getLoggingLevel());
                chartComponent.validate(userSession, null);
                chartComponent.setDataAction(actionPath);
                chartComponent.setUrlTemplate(urlDrillTemplate);
                // $NON-NLS-1$
                String seriesName = parameterProvider.getStringParameter("series-name", null);
                if (chartComponent instanceof CategoryDatasetChartComponent) {
                    ((CategoryDatasetChartComponent) chartComponent).setSeriesName(seriesName);
                }
                // WARNING!!! This is an atypical way to access data for the chart... these parameters and their
                // usage are undocumented, and only left in here to support older solutions that may be using them.
                // *************** START QUESTIONABLE CODE ********************************************************
                // $NON-NLS-1$
                String connectionName = parameterProvider.getStringParameter("connection", null);
                // $NON-NLS-1$
                String query = parameterProvider.getStringParameter("query", null);
                // $NON-NLS-1$
                String dataAction = parameterProvider.getStringParameter("data-process", null);
                IPentahoConnection connection = null;
                try {
                    chartComponent.setParamName(innerParam);
                    chartComponent.setParameterProvider(IParameterProvider.SCOPE_REQUEST, parameterProvider);
                    if ((connectionName != null) && (query != null)) {
                        // connection = new SQLConnection(connectionName, logger)
                        // TODO support non-SQL data sources. Much easier now using the factory
                        connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, userSession, logger);
                        try {
                            query = TemplateUtil.applyTemplate(query, TemplateUtil.parametersToProperties(parameterProvider), null);
                            IPentahoResultSet results = connection.executeQuery(query);
                            chartComponent.setValues(results);
                        } finally {
                            boolean ignored = true;
                        }
                        chartComponent.setUrlTemplate(urlDrillTemplate);
                        if (outerParams != null) {
                            // $NON-NLS-1$
                            StringTokenizer tokenizer = new StringTokenizer(outerParams, ";");
                            while (tokenizer.hasMoreTokens()) {
                                chartComponent.addOuterParamName(tokenizer.nextToken());
                            }
                        }
                    } else if (dataAction != null) {
                        chartComponent.setDataAction(dataAction);
                    }
                    // ***************** END QUESTIONABLE CODE ********************************************************
                    // $NON-NLS-1$
                    content = chartComponent.getContent("text/html");
                } finally {
                    if (connection != null) {
                        connection.close();
                    }
                }
            } catch (Throwable e) {
                // $NON-NLS-1$
                logger.error(Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), e);
            }
        }
        try {
            if (content == null) {
                PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, // $NON-NLS-1$ //$NON-NLS-2$
                messageBuffer);
                content = messageBuffer.toString();
                result = false;
            }
            outputStream.append(content);
        } catch (Exception e) {
            // $NON-NLS-1$
            logger.error(Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), e);
        }
    } finally {
        if (chartComponent != null) {
            chartComponent.dispose();
        }
    }
    return result;
}
Also used : Node(org.dom4j.Node) Document(org.dom4j.Document) IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) StringTokenizer(java.util.StringTokenizer) IMessageFormatter(org.pentaho.platform.api.engine.IMessageFormatter) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper)

Example 22 with IPentahoRequestContext

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

the class XYSeriesCollectionChartComponent method getXmlContent.

@Override
public Document getXmlContent() {
    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("baseUrl", contextPath + "/");
    // $NON-NLS-1$
    String mapName = "chart" + AbstractChartComponent.chartCount++;
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
    if (chartDefinition == null) {
        // $NON-NLS-1$
        Element errorElement = result.addElement("error");
        errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
        // $NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", definitionPath);
        // $NON-NLS-1$
        errorElement.addElement("message").setText(message);
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);
    if (dataDefinition == null) {
        // $NON-NLS-1$
        Element errorElement = result.addElement("error");
        errorElement.addElement("title").setText(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART"));
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath);
        // $NON-NLS-1$
        errorElement.addElement("message").setText(message);
        // System .out.println( result.asXML() );
        return result;
    }
    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    // $NON-NLS-1$
    String chartTitle = "";
    try {
        if (width == -1) {
            // $NON-NLS-1$
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText());
        }
        if (height == -1) {
            // $NON-NLS-1$
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText());
        }
    } catch (Exception e) {
    // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) {
        // $NON-NLS-1$
        urlTemplate = // $NON-NLS-1$
        chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME).getText();
    }
    if (chartDefinition.selectSingleNode("/chart/paramName") != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText();
    }
    // $NON-NLS-1$
    Element root = result.addElement("charts");
    XYSeriesCollection chartDataDefinition = (XYSeriesCollection) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, JFreeChartEngine.OUTPUT_PNG, printWriter, info, // $NON-NLS-1$
        this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        // $NON-NLS-1$
        Element chartElement = root.addElement("chart");
        // $NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName);
        // $NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width));
        // $NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height));
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                Number columnKey = chartDataDefinition.getX(row, column);
                // $NON-NLS-1$
                Element valueElement = chartElement.addElement("value2D");
                // $NON-NLS-1$
                valueElement.addElement("value").setText(value.toString());
                // $NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString());
                // $NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString());
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        // $NON-NLS-1$
        chartElement.addElement("imageMap").setText(mapString);
        // $NON-NLS-1$
        chartElement.addElement("image").setText(fileName);
    }
    return result;
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) StringWriter(java.io.StringWriter) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) PrintWriter(java.io.PrintWriter)

Example 23 with IPentahoRequestContext

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

the class SolutionEngineAgent method execute.

public int execute() {
    PentahoSystem.systemEntryPoint();
    try {
        // create a generic session object
        StandaloneSession session = new StandaloneSession(userId);
        solutionEngine = PentahoSystem.get(SolutionEngine.class, session);
        solutionEngine.init(session);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        // $NON-NLS-1$
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
        String processName = description;
        boolean persisted = false;
        List messages = new ArrayList();
        outputStream = new ByteArrayOutputStream(0);
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            outputHandler = new SimpleOutputHandler(outputStream, false);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        PentahoSystem.systemExitPoint();
    }
    return solutionEngine.getStatus();
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 24 with IPentahoRequestContext

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

the class SolutionHelper method execute.

/**
 * Runs an action sequence. This method uses the base URL set by the Application Context
 *
 * @param description
 *          An identifier for this process. This is used for auditing and logging purposes only.
 * @param session
 *          The user session that is requesting this execution. This is used for auditing and logging and also
 *          can be used in action sequences (for example to filter data)
 * @param actionSequence
 *          Path to the action sequence file
 * @param parameters
 *          Parameters to be passed to the action sequence
 * @param outputStream
 *          The output stream for content generated by the action sequence. Can be null.
 * @param execListener
 *          An execution listener for feedback during execution. Can be null.
 * @return
 */
public static ISolutionEngine execute(final String description, final IPentahoSession session, final String actionSequence, final Map parameters, OutputStream outputStream, final IExecutionListener execListener, final boolean collateMessages, final boolean manageHibernate) {
    if (manageHibernate) {
        PentahoSystem.systemEntryPoint();
    }
    ISolutionEngine solutionEngine = null;
    try {
        solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
        solutionEngine.init(session);
        solutionEngine.setlistener(execListener);
        SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
        String url = requestContext.getContextPath();
        // Modifications by Ezequiel Cuellar
        // Old code.
        // String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
        // New code. Since the SubActionComponent is being instantiated below to return feedback
        // it is necesary to configure the baseUrl to include the ViewAction.
        Object actionUrlComponent = parameters.get(StandardSettings.ACTION_URL_COMPONENT);
        if ((actionUrlComponent != null) && (actionUrlComponent.toString().length() > 0)) {
            url += actionUrlComponent.toString();
        } else {
            // $NON-NLS-1$
            url += "ViewAction?";
        }
        HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
        parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory(url);
        String processName = description;
        boolean persisted = false;
        // for now, the messages list needs to be untyped since we may put exceptions as well as strings in it
        List<?> messages = null;
        if (collateMessages) {
            messages = new ArrayList();
        }
        if (outputStream == null) {
            outputStream = new ByteArrayOutputStream(0);
        }
        SimpleOutputHandler outputHandler = null;
        if (outputStream != null) {
            // Modifications by Ezequiel Cuellar
            // Old code.
            // outputHandler = new SimpleOutputHandler(outputStream, false);
            // New code. Without setting the allowFeedback parameter to true it is assumed that SubActionComponent
            // instances
            // are never capable of returning feedback which may not always be the case.
            outputHandler = new SimpleOutputHandler(outputStream, true);
            outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
        }
        solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
    } finally {
        if (manageHibernate) {
            PentahoSystem.systemExitPoint();
        }
    }
    return solutionEngine;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 25 with IPentahoRequestContext

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

Aggregations

IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)32 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)11 ArrayList (java.util.ArrayList)9 Document (org.dom4j.Document)9 Element (org.dom4j.Element)9 IOException (java.io.IOException)8 PrintWriter (java.io.PrintWriter)8 StringWriter (java.io.StringWriter)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)7 StandardEntityCollection (org.jfree.chart.entity.StandardEntityCollection)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)5 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)4