28
28
import org .springframework .data .mongodb .core .aggregation .AggregationExpressions .Filter .AsBuilder ;
29
29
import org .springframework .data .mongodb .core .aggregation .AggregationExpressions .Let .ExpressionVariable ;
30
30
import org .springframework .data .mongodb .core .aggregation .ExposedFields .ExposedField ;
31
- import org .springframework .data .mongodb .core .aggregation .ExposedFields .FieldReference ;
32
31
import org .springframework .data .mongodb .core .query .CriteriaDefinition ;
33
32
import org .springframework .util .Assert ;
34
33
import org .springframework .util .ClassUtils ;
@@ -3905,31 +3904,19 @@ public static AsBuilder filter(List<?> values) {
3905
3904
*/
3906
3905
@ Override
3907
3906
public DBObject toDbObject (final AggregationOperationContext context ) {
3908
-
3909
- return toFilter (new ExposedFieldsAggregationOperationContext (ExposedFields .from (as ), context ) {
3910
-
3911
- @ Override
3912
- public FieldReference getReference (Field field ) {
3913
-
3914
- FieldReference ref = null ;
3915
- try {
3916
- ref = context .getReference (field );
3917
- } catch (Exception e ) {
3918
- // just ignore that one.
3919
- }
3920
- return ref != null ? ref : super .getReference (field );
3921
- }
3922
- });
3907
+ return toFilter (ExposedFields .from (as ), context );
3923
3908
}
3924
3909
3925
- private DBObject toFilter (AggregationOperationContext context ) {
3910
+ private DBObject toFilter (ExposedFields exposedFields , AggregationOperationContext context ) {
3926
3911
3927
3912
DBObject filterExpression = new BasicDBObject ();
3913
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
3914
+ exposedFields , context );
3928
3915
3929
3916
filterExpression .putAll (context .getMappedObject (new BasicDBObject ("input" , getMappedInput (context ))));
3930
3917
filterExpression .put ("as" , as .getTarget ());
3931
3918
3932
- filterExpression .putAll (context .getMappedObject (new BasicDBObject ("cond" , getMappedCondition (context ))));
3919
+ filterExpression .putAll (context .getMappedObject (new BasicDBObject ("cond" , getMappedCondition (operationContext ))));
3933
3920
3934
3921
return new BasicDBObject ("$filter" , filterExpression );
3935
3922
}
@@ -6019,27 +6006,14 @@ public Map andApply(final AggregationExpression expression) {
6019
6006
6020
6007
@ Override
6021
6008
public DBObject toDbObject (final AggregationOperationContext context ) {
6022
-
6023
- return toMap (new ExposedFieldsAggregationOperationContext (
6024
- ExposedFields .synthetic (Fields .fields (itemVariableName )), context ) {
6025
-
6026
- @ Override
6027
- public FieldReference getReference (Field field ) {
6028
-
6029
- FieldReference ref = null ;
6030
- try {
6031
- ref = context .getReference (field );
6032
- } catch (Exception e ) {
6033
- // just ignore that one.
6034
- }
6035
- return ref != null ? ref : super .getReference (field );
6036
- }
6037
- });
6009
+ return toMap (ExposedFields .synthetic (Fields .fields (itemVariableName )), context );
6038
6010
}
6039
6011
6040
- private DBObject toMap (AggregationOperationContext context ) {
6012
+ private DBObject toMap (ExposedFields exposedFields , AggregationOperationContext context ) {
6041
6013
6042
6014
BasicDBObject map = new BasicDBObject ();
6015
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
6016
+ exposedFields , context );
6043
6017
6044
6018
BasicDBObject input ;
6045
6019
if (sourceArray instanceof Field ) {
@@ -6050,7 +6024,8 @@ private DBObject toMap(AggregationOperationContext context) {
6050
6024
6051
6025
map .putAll (context .getMappedObject (input ));
6052
6026
map .put ("as" , itemVariableName );
6053
- map .put ("in" , functionToApply .toDbObject (new NestedDelegatingExpressionAggregationOperationContext (context )));
6027
+ map .put ("in" ,
6028
+ functionToApply .toDbObject (new NestedDelegatingExpressionAggregationOperationContext (operationContext )));
6054
6029
6055
6030
return new BasicDBObject ("$map" , map );
6056
6031
}
@@ -6792,22 +6767,7 @@ public interface LetBuilder {
6792
6767
6793
6768
@ Override
6794
6769
public DBObject toDbObject (final AggregationOperationContext context ) {
6795
-
6796
- return toLet (new ExposedFieldsAggregationOperationContext (
6797
- ExposedFields .synthetic (Fields .fields (getVariableNames ())), context ) {
6798
-
6799
- @ Override
6800
- public FieldReference getReference (Field field ) {
6801
-
6802
- FieldReference ref = null ;
6803
- try {
6804
- ref = context .getReference (field );
6805
- } catch (Exception e ) {
6806
- // just ignore that one.
6807
- }
6808
- return ref != null ? ref : super .getReference (field );
6809
- }
6810
- });
6770
+ return toLet (ExposedFields .synthetic (Fields .fields (getVariableNames ())), context );
6811
6771
}
6812
6772
6813
6773
private String [] getVariableNames () {
@@ -6816,20 +6776,23 @@ private String[] getVariableNames() {
6816
6776
for (int i = 0 ; i < this .vars .size (); i ++) {
6817
6777
varNames [i ] = this .vars .get (i ).variableName ;
6818
6778
}
6779
+
6819
6780
return varNames ;
6820
6781
}
6821
6782
6822
- private DBObject toLet (AggregationOperationContext context ) {
6783
+ private DBObject toLet (ExposedFields exposedFields , AggregationOperationContext context ) {
6823
6784
6824
6785
DBObject letExpression = new BasicDBObject ();
6825
-
6826
6786
DBObject mappedVars = new BasicDBObject ();
6787
+ InheritingExposedFieldsAggregationOperationContext operationContext = new InheritingExposedFieldsAggregationOperationContext (
6788
+ exposedFields , context );
6789
+
6827
6790
for (ExpressionVariable var : this .vars ) {
6828
6791
mappedVars .putAll (getMappedVariable (var , context ));
6829
6792
}
6830
6793
6831
6794
letExpression .put ("vars" , mappedVars );
6832
- letExpression .put ("in" , getMappedIn (context ));
6795
+ letExpression .put ("in" , getMappedIn (operationContext ));
6833
6796
6834
6797
return new BasicDBObject ("$let" , letExpression );
6835
6798
}
0 commit comments