Search in sources :

Example 1 with IBackgroundExecution

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

the class ViewActionServletIT method testBackgroundExecution.

@Test
public void testBackgroundExecution() throws ServletException, IOException, BackgroundExecutionException {
    when(request.getParameter(eq("background"))).thenReturn(Boolean.TRUE.toString());
    final PrintWriter printWriter = mock(PrintWriter.class);
    when(response.getWriter()).thenReturn(printWriter);
    final IBackgroundExecution backgroundExecution = mock(IBackgroundExecution.class);
    mp.defineInstance(IBackgroundExecution.class, backgroundExecution);
    servlet.service(request, response);
    verify(backgroundExecution).backgroundExecuteAction(eq(PentahoSessionHolder.getSession()), any(IParameterProvider.class));
    verify(printWriter, atLeast(1)).print(anyString());
    verify(response).setHeader(eq("background_execution"), eq("true"));
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) PrintWriter(java.io.PrintWriter) IBackgroundExecution(org.pentaho.platform.api.engine.IBackgroundExecution) Test(org.junit.Test)

Example 2 with IBackgroundExecution

use of org.pentaho.platform.api.engine.IBackgroundExecution 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)2 PrintWriter (java.io.PrintWriter)1 Test (org.junit.Test)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)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