@Override public void create(TaskExecution aTaskExecution) { collection .updateOne( eq("_id", aTaskExecution.getJobId()), push(DSL.EXECUTION, aTaskExecution) ); }
bsons.add(set(studyIdStr + '.' + NEW_STUDY_FIELD, false)); } else if (binaryList.size() == 1) { bsons.add(resumeStageLoad ? addToSet(fieldName, binaryList.get(0)) : push(fieldName, binaryList.get(0))); } else { bsons.add(resumeStageLoad ? addEachToSet(fieldName, binaryList) : pushEach(fieldName, binaryList));
@Override public void nativeInsert(Map<String, Object> project, String userId) throws CatalogDBException { Bson query = Filters.and(Filters.eq(UserDBAdaptor.QueryParams.ID.key(), userId), Filters.ne(UserDBAdaptor.QueryParams.PROJECTS_ID.key(), project.get(QueryParams.ID.key()))); Bson update = Updates.push("projects", getMongoDBDocument(project, "project")); //Update object QueryResult<UpdateResult> queryResult = userCollection.update(query, update, null); if (queryResult.getResult().get(0).getModifiedCount() == 0) { // Check if the project has been inserted throw new CatalogDBException("Project {" + project.get(QueryParams.ID.key()) + "\"} already exists for this user"); } }
updates.add(push(STUDIES_FIELD, studyDocument));
@Override public void appendMessage(final String jobId, final JobMessage jobMessage) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage))); }
@Override public void appendMessage(final String jobId, final JobMessage jobMessage) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), combine(push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage)), set(JobStructure.LAST_UPDATED.key(), Date.from(jobMessage.getTimestamp().toInstant())))); }
/** * Add the user's computational resource for notebook into database. * * @param user user name. * @param exploratoryName name of exploratory. * @param computationalDTO object of computational resource. * @return <b>true</b> if operation was successful, otherwise <b>false</b>. */ public boolean addComputational(String user, String exploratoryName, UserComputationalResource computationalDTO) { Optional<Document> optional = findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, eq(COMPUTATIONAL_NAME, computationalDTO.getComputationalName()))) ); if (!optional.isPresent()) { updateOne(USER_INSTANCES, exploratoryCondition(user, exploratoryName), push(COMPUTATIONAL_RESOURCES, convertToBson(computationalDTO))); return true; } else { return false; } }
@Override public QueryResult<User.Filter> addFilter(String userId, User.Filter filter) throws CatalogDBException { long startTime = startQuery(); // Insert the filter Bson bsonQuery = Filters.and( Filters.eq(QueryParams.ID.key(), userId), Filters.ne(QueryParams.CONFIGS_FILTERS_NAME.key(), filter.getName()) ); Bson filterDocument = getMongoDBDocument(filter, "Filter"); Bson update = Updates.push(QueryParams.CONFIGS_FILTERS.key(), filterDocument); QueryResult<UpdateResult> queryResult = userCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() != 1) { if (queryResult.first().getModifiedCount() == 0) { throw new CatalogDBException("Internal error: The filter could not be stored."); } else { // This error should NEVER be raised. throw new CatalogDBException("User: There was a critical error when storing the filter. Is has been inserted " + queryResult.first().getModifiedCount() + " times."); } } return endQuery("addFilter", startTime, Arrays.asList(filter)); }
/** * Add the user's library for exploratory into database. * * @param user user name. * @param exploratoryName name of exploratory. * @param library library. * @return <b>true</b> if operation was successful, otherwise <b>false</b>. */ public boolean addLibrary(String user, String exploratoryName, LibInstallDTO library, boolean reinstall) { Optional<Document> opt = findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), libraryConditionExploratory(library.getGroup(), library.getName(), library.getVersion()))); if (!opt.isPresent()) { updateOne(USER_INSTANCES, exploratoryCondition(user, exploratoryName), push(EXPLORATORY_LIBS, convertToBson(library))); return true; } else { Document values = updateLibraryFields(library, null); if (reinstall) { values.append(libraryFieldFilter(LIB_INSTALL_DATE), null); values.append(libraryFieldFilter(LIB_ERROR_MESSAGE), null); } updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), libraryConditionExploratory(library.getGroup(), library.getName(), library.getVersion())), new Document(SET, values)); return false; } }
updateOne(USER_INSTANCES, runningExploratoryAndComputationalCondition(user, exploratoryName, computationalName), push(COMPUTATIONAL_LIBS + "." + computationalName, convertToBson(library))); return true; } else {
Bson update = Updates.push("projects", projectDocument);
@Override public QueryResult<VariableSet> createVariableSet(long studyId, VariableSet variableSet) throws CatalogDBException { long startTime = startQuery(); if (variableSetExists(variableSet.getId(), studyId) > 0) { throw new CatalogDBException("VariableSet { name: '" + variableSet.getId() + "'} already exists."); } long variableSetId = getNewId(); variableSet.setUid(variableSetId); Document object = getMongoDBDocument(variableSet, "VariableSet"); object.put(PRIVATE_UID, variableSetId); Bson bsonQuery = Filters.eq(PRIVATE_UID, studyId); Bson update = Updates.push("variableSets", object); QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() == 0) { throw new CatalogDBException("createVariableSet: Could not create a new variable set in study " + studyId); } return endQuery("createVariableSet", startTime, getVariableSet(variableSetId, null)); }
@Override public QueryResult<VariableSet> addFieldToVariableSet(long variableSetId, Variable variable, String user) throws CatalogDBException, CatalogAuthorizationException { long startTime = startQuery(); QueryResult<VariableSet> variableSet = getVariableSet(variableSetId, new QueryOptions(), user); checkVariableNotInVariableSet(variableSet.first(), variable.getId()); Bson bsonQuery = Filters.eq(QueryParams.VARIABLE_SET_UID.key(), variableSetId); Bson update = Updates.push(QueryParams.VARIABLE_SET.key() + ".$." + VariableSetParams.VARIABLE.key(), getMongoDBDocument(variable, "variable")); QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() == 0) { throw CatalogDBException.updateError("VariableSet", variableSetId); } if (variable.isRequired()) { dbAdaptorFactory.getCatalogSampleDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogCohortDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogIndividualDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogFamilyDBAdaptor().addVariableToAnnotations(variableSetId, variable); dbAdaptorFactory.getCatalogFileDBAdaptor().addVariableToAnnotations(variableSetId, variable); } return endQuery("Add field to variable set", startTime, getVariableSet(variableSetId, null)); }