@Deprecated /** * Creates and links an external folder. * * @param studyId StudyId where to place the folder * @param filePath Path to create the folder * @param parents Make parent directories as needed * @param description Folder description * @param calculateChecksum Calculate checksum from the new linked file * @param externalUri External file to link * @param createFoundFiles Create a simple catalog file entry for found files. * @param relink Change the existing link of a file. * @param sessionId User's sessionId * @return Created folder * @throws CatalogException CatalogException */ public File linkFolder(long studyId, String filePath, boolean parents, String description, boolean calculateChecksum, URI externalUri, boolean createFoundFiles, boolean relink, String sessionId) throws CatalogException { ParamUtils.checkObj(externalUri, "externalUri"); File folder = catalogManager.getFileManager().createFolder(Long.toString(studyId), Paths.get(filePath).toString(), new File.FileStatus(File.FileStatus.STAGE), parents, description, null, sessionId).first(); checkCanLinkFile(folder, relink); return linkFolder(folder, calculateChecksum, externalUri, createFoundFiles, relink, sessionId); }
@Test public void createInheritedSharedFile() throws CatalogException { catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data/d1/d2/folder/").toString(), null, false, null, QueryOptions.empty(), externalSessionId); }
@Test public void createExplicitlySharedFile() throws CatalogException { catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data/d1/folder/").toString(), null, false, null, QueryOptions.empty(), externalSessionId); }
@Test public void createInheritedForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data/d1/d2/d3/d4/folder/").toString(), null, false, null, QueryOptions.empty(), externalSessionId); }
@Test public void createExplicitlyForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data/d1/d2/d3/folder/").toString(), null, false, null, QueryOptions.empty(), externalSessionId); }
@Test public void createNonSharedFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().createFolder(studyFqn, Paths.get("folder/").toString(), null, false, null, QueryOptions.empty(), externalSessionId); }
@Test public void createFileByOwnerNoGroups() throws CatalogException { QueryResult<File> folder = catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data/newFolder").toString(), null, true, null, QueryOptions.empty(), ownerSessionId); assertEquals(1, folder.getNumResults()); }
@Before public void setUp() throws IOException, CatalogException, URISyntaxException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/vcf/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); Path vcfPath = catalogManagerExternalResource.getOpencgaHome().resolve(VCF_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + VCF_FILE_NAME), vcfPath, StandardCopyOption.REPLACE_EXISTING); vcfFileUri = vcfPath.toUri(); Path bamPath = catalogManagerExternalResource.getOpencgaHome().resolve(BAM_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + BAM_FILE_NAME), bamPath, StandardCopyOption.REPLACE_EXISTING); bamFileUri = bamPath.toUri(); }
@Test public void assignPermissionsRecursively() throws Exception { Path folderPath = Paths.get("data", "new", "folder"); catalogManager.getFileManager().createFolder(studyFqn, folderPath.toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); Path filePath = Paths.get("data", "file1.txt"); fileManager.create(studyFqn, File.Type.FILE, File.Format.UNKNOWN, File.Bioformat.UNKNOWN, filePath.toString(), "", "", new File.FileStatus(), 10, -1, null, -1, null, null, true, "My content", null, sessionIdUser); List<QueryResult<FileAclEntry>> queryResults = fileManager.updateAcl(studyFqn, Arrays.asList("data/new/", filePath.toString()), "user2", new File.FileAclParams("VIEW", AclParams.Action.SET, null), sessionIdUser); assertEquals(3, queryResults.size()); for (QueryResult<FileAclEntry> queryResult : queryResults) { assertEquals("user2", queryResult.getResult().get(0).getMember()); assertEquals(1, queryResult.getResult().get(0).getPermissions().size()); assertEquals(FileAclEntry.FilePermissions.VIEW, queryResult.getResult().get(0).getPermissions().iterator().next()); } }
@Test public void createFileNoStudyMember() 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().createFolder(studyFqn, Paths.get("data/my_folder/").toString(), null, false, null, QueryOptions.empty(), sessionId); }
@Test public void testCreateFolderAlreadyExists() throws Exception { Set<String> paths = catalogManager.getFileManager().get(studyFqn3, new Query("type", File.Type.DIRECTORY), new QueryOptions(), sessionIdUser2).getResult().stream().map(File::getPath).collect(Collectors.toSet()); assertEquals(1, paths.size()); assertTrue(paths.contains("")); //root // assertTrue(paths.contains("data/")); //data // assertTrue(paths.contains("analysis/")); //analysis Path folderPath = Paths.get("data", "new", "folder"); File folder = catalogManager.getFileManager().createFolder(studyFqn3, folderPath.toString(), null, true, null, null, sessionIdUser2).first(); assertNotNull(folder); assertTrue(folder.getPath().contains(folderPath.toString())); // When creating the same folder, we should not complain and return it directly File sameFolder = catalogManager.getFileManager().createFolder(studyFqn3, folderPath.toString(), null, true, null, null, sessionIdUser2).first(); assertNotNull(sameFolder); assertEquals(folder.getPath(), sameFolder.getPath()); assertEquals(folder.getUid(), sameFolder.getUid()); // However, a user without create permissions will receive an exception thrown.expect(CatalogAuthorizationException.class); catalogManager.getFileManager().createFolder(studyFqn3, folderPath.toString(), null, true, null, null, sessionIdUser3); }
@Before public void setUp() throws IOException, CatalogException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/test/folder/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); directory = catalogManagerExternalResource.getOpencgaHome().resolve("catalog_scan_test_folder").toAbsolutePath(); if (directory.toFile().exists()) { IOUtils.deleteDirectory(directory); } Files.createDirectory(directory); }
File folder = catalogManager.getFileManager().createFolder(study.getFqn(), folderPath.toString(), null, true, null, QueryOptions.empty(), sessionIdUser2).first(); System.out.println(folder); assertTrue(!catalogManager.getCatalogIOManagerFactory().get(uri).exists(uri)); catalogManager.getFileManager().createFolder(study.getFqn(), Paths.get("WOLOLO").toString(), null, true, null, QueryOptions.empty(), sessionIdUser2); String newStudy = catalogManager.getStudyManager().create(project2, "alias", null, "name", Study.Type.CASE_CONTROL, "", "", null, null, null, myStudy.toUri(), null, null, null, null, sessionIdUser2).first().getFqn(); folder = catalogManager.getFileManager().createFolder(newStudy, Paths.get("WOLOLO").toString(), null, true, null, QueryOptions.empty(), sessionIdUser2).first(); assertTrue(!ioManager.exists(folder.getUri()));
@Test public void renameFileAlreadyExists() throws CatalogException { catalogManager.getFileManager().createFolder(studyFqn, "analysis/", new File.FileStatus(), false, "", new QueryOptions(), sessionIdUser); thrown.expect(CatalogException.class); thrown.expectMessage("already exists"); catalogManager.getFileManager().rename(studyFqn, "data/", "analysis", sessionIdUser); }
studyId = study.getFqn(); studyUid = study.getUid(); outputId = catalogManager.getFileManager().createFolder(studyId, Paths.get("data", "index").toString(), null, true, null, QueryOptions.empty(), sessionId).first().getUid();
private File createBasicDirectoryFileTestEnvironment(List<File> folderFiles) throws CatalogException { File folder = catalogManager.getFileManager().createFolder(studyFqn, Paths.get("folder").toString(), null, false, null, QueryOptions.empty(), sessionIdUser).first(); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my.txt"), false, StringUtils.randomString(200), null, sessionIdUser).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my2.txt"), false, StringUtils.randomString(200), null, sessionIdUser).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my3.txt"), false, StringUtils.randomString(200), null, sessionIdUser).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/my4.txt"), true, StringUtils.randomString(200), null, sessionIdUser).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/my5.txt"), false, StringUtils.randomString(200), null, sessionIdUser).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/subsubfolder/my6.txt"), true, StringUtils.randomString(200), null, sessionIdUser).first() ); return folder; }
private File prepareFiles(List<File> folderFiles) throws CatalogException { File folder = catalogManager.getFileManager().createFolder(studyFqn, Paths.get("folder").toString(), null, false, null, QueryOptions.empty(), userSessionId).first(); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my.txt"), false, StringUtils.randomString(200), null, userSessionId).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my2.txt"), false, StringUtils.randomString(200), null, userSessionId).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/my3.txt"), false, StringUtils.randomString(200), null, userSessionId).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/my4.txt"), true, StringUtils.randomString(200), null, userSessionId).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/my5.txt"), false, StringUtils.randomString(200), null, userSessionId).first() ); folderFiles.add( catalogManager.getFileManager().create(studyFqn, new File().setPath("folder/subfolder/subsubfolder/my6.txt"), true, StringUtils.randomString(200), null, userSessionId).first() ); return folder; }
studyId = study.getId(); studyFqn = study.getFqn(); outputId = catalogManager.getFileManager().createFolder(studyFqn, Paths.get("data", "index").toString(), null, true, null, QueryOptions.empty(), sessionId).first().getId(); outputPath = "data/index/"; studyId2 = catalogManager.getStudyManager().create(projectId, "s2", "s2", "s2", Study.Type.CASE_CONTROL, null, "Study " + "2", null, null, null, null, Collections.singletonMap(File.Bioformat.VARIANT, new DataStore(getStorageEngine(), dbName)), null, Collections.singletonMap(VariantStorageEngine.Options.AGGREGATED_TYPE.key(), getAggregation()), null, sessionId).first().getId(); outputId2 = catalogManager.getFileManager().createFolder(studyId2, Paths.get("data", "index").toString(), null, true, null, QueryOptions.empty(), sessionId).first().getId();
protected File transformFile(File inputFile, QueryOptions queryOptions, String path) throws CatalogException, IOException, StorageEngineException, URISyntaxException { catalogManager.getFileManager().createFolder(studyFqn, path, null, true, null, null, sessionId); } catch (CatalogException ignore) {}
/** * Job methods * *************************** */ @Test public void testCreateJob() throws CatalogException, IOException { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); String studyId = catalogManager.getStudyManager().get(query, null, sessionIdUser).first().getId(); File outDir = catalogManager.getFileManager().createFolder(studyId, Paths.get("jobs", "myJob").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); catalogManager.getJobManager().create(studyId,new Job().setId("myJob").setToolId("samtool").setDescription("description") .setOutDir(outDir).setExecution("echo \"Hello world!\"").setStatus(new Job.JobStatus(Job.JobStatus.PREPARED)), null, sessionIdUser); catalogManager.getJobManager().create(studyId, new Job().setId("myReadyJob").setToolId("samtool").setDescription("description") .setOutDir(outDir).setExecution("echo \"Hello world!\"").setStatus(new Job.JobStatus(Job.JobStatus.READY)), null, sessionIdUser); catalogManager.getJobManager().create(studyId, new Job().setId("myQueuedJob").setToolId("samtool").setDescription("description") .setOutDir(outDir).setExecution("echo \"Hello world!\"").setStatus(new Job.JobStatus(Job.JobStatus.QUEUED)), null, sessionIdUser); catalogManager.getJobManager().create(studyId, new Job().setId("myErrorJob").setToolId("samtool").setDescription("description") .setOutDir(outDir).setExecution("echo \"Hello world!\"").setStatus(new Job.JobStatus(Job.JobStatus.ERROR)), null, sessionIdUser); query = new Query() .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), Arrays.asList(Job.JobStatus.PREPARED, Job.JobStatus.QUEUED, Job.JobStatus.RUNNING, Job.JobStatus.DONE)); QueryResult<Job> unfinishedJobs = catalogManager.getJobManager().get(String.valueOf(studyId), query, null, sessionIdUser); assertEquals(2, unfinishedJobs.getNumResults()); QueryResult<Job> allJobs = catalogManager.getJobManager().get(String.valueOf(studyId), (Query) null, null, sessionIdUser); assertEquals(4, allJobs.getNumResults()); }