/** * Upload a file in Catalog. * * @param studyStr study where the file will be uploaded. * @param sourceUri URI of the file to be uploaded. * @param file File object containing at least the basic metadata necessary for a successful upload: path * @param overwrite Overwrite the current file if any. * @param parents boolean indicating whether unexisting parent folders should also be created automatically. * @param sessionId session id of the user performing the upload. * @return a QueryResult with the file uploaded. * @throws CatalogException if the user does not have permissions or any other unexpected issue happens. */ public QueryResult<File> upload(String studyStr, URI sourceUri, File file, boolean overwrite, boolean parents, String sessionId) throws CatalogException { ParamUtils.checkObj(sourceUri, "source uri"); return upload(studyStr, sourceUri, file, overwrite, parents, true, true, sessionId); }
/** * Upload a file in Catalog. * * @param studyStr study where the file will be uploaded. * @param fileInputStream Input stream of the file to be uploaded. * @param file File object containing at least the basic metadata necessary for a successful upload: path * @param overwrite Overwrite the current file if any. * @param parents boolean indicating whether unexisting parent folders should also be created automatically. * @param sessionId session id of the user performing the upload. * @return a QueryResult with the file uploaded. * @throws CatalogException if the user does not have permissions or any other unexpected issue happens. */ public QueryResult<File> upload(String studyStr, InputStream fileInputStream, File file, boolean overwrite, boolean parents, String sessionId) throws CatalogException { ParamUtils.checkObj(fileInputStream, "file input stream"); return upload(studyStr, null, fileInputStream, file, overwrite, parents, true, true, sessionId); }
/** * Upload a file in Catalog. * * @param studyStr study where the file will be uploaded. * @param sourceUri URI of the file to be uploaded. * @param file File object containing at least the basic metadata necessary for a successful upload: path * @param overwrite Overwrite the current file if any. * @param parents boolean indicating whether unexisting parent folders should also be created automatically. * @param deleteSource After moving, delete file. If false, force copy. * @param calculateChecksum Calculate checksum * @param sessionId session id of the user performing the upload. * @return a QueryResult with the file uploaded. * @throws CatalogException if the user does not have permissions or any other unexpected issue happens. */ public QueryResult<File> upload(String studyStr, URI sourceUri, File file, boolean overwrite, boolean parents, boolean calculateChecksum, boolean deleteSource, String sessionId) throws CatalogException { ParamUtils.checkObj(sourceUri, "source uri"); return upload(studyStr, sourceUri, null, file, overwrite, parents, calculateChecksum, deleteSource, sessionId); }
public static void insertPedigreeFile(CatalogManager catalogManager, Path inputFile, String sessionId) throws CatalogException, FileNotFoundException { String path = "data/peds"; URI sourceUri = inputFile.toUri(); File file = catalogManager.getFileManager().upload("user1@default:study1", new FileInputStream(new java.io.File(sourceUri)), new File().setPath(Paths.get(path, inputFile.getFileName().toString()).toString()), false, true, sessionId).first(); // Load samples using the pedigree file CatalogSampleAnnotationsLoader catalogSampleAnnotationsLoader = new CatalogSampleAnnotationsLoader(catalogManager); catalogSampleAnnotationsLoader.loadSampleAnnotations(file, null, sessionId); } //
start = System.currentTimeMillis(); file = catalogManager.getFileManager().upload(study.getFqn(), uri, new File().setPath(filePath), overwrite, true, calculateChecksum, deleteSource, sessionId).first(); .upload(study.getFqn(), uri, file, overwrite, true, calculateChecksum, deleteSource, sessionId).first();
@Test public void testDeleteExisting() throws IOException, CatalogException { QueryResult<File> queryResult = catalogManager.getFileManager().upload(study.getFqn(), CatalogManagerTest.createDebugFile().toURI(), new File().setPath(folder.getPath() + "file1.txt"), false, false, sessionIdUser); File file = queryResult.first(); CatalogManagerTest.createDebugFile(directory.resolve("file1.txt").toString()); List<File> files = new FileScanner(catalogManager).scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.DELETE, false, true, sessionIdUser); files.forEach((File f) -> assertFalse(f.getAttributes().containsKey("checksum"))); assertEquals(File.FileStatus.DELETED, getFile(file.getUid()).getStatus().getName()); }
@Test public void testGetMetadataFromVcf() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), vcfFileUri, new File().setPath(folder.getPath() + VCF_FILE_NAME), false, false, sessionIdUser).first(); assertTrue(file.getSize() > 0); file = FileMetadataReader.get(catalogManager). setMetadataInformation(file, null, null, sessionIdUser, false); assertEquals(File.FileStatus.READY, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertEquals(4, file.getSamples().size()); assertEquals(expectedSampleNames, ((Map<String, Object>) file.getAttributes().get(VARIANT_FILE_METADATA)).get("sampleIds")); catalogManager.getSampleManager().get(study.getFqn(), new Query(SampleDBAdaptor.QueryParams.ID.key(), file.getSamples().stream().map(Sample::getId).collect(Collectors.toList())), new QueryOptions(), sessionIdUser).getResult(); assertTrue(expectedSampleNames.containsAll(file.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()))); }
@Test public void testReplaceExisting() throws IOException, CatalogException { // Create and register file1.txt and s/file2.txt File file = catalogManager.getFileManager().upload(study.getFqn(), CatalogManagerTest.createDebugFile().toURI(), new File().setPath(folder.getPath() + "file1.txt"), false, false, true, true, sessionIdUser).first(); catalogManager.getFileManager().upload(study.getFqn(), CatalogManagerTest.createDebugFile().toURI(), new File().setPath(folder.getPath() + "s/file2.txt"), false, true, true, true, sessionIdUser).first(); // Create same file structure, and replace CatalogManagerTest.createDebugFile(directory.resolve("file1.txt").toString()); Files.createDirectory(directory.resolve("s/")); CatalogManagerTest.createDebugFile(directory.resolve("s/file2.txt").toString()); FileScanner fileScanner = new FileScanner(catalogManager); fileScanner.scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); File replacedFile = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(File.FileStatus.READY, replacedFile.getStatus().getName()); assertEquals(file.getUid(), replacedFile.getUid()); assertNotEquals(replacedFile.getChecksum(), file.getChecksum()); assertEquals(replacedFile.getChecksum(), catalogManager.getCatalogIOManagerFactory().getDefault().calculateChecksum(replacedFile.getUri())); }
catalogManager.getFileManager().upload(studyFqn, fileTest.toURI(), new File().setPath("data/deletable/folder/" + fileName), false, true, sessionIdUser); QueryResult<File> fileQueryResult = catalogManager.getFileManager().upload(studyFqn2, fileTest.toURI(), new File().setPath("data/deletable/" + fileName), false, true, false, false, sessionIdUser); assertTrue(fileTest.delete()); fileQueryResult = catalogManager.getFileManager().upload(studyFqn2, fileTest.toURI(), new File().setPath(fileName).setDescription("file at root"), false, true, false, false, sessionIdUser); assertEquals(1, fileQueryResult.getNumResults()); fileTest = createDebugFile(); long size = Files.size(fileTest.toPath()); catalogManager.getFileManager().upload(studyFqn2, fileTest.toURI(), new File().setPath(fileName).setDescription("file at root"), false, true, sessionIdUser);
@Test public void testGetMetadataFromBam() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), bamFileUri, new File().setPath(folder.getPath() + BAM_FILE_NAME), false, false, sessionIdUser).first(); assertTrue(file.getSize() > 0); file = FileMetadataReader.get(catalogManager). setMetadataInformation(file, null, null, sessionIdUser, false); assertEquals(File.FileStatus.READY, file.getStatus().getName()); // assertEquals(File.Format.GZIP, file.getFormat()); assertEquals(File.Bioformat.ALIGNMENT, file.getBioformat()); assertNotNull(file.getAttributes().get("alignmentHeader")); assertEquals(1, file.getSamples().size()); assertEquals("HG00096", catalogManager.getSampleManager().get(study.getFqn(), file.getSamples().get(0).getId(), null, sessionIdUser).first().getId()); }
@Test public void testDoNotOverwriteSampleIds() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), vcfFileUri, new File().setPath(folder.getPath() + VCF_FILE_NAME), false, false, sessionIdUser).first(); assertEquals(File.FileStatus.READY, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertEquals(4, file.getSamples().size()); //Add a sampleId String sampleId = catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId("Bad_Sample"), null, sessionIdUser) .first().getId(); catalogManager.getFileManager().update(study.getFqn(), file.getPath(), new ObjectMap(FileDBAdaptor.QueryParams.SAMPLES.key(), Collections.singletonList(sampleId)), new QueryOptions(), sessionIdUser); file = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(5, file.getSamples().size()); assertEquals(sampleId, file.getSamples().get(4).getId()); }
@Test public void testDeleteTrashed() throws IOException, CatalogException { QueryResult<File> queryResult = catalogManager.getFileManager().upload(study.getFqn(), CatalogManagerTest.createDebugFile().toURI(), new File().setPath(folder.getPath() + "file1.txt"), false, false, sessionIdUser); File file = queryResult.first(); catalogManager.getFileManager().delete(study.getFqn(), new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), new QueryOptions(), sessionIdUser); QueryResult<File> fileQueryResult = catalogManager.getFileManager().get(study.getFqn(), new Query() .append(FileDBAdaptor.QueryParams.UID.key(), file.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), "!=EMPTY"), new QueryOptions(), sessionIdUser); file = fileQueryResult.first(); assertEquals(File.FileStatus.TRASHED, file.getStatus().getName()); }