Package org.pentaho.platform.api.engine

Examples of org.pentaho.platform.api.engine.IRuntimeContext


  public static String executeScheduleUi( RepositoryFile file, HttpServletRequest httpServletRequest,
                                          HttpServletResponse httpServletResponse, IPentahoSession userSession,
                                          IMimeTypeListener mimeTypeListener )
    throws Exception {
    IParameterProvider requestParams = new HttpRequestParameterProvider( httpServletRequest );
    IRuntimeContext runtime = null;
    try {
      HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider( userSession );
      HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider( httpServletRequest );

      boolean doMessages = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "debug", "false" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      boolean doWrapper = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "wrapper", "true" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      IOutputHandler outputHandler =
        createOutputHandler( httpServletResponse, getOutputStream( httpServletResponse, doMessages ) );
      if ( mimeTypeListener == null ) {
        mimeTypeListener = new HttpMimeTypeListener( httpServletRequest, httpServletResponse, null );
      }
      outputHandler.setMimeTypeListener( mimeTypeListener );
      outputHandler.setSession( userSession );

      Map parameterProviders = new HashMap();
      parameterProviders.put( "request", requestParameters ); //$NON-NLS-1$
      parameterProviders.put( "session", sessionParameters ); //$NON-NLS-1$
      createOutputFileName( file, outputHandler );
      int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
      outputHandler.setOutputPreference( outputPreference );
      List messages = new ArrayList();

      // forcePrompt=true when displaying the scheduling UI
      runtime =
        executeInternal( file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession,
          true, messages );
      String str =
        postExecute( runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest,
          httpServletResponse, messages );
      return str;
    } catch ( Exception e ) {
      logger.error(
        Messages.getInstance().getString( "XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName() ),
        e ); //$NON-NLS-1$
      throw e;
    } finally {
      if ( runtime != null ) {
        runtime.dispose();
      }
    }
  }
View Full Code Here


      boolean forcePrompt = "true".equalsIgnoreCase(
        requestParams.getStringParameter( "prompt", "false" ) ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

      OutputStream contentStream = new ByteArrayOutputStream();
      SimpleOutputHandler outputHandler = new SimpleOutputHandler( contentStream, false );
      IRuntimeContext runtime = null;
      try {
        runtime =
          executeInternal( file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession,
            forcePrompt, messages );
        Document responseDoc = SoapHelper.createSoapResponseDocument( runtime, outputHandler, contentStream, messages );
        OutputFormat format = OutputFormat.createCompactFormat();
        format.setSuppressDeclaration( true );
        format.setEncoding( "utf-8" ); //$NON-NLS-1$
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter( outputStream, format );
        writer.write( responseDoc );
        writer.flush();
        return outputStream.toString( "utf-8" ); //$NON-NLS-1$
      } finally {
        if ( runtime != null ) {
          runtime.dispose();
        }
      }
    } catch ( Exception e ) {
      logger.warn( Messages.getInstance().getString( "XactionUtil.XML_OUTPUT_NOT_SUPPORTED" ) ); //$NON-NLS-1$
      throw e;
View Full Code Here

  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 {

      final org.w3c.dom.Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      final org.w3c.dom.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 ) {

          org.w3c.dom.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 ) {
            org.w3c.dom.Element valuesElement = document.createElement( "values" );
            for ( Object value : values ) {
              org.w3c.dom.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 ) {
            org.w3c.dom.Element valuesElement = document.createElement( "selected-values" );
            if ( defaultValues instanceof List ) {
              for ( Object value : (List) defaultValues ) {
                org.w3c.dom.Element valueElement = document.createElement( "value" );
                valueElement.setAttribute( "value", "" + value );
                valuesElement.appendChild( valueElement );
              }
            } else {
              org.w3c.dom.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();
    }
View Full Code Here

    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();

    IPentahoUrlFactory urlFactory = new SimpleUrlFactory( contextPath ); //$NON-NLS-1$

    IRuntimeContext runtime;
    IParameterProvider requestParmProvider = parameterProviders.get( "request" );
    if ( requestParmProvider.hasParameter( "obj_id" ) ) {

      final String obj_id = (String) requestParmProvider.getParameter( "obj_id" );
      final String msg_name = (String) requestParmProvider.getParameter( "message_name" );
      final String job_id = (String) requestParmProvider.getParameter( "job_id" );

      runtime = solutionEngine.execute( doc.toString(), obj_id, job_id, false, true, //$NON-NLS-1$ //$NON-NLS-2$
          msg_name, true, parameterProviders, outputHandler, null, urlFactory, new ArrayList() ); //$NON-NLS-1$
    } else {
      runtime = solutionEngine.execute( doc.toString(), "chartbeans_mql", "myprocessid", false, true, //$NON-NLS-1$ //$NON-NLS-2$
          "myinstanceid", true, parameterProviders, outputHandler, null, urlFactory, new ArrayList() ); //$NON-NLS-1$
    }

    if ( ( runtime != null ) && ( runtime.getStatus() != IRuntimeContext.RUNTIME_STATUS_SUCCESS ) ) {
      StringBuilder buf = new StringBuilder();
      boolean firstIteration = true;
      for ( Object /* String */message : runtime.getMessages() ) {

        if ( message instanceof Exception ) {
          Exception ex = (Exception) message;
          if ( ex.getCause() instanceof RuntimeException ) {
            throw (RuntimeException) ex.getCause();
View Full Code Here

    parameterProvider.setParameter( "type", "html" ); //$NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream( "ReportingTest.testJFreeReportParameterPage", ".html" ); //$NON-NLS-1$ //$NON-NLS-2$
    SimpleOutputHandler outputHandler = new SimpleOutputHandler( outputStream, true );
    StandaloneSession session =
        new StandaloneSession( Messages.getInstance().getString( "BaseTest.DEBUG_JUNIT_SESSION" ) ); //$NON-NLS-1$
    IRuntimeContext context =
        run(
            "/test/reporting/jfreereport-reports-test-param.xaction", null, false, parameterProvider, outputHandler, session ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$
    // TODO need some validation of success
    finishTest();
  }
View Full Code Here

    parameterProvider.setParameter( "type", "html" ); //$NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream( "ReportingTest.testJFreeReportParameterPage2", ".html" ); //$NON-NLS-1$ //$NON-NLS-2$
    SimpleOutputHandler outputHandler = new SimpleOutputHandler( outputStream, true );
    StandaloneSession session =
        new StandaloneSession( Messages.getInstance().getString( "BaseTest.DEBUG_JUNIT_SESSION" ) ); //$NON-NLS-1$
    IRuntimeContext context =
        run(
            "/test/reporting/jfreereport-reports-test-param2.xaction", null, false, parameterProvider, outputHandler, session ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$
    // TODO need some validation of success
    finishTest();
  }
View Full Code Here

    parameterProvider.setParameter( SOLUTION_NAME_PARAM, SOLUTION_NAME );
    parameterProvider.setParameter( SOLUTION_PATH_PARAM, "platform" );
    parameterProvider.setParameter( SUBACTION_PARAM, SUBACTION );
    parameterProvider.setParameter( TEST_INPUT_PARAM, TEST_STRING );

    IRuntimeContext context =
        run( "/" + SOLUTION_NAME + "/platform/" + TEST_XACTION, parameterProvider, testName, CO_TEST_EXTN );
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    IActionParameter rtn = context.getOutputParameter( TEST_OUTPUT_PARAM );
    Object value = rtn.getValue();
    assertEquals( TEST_STRING, value );

    finishTest();
  }
View Full Code Here

   * sub-action creates result set, uses, and passes nothing to parent action
   */
  public void testChildConnectionNotSharing() {
    startTest();
    info( "Expected: Failed execution with object not available" ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/platform/SubActionConnectionTest2.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    // xaction should fail, because connection isn't available
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() ); //$NON-NLS-1$

    finishTest();
  }
View Full Code Here

    OutputStream outputStream = getOutputStream( "RuntimeTest.testHelloWorld", ".html" ); //$NON-NLS-1$ //$NON-NLS-2$
    SimpleOutputHandler outputHandler = new SimpleOutputHandler( outputStream, true );
    StandaloneSession session =
        new StandaloneSession( Messages.getInstance().getString( "BaseTest.DEBUG_JUNIT_SESSION" ) ); //$NON-NLS-1$

    IRuntimeContext context =
        run( "/test/platform/HelloWorld.xaction", null, false, parameterProvider, outputHandler, session ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    finishTest();
  }
View Full Code Here

  public String publish( final IPentahoSession localSession ) {
    try {
      HashMap<String, String> parameters = new HashMap<String, String>();
      ISolutionEngine engine = SolutionHelper.execute( "publisher", localSession, "admin/clean_repository.xaction", //$NON-NLS-1$//$NON-NLS-2$
          parameters, null );
      IRuntimeContext context = engine.getExecutionContext();
      int status = context.getStatus();
      if ( status != IRuntimeContext.RUNTIME_STATUS_SUCCESS ) {
        return Messages.getInstance().getString( "CleanRepoPublisher.ERROR_0001_CLEAN_REPO_FAILED" ); //$NON-NLS-1$
      }
    } catch ( Throwable t ) {
      error(
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.engine.IRuntimeContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.