Search in sources :

Example 1 with PrefixingDelegatingAggregationOperationContext

use of org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext in project spring-data-mongodb by spring-projects.

the class ChangeStreamTask method prepareFilter.

List<Document> prepareFilter(MongoTemplate template, ChangeStreamOptions options) {
    if (!options.getFilter().isPresent()) {
        return Collections.emptyList();
    }
    Object filter = options.getFilter().get();
    if (filter instanceof Aggregation) {
        Aggregation agg = (Aggregation) filter;
        AggregationOperationContext context = agg instanceof TypedAggregation ? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(), template.getConverter().getMappingContext(), queryMapper) : Aggregation.DEFAULT_CONTEXT;
        return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", blacklist));
    } else if (filter instanceof List) {
        return (List<Document>) filter;
    } else {
        throw new IllegalArgumentException("ChangeStreamRequestOptions.filter mut be either an Aggregation or a plain list of Documents");
    }
}
Also used : TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) List(java.util.List) Document(org.bson.Document) ChangeStreamDocument(com.mongodb.client.model.changestream.ChangeStreamDocument) BsonDocument(org.bson.BsonDocument) FullDocument(com.mongodb.client.model.changestream.FullDocument) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Example 2 with PrefixingDelegatingAggregationOperationContext

use of org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplate method changeStream.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#tail(org.springframework.data.mongodb.core.aggregation.Aggregation, java.lang.Class, org.springframework.data.mongodb.core.ChangeStreamOptions, java.lang.String)
	 */
@Override
public <T> Flux<ChangeStreamEvent<T>> changeStream(@Nullable Aggregation filter, Class<T> resultType, ChangeStreamOptions options, String collectionName) {
    Assert.notNull(resultType, "Result type must not be null!");
    Assert.notNull(options, "ChangeStreamOptions must not be null!");
    Assert.hasText(collectionName, "Collection name must not be null or empty!");
    if (filter == null) {
        return changeStream(Collections.emptyList(), resultType, options, collectionName);
    }
    AggregationOperationContext context = filter instanceof TypedAggregation ? new TypeBasedAggregationOperationContext(((TypedAggregation) filter).getInputType(), mappingContext, queryMapper) : Aggregation.DEFAULT_CONTEXT;
    return changeStream(filter.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", Arrays.asList("operationType", "fullDocument", "documentKey", "updateDescription", "ns"))), resultType, options, collectionName);
}
Also used : PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Aggregations

AggregationOperationContext (org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)2 PrefixingDelegatingAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext)2 TypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)2 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)2 ChangeStreamDocument (com.mongodb.client.model.changestream.ChangeStreamDocument)1 FullDocument (com.mongodb.client.model.changestream.FullDocument)1 List (java.util.List)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1