@Transactional public File get( User user, Long resourceSid ) throws IOException { MDOAlbumResource resource = this.daoAlbumResource.get( user.getLogin(), resourceSid ); if ( resource != null && resource instanceof MDOPhysicalResource ) { File f = new File( resource.calculateAbsolutePath( daoSettings.getSettings() ) ); if ( f.exists() ) { return f; } } throw new IOException( "Album resource not found!" ); } }
@Transactional public void remove( User user, Long resourceSid ) throws IOException { MDOAlbumResource resource = this.daoAlbumResource.get( user.getLogin(), resourceSid ); if ( resource != null ) { // first, removing the resource file String path = resource.calculateAbsolutePath( daoSettings.getSettings() ); File fpath = new File( path ); fpath.delete(); // after, removing the album data from database this.daoAlbumResource.remove( resource ); } }
public byte[] getAlbumResource( User mdouser, Long resourceSid ) throws SidNotFoundMessicException, ResourceNotFoundMessicException, IOException { MDOAlbumResource resource = daoAlbumResource.get( resourceSid ); if ( resource != null ) { String resourcePath = resource.calculateAbsolutePath( daoSettings.getSettings() ); File ftor = new File( resourcePath ); if ( ftor.exists() ) { return Util.readFile( resourcePath ); } else { throw new ResourceNotFoundMessicException( resourcePath ); } } else { throw new SidNotFoundMessicException(); } }