RepositoryPublishResource { @POST @Path ( "/publishfile" ) @Consumes ( { MediaType.MULTIPART_FORM_DATA } ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully publish the artifact." ), @ResponseCode ( code = 403, condition = "Failure to publish the file due to permissions." ), @ResponseCode ( code = 500, condition = "Failure to publish the file due to a server error." ), } ) @Facet( name = "Unsupported" ) public Response writeFile( @FormDataParam ( "importPath" ) String pathId, @FormDataParam ( "fileUpload" ) InputStream fileContents, @FormDataParam ( "overwriteFile" ) Boolean overwriteFile, @FormDataParam ( "fileUpload" ) FormDataContentDisposition fileInfo ) { try { repositoryPublishService.writeFile( pathId, fileContents, overwriteFile ); return buildPlainTextOkResponse( "SUCCESS" ); } catch ( PentahoAccessControlException e ) { return buildStatusResponse( UNAUTHORIZED, PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL ); } catch ( PlatformImportException e ) { logger.error( e ); return buildStatusResponse( PRECONDITION_FAILED, e.getErrorStatus() ); } catch ( Exception e ) { logger.error( e ); return buildServerErrorResponse( PlatformImportException.PUBLISH_GENERAL_ERROR ); } } RepositoryPublishResource(); @POST @Path ( "/publishfile" ) @Consumes ( { MediaType.MULTIPART_FORM_DATA } ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully publish the artifact." ), @ResponseCode ( code = 403, condition = "Failure to publish the file due to permissions." ), @ResponseCode ( code = 500, condition = "Failure to publish the file due to a server error." ), } ) @Facet( name = "Unsupported" ) Response writeFile( @FormDataParam ( "importPath" ) String pathId,
                             @FormDataParam ( "fileUpload" ) InputStream fileContents,
                             @FormDataParam ( "overwriteFile" ) Boolean overwriteFile,
                             @FormDataParam ( "fileUpload" ) FormDataContentDisposition fileInfo ); @POST @Path ( "/file" ) @Consumes ( { MediaType.MULTIPART_FORM_DATA } ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully publish the file." ), @ResponseCode ( code = 403, condition = "Failure to publish the file due to permissions." ), @ResponseCode ( code = 422, condition = "Failure to publish the file due to failed validation." ), @ResponseCode ( code = 500, condition = "Failure to publish the file due to a server error." ), } ) @Facet( name = "Unsupported" ) Response writeFileWithEncodedName( @FormDataParam( "importPath" ) String pathId,
                                            @FormDataParam( "fileUpload" ) InputStream fileContents,
                                            @FormDataParam( "overwriteFile" ) Boolean overwriteFile,
                                            @FormDataParam( "fileUpload" ) FormDataContentDisposition fileInfo ); @POST @Path ( "/fileWithOptions" ) @Consumes ( { MediaType.MULTIPART_FORM_DATA } ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully publish the file." ), @ResponseCode ( code = 403, condition = "Failure to publish the file due to permissions." ), @ResponseCode ( code = 422, condition = "Failure to publish the file due to failed validation." ), @ResponseCode ( code = 500, condition = "Failure to publish the file due to a server error." ), } ) @Facet( name = "Unsupported" ) Response writeFileWithEncodedNameWithOptions( @FormDataParam( "properties" ) String properties,
                                                       @FormDataParam( "importPath" ) String pathId,
                                                       @FormDataParam( "fileUpload" ) InputStream fileContents,
                                                       @FormDataParam( "fileUpload" ) FormDataContentDisposition fileInfo );  }
@Test public void testWriteFile() throws Exception { String pathId = "pathId"; InputStream fileContents = emptyStream(); FormDataContentDisposition mockFormDataContentDisposition = mock( FormDataContentDisposition.class ); doNothing().when( repositoryPublishResource.repositoryPublishService ).writeFile( pathId, fileContents, true ); String okResponseText = "SUCCESS"; Response testResponse = repositoryPublishResource.writeFile( pathId, fileContents, true, mockFormDataContentDisposition ); assertResponse( testResponse, OK, okResponseText ); verify( repositoryPublishResource.repositoryPublishService, times( 1 ) ).writeFile( pathId, fileContents, true ); verify( repositoryPublishResource, times( 1 ) ).buildPlainTextOkResponse( okResponseText ); }