@Override public QueryResult<Long> extractSampleFromFiles(Query query, List<Long> sampleIds) throws CatalogDBException { long startTime = startQuery(); Bson bsonQuery = parseQuery(query, true); Bson update = new Document("$pull", new Document(QueryParams.SAMPLES.key(), new Document(PRIVATE_UID, new Document("$in", sampleIds)))); QueryOptions multi = new QueryOptions(MongoDBCollection.MULTI, true); QueryResult<UpdateResult> updateQueryResult = fileCollection.update(bsonQuery, update, multi); return endQuery("Extract samples from files", startTime, Collections.singletonList(updateQueryResult.first().getModifiedCount())); }
@Override public void addSamplesToFile(long fileId, List<Sample> samples) throws CatalogDBException { if (samples == null || samples.size() == 0) { return; } List<Document> sampleList = fileConverter.convertSamples(samples); Bson update = Updates.addEachToSet(QueryParams.SAMPLES.key(), sampleList); fileCollection.update(Filters.eq(PRIVATE_UID, fileId), update, QueryOptions.empty()); }
@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); }
@Override public QueryResult groupBy(Query query, List<String> fields, QueryOptions options) throws CatalogDBException { filterOutDeleted(query); Bson bsonQuery = parseQuery(query, false); return groupBy(fileCollection, bsonQuery, fields, QueryParams.NAME.key(), options); }
private void filterOutDeleted(Query query) { if (!query.containsKey(QueryParams.STATUS_NAME.key()) && !query.containsKey(QueryParams.UID.key())) { query.append(QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + Status.DELETED + ";!=" + File.FileStatus.REMOVED + ";!=" + File.FileStatus.PENDING_DELETE + ";!=" + File.FileStatus.DELETING); } }
@Override public QueryResult<Long> restore(Query query, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); query.put(QueryParams.STATUS_NAME.key(), File.FileStatus.TRASHED); return endQuery("Restore files", startTime, setStatus(query, File.FileStatus.READY)); }
@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()); }
@Override public void delete(long id) throws CatalogDBException { Query query = new Query(QueryParams.UID.key(), id); delete(query); }
@Override public QueryResult<File> getAllInStudy(long studyId, QueryOptions options) throws CatalogDBException { dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); Query query = new Query(QueryParams.STUDY_UID.key(), studyId); return get(query, options); }
@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 void setUri(String studyStr, String fileId, String uri, String sessionId) throws CatalogException { MyResource<File> resource = getUid(fileId, studyStr, sessionId); String userId = resource.getUser(); long studyId = resource.getStudy().getUid(); authorizationManager.checkFilePermission(studyId, resource.getResource().getUid(), userId, FileAclEntry.FilePermissions.WRITE); ObjectMap parameters = new ObjectMap(FileDBAdaptor.QueryParams.URI.key(), uri); fileDBAdaptor.update(resource.getResource().getUid(), parameters, QueryOptions.empty()); auditManager.recordUpdate(AuditRecord.Resource.file, resource.getResource().getUid(), userId, parameters, null, null); }
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); }
@Deprecated public QueryResult<File> getParents(long fileId, QueryOptions options, String sessionId) throws CatalogException { QueryResult<File> fileQueryResult = fileDBAdaptor.get(fileId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(FileDBAdaptor.QueryParams.PATH.key(), FileDBAdaptor.QueryParams.STUDY_UID.key()))); if (fileQueryResult.getNumResults() == 0) { return fileQueryResult; } String userId = userManager.getUserId(sessionId); authorizationManager.checkFilePermission(fileQueryResult.first().getStudyUid(), fileId, userId, FileAclEntry.FilePermissions.VIEW); return getParents(true, options, fileQueryResult.first().getPath(), fileQueryResult.first().getStudyUid()); }
@Test public void includeFields() throws CatalogDBException { QueryResult<File> fileQueryResult = catalogFileDBAdaptor.get(7, new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.PATH.key())); List<File> files = fileQueryResult.getResult(); assertEquals("Include path does not work.", "data/file.vcf", files.get(0).getPath()); assertEquals("Include not working.", null, files.get(0).getName()); }
private QueryResult<File> getParents(boolean rootFirst, QueryOptions options, String filePath, long studyId) throws CatalogException { List<String> paths = getParentPaths(filePath); Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), paths); query.put(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyId); QueryResult<File> result = fileDBAdaptor.get(query, options); result.getResult().sort(rootFirst ? ROOT_FIRST_COMPARATOR : ROOT_LAST_COMPARATOR); return result; }
@Override public QueryResult<File> search(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { String userId = userManager.getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); // Fix query if it contains any annotation AnnotationUtils.fixQueryAnnotationSearch(study, query); fixQueryObject(study, query, sessionId); query.append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); QueryResult<File> queryResult = fileDBAdaptor.get(query, options, userId); return queryResult; }
@Test @Ignore public void deleteSampleFail2Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long fileId = dbAdaptorFactory.getCatalogFileDBAdaptor().getId(user3.getProjects().get(0).getStudies().get(0).getUid(), "data/file.vcf"); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogFileDBAdaptor().update(fileId, new ObjectMap(FileDBAdaptor.QueryParams.SAMPLES.key(), createResult.first().getUid()), QueryOptions.empty()); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Override public QueryResult groupBy(Query query, String field, QueryOptions options) throws CatalogDBException { filterOutDeleted(query); Bson bsonQuery = parseQuery(query, false); return groupBy(fileCollection, bsonQuery, field, QueryParams.NAME.key(), options); }
public void setDiskUsage(String studyStr, String fileId, long size, String sessionId) throws CatalogException { MyResource<File> resource = getUid(fileId, studyStr, sessionId); authorizationManager.checkFilePermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), FileAclEntry.FilePermissions.WRITE); ObjectMap parameters = new ObjectMap(FileDBAdaptor.QueryParams.SIZE.key(), size); fileDBAdaptor.update(resource.getResource().getUid(), parameters, QueryOptions.empty()); auditManager.recordUpdate(AuditRecord.Resource.file, resource.getResource().getUid(), resource.getUser(), parameters, null, null); }