Search in sources :

Example 1 with ExposedField

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

the class ProjectionOperation method getFields.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.aggregation.FieldsExposingAggregationOperation#getFields()
	 */
@Override
public ExposedFields getFields() {
    ExposedFields fields = null;
    for (Projection projection : projections) {
        ExposedField field = projection.getExposedField();
        fields = fields == null ? ExposedFields.from(field) : fields.and(field);
    }
    return fields != null ? fields : ExposedFields.empty();
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) FieldProjection(org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.FieldProjection)

Example 2 with ExposedField

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

the class ExposedFields method createFields.

/**
 * Creates a new {@link ExposedFields} instance for the given fields in either synthetic or non-synthetic way.
 *
 * @param fields must not be {@literal null}.
 * @param synthetic
 * @return
 */
private static ExposedFields createFields(Fields fields, boolean synthetic) {
    Assert.notNull(fields, "Fields must not be null!");
    List<ExposedField> result = new ArrayList<ExposedField>();
    for (Field field : fields) {
        result.add(new ExposedField(field, synthetic));
    }
    return from(result);
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) ArrayList(java.util.ArrayList)

Example 3 with ExposedField

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

the class TypeBasedAggregationOperationContext method getReferenceFor.

private FieldReference getReferenceFor(Field field) {
    PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(field.getTarget(), type);
    Field mappedField = field(field.getName(), propertyPath.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE));
    return new DirectFieldReference(new ExposedField(mappedField, true));
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) DirectFieldReference(org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference)

Example 4 with ExposedField

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

the class TypeBasedAggregationOperationContextUnitTests method aliasesIdFieldCorrectly.

// DATAMONGO-806
@Test
public void aliasesIdFieldCorrectly() {
    AggregationOperationContext context = getContext(Foo.class);
    assertThat(context.getReference("id"), is(new DirectFieldReference(new ExposedField(field("id", "_id"), true))));
}
Also used : ExposedField(org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField) DirectFieldReference(org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference) Test(org.junit.Test)

Aggregations

ExposedField (org.springframework.data.mongodb.core.aggregation.ExposedFields.ExposedField)4 DirectFieldReference (org.springframework.data.mongodb.core.aggregation.ExposedFields.DirectFieldReference)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FieldProjection (org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.FieldProjection)1 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)1