@Override public void upgrade() { final FindIterable<Document> documentsWithMissingFields = collection.find(or(not(exists(ContentPack.FIELD_META_ID)), not(exists(ContentPack.FIELD_META_REVISION)))); for (Document document : documentsWithMissingFields) { final ObjectId objectId = document.getObjectId("_id"); LOG.debug("Found document with missing \"id\" or \"rev\" field with ID <{}>", objectId); final String id = document.get("id", objectId.toHexString()); final int rev = document.get("rev", 0); document.put("id", id); document.put("rev", rev); final UpdateResult updateResult = collection.replaceOne(eq("_id", objectId), document); if (updateResult.wasAcknowledged()) { LOG.debug("Successfully updated document with ID <{}>", objectId); } else { LOG.error("Failed to update document with ID <{}>", objectId); } } } }
/** * Creates a visitor to create policy-restriction Bson objects. * * @param authorizationSubjectsPredicate the predicate returning the "subject ids" of the search request. */ private CreatePolicyRestrictionBsonVisitor(final Predicate authorizationSubjectsPredicate) { grantedBson = CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_GRANTED); notRevokedBson = Filters.not(CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_REVOKED)); }
@Override public Bson visitNotExpr(NotExprContext ctx) { return not(this.visit(ctx.expr())); }
/** * Creates a visitor to create policy-restriction Bson objects. * * @param authorizationSubjectsPredicate the predicate returning the "subject ids" of the search request. */ private CreatePolicyRestrictionBsonVisitor(final Predicate authorizationSubjectsPredicate) { grantedBson = CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_GRANTED); notRevokedBson = Filters.not(CreateBsonPredicateVisitor.apply(authorizationSubjectsPredicate, PersistenceConstants.FIELD_GRANTS_REVOKED)); }
@Override public BsonFilterExpression visit(NotFilter filter, MongoResolutionContext<?> context) { final BsonFilterExpression toNegate = context.resolveOrFail(filter.getComposition().get(0), BsonFilterExpression.class); return toNegate.getPipeline() .map(pipeline -> BsonFilterExpression.create(Filters.not(pipeline.getMatch()), pipeline.getProjection().orElse(null))) .orElse(BsonFilterExpression.create(Filters.not(toNegate.getExpression()))); }
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))))); }
@Override public BsonFilterExpression visit(NullFilter filter, MongoResolutionContext<?> context) { // not exists or it is not null return resolveFieldName(filter.getLeftOperand(), context) .map(fn -> Filters.or(Filters.not(Filters.exists(fn)), Filters.type(fn, BsonType.NULL))) .map(bson -> BsonFilterExpression.create(bson)).orElse(null); }
@Override public BsonFilterExpression visit(NotNullFilter filter, MongoResolutionContext<?> context) { // exists and it is not null return resolveFieldName(filter.getLeftOperand(), context) .map(fn -> Filters.and(Filters.exists(fn), Filters.not(Filters.type(fn, BsonType.NULL)))) .map(bson -> BsonFilterExpression.create(bson)).orElse(null); }
@Override public Long getActiveConversationCount(String botId, Integer botVersion) { Bson query = Filters.and(Filters.eq("botId", botId), Filters.eq("botVersion", botVersion), Filters.not(new Document("conversationState", ENDED.toString()))); return conversationCollection.countDocuments(query); }
public boolean edgeNodeExist(String user) { return findOne(USER_EDGE, and(eq(ID, user), not(in(EDGE_STATUS, UserInstanceStatus.TERMINATING.toString(), UserInstanceStatus.TERMINATED.toString())))) .isPresent(); }
private Bson getQueryFindMedia(String hash, String api, String mediaType) { Bson addQuery = api == null ? not(exists("metadata.api")) : eq("metadata.api", api); return and(eq("metadata.type", mediaType), eq("metadata.hash", hash), addQuery); }
/** * Finds and returns the info of all user's notebooks whose status is absent among predefined ones. * * @param user user name. * @param statuses array of statuses. */ public List<UserInstanceDTO> fetchUserExploratoriesWhereStatusNotIn(String user, UserInstanceStatus... statuses) { final List<String> statusList = statusList(statuses); return getUserInstances( and( eq(USER, user), not(in(STATUS, statusList)) ), false); }
Filters.not(Filters.type(countByField, BsonType.NULL))))); if (!query.getDefinition().isDistinct()) {
/** * 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; }
and(eq(ComputationalDAO.COMPUTATIONAL_NAME, computationalName), eq(COMPUTATIONAL_SPOT, true), not(eq(STATUS, TERMINATED.toString())))), include(COMPUTATIONAL_RESOURCES + "." + COMPUTATIONAL_SPOT)) ).orElse(null);
/** * 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); } }
elemMatch(COMPUTATIONAL_RESOURCES, and(eq(COMPUTATIONAL_NAME, dto.getComputationalName()), not(eq(STATUS, TERMINATED.toString()))))), new Document(SET, values)); } catch (Exception t) {