=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResource.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResource.java 2016-01-04 02:27:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/fileresource/FileResource.java 2016-03-01 11:31:05 +0000 @@ -180,6 +180,19 @@ return assigned; } + public void setAssigned( boolean assigned ) + { + this.assigned = assigned; + } + + @JsonProperty + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public FileResourceStorageStatus getStorageStatus() + { + return storageStatus; + } + public void setStorageStatus( FileResourceStorageStatus storageStatus ) { this.storageStatus = storageStatus; @@ -188,16 +201,6 @@ @JsonProperty @JsonView( { DetailedView.class, ExportView.class } ) @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public FileResourceStorageStatus getStorageStatus() - { - return storageStatus; - } - - public void setAssigned( boolean assigned ) - { - this.assigned = assigned; - } - public FileResourceDomain getDomain() { return domain; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileResourceController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileResourceController.java 2016-01-04 04:14:42 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileResourceController.java 2016-03-01 11:31:05 +0000 @@ -85,9 +85,9 @@ @Autowired private ServletContext servletContext; - // --------------------------------------------------------------------- + // ------------------------------------------------------------------------- // Controller methods - // --------------------------------------------------------------------- + // ------------------------------------------------------------------------- @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) public @ResponseBody FileResource getFileResource( @PathVariable String uid ) @@ -95,7 +95,8 @@ { FileResource fileResource = fileResourceService.getFileResource( uid ); - if ( fileResource == null ) { + if ( fileResource == null ) + { throw new WebMessageException( WebMessageUtils.notFound( FileResource.class, uid ) ); } @@ -118,21 +119,7 @@ throw new WebMessageException( WebMessageUtils.conflict( "Could not read file or file is empty." ) ); } - ByteSource bytes = new ByteSource() - { - @Override - public InputStream openStream() throws IOException - { - try - { - return file.getInputStream(); - } - catch ( IOException ioe ) - { - return new NullInputStream( 0 ); - } - } - }; + ByteSource bytes = new MultipartFileByteSource( file ); String contentMd5 = bytes.hash( Hashing.md5() ).toString(); @@ -155,10 +142,10 @@ return webMessage; } - - // --------------------------------------------------------------------- + + // ------------------------------------------------------------------------- // Supportive methods - // --------------------------------------------------------------------- + // ------------------------------------------------------------------------- private boolean isValidContentType( String contentType ) { @@ -184,4 +171,32 @@ return tmpFile; } + + // ------------------------------------------------------------------------- + // Inner classes + // ------------------------------------------------------------------------- + + private class MultipartFileByteSource + extends ByteSource + { + private MultipartFile file; + + public MultipartFileByteSource( MultipartFile file ) + { + this.file = file; + } + + @Override + public InputStream openStream() throws IOException + { + try + { + return file.getInputStream(); + } + catch ( IOException ioe ) + { + return new NullInputStream( 0 ); + } + } + } }