public QueryResult<File> getFilesFromFolder(String folderStr, String studyStr, QueryOptions options, String sessionId) throws CatalogException { ParamUtils.checkObj(folderStr, "folder"); MyResource<File> resource = getUid(folderStr, studyStr, sessionId); options = ParamUtils.defaultObject(options, QueryOptions::new); if (!resource.getResource().getType().equals(File.Type.DIRECTORY)) { throw new CatalogDBException("File {path:'" + resource.getResource().getPath() + "'} is not a folder."); } Query query = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), resource.getResource().getPath()); return get(studyStr, query, options, sessionId); }
@Test public void readInheritedForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3_d4, null, externalSessionId); }
@Test public void readNonSharedFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data, null, externalSessionId); }
@Test public void readExplicitlyForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3, null, externalSessionId); }
@Test public void readExplicitlyUnsharedFile() throws CatalogException { QueryResult<File> file = catalogManager.getFileManager().get(studyFqn, data_d1, null, memberSessionId); assertEquals(1, file.getNumResults()); // Set an ACL with no permissions fileManager.updateAcl(studyFqn, Arrays.asList(data_d1), memberUser, new File.FileAclParams(null, AclParams.Action.SET, null), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data_d1, null, memberSessionId); }
@Test public void readExplicitlySharedFile() throws CatalogException { QueryResult<File> file = catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3_d4_txt, null, externalSessionId); assertEquals(1, file.getNumResults()); }
@Test public void readInheritedSharedFile() throws CatalogException { QueryResult<File> file = catalogManager.getFileManager().get(studyFqn, data_d1_d2, null, externalSessionId); assertEquals(1, file.getNumResults()); }
@Test public void readFileByOwner() throws CatalogException { QueryResult<File> file = catalogManager.getFileManager().get(studyFqn, data_d1, null, ownerSessionId); assertEquals(1, file.getNumResults()); }
@Test public void testIndexFromFolder() throws Exception { QueryOptions queryOptions = new QueryOptions(VariantStorageEngine.Options.ANNOTATE.key(), false) .append(VariantStorageEngine.Options.CALCULATE_STATS.key(), false); File file = getFile(0); Path pathParent = Paths.get(file.getPath()).getParent(); File parent = catalogManager.getFileManager().get(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), pathParent.toString() + "/"), null, sessionId).first(); indexFiles(singletonList(parent), singletonList(file), queryOptions, outputId); }
@Test public void testDeleteLeafFolder() throws CatalogException, IOException { File deletable = catalogManager.getFileManager().get(studyFqn2, "/data/test/folder/", QueryOptions.empty(), sessionIdUser).first(); deleteFolderAndCheck(deletable); }
@Test public void testSearchFileFail1() throws CatalogException { thrown.expect(CatalogDBException.class); catalogManager.getFileManager().get(studyFqn, new Query(FileDBAdaptor.QueryParams.NATTRIBUTES.key() + ".numValue", "==NotANumber"), null, sessionIdUser); }
public File getFile(long id) throws CatalogException { return catalogManager.getFileManager().get(String.valueOf(study.getFqn()), new Query(FileDBAdaptor.QueryParams.UID.key(), id) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), Status.DELETED + "," + File.FileStatus.TRASHED + "," + Status.READY) , null, sessionIdUser) .first(); }
@Test public void readFileForbiddenForUser() throws CatalogException { // Remove all permissions to the admin group in that folder catalogManager.getStudyManager().createGroup(studyFqn, groupMember, externalUser, ownerSessionId); catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), groupMember, new Study.StudyAclParams("", AclParams.Action.SET, "admin"), ownerSessionId); fileManager.updateAcl(studyFqn, Arrays.asList(data_d1_d2), externalUser, new File.FileAclParams(DENY_FILE_PERMISSIONS, AclParams.Action.SET, null), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data_d1_d2, null, externalSessionId); }
protected File create(String studyId, URI uri, String path) throws IOException, CatalogException { File file; file = fileMetadataReader.create(studyId, uri, path, "", true, null, sessionId).first(); // File.Format format = FormatDetector.detect(uri); // File.Bioformat bioformat = BioformatDetector.detect(uri); // file = catalogManager.createFile(studyId, format, bioformat, "data/vcfs/", "", true, -1, sessionId).first(); catalogFileUtils.upload(uri, file, null, sessionId, false, false, true, false, Long.MAX_VALUE); return catalogManager.getFileManager().get(studyId, file.getId(), null, sessionId).first(); }
@Test public void readFileNoStudyMember() throws CatalogException, IOException { String newUser = "newUser"; catalogManager.getUserManager().create(newUser, newUser, "asda@mail.com", password, "org", 1000L, Account.FULL, null, null); String sessionId = catalogManager.getUserManager().login(newUser, password); thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().get(studyFqn, data, null, sessionId); }
@Test public void testBySteps2() throws Exception { File transformFile = transformFile(inputFile2, new QueryOptions()); Assert.assertNull(catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getIndex().getStatus()); Assert.assertEquals(FileIndex.IndexStatus.TRANSFORMED, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getIndex().getStatus().getName()); loadFile(transformFile, new QueryOptions(), outputId); Assert.assertNull(catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getIndex().getStatus()); Assert.assertEquals(FileIndex.IndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getIndex().getStatus().getName()); } }
@Test public void testIndex1() throws Exception { indexFile(inputFile1, new QueryOptions(), outputId); Assert.assertEquals(FileIndex.IndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getIndex().getStatus().getName()); Assert.assertNull(catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getIndex().getStatus()); }
public File createFile(String studyId, String resourceName, String sessionId) throws IOException, CatalogException { File file; URI uri = getResourceUri(resourceName); CatalogManager catalogManager = getCatalogManager(); file = new FileMetadataReader(catalogManager).create(studyId, uri, "data/vcfs/", "", true, null, sessionId).first(); new FileUtils(catalogManager).upload(uri, file, null, sessionId, false, false, true, false, Long.MAX_VALUE); return catalogManager.getFileManager().get(studyId, file.getId(), null, sessionId).first(); }
@Test public void testDeleteRootFolder() throws CatalogException, IOException { File deletable = catalogManager.getFileManager().get(studyFqn2, "/", QueryOptions.empty(), sessionIdUser).first(); WriteResult result = catalogManager.getFileManager().delete(studyFqn2, new Query(FileDBAdaptor.QueryParams.PATH.key(), deletable.getPath()), null, sessionIdUser); assertEquals(1, result.getNumMatches()); assertEquals(0, result.getNumModified()); assertEquals("Root directories cannot be deleted", result.getFailed().get(0).getMessage()); }
@Test public void testIndexWithStatsLowerCaseAggregationType() throws Exception { QueryOptions queryOptions = new QueryOptions(VariantStorageEngine.Options.ANNOTATE.key(), false); queryOptions.put(VariantStorageEngine.Options.CALCULATE_STATS.key(), true); queryOptions.put(VariantStorageEngine.Options.AGGREGATED_TYPE.key(), "none"); queryOptions.putIfNotNull(StorageOperation.CATALOG_PATH, outputId); variantManager.index(studyId, getFile(0).getId(), newTmpOutdir(), queryOptions, sessionId); assertEquals(500, getDefaultCohort(studyId).getSamples().size()); assertEquals(Cohort.CohortStatus.READY, getDefaultCohort(studyId).getStatus().getName()); assertNotNull(catalogManager.getFileManager().get(studyId, getFile(0).getId(), null, sessionId).first().getStats().get(FileMetadataReader.VARIANT_FILE_STATS)); }