/** * Return condition for search library into exploratory data. * * @param libraryGroup the name of group. * @param libraryName the name of library. * @param libraryVersion the name of library. */ private static Bson libraryConditionExploratory(String libraryGroup, String libraryName, String libraryVersion) { return elemMatch(EXPLORATORY_LIBS, libCondition(libraryGroup, libraryName, libraryVersion)); }
/** * Return condition for search library into computational data. * * @param computationalName computational name * @param libraryGroup the name of group. * @param libraryName the name of library. * @param libraryVersion the name of library. */ private static Bson libraryConditionComputational(String computationalName, String libraryGroup, String libraryName, String libraryVersion) { return elemMatch(COMPUTATIONAL_LIBS + "." + computationalName, libCondition(libraryGroup, libraryName, libraryVersion)); }
/** * Finds and returns the unique id for computational resource. * * @param user user name. * @param exploratoryName the name of exploratory. * @param computationalName name of computational resource. */ public String fetchComputationalId(String user, String exploratoryName, String computationalName) { Document doc = findOne(USER_INSTANCES, exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, eq(COMPUTATIONAL_NAME, computationalName))) .orElse(new Document()); return getDottedOrDefault(doc, computationalFieldFilter(COMPUTATIONAL_ID), EMPTY).toString(); }
private Bson computationalFilter(String user, String exploratoryName, String computationalStatus, String computationalImage, UserInstanceStatus[] excludedStatuses) { final String[] statuses = Arrays.stream(excludedStatuses) .map(UserInstanceStatus::toString) .toArray(String[]::new); return and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, and(eq(IMAGE, computationalImage), not(in(STATUS, statuses)), not(eq(STATUS, computationalStatus))))); }
/** * Finds and returns the of computational resource. * * @param user user name. * @param exploratoryName the name of exploratory. * @param computationalName name of computational resource. * @throws DlabException if exception occurs */ public UserComputationalResource fetchComputationalFields(String user, String exploratoryName, String computationalName) { Optional<UserInstanceDTO> opt = findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, eq(COMPUTATIONAL_NAME, computationalName))), fields(include(COMPUTATIONAL_RESOURCES), excludeId()), UserInstanceDTO.class); if (opt.isPresent()) { List<UserComputationalResource> list = opt.get().getResources(); UserComputationalResource comp = list.stream() .filter(r -> r.getComputationalName().equals(computationalName)) .findFirst() .orElse(null); if (comp != null) { return comp; } } throw new DlabException("Computational resource " + computationalName + " for user " + user + " with " + "exploratory name " + exploratoryName + " not found."); }
private Bson imageLibraryCondition(String user, String imageFullName, LibStatus status) { return and(eq(USER, user), eq(IMAGE_FULL_NAME, imageFullName), elemMatch(LIBRARIES, eq(STATUS, status.name()))); }
updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName))
@Override public QueryResult<String> getCdna(String id) { Bson bson = Filters.eq("transcripts.xrefs.id", id); Bson elemMatch = Projections.elemMatch("transcripts", Filters.eq("xrefs.id", id)); Bson include = Projections.include("transcripts.cDnaSequence"); // elemMatch and include are combined to reduce the data sent from the server Bson projection = Projections.fields(elemMatch, include); QueryResult<Document> result = mongoDBCollection.find(bson, projection, new QueryOptions()); String sequence = null; if (result != null && !result.getResult().isEmpty()) { List<Document> transcripts = (List<Document>) result.getResult().get(0).get("transcripts"); sequence = transcripts.get(0).getString("cDnaSequence"); } return new QueryResult<>(id, result.getDbTime(), result.getNumResults(), result.getNumTotalResults(), result.getWarningMsg(), result.getErrorMsg(), Collections.singletonList(sequence)); }
@Override public QueryResult<String> getCdna(String id) { Bson bson = Filters.eq("transcripts.xrefs.id", id); Bson elemMatch = Projections.elemMatch("transcripts", Filters.eq("xrefs.id", id)); Bson include = Projections.include("transcripts.cDnaSequence"); // elemMatch and include are combined to reduce the data sent from the server Bson projection = Projections.fields(elemMatch, include); QueryResult<Document> result = mongoDBCollection.find(bson, projection, new QueryOptions()); String sequence = null; if (result != null && !result.getResult().isEmpty()) { List<Document> transcripts = (List<Document>) result.getResult().get(0).get("transcripts"); sequence = transcripts.get(0).getString("cDnaSequence"); } return new QueryResult<>(id, result.getDbTime(), result.getNumResults(), result.getNumTotalResults(), result.getWarningMsg(), result.getErrorMsg(), Collections.singletonList(sequence)); }
@Override public long getId(final String userId, final String projectIdStr) throws CatalogDBException { String projectId = projectIdStr; if (projectId.contains("@")) { projectId = projectId.split("@", 2)[1]; } QueryResult<Document> queryResult = userCollection.find( new BsonDocument(UserDBAdaptor.QueryParams.PROJECTS_ID.key(), new BsonString(projectId)) .append(UserDBAdaptor.QueryParams.ID.key(), new BsonString(userId)), Projections.fields(Projections.include(UserDBAdaptor.QueryParams.PROJECTS_UID.key()), Projections.elemMatch("projects", Filters.eq(QueryParams.ID.key(), projectId))), null); User user = parseUser(queryResult); if (user == null || user.getProjects().isEmpty()) { return -1; } else { return user.getProjects().get(0).getUid(); } }
@Override public QueryResult<VariableSet> getVariableSet(long variableSetId, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); Query query = new Query(QueryParams.VARIABLE_SET_UID.key(), variableSetId); Bson projection = Projections.elemMatch("variableSets", Filters.eq(PRIVATE_UID, variableSetId)); if (options == null) { options = new QueryOptions(); } QueryOptions qOptions = new QueryOptions(options); qOptions.put(MongoDBCollection.ELEM_MATCH, projection); QueryResult<Study> studyQueryResult = get(query, qOptions); if (studyQueryResult.getResult().isEmpty() || studyQueryResult.first().getVariableSets().isEmpty()) { throw new CatalogDBException("VariableSet {id: " + variableSetId + "} does not exist."); } return endQuery("", startTime, studyQueryResult.first().getVariableSets()); }
Document doc = findOne(USER_INSTANCES, exploratoryCondition(user, exploratoryName), and(elemMatch(COMPUTATIONAL_RESOURCES, and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName), eq(COMPUTATIONAL_SPOT, true),
/** * 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; } }
public void updateSchedulerSyncFlag(String user, String exploratoryName, boolean syncFlag) { final String syncStartField = SCHEDULER_DATA + ".sync_start_required"; UpdateResult result; do { result = updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, and(ne(SCHEDULER_DATA, null), ne(syncStartField, syncFlag)))), set(computationalFieldFilter(syncStartField), syncFlag)); } while (result.getModifiedCount() != 0); }
/** * Updates the status of computational resource in Mongo database. * * @param dto object of computational resource status. * @return The result of an update operation. */ public UpdateResult updateComputationalStatus(ComputationalStatusDTO dto) { try { Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus()); return updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()), elemMatch(COMPUTATIONAL_RESOURCES, and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()), not(eq(STATUS, TERMINATED.toString()))))), new Document(SET, values)); } catch (Exception t) { throw new DlabException("Could not update computational resource status", t); } }
private void updateComputationalLibraryFields(LibInstallStatusDTO dto) { for (LibInstallDTO lib : dto.getLibs()) { try { Document values = updateComputationalLibraryFields(dto.getComputationalName(), lib, dto.getUptime()); updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()), elemMatch(COMPUTATIONAL_LIBS + "." + dto.getComputationalName(), libCondition(lib.getGroup(), lib.getName(), lib.getVersion()))), new Document(SET, values)); } catch (Exception e) { throw new DlabException(String.format("Could not update library %s for %s/%s", lib, dto.getExploratoryName(), dto.getComputationalName()), e); } } }
/** * Updates the status of exploratory notebooks in Mongo database. * * @param dto object of exploratory status info. * @return The result of an update operation. */ public int updateComputationalStatusesForExploratory(StatusEnvBaseDTO<?> dto) { Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus()); values.append(computationalFieldFilter(UPTIME), null); int count = 0; UpdateResult result; do { result = updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()), elemMatch(COMPUTATIONAL_RESOURCES, and(not(eq(STATUS, TERMINATED.toString())), not(eq(STATUS, dto.getStatus()))))), new Document(SET, values)); count += result.getModifiedCount(); } while (result.getModifiedCount() > 0); return count; }
elemMatch(COMPUTATIONAL_RESOURCES, and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()), not(eq(STATUS, TERMINATED.toString()))))),