Browse Source

DATAMONGO-2671 - Fix dateFromParts millisecond field name.

Use millisecond instead of milliseconds field name.

Related to: https://jira.mongodb.org/browse/DOCS-10652
Original pull request: #897.
pull/3541/head
Christoph Strobl 5 years ago committed by Mark Paluch
parent
commit
a0d5c2bded
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 60
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/DateOperators.java
  2. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java
  3. 12
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java
  4. 8
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java

60
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/DateOperators.java

@ -1829,34 +1829,74 @@ public class DateOperators { @@ -1829,34 +1829,74 @@ public class DateOperators {
}
/**
* Set the {@literal milliseconds} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
* Set the {@literal millisecond} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
* a simple value, {@link Field field reference} or {@link AggregationExpression expression}.
*
* @param milliseconds must not be {@literal null}.
* @param millisecond must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal milliseconds} is {@literal null}
* @throws IllegalArgumentException if given {@literal millisecond} is {@literal null}
* @deprecated use {@link #millisecond(Object)} instead.
*/
T milliseconds(Object milliseconds);
@Deprecated
default T milliseconds(Object millisecond) {
return millisecond(millisecond);
}
/**
* Set the {@literal millisecond} to the given value which must resolve to a value in range {@code 0 - 999}. Can be
* a simple value, {@link Field field reference} or {@link AggregationExpression expression}.
*
* @param millisecond must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal millisecond} is {@literal null}
*/
T millisecond(Object millisecond);
/**
* Set the {@literal milliseconds} to the value resolved by following the given {@link Field field reference}.
* Set the {@literal millisecond} to the value resolved by following the given {@link Field field reference}.
*
* @param fieldReference must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal fieldReference} is {@literal null}.
* @deprecated use {@link #millisecondOf(String)} instead.
*/
@Deprecated
default T millisecondsOf(String fieldReference) {
return millisecondOf(fieldReference);
}
/**
* Set the {@literal millisecond} to the value resolved by following the given {@link Field field reference}.
*
* @param fieldReference must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal fieldReference} is {@literal null}.
*/
default T millisecondOf(String fieldReference) {
return milliseconds(Fields.field(fieldReference));
}
/**
* Set the {@literal milliseconds} to the result of the given {@link AggregationExpression expression}.
* Set the {@literal millisecond} to the result of the given {@link AggregationExpression expression}.
*
* @param expression must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal expression} is {@literal null}.
* @deprecated use {@link #millisecondOf(AggregationExpression)} instead.
*/
@Deprecated
default T millisecondsOf(AggregationExpression expression) {
return millisecondOf(expression);
}
/**
* Set the {@literal milliseconds} to the result of the given {@link AggregationExpression expression}.
*
* @param expression must not be {@literal null}.
* @return new instance.
* @throws IllegalArgumentException if given {@literal expression} is {@literal null}.
*/
default T millisecondOf(AggregationExpression expression) {
return milliseconds(expression);
}
}
@ -1971,8 +2011,8 @@ public class DateOperators { @@ -1971,8 +2011,8 @@ public class DateOperators {
}
@Override
public DateFromParts milliseconds(Object milliseconds) {
return new DateFromParts(append("milliseconds", milliseconds));
public DateFromParts millisecond(Object millisecond) {
return new DateFromParts(append("millisecond", millisecond));
}
/**
@ -2147,8 +2187,8 @@ public class DateOperators { @@ -2147,8 +2187,8 @@ public class DateOperators {
}
@Override
public IsoDateFromParts milliseconds(Object milliseconds) {
return new IsoDateFromParts(append("milliseconds", milliseconds));
public IsoDateFromParts millisecond(Object millisecond) {
return new IsoDateFromParts(append("millisecond", millisecond));
}
/**

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/MethodReferenceNode.java

@ -145,9 +145,9 @@ public class MethodReferenceNode extends ExpressionNode { @@ -145,9 +145,9 @@ public class MethodReferenceNode extends ExpressionNode {
map.put("dateFromString", mapArgRef().forOperator("$dateFromString") //
.mappingParametersTo("dateString", "format", "timezone", "onError", "onNull"));
map.put("dateFromParts", mapArgRef().forOperator("$dateFromParts").mappingParametersTo("year", "month", "day",
"hour", "minute", "second", "milliseconds", "timezone"));
"hour", "minute", "second", "millisecond", "timezone"));
map.put("isoDateFromParts", mapArgRef().forOperator("$dateFromParts").mappingParametersTo("isoWeekYear", "isoWeek",
"isoDayOfWeek", "hour", "minute", "second", "milliseconds", "timezone"));
"isoDayOfWeek", "hour", "minute", "second", "millisecond", "timezone"));
map.put("dateToParts", mapArgRef().forOperator("$dateToParts") //
.mappingParametersTo("date", "timezone", "iso8601"));
map.put("isoDayOfWeek", singleArgRef().forOperator("$isoDayOfWeek"));

12
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/ProjectionOperationUnitTests.java

@ -1990,15 +1990,15 @@ public class ProjectionOperationUnitTests { @@ -1990,15 +1990,15 @@ public class ProjectionOperationUnitTests {
assertThat(agg).isEqualTo(Document.parse("{ $project : { newDate: { $dateFromParts: { year : 2018 } } } }"));
}
@Test // DATAMONGO-1834
@Test // DATAMONGO-1834, DATAMONGO-2671
public void shouldRenderDateFromParts() {
Document agg = project()
.and(DateOperators.dateFromParts().year(2018).month(3).day(23).hour(14).minute(25).second(10).milliseconds(2))
.and(DateOperators.dateFromParts().year(2018).month(3).day(23).hour(14).minute(25).second(10).millisecond(2))
.as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
assertThat(agg).isEqualTo(Document.parse(
"{ $project : { newDate: { $dateFromParts: { year : 2018, month : 3, day : 23, hour : 14, minute : 25, second : 10, milliseconds : 2 } } } }"));
"{ $project : { newDate: { $dateFromParts: { year : 2018, month : 3, day : 23, hour : 14, minute : 25, second : 10, millisecond : 2 } } } }"));
}
@Test // DATAMONGO-1834
@ -2021,14 +2021,14 @@ public class ProjectionOperationUnitTests { @@ -2021,14 +2021,14 @@ public class ProjectionOperationUnitTests {
assertThat(agg).isEqualTo(Document.parse("{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018 } } } }"));
}
@Test // DATAMONGO-1834
@Test // DATAMONGO-1834, DATAMONGO-2671
public void shouldRenderIsoDateFromParts() {
Document agg = project().and(DateOperators.dateFromParts().isoWeekYear(2018).isoWeek(12).isoDayOfWeek(5).hour(14)
.minute(30).second(42).milliseconds(2)).as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
.minute(30).second(42).millisecond(2)).as("newDate").toDocument(Aggregation.DEFAULT_CONTEXT);
assertThat(agg).isEqualTo(Document.parse(
"{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018, isoWeek : 12, isoDayOfWeek : 5, hour : 14, minute : 30, second : 42, milliseconds : 2 } } } }"));
"{ $project : { newDate: { $dateFromParts: { isoWeekYear : 2018, isoWeek : 12, isoDayOfWeek : 5, hour : 14, minute : 30, second : 42, millisecond : 2 } } } }"));
}
@Test // DATAMONGO-1834

8
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/aggregation/SpelExpressionTransformerUnitTests.java

@ -902,18 +902,18 @@ public class SpelExpressionTransformerUnitTests { @@ -902,18 +902,18 @@ public class SpelExpressionTransformerUnitTests {
"{ \"$dateFromString\" : {\"dateString\" : \"$field\", \"format\" : \"DD-MM-YYYY\", \"timezone\" : \"UTC\", \"onError\" : -1, \"onNull\" : -2}}"));
}
@Test // DATAMONGO-2077
@Test // DATAMONGO-2077, DATAMONGO-2671
public void shouldRenderDateFromParts() {
assertThat(transform("dateFromParts(y, m, d, h, mm, s, ms, 'UTC')")).isEqualTo(Document.parse(
"{ \"$dateFromParts\" : {\"year\" : \"$y\", \"month\" : \"$m\", \"day\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"milliseconds\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
"{ \"$dateFromParts\" : {\"year\" : \"$y\", \"month\" : \"$m\", \"day\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"millisecond\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
}
@Test // DATAMONGO-2077
@Test // DATAMONGO-2077, DATAMONGO-2671
public void shouldRenderIsoDateFromParts() {
assertThat(transform("isoDateFromParts(y, m, d, h, mm, s, ms, 'UTC')")).isEqualTo(Document.parse(
"{ \"$dateFromParts\" : {\"isoWeekYear\" : \"$y\", \"isoWeek\" : \"$m\", \"isoDayOfWeek\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"milliseconds\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
"{ \"$dateFromParts\" : {\"isoWeekYear\" : \"$y\", \"isoWeek\" : \"$m\", \"isoDayOfWeek\" : \"$d\", \"hour\" : \"$h\", \"minute\" : \"$mm\", \"second\" : \"$s\", \"millisecond\" : \"$ms\", \"timezone\" : \"UTC\"}}"));
}
@Test // DATAMONGO-2077

Loading…
Cancel
Save