Skip to content

Commit

Permalink
feat: allow to support jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
ajclopez committed Jun 6, 2024
1 parent deb6735 commit f0d4e02
Show file tree
Hide file tree
Showing 22 changed files with 392 additions and 428 deletions.
30 changes: 16 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@ jobs:
environment:
JVM_OPTS: -Xmx3200m
docker:
- image: circleci/openjdk:14-jdk-buster-node

- image: circleci/openjdk:17-jdk-buster-node
working_directory: ~/project

steps:
- checkout
- restore_cache:
keys:
- mongo-spring-search-{{ checksum "pom.xml" }}
- mongo-spring-search-

- run: mvn dependency:go-offline

- run:
name: Download dependencies
command: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: mongo-spring-search-{{ checksum "pom.xml" }}

# run tests!
- run: mvn clean test
- run:
name: Run tests
command: mvn clean test
- store_artifacts:
path: target/surefire-reports
destination: surefire-reports
- store_artifacts:
path: ~/project/target/coverage-reports
- codecov/upload:
file: ~/project/target/coverage-reports/jacoco/jacoco.xml
flags: coverage
upload_name: Coverage
path: target/coverage-reports
destination: coverage-reports
- run:
name: Upload coverage to Codecov
command: bash <(curl -s https://codecov.io/bash) -f target/coverage-reports/jacoco/jacoco.xml


workflows:
version: 2
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ You could create custom repository methods to perform your searches. You could a

##### Maven

Include the dependency to your project inside your `pom.xml` file
Include the dependency to your project inside your `pom.xml` file.

For Java 17:
```xml
<dependency>
<groupId>io.github.ajclopez</groupId>
<artifactId>mongo-spring-search</artifactId>
<version>2.0.0</version>
</dependency>
```

For Java 14:
```xml
<dependency>
<groupId>io.github.ajclopez</groupId>
Expand All @@ -64,10 +74,20 @@ Include the dependency to your project inside your `pom.xml` file

Add implementation to your project in your `build.gradle` file

For Java 17:
```
implementation 'io.github.ajclopez:mongo-spring-search:2.0.0'
````
For Java 14:
```
implementation 'io.github.ajclopez:mongo-spring-search:1.0.5'
````
#### Note
- **Version 2.x.x:** Requires Java 17.
- **Version 1.x.x:** Requires Java 14.
## Usage
Converts query into a MongoDB query object.
Expand Down
53 changes: 35 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.ajclopez</groupId>
<artifactId>mongo-spring-search</artifactId>
<version>1.0.5</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>mongo-spring-search</name>
Expand All @@ -29,16 +29,16 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>14</java.version>
<junit.version>4.13.1</junit.version>
<spring.data.mongodb.version>3.4.5</spring.data.mongodb.version>
<antlr.version>4.9</antlr.version>
<java.version>17</java.version>
<junit.version>5.10.2</junit.version>
<spring.data.mongodb.version>4.3.0</spring.data.mongodb.version>
<antlr.version>4.13.1</antlr.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Expand All @@ -62,16 +62,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>14</source>
<target>14</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5</version> <!-- use older version to process Query.g4, the latest version (4.9) could not find the file. -->
<version>4.13.1</version> <!-- use older version to process Query.g4, the latest version (4.9) could not find the file. -->
<configuration>
<listener>true</listener>
<visitor>true</visitor>
Expand All @@ -93,7 +93,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand All @@ -111,7 +111,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.2.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -131,7 +131,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -151,11 +151,11 @@
</goals>
</execution>
</executions>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.6.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -165,10 +165,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<version>0.8.12</version>
<configuration>
<excludes>
<exclude>io/github/ajclopez/mss/Query*</exclude>
Expand Down Expand Up @@ -233,6 +243,13 @@
<developerConnection>scm:git:ssh://github.com:ajclopez/mongo-spring-search.git</developerConnection>
<url>https://github.com/ajclopez/mongo-spring-search/tree/master</url>
</scm>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<distributionManagement>
<snapshotRepository>
Expand Down
2 changes: 1 addition & 1 deletion src/main/antlr4/Query.g4
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ NEG_IDENTIFIER
;
ENCODED_STRING
: ~([ \[\]<>!=()])+
: ~([ \\[\]<>!=()])+
;
LineTerminator
Expand Down
42 changes: 23 additions & 19 deletions src/main/java/io/github/ajclopez/mss/MongoSpringSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import io.github.ajclopez.mss.criteria.CriteriaImpl;
import io.github.ajclopez.mss.criteria.CriteriaQueryVisitor;
import io.github.ajclopez.mss.exception.ArgumentNotValidException;
import io.github.ajclopez.mss.model.*;
import io.github.ajclopez.mss.model.Configuration;
import io.github.ajclopez.mss.model.SearchCriteria;
import io.github.ajclopez.mss.model.CastType;
import io.github.ajclopez.mss.model.KeySearchOperation;
import io.github.ajclopez.mss.model.SortSearchOperation;
import io.github.ajclopez.mss.parser.QueryParser;
import io.github.ajclopez.mss.pattern.SearchPatterns;
import org.antlr.v4.runtime.CharStreams;
Expand Down Expand Up @@ -61,17 +65,13 @@ public static Query mss(String query, Optional<Configuration> configuration) thr

Query mongoQuery = new Query();

List<SearchCriteria> filters = new ArrayList<SearchCriteria>();
List<SearchCriteria> filters = new ArrayList<>();

Map<String, CastType> casters = configuration.isPresent() ? configuration.get().getCasters() : null;
Map<String, CastType> casters = configuration.map(Configuration::casters).orElse(null);
Criteria filterCriteria = null;

for ( SearchCriteria criteria : QueryParser.parse(query, casters) ) {
switch (KeySearchOperation.getKeyOperation(criteria.getKey())) {
case DEFAULT:
default:
filters.add(criteria);
break;
case FILTER:
filterCriteria = parseFilterAdvanced(criteria.getValue(), casters);
break;
Expand All @@ -87,6 +87,10 @@ public static Query mss(String query, Optional<Configuration> configuration) thr
case SORT:
parseSort(mongoQuery, criteria.getValue());
break;
case DEFAULT:
default:
filters.add(criteria);
break;
}
}

Expand All @@ -99,21 +103,21 @@ private static void parseDefaultFilter(Query query, List<SearchCriteria> filters

Map<String, List<SearchCriteria>> groups = filters.stream().collect(Collectors.groupingBy(SearchCriteria::getKey));

List<Criteria> criterias = new ArrayList<Criteria>();
List<Criteria> criterias = new ArrayList<>();

if ( filterCriteria != null ) {
criterias.add(filterCriteria);
}

for ( String key : groups.keySet() ) {
for ( SearchCriteria criteria : groups.get(key) ) {
for ( Map.Entry<String, List<SearchCriteria>> entry : groups.entrySet() ) {
for ( SearchCriteria criteria : entry.getValue() ) {
criterias.add(CriteriaImpl.buildCriteria(criteria));
}
}

if ( !criterias.isEmpty() ) {

Criteria unique = filterCriteria != null ? filterCriteria : new Criteria().andOperator(criterias.toArray(new Criteria[criterias.size()]));
Criteria unique = filterCriteria != null ? filterCriteria : new Criteria().andOperator(criterias.toArray(new Criteria[criterias.size()]));
query.addCriteria(criterias.size() == 1 ? unique : new Criteria().andOperator(criterias.toArray(new Criteria[criterias.size()])));
}
}
Expand All @@ -129,9 +133,9 @@ private static void parseSkip(Query query, String value) {
private static void parseLimit(Query query, String value, Optional<Configuration> configuration) {
try {

Optional<Integer> maxLimit = configuration.isPresent()
? configuration.get().getMaxLimit() != null ? Optional.of(configuration.get().getMaxLimit()) : Optional.empty()
: Optional.empty();
Optional<Integer> maxLimit = configuration
.filter(config -> config.maxLimit() != null)
.map(Configuration::maxLimit);

if ( maxLimit.isPresent() ) {

Expand All @@ -143,8 +147,8 @@ private static void parseLimit(Query query, String value, Optional<Configuration
}

} catch(Exception e) {
if ( configuration.isPresent() && configuration.get().getDefaultLimit() != null ) {
query.limit(configuration.get().getDefaultLimit());
if ( configuration.isPresent() && configuration.get().defaultLimit() != null ) {
query.limit(configuration.get().defaultLimit());
return;
}

Expand Down Expand Up @@ -172,13 +176,13 @@ private static void parseSort(Query query, String value) {
}

switch (SortSearchOperation.getSortOperation(matcher.group(1))) {
case DESC:
query.with(Sort.by(Sort.Direction.DESC, matcher.group(2)));
break;
case ASC:
default:
query.with(Sort.by(Sort.Direction.ASC, matcher.group(2)));
break;
case DESC:
query.with(Sort.by(Sort.Direction.DESC, matcher.group(2)));
break;
}
}
}
Expand Down
Loading

0 comments on commit f0d4e02

Please sign in to comment.