public ProjectFileHandler getProjectFile ( final int projectId , final int version ) { log . info ( String . format ( "Fetching project file. project ID: %d version: %d" , projectId , version ) ) ; // TODO spyne: remove huge hack ! There should not be any special handling for Database Storage. if ( this . storage instanceof DatabaseStorage ) { return ( ( DatabaseStorage ) this . storage ) . get ( projectId , version ) ; } /* Fetch meta data from db */ final ProjectFileHandler pfh = this . projectLoader . fetchProjectMetaData ( projectId , version ) ; /* Fetch project file from storage and copy to local file */ final String resourceId = requireNonNull ( pfh . getResourceId ( ) , String . format ( "URI is null. project ID: %d version: %d" , pfh . getProjectId ( ) , pfh . getVersion ( ) ) ) ; try ( InputStream is = this . storage . get ( resourceId ) ) { final File file = createTempOutputFile ( pfh ) ; /* Copy from storage to output stream */ try ( FileOutputStream fos = new FileOutputStream ( file ) ) { IOUtils . copy ( is , fos ) ; } /* Validate checksum */ validateChecksum ( file , pfh ) ; /* Attach file to handler */ pfh . setLocalFile ( file ) ; return pfh ; } catch ( final IOException e ) { throw new StorageException ( e ) ; } }
Fetch project file from storage .