Package org.pentaho.platform.api.engine

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


      out = outputStream;
    }

    @Override
    public void execute() throws Exception {
      IParameterProvider pathParams = parameterProviders.get( "path" );
      String command = pathParams.getStringParameter( "cmd", "" );

      IOUtils.write( "hello this is service content generator servicing command " + command, out );
      out.close();
    }
View Full Code Here


  private static final String PLUGIN_ID = CdfEngine.getEnvironment().getPluginId();

  @Override
  public void createContent() throws Exception {
    OutputStream out = null;
    final IParameterProvider pathParams;
    final String method;
    final String payload;
    logger.info( "[Timing] CDF content generator took over: "
      + ( new SimpleDateFormat( "HH:mm:ss.SSS" ) ).format( new Date() ) );
    try {

      out = getResponseOutputStream( MimeTypes.HTML );

      if ( parameterProviders.get( Parameter.PATH ) != null
        && parameterProviders.get( Parameter.PATH ).getParameter( "httprequest" ) != null
        && ( (HttpServletRequest) parameterProviders.get( Parameter.PATH ).getParameter( "httprequest" ) )
        .getContextPath() != null ) {
        RELATIVE_URL =
          ( (HttpServletRequest) parameterProviders.get( Parameter.PATH ).getParameter( "httprequest" ) )
            .getContextPath();
      } else {
        RELATIVE_URL = CdfEngine.getEnvironment().getApplicationBaseContentUrl();
        /*
         * If we detect an empty string, things will break. If we detect an absolute url, things will *probably* break.
         * In either of these cases, we'll resort to Catalina's context, and its getContextPath() method for better
         * results.
         */
        if ( "".equals( RELATIVE_URL ) || RELATIVE_URL.matches( "^http://.*" ) ) {
          Object context = PentahoSystem.getApplicationContext().getContext();
          Method getContextPath = context.getClass().getMethod( "getContextPath", null );
          if ( getContextPath != null ) {
            RELATIVE_URL = getContextPath.invoke( context, null ).toString();
          }
        }
      }

      if ( RELATIVE_URL.endsWith( "/" ) ) {
        RELATIVE_URL = RELATIVE_URL.substring( 0, RELATIVE_URL.length() - 1 );
      }

      // If callbacks is properly setup, we assume we're being called from another plugin
      if ( this.callbacks != null && callbacks.size() > 0 && HashMap.class.isInstance( callbacks.get( 0 ) ) ) {
        HashMap<String, Object> iface = (HashMap<String, Object>) callbacks.get( 0 );
        pathParams = parameterProviders.get( Parameter.PATH );
        method = "/" + (String) iface.get( "method" );
        payload = (String) iface.get( "payload" );
        this.userSession = this.userSession != null ? this.userSession : (IPentahoSession) iface.get( "usersession" );
      } else { // if not, we handle the request normally
        pathParams = parameterProviders.get( Parameter.PATH );
        method = pathParams.getStringParameter( Parameter.PATH, null );
        payload = "";
      }

      // make sure we have a workable state
      if ( outputHandler == null ) {
View Full Code Here

    // Each block will call a different method. If in the future this extends a lot we can think
    // about using reflection for class loading, but I don't expect that to happen.

    HttpServletRequest request =
      ( (HttpServletRequest) parameterProviders.get( Parameter.PATH ).getParameter( "httprequest" ) );
    final IParameterProvider requestParams = parameterProviders.get( IParameterProvider.SCOPE_REQUEST );

    if ( urlPath.equals( RENDER_XCDF ) ) {
      renderXcdfDashboard( out, requestParams );
    } else if ( urlPath.equals( JSON_SOLUTION ) ) {
      jsonSolution( out, requestParams );
    } else if ( urlPath.equals( GET_CDF_RESOURCE ) ) {
      getCDFResource( urlPath, out, requestParams );
    } else if ( urlPath.equals( RENDER_HTML ) ) {
      renderHtml( out, requestParams );
    } else if ( urlPath.equals( EXPORT ) ) {
      exportFile( requestParams, out );
    } else if ( urlPath.equals( SETTINGS ) ) {
      cdfSettings( requestParams, out );
    } else if ( urlPath.equals( CALLACTION ) ) {
      ActionEngine.getInstance().execute( requestParams, userSession, out );
    } else if ( urlPath.equals( COMMENTS ) ) {
      processComments( requestParams, out );
    } else if ( urlPath.equals( STORAGE ) ) {
      processStorage( requestParams, out );
    } else if ( urlPath.equals( CONTEXT ) ) {
      int inactiveInterval = 120 * 60;
      if ( request != null && request.getSession() != null ) {
        inactiveInterval = request.getSession().getMaxInactiveInterval();
      }
      ContextEngine
        .generateContext( out, Parameter.asHashMap( request ), inactiveInterval );
    } else if ( urlPath.equals( CLEAR_CACHE ) ) {
      clearCache( out );
    } else if ( urlPath.equals( VIEWS ) ) {
      views( requestParams, out );
    } else if ( urlPath.equals( GETHEADERS ) ) {
      if ( !StringUtils.isEmpty( payload ) ) {
        CdfHtmlRenderer.getHeaders( payload, Parameter.asHashMap( requestParams ), out );
      } else {
        CdfHtmlRenderer.getHeaders( requestParams.getStringParameter( Parameter.DASHBOARD_CONTENT, null ), Parameter
          .asHashMap( requestParams ), out );
      }
    } else if ( urlPath.equalsIgnoreCase( PING ) ) {
      out.write( "{\"ping\":\"ok\"}".getBytes( CharsetHelper.getEncoding() ) );
    } else if ( urlPath.equalsIgnoreCase( GET_SCHEDULES ) ) {
View Full Code Here

    renderHtmlDashboard( out, solution, path, templateName == null ? "template.html" : templateName, template,
      messageBaseFilename );
  }

  private void returnResource( final String urlPath, final OutputStream out ) throws Exception {
    final IParameterProvider pathParams = parameterProviders.get( Parameter.PATH ); //$NON-NLS-1$

    final IResourceLoader resLoader = CdfEngine.getEnvironment().getResourceLoader();
    final String maxAge = resLoader.getPluginSetting( CdfContentGenerator.class, "settings/max-age" );
    final HttpServletResponse response = (HttpServletResponse) pathParams.getParameter( "httpresponse" );
    if ( maxAge != null && response != null ) {
      response.setContentType( MimeTypes.getMimeType( urlPath ) );
      response.setHeader( "Cache-Control", "max-age=" + maxAge );
    }
View Full Code Here

  @Exposed( accessLevel = AccessLevel.PUBLIC )
  @Audited( action = "edit" )
  public void edit( final OutputStream out ) throws Exception {
    // 0 - Check security. Caveat: if no path is supplied, then we're in the new parameter
    IParameterProvider requestParams = getRequestParameters();
    IParameterProvider pathParams = getPathParameters();

    boolean debugMode = requestParams.hasParameter( MethodParams.DEBUG )
      && requestParams.getParameter( MethodParams.DEBUG ).toString().equals( "true" );

    String wcdfPath = getWcdfRelativePath( requestParams );
View Full Code Here

    writeOut( out, result );
  }

  @Exposed( accessLevel = AccessLevel.PUBLIC )
  public void syncTemplates( final OutputStream out ) throws Exception {
    IParameterProvider requestParams = getRequestParameters();
    String method = requestParams.getStringParameter( REQUEST_PARAM_OPERATION, null );

    final CdfTemplates cdfTemplates = new CdfTemplates( GET_RESOURCE );

    if ( method.equals( OPERATION_LOAD ) ) {
      Object result = cdfTemplates.load();
      JsonUtils.buildJsonResult( out, true, result );
    } else if ( method.equals( OPERATION_SAVE ) ) {
      String file = requestParams.getStringParameter( REQUEST_PARAM_FILE, null ),
        structure = requestParams.getStringParameter( CdeConstants.MethodParams.CDF_STRUCTURE, null );
      cdfTemplates.save( file, structure );
      JsonUtils.buildJsonResult( out, true, null );
    }
  }
View Full Code Here

  }

  @Exposed( accessLevel = AccessLevel.PUBLIC )
  public void exploreFolder( final OutputStream out ) throws IOException, JSONException {

    IParameterProvider requestParams = getRequestParameters();
    final String folder = requestParams.getStringParameter( "dir", null );
    final String fileExtensions = requestParams.getStringParameter( "fileExtensions", null );
    final String permission = requestParams.getStringParameter( "access", null );
    final String outputType = requestParams.getStringParameter( "outputType", null );

    if ( outputType != null && outputType.equals( "json" ) ) {
      try {
        writeOut( out, RepositoryHelper.toJSON( folder, getFileList( folder, fileExtensions, permission ) ) );
      } catch ( JSONException e ) {
View Full Code Here

  }

  @Exposed( accessLevel = AccessLevel.PUBLIC )
  public void writeFile( OutputStream out ) throws PentahoAccessControlException, IOException {

    IParameterProvider requestParams = getRequestParameters();
    String path = requestParams.getStringParameter( MethodParams.PATH, null );
    String contents = requestParams.getStringParameter( MethodParams.DATA, null );
    boolean createNew = requestParams.hasParameter( "createNew" );

    IUserContentAccess access = CdeEnvironment.getUserContentAccess();

    if ( access.hasAccess( path, FileAccess.WRITE )
      || ( createNew && access.hasAccess( FilenameUtils.getFullPath( path ), FileAccess.WRITE ) ) ) {
View Full Code Here

    }
  }

  private CdfRunJsDashboardWriteResult loadDashboard()
    throws ThingWriteException {
    IParameterProvider pathParams = parameterProviders.get( "path" );
    IParameterProvider requestParams = parameterProviders.get( "request" );

    String scheme = ( requestParams.hasParameter( "inferScheme" ) && requestParams
      .getParameter( "inferScheme" ).equals( "false" ) ) ? ""
      : getScheme( pathParams );

    String absRoot = requestParams.getStringParameter( "root", "" );

    boolean absolute = requestParams.hasParameter( "absolute" )
      && requestParams.getParameter( "absolute" ).equals( "true" );

    boolean bypassCacheRead = requestParams.hasParameter( "bypassCache" )
      && requestParams.getParameter( "bypassCache" ).equals( "true" );

    boolean debug = requestParams.hasParameter( "debug" )
      && requestParams.getParameter( "debug" ).equals( "true" );

    String wcdfFilePath = getWcdfRelativePath( requestParams );

    String style = requestParams.getStringParameter( "style", "" );

    CdfRunJsDashboardWriteOptions options = new CdfRunJsDashboardWriteOptions(
      absolute, debug, absRoot, scheme );

    return DashboardManager.getInstance().getDashboardCdfRunJs(
View Full Code Here

    return logger;
  }

  @Override
  public void createContent() throws Exception {
    IParameterProvider requestParams = parameterProviders.get( MethodParams.REQUEST );
    IParameterProvider pathParams = parameterProviders.get( MethodParams.PATH );

    String solution = getRequestParameterAsString( MethodParams.SOLUTION, "" ),
           path = getRequestParameterAsString( MethodParams.PATH, "" ),
           file = getRequestParameterAsString( MethodParams.FILE, "" );
    String root = getRequestParameterAsString( MethodParams.ROOT, "" );

    String viewId = getRequestParameterAsString( MethodParams.VIEWID, "" );

    String filePath = getPathParameterAsString( MethodParams.PATH, "" );

    boolean inferScheme = requestParams.hasParameter( MethodParams.INFER_SCHEME )
      && getRequestParameterAsString( MethodParams.INFER_SCHEME, "" ).equals( "false" );
    boolean absolute = requestParams.hasParameter( MethodParams.ABSOLUTE )
      && getRequestParameterAsString( MethodParams.ABSOLUTE, "" ).equals( "true" );
    boolean bypassCacheRead = requestParams.hasParameter( MethodParams.BYPASS_CACHE )
      && getRequestParameterAsString( MethodParams.BYPASS_CACHE, "" ).equals( "true" );
    boolean debug = requestParams.hasParameter( MethodParams.DEBUG )
      && getRequestParameterAsString( MethodParams.DEBUG, "" ).equals( "true" );

    String style = getRequestParameterAsString( MethodParams.STYLE, "" );

    RenderApi renderer = new RenderApi();

    long start = System.currentTimeMillis();
    UUID uuid = CpfAuditHelper.startAudit( getPluginName(), filePath, getObjectName(),
      this.userSession, this, requestParams );

    if ( create ) {
      String result = renderer.newDashboard( filePath, debug, true, getRequest(), getResponse() );
      IOUtils.write( result, getResponse().getOutputStream() );
    } else if ( edit ) {
      //TODO: file to path
      String result = renderer.edit( "", "", filePath, debug, true, getRequest(), getResponse() );
      IOUtils.write( result, getResponse().getOutputStream() );

    } else if ( resource ) {
      // TODO review later if there is a viable solution to making resources being
      // called via cde resources rest api (pentaho/plugin/pentaho-cdf-dd/api/resources?resource=)
      // this has to take into consideration:
      // 1 - token replacement (see cde-core#CdfRunJsDashboardWriteContext.replaceTokens())
      // 2 - resources being called from other resources (ex: resource plugin-samples/template.css calls resource
      // images/button-contact-png)

      new ResourcesApi().getResource( pathParams.getStringParameter( MethodParams.COMMAND, "" ), getResponse() );

    } else {
      String result = renderer
          .render( "", "", filePath, inferScheme, root, absolute, bypassCacheRead, debug, viewId, style, getRequest() );
      getResponse().setContentType( MimeTypes.HTML );
View Full Code Here

TOP

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

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.