15
15
*/
16
16
package org .springframework .data .mongodb .core ;
17
17
18
- import java .util .Arrays ;
19
- import java .util .Collections ;
20
18
import java .util .List ;
21
19
import java .util .Optional ;
22
20
import java .util .stream .Collectors ;
23
21
24
22
import org .bson .Document ;
25
23
import org .springframework .data .mapping .context .MappingContext ;
26
24
import org .springframework .data .mongodb .core .aggregation .Aggregation ;
27
- import org .springframework .data .mongodb .core .aggregation .AggregationOperation ;
28
25
import org .springframework .data .mongodb .core .aggregation .AggregationOperationContext ;
29
- import org .springframework .data .mongodb .core .aggregation .AggregationOptions ;
30
26
import org .springframework .data .mongodb .core .aggregation .AggregationOptions .DomainTypeMapping ;
31
- import org .springframework .data .mongodb .core .aggregation .CountOperation ;
32
27
import org .springframework .data .mongodb .core .aggregation .RelaxedTypeBasedAggregationOperationContext ;
33
28
import org .springframework .data .mongodb .core .aggregation .TypeBasedAggregationOperationContext ;
34
29
import org .springframework .data .mongodb .core .aggregation .TypedAggregation ;
35
30
import org .springframework .data .mongodb .core .convert .QueryMapper ;
36
31
import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
37
32
import org .springframework .data .mongodb .core .mapping .MongoPersistentProperty ;
38
- import org .springframework .data .mongodb .core .query .CriteriaDefinition ;
39
- import org .springframework .data .mongodb .core .query .Query ;
40
33
import org .springframework .data .util .Lazy ;
41
34
import org .springframework .lang .Nullable ;
42
- import org .springframework .util .Assert ;
43
- import org .springframework .util .ObjectUtils ;
44
35
45
36
/**
46
37
* Utility methods to map {@link org.springframework.data.mongodb.core.aggregation.Aggregation} pipeline definitions and
@@ -75,21 +66,19 @@ AggregationOperationContext createAggregationContext(Aggregation aggregation, @N
75
66
76
67
if (!(aggregation instanceof TypedAggregation )) {
77
68
78
- if (inputType == null ) {
69
+ if (inputType == null ) {
79
70
return untypedMappingContext .get ();
80
71
}
81
72
82
- if (domainTypeMapping == DomainTypeMapping .STRICT
83
- && !aggregation .getPipeline ().containsUnionWith ()) {
73
+ if (domainTypeMapping == DomainTypeMapping .STRICT && !aggregation .getPipeline ().containsUnionWith ()) {
84
74
return new TypeBasedAggregationOperationContext (inputType , mappingContext , queryMapper );
85
75
}
86
76
87
77
return new RelaxedTypeBasedAggregationOperationContext (inputType , mappingContext , queryMapper );
88
78
}
89
79
90
80
inputType = ((TypedAggregation <?>) aggregation ).getInputType ();
91
- if (domainTypeMapping == DomainTypeMapping .STRICT
92
- && !aggregation .getPipeline ().containsUnionWith ()) {
81
+ if (domainTypeMapping == DomainTypeMapping .STRICT && !aggregation .getPipeline ().containsUnionWith ()) {
93
82
return new TypeBasedAggregationOperationContext (inputType , mappingContext , queryMapper );
94
83
}
95
84
@@ -104,12 +93,7 @@ AggregationOperationContext createAggregationContext(Aggregation aggregation, @N
104
93
* @return
105
94
*/
106
95
List <Document > createPipeline (Aggregation aggregation , AggregationOperationContext context ) {
107
-
108
- if (ObjectUtils .nullSafeEquals (context , Aggregation .DEFAULT_CONTEXT )) {
109
- return aggregation .toPipeline (context );
110
- }
111
-
112
- return mapAggregationPipeline (aggregation .toPipeline (context ));
96
+ return aggregation .toPipeline (context );
113
97
}
114
98
115
99
/**
@@ -120,16 +104,7 @@ List<Document> createPipeline(Aggregation aggregation, AggregationOperationConte
120
104
* @return
121
105
*/
122
106
Document createCommand (String collection , Aggregation aggregation , AggregationOperationContext context ) {
123
-
124
- Document command = aggregation .toDocument (collection , context );
125
-
126
- if (!ObjectUtils .nullSafeEquals (context , Aggregation .DEFAULT_CONTEXT )) {
127
- return command ;
128
- }
129
-
130
- command .put ("pipeline" , mapAggregationPipeline (command .get ("pipeline" , List .class )));
131
-
132
- return command ;
107
+ return aggregation .toDocument (collection , context );
133
108
}
134
109
135
110
private List <Document > mapAggregationPipeline (List <Document > pipeline ) {
0 commit comments