Skip to content

Commit

Permalink
Release 0.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
krraghavan committed Jul 10, 2024
1 parent d300b80 commit 83358d5
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Java CI with Maven](https://github.com/krraghavan/mongodb-aggregate-query-support/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/krraghavan/mongodb-aggregate-query-support/actions/workflows/maven.yml)[![Release Version](https://img.shields.io/badge/version-v0.9.2-red.svg)](https://github.com/krraghavan/mongodb-aggregate-query-support) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://img.shields.io/hexpm/l/plug.svg)
[![Java CI with Maven](https://github.com/krraghavan/mongodb-aggregate-query-support/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/krraghavan/mongodb-aggregate-query-support/actions/workflows/maven.yml)[![Release Version](https://img.shields.io/badge/version-v0.9.3-red.svg)](https://github.com/krraghavan/mongodb-aggregate-query-support) [![License](https://img.shields.io/hexpm/l/plug.svg)](https://img.shields.io/hexpm/l/plug.svg)

# MONGO DB AGGREGATE QUERY SUPPORT
This module provides annotated support for MongoDB aggregate queries much like the @Query annotation provided by the
Expand All @@ -8,6 +8,9 @@ The @Query annotation provided by Spring Data MongoDb allows queries to be execu
It is highly desirable to have a similar mechanism for MongoDB aggregate queries which allow us to execute sophisticated
queries with practically no code being written.

## New in 0.9.3 version
1. [Bug 49](https://github.com/krraghavan/mongodb-aggregate-query-support/issues/49): Fixed Date parsing when msecs are separated by dot (.).

## New in 0.9.2 version
1. Fixed date parsing in extended Bson parsing, longs, and ISO string formats with and without msecs is now correctly deserialized. See [Mongo Extended BSON Date](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Date)
1. Date in long format: ```{"$date":{"$numberLong":"1710005987717"}}```
Expand Down
2 changes: 1 addition & 1 deletion mongodb-aggregate-query-support-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>mongodb-aggregate-query-support</artifactId>
<groupId>com.github.krraghavan</groupId>
<version>0.9.3-SNAPSHOT</version>
<version>0.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
public class BsonDateToDateDeserializer extends GenericMongoExtendedJsonDeserializer<Date> {

private static final String NODE_KEY = "$date";
public static final String DATETIME_FORMAT_ERROR_MSG = "Only ISO date format (with or without msecs) is supported. If " +
"msecs are specified it can be HH:mm:ss.SSS or HH:mm:ss,SSS" +
"Could not deserialize: %s";

public BsonDateToDateDeserializer() {
super(Date.class, NODE_KEY);
Expand All @@ -41,14 +44,25 @@ protected Date doDeserialize(JsonNode s) {
return df.parse(dateTextValue);
}
catch (ParseException e) {
// try with no msecs
DateFormat dfNoMsec = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
return dfNoMsec.parse(dateTextValue);
// try msecs with dot
DateFormat dfMsecWithDot = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
try {
return dfMsecWithDot.parse(dateTextValue);
}
catch (ParseException ex) {
throw new UnsupportedOperationException(String.format(DATETIME_FORMAT_ERROR_MSG, dateTextValue), e);
}
}
catch (ParseException ex) {
throw new UnsupportedOperationException("Only ISO date format (with or without msecs) is supported. " +
"Could not deserialize " + dateTextValue, e);
catch (Exception e2) {
// try with no msecs
DateFormat dfNoMsec = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
return dfNoMsec.parse(dateTextValue);
}
catch (ParseException ex) {
throw new UnsupportedOperationException(String.format(DATETIME_FORMAT_ERROR_MSG, dateTextValue), e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static class TestBean {
DateFormat dfNoMsec = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String nowAsISONoMsec = dfNoMsec.format(expectedDate);
Date expectedDateNoMsec = dfNoMsec.parse(nowAsISONoMsec);
DateFormat dfMsecWithDot = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String nowAsISOMsecWithDot = dfMsecWithDot.format(expectedDate);
Date expectedDateWithDot = dfMsecWithDot.parse(nowAsISOMsecWithDot);
return new Object[][] {
// milliseconds
new Object[] {"{\"someDate\":" + String.format("{\"$date\":{\"$numberLong\":\"%s\"}}", epochMilli) + "}",
Expand All @@ -43,6 +46,8 @@ public static class TestBean {
new Object[] {"{\"someDate\":{\"$date\":\"" + nowAsISOMsec + "\"}}", expectedDate},
// ISO String, no msec
new Object[] {"{\"someDate\":{\"$date\":\"" + nowAsISONoMsec + "\"}}", expectedDateNoMsec},
// ISO String, msec with dot - fixes https://github.com/krraghavan/mongodb-aggregate-query-support/issues/49
new Object[] {"{\"someDate\":{\"$date\":\"" + nowAsISOMsecWithDot + "\"}}", expectedDateWithDot},
};
}

Expand All @@ -52,4 +57,5 @@ public void mustDeserializeDatesInDifferentFormats(String json, Date expectedDat
Assert.assertEquals(testBean.someDate, expectedDate);
}


}
13 changes: 12 additions & 1 deletion mongodb-aggregate-query-support-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.github.krraghavan</groupId>
<artifactId>mongodb-aggregate-query-support</artifactId>
<version>0.9.3-SNAPSHOT</version>
<version>0.9.3</version>
<relativePath>../../mongodb-aggregate-query-support/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -63,6 +63,17 @@
<artifactId>mongodb-aggregate-query-support-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
</dependencies>

Expand Down
13 changes: 12 additions & 1 deletion mongodb-aggregate-query-support-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.github.krraghavan</groupId>
<artifactId>mongodb-aggregate-query-support</artifactId>
<version>0.9.3-SNAPSHOT</version>
<version>0.9.3</version>
<relativePath>../../mongodb-aggregate-query-support/pom.xml</relativePath>
</parent>

Expand All @@ -51,6 +51,17 @@
<artifactId>mongodb-aggregate-query-support-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
</dependencies>

Expand Down
13 changes: 12 additions & 1 deletion mongodb-aggregate-query-support-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.krraghavan</groupId>
<artifactId>mongodb-aggregate-query-support</artifactId>
<version>0.9.3-SNAPSHOT</version>
<version>0.9.3</version>
</parent>

<artifactId>mongodb-aggregate-query-support-test</artifactId>
Expand All @@ -26,6 +26,17 @@
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${embedded-mongo-version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.krraghavan</groupId>
<artifactId>mongodb-aggregate-query-support</artifactId>
<version>0.9.3-SNAPSHOT</version>
<version>0.9.3</version>

<packaging>pom</packaging>

Expand Down Expand Up @@ -59,6 +59,7 @@
<mongo7.version>7.0.4</mongo7.version>
<testng.version>7.7.0</testng.version>

<commons-compress.version>1.26.2</commons-compress.version>
</properties>

<name>Mongo DB Aggregation Query Support</name>
Expand Down Expand Up @@ -139,7 +140,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.11.0</version>
<version>2.23.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -373,12 +374,12 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 83358d5

Please sign in to comment.