public boolean existProject(String userId, String projectId) throws CatalogIOException { return exists(getProjectUri(userId, projectId)); }
/** * Check if there is any file in the URI target. * * @throws org.opencb.opencga.catalog.exceptions.CatalogIOException */ private void checkTarget(File file, URI targetUri, CatalogIOManager targetIOManager, boolean overwrite) throws CatalogIOException { if (!overwrite && targetIOManager.exists(targetUri)) { throw new CatalogIOException("There is a file in the target!" + "file:{id:" + file.getPath() + ", targetUri: '" + targetUri + "' } " + "Needs 'overwrite = true' for continue."); } }
/** * This method creates the folders and workspace structure for storing the OpenCGA data. I * * @throws CatalogIOException CatalogIOException */ public void setup() throws CatalogIOException { setConfiguration(configuration); if (!exists(rootDir)) { logger.info("Initializing CatalogIOManager. Creating main folder '" + rootDir + "'"); createDirectory(rootDir, true); } checkDirectoryUri(rootDir, true); if (!exists(jobsDir)) { logger.info("Initializing CatalogIOManager. Creating jobs folder '" + jobsDir + "'"); createDirectory(jobsDir); } checkDirectoryUri(jobsDir, true); if (!exists(rootDir.resolve(OPENCGA_USERS_FOLDER))) { createDirectory(rootDir.resolve(OPENCGA_USERS_FOLDER)); } if (!exists(rootDir.resolve(OPENCGA_ANONYMOUS_USERS_FOLDER))) { createDirectory(rootDir.resolve(OPENCGA_ANONYMOUS_USERS_FOLDER)); } if (!exists(rootDir.resolve(OPENCGA_BIN_FOLDER))) { createDirectory(rootDir.resolve(OPENCGA_BIN_FOLDER)); } }
public URI createStudy(URI studyUri) throws CatalogIOException { checkUriScheme(studyUri); try { if (!exists(studyUri)) { studyUri = createDirectory(studyUri); } } catch (CatalogIOException e) { throw new CatalogIOException("createStudy method: could not create the study folder: " + e.toString(), e); } return studyUri; }
public URI createProject(String userId, String projectId) throws CatalogIOException { checkParam(projectId); URI projectUri = getProjectUri(userId, projectId); try { if (!exists(projectUri)) { projectUri = createDirectory(projectUri, true); } } catch (CatalogIOException e) { throw new CatalogIOException("createProject(): could not create the project folder", e); } return projectUri; }
public URI createFolder(URI studyUri, String folderName, boolean parent) throws CatalogIOException { checkParam(folderName); if (!folderName.endsWith("/")) { folderName += "/"; } checkDirectoryUri(studyUri, true); URI folderUri = null; try { folderUri = studyUri.resolve(new URI(null, folderName, null)); } catch (URISyntaxException e) { throw CatalogIOException.uriSyntaxException(folderName, e); } try { if (!exists(folderUri)) { if (parent) { createDirectory(folderUri, true); } else { checkDirectoryUri(folderUri.resolve(".."), true); createDirectory(folderUri); } } } catch (CatalogIOException e) { throw new CatalogIOException("createFolder(): could not create the directory", e); } return folderUri; }
if (!ioManager.exists(entry.getValue())) { untrackedFiles.put(entry.getKey(), entry.getValue()); continue;
public URI createUser(String userId) throws CatalogIOException { checkParam(userId); URI usersUri = getUsersUri(); checkDirectoryUri(usersUri, true); URI userPath = getUserUri(userId); try { if (!exists(userPath)) { createDirectory(userPath); createDirectory(userPath.resolve(CatalogIOManager.USER_PROJECTS_FOLDER)); createDirectory(userPath.resolve(CatalogIOManager.USER_BIN_FOLDER)); return userPath; } } catch (CatalogIOException e) { throw e; } return null; }
public URI createJobOutDir(String userId, String folderName) throws CatalogIOException { checkParam(folderName); URI jobsFolderUri = getJobsUri(userId); checkDirectoryUri(jobsFolderUri, true); URI jobUri; try { jobUri = jobsFolderUri.resolve(new URI(null, folderName, null)); } catch (URISyntaxException e) { throw CatalogIOException.uriSyntaxException(folderName, e); } if (!exists(jobUri)) { try { jobUri = createDirectory(jobUri, true); } catch (CatalogIOException e) { throw new CatalogIOException("createStudy method: could not create the study folder: " + e.toString(), e); } } else { throw new CatalogIOException("createJobOutDir method: Job folder " + folderName + "already exists."); } return jobUri; }
@Test public void deleteFilesTest2() throws CatalogException, IOException { QueryResult<File> queryResult = catalogManager.getFileManager().create(studyFqn, File.Type.FILE, File.Format.PLAIN, File.Bioformat.NONE, "my.txt", null, "", new File.FileStatus(File.FileStatus.STAGE), 0, -1, null, -1, null, null, false, null, null, userSessionId); new FileUtils(catalogManager).upload(new ByteArrayInputStream(StringUtils.randomString(200) .getBytes()), queryResult.first(), userSessionId, false, false, true); File file = catalogManager.getFileManager().get(studyFqn, queryResult.first().getPath(), null, userSessionId).first(); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(file.getUri()); assertTrue(ioManager.exists(file.getUri())); catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, userSessionId); assertTrue(ioManager.exists(file.getUri())); // catalogFileUtils.delete(file.getId(), userSessionId); // assertTrue(!ioManager.exists(catalogManager.getFileUri(catalogManager.getFile(file.getId(), userSessionId).first()))); }
@Test public void deleteFoldersTest() throws CatalogException, IOException { List<File> folderFiles = new LinkedList<>(); File folder = prepareFiles(folderFiles); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(catalogManager.getFileManager().getUri(folder)); for (File file : folderFiles) { assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); } catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), null, userSessionId); Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), File.FileStatus.TRASHED); QueryResult<File> fileQueryResult = catalogManager.getFileManager().get(studyFqn, query, QueryOptions.empty(), userSessionId); assertTrue(ioManager.exists(fileQueryResult.first().getUri())); for (File file : folderFiles) { assertTrue("File uri: " + file.getUri() + " should exist", ioManager.exists(file.getUri())); } }
@Test public void deleteFolderTest() throws CatalogException, IOException { List<File> folderFiles = new LinkedList<>(); File folder = createBasicDirectoryFileTestEnvironment(folderFiles); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(catalogManager.getFileManager().getUri(folder)); for (File file : folderFiles) { assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); } catalogManager.getFileManager().create(studyFqn, File.Type.FILE, File.Format.PLAIN, File.Bioformat.NONE, "folder/subfolder/subsubfolder/my_staged.txt", null, null, new File.FileStatus(File.FileStatus.STAGE), (long) 0, (long) -1, null, (long) -1, null, null, true, null, null, sessionIdUser).first(); WriteResult deleteResult = catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), null, sessionIdUser); assertEquals(0, deleteResult.getNumModified()); File fileTmp = catalogManager.getFileManager().get(studyFqn, folder.getPath(), null, sessionIdUser).first(); assertEquals("Folder name should not be modified", folder.getPath(), fileTmp.getPath()); assertTrue(ioManager.exists(fileTmp.getUri())); for (File file : folderFiles) { fileTmp = catalogManager.getFileManager().get(studyFqn, file.getPath(), null, sessionIdUser).first(); assertEquals("File name should not be modified", file.getPath(), fileTmp.getPath()); assertTrue("File uri: " + fileTmp.getUri() + " should exist", ioManager.exists(fileTmp.getUri())); } }
@Test public void testCreateFile() throws CatalogException, IOException { String content = "This is the content\tof the file"; try { fileManager.create(studyFqn3, File.Type.FILE, File.Format.UNKNOWN, File.Bioformat.UNKNOWN, "data/test/myTest/myFile.txt", null, null, new File.FileStatus(File.FileStatus.READY), 0, -1, null, -1, null, null, false, "This is the content\tof the file", null, sessionIdUser2); fail("An error should be raised because parents is false"); } catch (CatalogException e) { System.out.println("Correct"); } QueryResult<File> fileQueryResult = fileManager.create(studyFqn3, File.Type.FILE, File.Format.UNKNOWN, File.Bioformat.UNKNOWN, "data/test/myTest/myFile.txt", null, null, new File.FileStatus(File.FileStatus.READY), 0, -1, null, -1, null, null, true, content, null, sessionIdUser2); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(fileQueryResult.first().getUri()); assertTrue(ioManager.exists(fileQueryResult.first().getUri())); DataInputStream fileObject = ioManager.getFileObject(fileQueryResult.first().getUri(), -1, -1); assertEquals(content, fileObject.readLine()); }
@Test public void deleteFolderTest3() throws CatalogException, IOException { List<File> folderFiles = new LinkedList<>(); File folder = createBasicDirectoryFileTestEnvironment(folderFiles); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(catalogManager.getFileManager().getUri(folder)); for (File file : folderFiles) { assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); } catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), new ObjectMap(FileManager.SKIP_TRASH, true), sessionIdUser); Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), File.FileStatus.PENDING_DELETE); File fileTmp = fileManager.get(studyFqn, query, QueryOptions.empty(), sessionIdUser).first(); String myPath = Paths.get(folder.getPath()) + AbstractManager.INTERNAL_DELIMITER + "DELETED"; assertTrue("Folder name should have been modified", fileTmp.getPath().contains(myPath)); assertEquals("Status should be to PENDING_DELETE", File.FileStatus.PENDING_DELETE, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", folder.getName(), fileTmp.getName()); assertTrue(ioManager.exists(fileTmp.getUri())); for (File file : folderFiles) { query.put(FileDBAdaptor.QueryParams.UID.key(), file.getUid()); fileTmp = fileManager.get(studyFqn, query, QueryOptions.empty(), sessionIdUser).first(); assertTrue("Folder name should have been modified", fileTmp.getPath().contains(myPath)); assertEquals("Status should be to PENDING_DELETE", File.FileStatus.PENDING_DELETE, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); assertTrue("File uri: " + fileTmp.getUri() + " should exist", ioManager.exists(fileTmp.getUri())); } }
assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); assertEquals("Status should be to DELETED", File.FileStatus.DELETED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", folder.getName(), fileTmp.getName()); assertTrue(!ioManager.exists(fileTmp.getUri())); assertEquals("Status should be to DELETED", File.FileStatus.DELETED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); assertTrue("File uri: " + fileTmp.getUri() + " should not exist", !ioManager.exists(fileTmp.getUri()));
assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); assertEquals("Status should be DELETED", File.FileStatus.DELETED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", folder.getName(), fileTmp.getName()); assertTrue(!ioManager.exists(fileTmp.getUri())); assertEquals("Status should be to DELETED", File.FileStatus.DELETED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); assertTrue("File uri: " + fileTmp.getUri() + " should not exist", !ioManager.exists(fileTmp.getUri()));
CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(catalogManager.getFileManager().getUri(folder)); for (File file : folderFiles) { assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); QueryResult<File> fileQueryResult = catalogManager.getFileManager().get(studyFqn, query, QueryOptions.empty(), userSessionId); assertTrue(ioManager.exists(fileQueryResult.first().getUri())); for (File file : folderFiles) { assertTrue("File uri: " + file.getUri() + " should exist", ioManager.exists(file.getUri()));
@Test public void testUnlinkFolder() throws CatalogException, IOException { URI uri = Paths.get(getStudyURI()).resolve("data").toUri(); link(uri, "myDirectory", studyFqn, new ObjectMap("parents", true), sessionIdUser); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(uri); Query query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~myDirectory/*") .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), File.FileStatus.READY); QueryResult<File> fileQueryResultLinked = catalogManager.getFileManager().get(studyFqn, query, null, sessionIdUser); System.out.println("Number of files/folders linked = " + fileQueryResultLinked.getNumResults()); // Now we try to unlink them catalogManager.getFileManager().unlink(studyFqn, "myDirectory/data/", sessionIdUser); fileQueryResultLinked = catalogManager.getFileManager().get(studyFqn, query, null, sessionIdUser); assertEquals(1, fileQueryResultLinked.getNumResults()); query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~myDirectory/*") .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), File.FileStatus.REMOVED); QueryResult<File> fileQueryResultUnlinked = catalogManager.getFileManager().get(studyFqn, query, null, sessionIdUser); assertEquals(6, fileQueryResultUnlinked.getNumResults()); String myPath = "myDirectory/data" + AbstractManager.INTERNAL_DELIMITER + "REMOVED"; for (File file : fileQueryResultUnlinked.getResult()) { assertTrue("File name should have been modified", file.getPath().contains(myPath)); assertEquals("Status should be to REMOVED", File.FileStatus.REMOVED, file.getStatus().getName()); assertEquals("Name should not have changed", file.getName(), file.getName()); assertTrue("File uri: " + file.getUri() + " should exist", ioManager.exists(file.getUri())); } }
@Test public void deleteFolderTest2() throws CatalogException, IOException { List<File> folderFiles = new LinkedList<>(); File folder = createBasicDirectoryFileTestEnvironment(folderFiles); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(catalogManager.getFileManager().getUri(folder)); for (File file : folderFiles) { assertTrue(ioManager.exists(catalogManager.getFileManager().getUri(file))); } catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), null, sessionIdUser); Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), File.FileStatus.TRASHED); File fileTmp = catalogManager.getFileManager().get(studyFqn, query, QueryOptions.empty(), sessionIdUser).first(); assertEquals("Folder name should not be modified", folder.getPath(), fileTmp.getPath()); assertEquals("Status should be to TRASHED", File.FileStatus.TRASHED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", folder.getName(), fileTmp.getName()); assertTrue(ioManager.exists(fileTmp.getUri())); for (File file : folderFiles) { query.put(FileDBAdaptor.QueryParams.UID.key(), file.getUid()); fileTmp = fileManager.get(studyFqn, query, QueryOptions.empty(), sessionIdUser).first(); assertEquals("Folder name should not be modified", file.getPath(), fileTmp.getPath()); assertEquals("Status should be to TRASHED", File.FileStatus.TRASHED, fileTmp.getStatus().getName()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); assertTrue("File uri: " + fileTmp.getUri() + " should exist", ioManager.exists(fileTmp.getUri())); } }