Search in sources :

Example 1 with TypeBasedAggregationOperationContext

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

the class MongoTemplate method aggregate.

/* (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.MongoOperations#aggregate(org.springframework.data.mongodb.core.aggregation.TypedAggregation, java.lang.String, java.lang.Class)
	 */
@Override
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) {
    Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
    AggregationOperationContext context = new TypeBasedAggregationOperationContext(aggregation.getInputType(), mappingContext, queryMapper);
    return aggregate(aggregation, inputCollectionName, outputType, context);
}
Also used : AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Example 2 with TypeBasedAggregationOperationContext

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

the class ReactiveMongoTemplate method aggregate.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#aggregate(org.springframework.data.mongodb.core.aggregation.TypedAggregation, java.lang.String, java.lang.Class)
	 */
@Override
public <O> Flux<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) {
    Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
    AggregationOperationContext context = new TypeBasedAggregationOperationContext(aggregation.getInputType(), mappingContext, queryMapper);
    return aggregate(aggregation, inputCollectionName, outputType, context);
}
Also used : AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Example 3 with TypeBasedAggregationOperationContext

use of org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext 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 4 with TypeBasedAggregationOperationContext

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

the class MongoTemplate method aggregateStream.

/* (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.MongoOperations#aggregateStream(org.springframework.data.mongodb.core.aggregation.TypedAggregation, java.lang.String, java.lang.Class)
	 */
@Override
public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType) {
    Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
    AggregationOperationContext context = new TypeBasedAggregationOperationContext(aggregation.getInputType(), mappingContext, queryMapper);
    return aggregateStream(aggregation, inputCollectionName, outputType, context);
}
Also used : AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Example 5 with TypeBasedAggregationOperationContext

use of org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext 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)5 TypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)5 PrefixingDelegatingAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext)3 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