RepositoryResource extends AbstractJaxRSResource { @GET @Path ( "{pathId : .+}/default" ) @Produces ( { WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 303, condition = "Successfully get the resource." ), @ResponseCode ( code = 404, condition = "Failed to find the resource." ) } ) public Response doExecuteDefault( @PathParam ( "pathId" ) String pathId ) throws FileNotFoundException, MalformedURLException, URISyntaxException { String perspective = null; StringBuffer buffer = null; String url = null; String path = FileResource.idToPath( pathId ); if ( FileResource.getRepository().getFile( path ) == null ) { return Response.status( Status.NOT_FOUND ).build(); } String extension = path.substring( path.lastIndexOf( '.' ) + 1 ); IPluginManager pluginManager = PentahoSystem.get( IPluginManager.class, PentahoSessionHolder.getSession() ); IContentInfo info = pluginManager.getContentTypeInfo( extension ); for ( IPluginOperation operation : info.getOperations() ) { if ( operation.getId().equalsIgnoreCase( "RUN" ) ) { perspective = operation.getPerspective(); break; } } if ( perspective == null ) { perspective = GENERATED_CONTENT_PERSPECTIVE; } buffer = httpServletRequest.getRequestURL(); String queryString = httpServletRequest.getQueryString(); url = buffer.substring( 0, buffer.lastIndexOf( "/" ) + 1 ) + perspective + ( ( queryString != null && queryString.length() > 0 ) ? "?" + httpServletRequest.getQueryString() : "" ); return Response.seeOther( ( new URL( url ) ).toURI() ).build(); }  @GET @Path ( "{pathId : .+}/content" ) @Produces ( { WILDCARD } ) @Facet ( name = "Unsupported" ) Response doGetFileOrDir( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/default" ) @Produces ( { WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 303, condition = "Successfully get the resource." ), @ResponseCode ( code = 404, condition = "Failed to find the resource." ) } ) Response doExecuteDefault( @PathParam ( "pathId" ) String pathId ); @Path ( "/{contextId}/{resourceId : .+}" ) @POST @Consumes ( APPLICATION_FORM_URLENCODED ) @Produces ( { WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully get the resource." ), @ResponseCode ( code = 404, condition = "Failed to find the resource." ) } ) Response doFormPost( @PathParam ( "contextId" ) String contextId, @PathParam ( "resourceId" ) String resourceId,
                              final MultivaluedMap<String, String> formParams ); @Path ( "/{contextId}/{resourceId : .+}" ) @GET @Produces ( { WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully get the resource." ), @ResponseCode ( code = 404, condition = "Failed to find the resource." ) } ) Response doGet( @PathParam ( "contextId" ) String contextId, @PathParam ( "resourceId" ) String resourceId ); @Path ( "/executableTypes" ) @GET @Produces ( { APPLICATION_XML, APPLICATION_JSON } ) @Facet ( name = "Unsupported" ) Response getExecutableTypes(); RepositoryDownloadWhitelist getWhitelist(); void setWhitelist( RepositoryDownloadWhitelist whitelist ); static final String GENERATED_CONTENT_PERSPECTIVE; }
@Test public void doExecuteDefaultNotFound() throws Exception { doReturn( null ).when( repository ).getFile( "/home/admin/comments.wcdf" ); Response response = new RepositoryResource().doExecuteDefault( ":home:admin:comments.wcdf" ); assertEquals( Response.Status.NOT_FOUND.getStatusCode(), response.getStatus() ); }