@Override public void nativeInsert(Map<String, Object> sample, String userId) throws CatalogDBException { Document sampleDocument = getMongoDBDocument(sample, "sample"); sampleCollection.insert(sampleDocument, null); }
@Override public void nativeInsert(Map<String, Object> job, String userId) throws CatalogDBException { Document document = getMongoDBDocument(job, "job"); jobCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> interpretation, String userId) throws CatalogDBException { Document document = getMongoDBDocument(interpretation, "clinicalAnalysis"); interpretationCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> clinicalAnalysis, String userId) throws CatalogDBException { Document document = getMongoDBDocument(clinicalAnalysis, "clinicalAnalysis"); clinicalCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> individual, String userId) throws CatalogDBException { Document document = getMongoDBDocument(individual, "individual"); individualCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> file, String userId) throws CatalogDBException { Document fileDocument = getMongoDBDocument(file, "sample"); fileCollection.insert(fileDocument, null); }
@Override public void nativeInsert(Map<String, Object> family, String userId) throws CatalogDBException { Document document = getMongoDBDocument(family, "family"); familyCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> cohort, String userId) throws CatalogDBException { Document document = getMongoDBDocument(cohort, "cohort"); cohortCollection.insert(document, null); }
@Override public void nativeInsert(Map<String, Object> study, String userId) throws CatalogDBException { Document studyDocument = getMongoDBDocument(study, "study"); studyDocument.put(PRIVATE_OWNER_ID, userId); studyCollection.insert(studyDocument, null); }
@Override public boolean write(List<Document> batch) { BulkWriteResult result = collection.insert(batch, QueryOptions.empty()).first(); insertedCount += result.getInsertedCount(); return true; }
@Override public QueryResult<AuditRecord> insertAuditRecord(AuditRecord auditRecord) throws CatalogDBException { long startQuery = startQuery(); Document auditRecordDbObject = MongoDBUtils.getMongoDBDocument(auditRecord, "AuditRecord"); auditCollection.insert(auditRecordDbObject, new QueryOptions()); return endQuery("insertAuditRecord", startQuery, Collections.singletonList(auditRecord)); }
@Override public void initializeCatalogDB(Admin admin) throws CatalogDBException { //If "metadata" document doesn't exist, create. if (!isCatalogDBReady()) { /* Check all collections are empty */ for (Map.Entry<String, MongoDBCollection> entry : collections.entrySet()) { if (entry.getValue().count().first() != 0L) { throw new CatalogDBException("Fail to initialize Catalog Database in MongoDB. Collection " + entry.getKey() + " is " + "not empty."); } } try { // DBObject metadataObject = getDbObject(new Metadata(), "Metadata"); Document metadataObject = getMongoDBDocument(new Metadata(), "Metadata"); metadataObject.put("id", METADATA_OBJECT_ID); metadataObject.put("admin", getMongoDBDocument(admin, "Admin")); metaCollection.insert(metadataObject, null); } catch (DuplicateKeyException e) { logger.warn("Trying to replace MetadataObject. DuplicateKey"); } } else { throw new CatalogDBException("Catalog already initialized"); } }
clinicalCollection.insert(clinicalObject, null);
@Override public QueryResult<Job> insert(Job job, long studyId, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); this.dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); List<Bson> filterList = new ArrayList<>(); filterList.add(Filters.eq(QueryParams.ID.key(), job.getId())); filterList.add(Filters.eq(PRIVATE_STUDY_ID, studyId)); filterList.add(Filters.eq(QueryParams.STATUS_NAME.key(), Status.READY)); Bson bson = Filters.and(filterList); QueryResult<Long> count = jobCollection.count(bson); if (count.getResult().get(0) > 0) { throw new CatalogDBException("Job { id: '" + job.getId() + "'} already exists."); } long jobId = getNewId(); job.setUid(jobId); job.setStudyUid(studyId); if (StringUtils.isEmpty(job.getUuid())) { job.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.JOB)); } Document jobObject = jobConverter.convertToStorageType(job); if (StringUtils.isNotEmpty(job.getCreationDate())) { jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(job.getCreationDate())); } else { jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate()); } jobObject.put(PERMISSION_RULES_APPLIED, Collections.emptyList()); jobCollection.insert(jobObject, null); //TODO: Check results.get(0).getN() != 0 return endQuery("Create Job", startTime, get(jobId, filterOptions(options, FILTER_ROUTE_JOBS))); }
@Override public QueryResult<Interpretation> insert(long studyId, Interpretation interpretation, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); List<Bson> filterList = new ArrayList<>(); filterList.add(Filters.eq(QueryParams.ID.key(), interpretation.getInterpretation().getId())); filterList.add(Filters.eq(PRIVATE_STUDY_ID, studyId)); filterList.add(Filters.eq(QueryParams.STATUS.key(), Status.READY)); Bson bson = Filters.and(filterList); QueryResult<Long> count = interpretationCollection.count(bson); if (count.getResult().get(0) > 0) { throw new CatalogDBException("Cannot create interpretation. An interpretation with { id: '" + interpretation.getInterpretation().getId() + "'} already exists."); } long interpretationUid = getNewId(); interpretation.setUid(interpretationUid); interpretation.setStudyUid(studyId); if (StringUtils.isEmpty(interpretation.getUuid())) { interpretation.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.INTERPRETATION)); } Document interpretationObject = interpretationConverter.convertToStorageType(interpretation); if (StringUtils.isNotEmpty(interpretation.getInterpretation().getCreationDate())) { interpretationObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(interpretation.getInterpretation().getCreationDate())); } else { interpretationObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate()); } interpretationCollection.insert(interpretationObject, null); return endQuery("createInterpretation", startTime, get(interpretationUid, options)); }
public void initializeMetaCollection(Configuration configuration) throws CatalogException { Admin admin = configuration.getAdmin(); admin.setPassword(CatalogAuthenticationManager.cypherPassword(admin.getPassword())); Metadata metadata = new Metadata().setIdCounter(configuration.getCatalog().getOffset()).setVersion(VERSION); Document metadataObject = getMongoDBDocument(metadata, "Metadata"); metadataObject.put(PRIVATE_ID, MongoDBAdaptorFactory.METADATA_OBJECT_ID); Document adminDocument = getMongoDBDocument(admin, "Admin"); metadataObject.put("admin", adminDocument); metaCollection.insert(metadataObject, null); }
/** * Creates a new version for all the interpretations matching the query. * * @param query Query object. */ private void createNewVersion(Query query) throws CatalogDBException { QueryResult<Document> queryResult = nativeGet(query, new QueryOptions(QueryOptions.EXCLUDE, "_id")); for (Document document : queryResult.getResult()) { Document updateOldVersion = new Document(); updateOldVersion.put(LAST_OF_VERSION, false); // Perform the update on the previous version Document queryDocument = new Document() .append(PRIVATE_STUDY_ID, document.getLong(PRIVATE_STUDY_ID)) .append(QueryParams.VERSION.key(), document.getInteger(QueryParams.VERSION.key())) .append(PRIVATE_UID, document.getLong(PRIVATE_UID)); QueryResult<UpdateResult> updateResult = interpretationCollection.update(queryDocument, new Document("$set", updateOldVersion), null); if (updateResult.first().getModifiedCount() == 0) { throw new CatalogDBException("Internal error: Could not update interpretation"); } // We update the information for the new version of the document document.put(LAST_OF_VERSION, true); document.put(QueryParams.VERSION.key(), document.getInteger(QueryParams.VERSION.key()) + 1); // Insert the new version document interpretationCollection.insert(document, QueryOptions.empty()); } }
@Override public QueryResult<Dataset> insert(Dataset dataset, long studyId, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); Query query = new Query(QueryParams.NAME.key(), dataset.getName()).append(QueryParams.STUDY_ID.key(), studyId); QueryResult<Long> count = count(query); if (count.getResult().get(0) > 0) { throw new CatalogDBException("Dataset { name: \"" + dataset.getName() + "\" } already exists in the study { " + studyId + " }."); } long newId = getNewId(); dataset.setId(newId); Document datasetObject = datasetConverter.convertToStorageType(dataset); datasetCollection.insert(datasetObject, null); return endQuery("createDataset", startTime, get(dataset.getId(), options)); }
fileCollection.insert(fileDocument, null); } catch (MongoWriteException e) { throw CatalogDBException.alreadyExists("File", studyId, "path", file.getPath(), e);
@Override public QueryResult<Cohort> insert(long studyId, Cohort cohort, List<VariableSet> variableSetList, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); checkCohortNameExists(studyId, cohort.getId()); long newId = dbAdaptorFactory.getCatalogMetaDBAdaptor().getNewAutoIncrementId(); cohort.setUid(newId); cohort.setStudyUid(studyId); if (StringUtils.isEmpty(cohort.getUuid())) { cohort.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.COHORT)); } Document cohortObject = cohortConverter.convertToStorageType(cohort, variableSetList); if (StringUtils.isNotEmpty(cohort.getCreationDate())) { cohortObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(cohort.getCreationDate())); } else { cohortObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate()); } cohortObject.put(PERMISSION_RULES_APPLIED, Collections.emptyList()); try { cohortCollection.insert(cohortObject, null); } catch (MongoWriteException e) { throw ifDuplicateKeyException(() -> CatalogDBException.alreadyExists("Cohort", studyId, "name", cohort.getId(), e), e); } Query query = new Query() .append(QueryParams.UID.key(), newId) .append(QueryParams.STUDY_UID.key(), studyId); return endQuery("createCohort", startTime, get(query, options)); }