Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this file,
   * You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  package pt.webdetails.cda;
  
 import java.util.*;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static javax.ws.rs.core.MediaType.APPLICATION_XML;
 import static javax.ws.rs.core.MediaType.WILDCARD;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
 
 
 import  javax.ws.rs.Consumes;
 import  javax.ws.rs.GET;
 import  javax.ws.rs.POST;
 import  javax.ws.rs.Path;
 import  javax.ws.rs.Produces;
 import  javax.ws.rs.DefaultValue;
 import  javax.ws.rs.QueryParam;
 import  javax.ws.rs.FormParam;
 import  javax.ws.rs.core.Context;
 import  javax.servlet.http.HttpServletResponse;
 import  javax.servlet.http.HttpServletRequest;
 import  javax.ws.rs.core.MultivaluedMap;
 
 
 import  org.apache.commons.io.IOUtils;
 import  org.apache.commons.logging.Log;
 import  org.apache.commons.logging.LogFactory;
 import  org.pentaho.platform.engine.core.system.PentahoSystem;
 import  org.apache.commons.lang.StringUtils;
 
 import  pt.webdetails.cpf.repository.RepositoryAccess;
 import  pt.webdetails.cpf.repository.RepositoryAccess.FileAccess;
 
 import  org.pentaho.platform.api.engine.IPentahoSession;
 import  org.pentaho.platform.api.engine.IPluginResourceLoader;
 import  org.pentaho.platform.api.engine.IPluginManager;
 
 import  org.hibernate.Session;
 import  org.pentaho.platform.engine.core.system.PentahoSessionHolder;
 import  org.pentaho.platform.engine.security.SecurityHelper;
 import  org.pentaho.util.messages.LocaleHelper;
 
 
 @Path("/cda/api")
 public class CdaUtils {
   private static final Log logger = LogFactory.getLog(CdaUtils.class);
   private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
   
   public static final String PLUGIN_NAME = "cda";
   private static final long serialVersionUID = 1L;
   private static final String EDITOR_SOURCE = "/editor/editor.html";
   private static final String EXT_EDITOR_SOURCE = "/editor/editor-cde.html";
   private static final String PREVIEWER_SOURCE = "/previewer/previewer.html";
   private static final String CACHE_MANAGER_PATH = "/cachemanager/cache.html";
   private static final int DEFAULT_PAGE_SIZE = 20;
   private static final int DEFAULT_START_PAGE = 0;
   private static final String PREFIX_PARAMETER = "param";
   private static final String PREFIX_SETTING = "setting";
   public static final String ENCODING = "UTF-8";
   public static final String WRAP_QUERY_TRUE_VALUE = "wrapIt";
   public static final String LANGUAGE_CODE_TOKEN = "LANGUAGE_CODE"//i18n
   
   
   public CdaUtils() {
 
   }
   
   protected static String getEncoding() { return ; }
   
   @POST
   @Path( "/doQuery" )
   @Consumes( { APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED } )
   public void doQueryPost( @FormParam( "path" ) String path,
       @DefaultValue( "json" ) @FormParam( "outputType" ) String outputType,
       @DefaultValue( "1" ) @FormParam( "outputIndexId" ) int outputIndexId,
       @DefaultValue( "1" ) @FormParam( "dataAccessId" ) String dataAccessId,
       @DefaultValue( "false" ) @FormParam( "bypassCache" ) Boolean bypassCache,
      @DefaultValue( "false" ) @FormParam( "paginateQuery" ) Boolean paginateQuery,
      @DefaultValue( "0" ) @FormParam( "pageSize" ) int pageSize,
      @DefaultValue( "0" ) @FormParam( "pageStart" ) int pageStart,
      @DefaultValue( "" ) @FormParam( "wrapItUp" ) String wrapItUp, @FormParam( "sortBy" ) List<StringsortBy,
      MultivaluedMap<StringStringformParams, @Context HttpServletResponse servletResponse ) throws Exception {
    HashMap<StringObjectparams = new HashMap<StringObject>();
    for ( Map.Entry<StringList<String>> pair : formParams.entrySet() ) {
      ifpair.getValue().size() == 1) {
        params.putpair.getKey(), pair.getValue().get(0) ); //assigns the value
      } else {
        params.putpair.getKey(), pair.getValue().toArray() ); //assigns the array
      }
    }
    
    boolean wrapIt = .equalsIgnoreCase(wrapItUp);
    handleDoQuerypathoutputTypeoutputIndexIddataAccessIdbypassCachepaginateQuerypageSizepageStart,
        wrapItsortByparamsservletResponse );
  }
  
  @GET
  @Path( "/doQuery" )
  @Consumes( { APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED } )
  public void doQueryGet( @QueryParam( "path" ) String path,
      @DefaultValue( "json" ) @QueryParam( "outputType" ) String outputType,
      @DefaultValue( "1" ) @QueryParam( "outputIndexId" ) int outputIndexId,
      @DefaultValue( "1" ) @QueryParam( "dataAccessId" ) String dataAccessId,
      @DefaultValue( "false" ) @QueryParam( "bypassCache" ) Boolean bypassCache,
      @DefaultValue( "false" ) @QueryParam( "paginateQuery" ) Boolean paginateQuery,
      @DefaultValue( "0" ) @QueryParam( "pageSize" ) int pageSize,
      @DefaultValue( "0" ) @QueryParam( "pageStart" ) int pageStart,
      @DefaultValue( "" ) @QueryParam( "wrapItUp" ) String wrapItUp, @QueryParam( "sortBy" ) List<StringsortBy,
      @Context HttpServletResponse servletResponse, @Context HttpServletRequest servletRequest ) throws Exception {
    HashMap<StringObjectparams = new HashMap<StringObject>();
    final Enumeration enumeration = servletRequest.getParameterNames();
    while ( enumeration.hasMoreElements() ) {
      final String param = (Stringenumeration.nextElement();
      final String[] values = servletRequest.getParameterValues( param );
      if ( values.length == 1 ) {
        params.putparamvalues[0] ); //assigns the value
      } else {
        params.putparamvalues ); //assigns the array
      }
    }
    boolean wrapIt = .equalsIgnoreCase(wrapItUp);
    
    handleDoQuerypathoutputTypeoutputIndexIddataAccessIdbypassCachepaginateQuerypageSizepageStart,
        wrapItsortByparamsservletResponse );
  }
  private void handleDoQueryString pathString outputTypeint outputIndexIdString dataAccessId,
      Boolean bypassCacheBoolean paginateQueryint pageSizeint pageStartBoolean wrapItUpList<StringsortBy,
      HashMap<StringObjectparams, HttpServletResponse servletResponse ) throws Exception {
    final CdaEngine engine = CdaEngine.getInstance();
    final QueryOptions queryOptions = new QueryOptions();
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFilepath );
    // Handle paging options
    // We assume that any paging options found mean that the user actively wants paging.
    if ( pageSize > 0 || pageStart > 0 || paginateQuery ) {
      if ( pageSize > . || pageStart > . ) {
        throw new ArithmeticException"Paging values too large" );
      }
      queryOptions.setPaginatetrue );
      queryOptions.setPageSizepageSize > 0 ? (intpageSize : paginateQuery ?  : 0 );
      queryOptions.setPageStartpageStart > 0 ? (intpageStart : paginateQuery ?  : 0 );
    }
    // Support for bypassCache (we'll maintain the name we use in CDE
    queryOptions.setCacheBypassbypassCache );
    // Handle the query itself and its output format...
    queryOptions.setOutputTypeoutputType );
    queryOptions.setDataAccessIddataAccessId );
    try {
      queryOptions.setOutputIndexIdoutputIndexId );
    } catch ( NumberFormatException e ) {
      .error( "Illegal outputIndexId '" + outputIndexId + "'" );
    }
    final ArrayList<Stringsort = new ArrayList<String>();
    for ( String string : sortBy ) {
      if ( !( (Stringstring ).equals"" ) ) {
        sort.add( (Stringstring );
      }
    }
    queryOptions.setSortBysort );
    // ... and the query parameters
    // We identify any pathParams starting with "param" as query parameters
    forMap.Entry<StringObjectpair : params.entrySet() ) {
      String param = pair.getKey();
      if ( param.startsWith ) ) {
        queryOptions.addParameterparam.substring.length() ), pair.getValue() );
      } else if ( param.startsWith ) ) {
        String value = (Stringpair.getValue();
        if ( value == null ) {
          value = "";
        }
        queryOptions.addSettingparam.substring.length() ), value );
      }
    }
    if ( wrapItUp ) {
      String uuid = engine.wrapQueryservletResponse.getOutputStream(), cdaSettingsqueryOptions );
      .debug( "doQuery: query wrapped as " + uuid );
      writeOutservletResponse.getOutputStream(), uuid );
      return;
    }
    Exporter exporter =
        ExporterEngine.getInstance().getExporterqueryOptions.getOutputType(), queryOptions.getExtraSettings() );
    String attachmentName = exporter.getAttachmentName();
    String mimeType = mimeType = exporter.getMimeType();
    if ( mimeType != null ) {
      servletResponse.setHeader( "Content-Type"mimeType );
    }
    if ( attachmentName != null ) {
      servletResponse.setHeader( "content-disposition""attachment; filename=" + attachmentName );
    }
    // Finally, pass the query to the engine
    engine.doQueryservletResponse.getOutputStream(), cdaSettingsqueryOptions );
  }
  
  @GET
  @Path("/unwrapQuery")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void unwrapQuery(@QueryParam("path"String path
                          @QueryParam("solution"String solution
                          @QueryParam("file"String file,
                          @QueryParam("uuid"String uuid,
                          @Context HttpServletResponse servletResponse
                          @Context HttpServletRequest servletRequestthrows Exception
  {
    final CdaEngine engine = CdaEngine.getInstance();
    //final String filePath = getRelativePath(path, solution, file);
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFile(path);
    QueryOptions queryOptions = engine.unwrapQuery(uuid);
    if(queryOptions != null) {
      Exporter exporter = ExporterEngine.getInstance().getExporter(queryOptions.getOutputType(), queryOptions.getExtraSettings());
      
      String attachmentName = exporter.getAttachmentName();
      String mimeType = mimeType = exporter.getMimeType();
      
      if(mimeType != null){
        servletResponse.setHeader("Content-Type"mimeType);
      }
    
      if(attachmentName != null){
        servletResponse.setHeader("content-disposition""attachment; filename=" + attachmentName);
      }
        
      engine.doQuery(servletResponse.getOutputStream(), cdaSettingsqueryOptions);
    }
    else {
      .error("unwrapQuery: uuid " + uuid + " not found.");
    }
    
  }
  
  @GET
  @Path("/listQueries")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED })
  public void listQueries(@QueryParam("path"String path
                          @QueryParam("solution"String solution
                          @QueryParam("file"String file,
                          @DefaultValue("json") @QueryParam("outputType"String outputType
                          
                          @Context HttpServletResponse servletResponse
                          @Context HttpServletRequest servletRequestthrows Exception
  {
    final CdaEngine engine = CdaEngine.getInstance();
    //final String filePath = getRelativePath(path, solution, file);
    if(StringUtils.isEmpty(path)){
      throw new IllegalArgumentException("No path provided");
    }
    .debug("Do Query: getSolPath:" + PentahoSystem.getApplicationContext().getSolutionPath(path));
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFile(path);
    // Handle the query itself and its output format...
    final DiscoveryOptions discoveryOptions = new DiscoveryOptions();
    discoveryOptions.setOutputType(outputType);
    String mimeType = ExporterEngine.getInstance().getExporter(discoveryOptions.getOutputType()).getMimeType();
    if(mimeType != null) {
      servletResponse.setHeader("Content-Type"mimeType);
    }
      
    engine.listQueries(servletResponse.getOutputStream(), cdaSettingsdiscoveryOptions);
  }
  
  
  @GET
  @Path("/listParameters")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED })
  public void listParameters(@QueryParam("path"String path
                             @QueryParam("solution"String solution
                              @QueryParam("file"String file,
                              @DefaultValue("json") @QueryParam("outputType"String outputType
                              @DefaultValue("<blank>") @QueryParam("dataAccessId"String dataAccessId
                            
                              @Context HttpServletResponse servletResponse
                              @Context HttpServletRequest servletRequestthrows Exception
  {
    final CdaEngine engine = CdaEngine.getInstance();
    //final String filePath = getRelativePath(path, solution, file);
    .debug("Do Query: getSolPath:" + path);
    final CdaSettings cdaSettings = SettingsManager.getInstance().parseSettingsFile(path);
    // Handle the query itself and its output format...
    final DiscoveryOptions discoveryOptions = new DiscoveryOptions();
    discoveryOptions.setOutputType(outputType);
    discoveryOptions.setDataAccessId(dataAccessId);
    String mimeType = ExporterEngine.getInstance().getExporter(discoveryOptions.getOutputType()).getMimeType();
    if(mimeType != null)
    {
      servletResponse.setHeader("Content-Type"mimeType);
    }
    engine.listParameters(servletResponse.getOutputStream(), cdaSettingsdiscoveryOptions);
  }
  
  
  @GET
  @Path("/getCdaFile")
  @Produces("text/xml")
  @Consumes({ WILDCARD })
  public void getCdaFile(@QueryParam("path"String path
                         @QueryParam("solution"String solution
                         @QueryParam("file"String file,
                            
                         @Context HttpServletResponse servletResponse
                         @Context HttpServletRequest servletRequestthrows Exception
  {
    String document = RepositoryAccess.getRepository().getResourceAsString(StringUtils.replace(path"///""/"), FileAccess.READ);
    writeOut(servletResponse.getOutputStream(), document);
  }
  
  
  @POST
  @Path("/writeCdaFile")
  @Produces("text/plain")
  @Consumes({ WILDCARD })
  public void writeCdaFile(@FormParam("path"String path
                          @FormParam("solution"String solution
                          @FormParam("file"String file,
                          @FormParam("data"String data,
                            
                           @Context HttpServletResponse servletResponse
                           @Context HttpServletRequest servletRequestthrows Exception
  {  
    //TODO: Validate the filename in some way, shape or form!
    RepositoryAccess repository = RepositoryAccess.getRepository(getPentahoSession());
    // Check if the file exists and we have permissions to write to it
    
    if(data == null){
      data = repository.getResourceAsString(path, FileAccess.READ);
      
      //writeOut(servletResponse.getOutputStream(), "Save unsuccessful!");
      //logger.error("writeCdaFile: no data to save provided " + path);
      //return;
    }
    //if (repository.canWrite(path))
    //{ 
      switch(repository.publishFile(pathdata.getBytes(), true)){
        case OK:
          SettingsManager.getInstance().clearCache();
          writeOut(servletResponse.getOutputStream(), "File saved.");
          break;
        case FAIL:
          writeOut(servletResponse.getOutputStream(), "Save unsuccessful!");
          .error("writeCdaFile: saving " + path);
          break;
      }
    //}
    //else
    //{
    //  throw new AccessDeniedException(path, null);
    //}
  }
  
  @GET
  @Path("/getCdaList")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void getCdaList(@QueryParam("path"String path
                         @QueryParam("solution"String solution
                         @QueryParam("file"String file,
                         @DefaultValue("json") @QueryParam("outputType"String outputType
                            
                         @Context HttpServletResponse servletResponse
                         @Context HttpServletRequest servletRequestthrows Exception
  {
    final CdaEngine engine = CdaEngine.getInstance();
    final DiscoveryOptions discoveryOptions = new DiscoveryOptions();
    discoveryOptions.setOutputType(outputType);
    String mimeType = ExporterEngine.getInstance().getExporter(discoveryOptions.getOutputType()).getMimeType();
    if(mimeType != null){
      servletResponse.setHeader("Content-Type"mimeType);
    }
      
    engine.getCdaList(servletResponse.getOutputStream(), discoveryOptionsgetPentahoSession());
  }
  @GET
  @Path("/clearCache")
  @Produces("text/plain")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void clearCache(@Context HttpServletResponse servletResponse
                         @Context HttpServletRequest servletRequestthrows Exception
  {
    // Check if user is admin
    Boolean accessible = SecurityHelper.getInstance().isPentahoAdministrator(getPentahoSession());
    if(!accessible){
      String msg = "Method clearCache not exposed or user does not have required permissions."
      .error(msg);
      servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, msg);
    }
    
    SettingsManager.getInstance().clearCache();
    AbstractDataAccess.clearCache();
    servletResponse.getOutputStream().write("Cache cleared".getBytes());
  }
  
  @GET
  @Path("/cacheMonitor")
  @Produces("text/plain")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED })
  public void cacheMonitor(@Context HttpServletResponse servletResponse
                           @Context HttpServletRequest servletRequestthrows Exception{
    Boolean accessible = SecurityHelper.getInstance().isPentahoAdministrator(getPentahoSession());
    if(!accessible){
      String msg = "Method cacheMonitor not exposed or user does not have required permissions."
      .error(msg);
      servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, msg);
    }
   
    CacheMonitorHandler.getInstance().handleCall(servletRequestservletResponse);
  }
  
  
  @GET
  @Path("/editFile")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void editFile(@Context HttpServletResponse servletResponse
                       @Context HttpServletRequest servletRequestthrows Exception
  {
    RepositoryAccess repository = RepositoryAccess.getRepository(getPentahoSession());
    
    // Check if the file exists and we have permissions to write to it
    //String filePath = getRelativePath(path, solution, file);
    //if (repository.canWrite(filePath))
    //{
      IPluginResourceLoader pluginResourceLoader = PentahoSystem.get(IPluginResourceLoader.class);
      IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
      final String editorPath;
      
      if(pluginManager.isBeanRegistered("wcdf")){
        editorPath = ;
      } else {
        editorPath = ;
      }
    
      ClassLoader classLoader = pluginManager.getClassLoader();
      InputStream inputStream = pluginResourceLoader.getResourceAsStream(classLoadereditorPath);
      
      StringWriter writer = new StringWriter();
      IOUtils.copy(inputStreamwriter);
      
      writeOut(servletResponse.getOutputStream(), writer.toString());
    //}
    /*else
    {
      servletResponse.setHeader("Content-Type", "text/plain");
      
      servletResponse.getOutputStream().write("Access Denied".getBytes());
      servletResponse.getOutputStream().flush();
    }*/
  }
  @GET
  @Path("/previewQuery")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void previewQuery(@Context HttpServletResponse servletResponse
                           @Context HttpServletRequest servletRequestthrows Exception
  {
    IPluginResourceLoader pluginResourceLoader = PentahoSystem.get(IPluginResourceLoader.class);
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    ClassLoader classLoader = pluginManager.getClassLoader();
    
    
    final String previewerPath = ;
    InputStream inputStream = pluginResourceLoader.getResourceAsStream(classLoaderpreviewerPath);
    
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStreamwriter);
    
    String result = ( writer == null || writer.toString() == null ) ? "" : writer.toString();
    
    // i18n token replacement
    ifresult.contains ) ){ 
    	result = result.replaceAll"#\\{" + "\\}", LocaleHelper.getLocale().getLanguage() ); 
    }
    
    writeOut(servletResponse.getOutputStream(), result);
  }
  @GET
  @Path("/getCssResource")
  @Produces("text/css")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void getCssResource(@QueryParam("resource"String resource,
          
                             @Context HttpServletResponse servletResponse
                             @Context HttpServletRequest servletRequestthrows Exception
  {
    RepositoryAccess repository = RepositoryAccess.getRepository(getPentahoSession());
    InputStream in = repository.getResourceInputStream(resource, FileAccess.READ);
    
    StringWriter writer = new StringWriter();
    IOUtils.copy(inwriter);
    
    writeOut(servletResponse.getOutputStream(), writer.toString());
  }
  @GET
  @Path("/getJsResource")
  @Produces("text/javascript")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void getJsResource(@QueryParam("resource"String resource,
          
                            @Context HttpServletResponse servletResponse
                            @Context HttpServletRequest servletRequestthrows Exception
  {
    RepositoryAccess repository = RepositoryAccess.getRepository(getPentahoSession());
    InputStream in = repository.getResourceInputStream(resource, FileAccess.READ);
    
    StringWriter writer = new StringWriter();
    IOUtils.copy(inwriter);
    
    writeOut(servletResponse.getOutputStream(), writer.toString());
  }
  
  @GET
  @Path("/listDataAccessTypes")
  @Produces("application/json")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void listDataAccessTypes(@DefaultValue("false") @QueryParam("refreshCache"Boolean refreshCache,
          
                                  @Context HttpServletResponse servletResponse
                                  @Context HttpServletRequest servletRequestthrows Exception
  {
    DataAccessConnectionDescriptor[] data = SettingsManager.getInstance().getDataAccessDescriptors(refreshCache);
    StringBuilder output = new StringBuilder("");
    if (data != null)
    {
      output.append("{\n");
      for (DataAccessConnectionDescriptor datum : data)
      {
        output.append(datum.toJSON() + ",\n");
      }
      writeOut(servletResponse.getOutputStream(), output.toString().replaceAll(",\n\\z""\n}"));
    }
  }
  @GET
  @Path("/cacheController")
  @Produces("text/plain")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON, APPLICATION_FORM_URLENCODED })
  public void cacheController(@QueryParam("method"String method,
                              @QueryParam("object"String object,
                              @QueryParam("id"String id,
  
                              @Context HttpServletResponse servletResponse
                              @Context HttpServletRequest servletRequest)
  {
    if(!method.isEmpty() && method != null){
      CacheScheduleManager cacheScheduleManager = CacheScheduleManager.getInstance();
      
      String upperCaseMethod = method.toUpperCase();
      
      try {
        if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.change(objectservletResponse.getOutputStream());
        } else if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.load(idservletResponse.getOutputStream());
        } else if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.list(servletResponse.getOutputStream());
        } else if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.execute(idservletResponse.getOutputStream());
        } else if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.delete(id);
        } else if(CacheScheduleManager.functions.valueOf(upperCaseMethod) == ..){
          cacheScheduleManager.importQueries(objectservletResponse.getOutputStream());
        } else {
          .error("Method called to cache controller is unknown");
        }
      } catch(Exception ex){
        .error("Error while calling CacheScheduleManager method "+methodex);
      }
      
    } else {
      .error("Method called to cache controller is empty");
    }
    
    
  }
  @GET
  @Path("/manageCache")
  @Produces("text/plain")
  @Consumes({ APPLICATION_XML, APPLICATION_JSON })
  public void manageCache(@Context HttpServletResponse servletResponse
                          @Context HttpServletRequest servletRequestthrows Exception
  {
    // Check if user is admin
    Boolean accessible = SecurityHelper.getInstance().isPentahoAdministrator(getPentahoSession());
    if(!accessible){
      String msg = "Method manageCache not exposed or user does not have required permissions."
      .error(msg);
      servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, msg);
    }
    
    IPluginResourceLoader pluginResourceLoader = PentahoSystem.get(IPluginResourceLoader.class);
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    ClassLoader classLoader = pluginManager.getClassLoader();
    
    final String cacheManagerPath = ;
    InputStream inputStream = pluginResourceLoader.getResourceAsStream(classLoadercacheManagerPath);
    
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStreamwriter);
    writeOut(servletResponse.getOutputStream(), writer.toString());
  }
  
  
  private synchronized Session getSession() throws PluginHibernateException {
    return PluginHibernateUtil.getSession();
  }
  
  private synchronized IPentahoSession getPentahoSession() {
    return PentahoSessionHolder.getSession();
  }
  
  private String getRelativePath(String solutionString pathString filethrows UnsupportedEncodingException
  {
    if (StringUtils.isEmpty(solution))
    {
      return path;
    }
    return StringUtils.join(new String[] {solutionpathfile}, "/" ).replaceAll("//""/");
  }
  
  protected void writeOut(OutputStream outString contentsthrows IOException {
      IOUtils.write(contentsoutgetEncoding());
      out.flush();
    }
New to GrepCode? Check out our FAQ X