Search in sources :

Example 1 with RelaxedTypeBasedAggregationOperationContext

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

the class AggregationUtil method createAggregationContext.

AggregationOperationContext createAggregationContext(Aggregation aggregation, @Nullable Class<?> inputType) {
    DomainTypeMapping domainTypeMapping = aggregation.getOptions().getDomainTypeMapping();
    if (domainTypeMapping == DomainTypeMapping.NONE) {
        return Aggregation.DEFAULT_CONTEXT;
    }
    if (!(aggregation instanceof TypedAggregation)) {
        if (inputType == null) {
            return untypedMappingContext.get();
        }
        if (domainTypeMapping == DomainTypeMapping.STRICT && !aggregation.getPipeline().containsUnionWith()) {
            return new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
        }
        return new RelaxedTypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
    }
    inputType = ((TypedAggregation<?>) aggregation).getInputType();
    if (domainTypeMapping == DomainTypeMapping.STRICT && !aggregation.getPipeline().containsUnionWith()) {
        return new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
    }
    return new RelaxedTypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper);
}
Also used : DomainTypeMapping(org.springframework.data.mongodb.core.aggregation.AggregationOptions.DomainTypeMapping) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Example 2 with RelaxedTypeBasedAggregationOperationContext

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

the class ReactiveMongoTemplate method prepareFilter.

List<Document> prepareFilter(ChangeStreamOptions options) {
    Object filter = options.getFilter().orElse(Collections.emptyList());
    if (filter instanceof Aggregation) {
        Aggregation agg = (Aggregation) filter;
        AggregationOperationContext context = agg instanceof TypedAggregation ? new TypeBasedAggregationOperationContext(((TypedAggregation<?>) agg).getInputType(), getConverter().getMappingContext(), queryMapper) : new RelaxedTypeBasedAggregationOperationContext(Object.class, mappingContext, queryMapper);
        return agg.toPipeline(new PrefixingDelegatingAggregationOperationContext(context, "fullDocument", Arrays.asList("operationType", "fullDocument", "documentKey", "updateDescription", "ns")));
    }
    if (filter instanceof List) {
        return (List<Document>) filter;
    }
    throw new IllegalArgumentException("ChangeStreamRequestOptions.filter mut be either an Aggregation or a plain list of Documents");
}
Also used : Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) AggregationOperationContext(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext) PrefixingDelegatingAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) ArrayList(java.util.ArrayList) List(java.util.List) RelaxedTypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext) TypeBasedAggregationOperationContext(org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)

Aggregations

RelaxedTypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext)2 TypeBasedAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.TypeBasedAggregationOperationContext)2 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1 AggregationOperationContext (org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)1 DomainTypeMapping (org.springframework.data.mongodb.core.aggregation.AggregationOptions.DomainTypeMapping)1 PrefixingDelegatingAggregationOperationContext (org.springframework.data.mongodb.core.aggregation.PrefixingDelegatingAggregationOperationContext)1