Search in sources :

Example 1 with BackgroundExecutionException

use of org.pentaho.platform.api.scheduler.BackgroundExecutionException in project pentaho-platform by pentaho.

the class ViewAction method doBackgroundExecution.

protected boolean doBackgroundExecution(final HttpServletRequest request, final HttpServletResponse response, final IPentahoSession userSession) throws ServletException, IOException {
    if ("true".equals(request.getParameter("background"))) {
        // $NON-NLS-1$ //$NON-NLS-2$
        IBackgroundExecution backgroundExecutionHandler = PentahoSystem.get(IBackgroundExecution.class, userSession);
        if (backgroundExecutionHandler != null) {
            HttpRequestParameterProvider parameterProvider = new HttpRequestParameterProvider(request);
            // $NON-NLS-1$
            String intro = "";
            // $NON-NLS-1$
            String footer = "";
            IUITemplater templater = PentahoSystem.get(IUITemplater.class, userSession);
            if (templater != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String[] sections = templater.breakTemplate("template-dialog.html", "", userSession);
                if ((sections != null) && (sections.length > 0)) {
                    intro = sections[0];
                }
                if ((sections != null) && (sections.length > 1)) {
                    footer = sections[1];
                }
            } else {
                // $NON-NLS-1$
                intro = Messages.getInstance().getString("ViewAction.ERROR_0002_BAD_TEMPLATE_OBJECT");
            }
            response.getWriter().print(intro);
            String backgroundResponse = null;
            try {
                backgroundResponse = backgroundExecutionHandler.backgroundExecuteAction(userSession, parameterProvider);
            } catch (BackgroundExecutionException bex) {
                backgroundResponse = bex.getLocalizedMessage();
                response.getWriter().print(backgroundResponse);
                response.getWriter().print(footer);
                error(Messages.getInstance().getErrorString("ViewAction.ERROR_0004_UNABLE_TO_PERFORM_BACKGROUND_EXECUTION"), // $NON-NLS-1$
                bex);
                return false;
            }
            response.setHeader("background_execution", "true");
            response.getWriter().print(backgroundResponse);
            response.getWriter().print(footer);
            return true;
        } else {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("ViewAction.ERROR_0001_BACKGROUND_EXECUTE_NOT_SUPPORTED"));
        }
    }
    return false;
}
Also used : BackgroundExecutionException(org.pentaho.platform.api.scheduler.BackgroundExecutionException) IUITemplater(org.pentaho.platform.api.engine.IUITemplater) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) IBackgroundExecution(org.pentaho.platform.api.engine.IBackgroundExecution)

Aggregations

IBackgroundExecution (org.pentaho.platform.api.engine.IBackgroundExecution)1 IUITemplater (org.pentaho.platform.api.engine.IUITemplater)1 BackgroundExecutionException (org.pentaho.platform.api.scheduler.BackgroundExecutionException)1 HttpRequestParameterProvider (org.pentaho.platform.web.http.request.HttpRequestParameterProvider)1