From 33ad2cb03d3892940a76f1ca80610a017219b419 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 12:03:17 +0100 Subject: [PATCH 01/23] chore: bump spring, java and kotlin versions --- pom.xml | 8 ++++---- .../com/sipios/springsearch/SpecificationImpl.kt | 10 +++++----- .../com/sipios/springsearch/SpecificationsBuilder.kt | 8 ++++---- .../sipios/springsearch/strategies/DateStrategy.kt | 6 +++--- .../sipios/springsearch/strategies/DoubleStrategy.kt | 6 +++--- .../springsearch/strategies/DurationStrategy.kt | 6 +++--- .../sipios/springsearch/strategies/FloatStrategy.kt | 6 +++--- .../springsearch/strategies/InstantStrategy.kt | 6 +++--- .../sipios/springsearch/strategies/IntStrategy.kt | 6 +++--- .../springsearch/strategies/LocalDateStrategy.kt | 6 +++--- .../springsearch/strategies/LocalDateTimeStrategy.kt | 6 +++--- .../springsearch/strategies/LocalTimeStrategy.kt | 6 +++--- .../springsearch/strategies/ParsingStrategy.kt | 6 +++--- .../sipios/springsearch/strategies/StringStrategy.kt | 6 +++--- src/test/kotlin/com/sipios/springsearch/Users.kt | 12 ++++++------ 15 files changed, 52 insertions(+), 52 deletions(-) diff --git a/pom.xml b/pom.xml index be0ccda..946df09 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.1 + 3.1.2 com.sipios @@ -14,8 +14,8 @@ API for generating spring boot database queries - 1.8 - 1.6.20 + 17 + 1.9.22 4.9 com.sipios.springsearch.grammar com/sipios/springsearch/grammar @@ -161,7 +161,7 @@ src/main/kotlin target/generated-sources/antlr4 - 1.8 + 21 diff --git a/src/main/kotlin/com/sipios/springsearch/SpecificationImpl.kt b/src/main/kotlin/com/sipios/springsearch/SpecificationImpl.kt index 3c4a631..d58ca96 100644 --- a/src/main/kotlin/com/sipios/springsearch/SpecificationImpl.kt +++ b/src/main/kotlin/com/sipios/springsearch/SpecificationImpl.kt @@ -2,12 +2,12 @@ package com.sipios.springsearch import com.sipios.springsearch.anotation.SearchSpec import com.sipios.springsearch.strategies.ParsingStrategy +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.CriteriaQuery +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate +import jakarta.persistence.criteria.Root import java.util.ArrayList -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.CriteriaQuery -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate -import javax.persistence.criteria.Root import org.springframework.data.jpa.domain.Specification import org.springframework.http.HttpStatus import org.springframework.web.server.ResponseStatusException diff --git a/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt b/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt index c0bb5ec..d5fc908 100644 --- a/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt +++ b/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch import com.sipios.springsearch.anotation.SearchSpec -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.CriteriaQuery -import javax.persistence.criteria.Predicate -import javax.persistence.criteria.Root +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.CriteriaQuery +import jakarta.persistence.criteria.Predicate +import jakarta.persistence.criteria.Root import org.springframework.data.jpa.domain.Specification class SpecificationsBuilder(searchSpecAnnotation: SearchSpec) { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt index 38368c9..36b9008 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt @@ -2,11 +2,11 @@ package com.sipios.springsearch.strategies import com.fasterxml.jackson.databind.util.StdDateFormat import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.text.DateFormat import java.util.Date -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class DateStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt index 4a4452d..62d52d9 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt @@ -1,9 +1,9 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import kotlin.reflect.KClass class DoubleStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt index 05f626d..c5d455a 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.Duration -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class DurationStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt index 0041d0a..ea727c9 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt @@ -1,9 +1,9 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import kotlin.reflect.KClass class FloatStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt index 5010a40..4e50c22 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.Instant -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class InstantStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt index 171f57e..a53c52a 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt @@ -1,9 +1,9 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import kotlin.reflect.KClass class IntStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt index 0b9baea..aecadee 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.LocalDate -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class LocalDateStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt index 4108016..0f1210a 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.LocalDateTime -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class LocalDateTimeStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt index b27725c..4f0fac6 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt @@ -1,10 +1,10 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.LocalTime -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass class LocalTimeStrategy : ParsingStrategy { diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt index 739adb9..a71298a 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt @@ -2,6 +2,9 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation import com.sipios.springsearch.anotation.SearchSpec +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate import java.time.Duration import java.time.Instant import java.time.LocalDate @@ -9,9 +12,6 @@ import java.time.LocalDateTime import java.time.LocalTime import java.util.Date import java.util.UUID -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt index 322748a..fd019a8 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt @@ -2,9 +2,9 @@ package com.sipios.springsearch.strategies import com.sipios.springsearch.SearchOperation import com.sipios.springsearch.anotation.SearchSpec -import javax.persistence.criteria.CriteriaBuilder -import javax.persistence.criteria.Path -import javax.persistence.criteria.Predicate +import jakarta.persistence.criteria.CriteriaBuilder +import jakarta.persistence.criteria.Path +import jakarta.persistence.criteria.Predicate class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { override fun buildPredicate( diff --git a/src/test/kotlin/com/sipios/springsearch/Users.kt b/src/test/kotlin/com/sipios/springsearch/Users.kt index fb6610a..73c506c 100644 --- a/src/test/kotlin/com/sipios/springsearch/Users.kt +++ b/src/test/kotlin/com/sipios/springsearch/Users.kt @@ -1,5 +1,11 @@ package com.sipios.springsearch +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import jakarta.persistence.Table import java.time.Duration import java.time.Instant import java.time.LocalDate @@ -7,12 +13,6 @@ import java.time.LocalDateTime import java.time.LocalTime import java.util.Date import java.util.UUID -import javax.persistence.Column -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.GenerationType -import javax.persistence.Id -import javax.persistence.Table @Entity @Table(name = "USERS") From 370ade65bec0358ffe902b1e3411e6cbb5d71234 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 12:03:48 +0100 Subject: [PATCH 02/23] refactor: replace deprecated lowercase method --- .../com/sipios/springsearch/strategies/StringStrategy.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt index fd019a8..d038c28 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt @@ -5,6 +5,7 @@ import com.sipios.springsearch.anotation.SearchSpec import jakarta.persistence.criteria.CriteriaBuilder import jakarta.persistence.criteria.Path import jakarta.persistence.criteria.Predicate +import java.util.Locale class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { override fun buildPredicate( @@ -15,7 +16,7 @@ class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { value: Any? ): Predicate? { if (!searchSpecAnnotation.caseSensitiveFlag) { - val lowerCasedValue = (value as String).toLowerCase() + val lowerCasedValue = (value as String).lowercase(Locale.getDefault()) val loweredFieldValue = builder.lower(path.get(fieldName)) return when (ops) { SearchOperation.STARTS_WITH -> builder.like(loweredFieldValue, "$lowerCasedValue%") From 4269e8ebb2e297e07cf4c1eeba8664a31665085b Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:19:37 +0100 Subject: [PATCH 03/23] fix: fix typo --- .../kotlin/com/sipios/springsearch/SpecificationsBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt b/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt index d5fc908..aab0610 100644 --- a/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt +++ b/src/main/kotlin/com/sipios/springsearch/SpecificationsBuilder.kt @@ -20,7 +20,7 @@ class SpecificationsBuilder(searchSpecAnnotation: SearchSpec) { /** * This function expect a search string to have been provided. - * The search string has been transformed into a Expression Queue with the format: [OR, value>100, AND, value<1000, label:*MONO*] + * The search string has been transformed into an Expression Queue with the format: [OR, value>100, AND, value<1000, label:*MONO*] * * @return A list of specification used to filter the underlying object using JPA specifications */ From beb3cb3986d52032477eeae0ee3f21861c9c399d Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:45:44 +0100 Subject: [PATCH 04/23] refactor: element access should use indexed access operators whenever easy --- .../com/sipios/springsearch/strategies/DateStrategy.kt | 4 ++-- .../com/sipios/springsearch/strategies/DoubleStrategy.kt | 4 ++-- .../sipios/springsearch/strategies/DurationStrategy.kt | 4 ++-- .../com/sipios/springsearch/strategies/FloatStrategy.kt | 4 ++-- .../com/sipios/springsearch/strategies/InstantStrategy.kt | 4 ++-- .../com/sipios/springsearch/strategies/IntStrategy.kt | 4 ++-- .../sipios/springsearch/strategies/LocalDateStrategy.kt | 4 ++-- .../springsearch/strategies/LocalDateTimeStrategy.kt | 4 ++-- .../sipios/springsearch/strategies/LocalTimeStrategy.kt | 4 ++-- .../com/sipios/springsearch/strategies/ParsingStrategy.kt | 8 ++++---- .../com/sipios/springsearch/strategies/StringStrategy.kt | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt index 36b9008..d240e70 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DateStrategy.kt @@ -20,8 +20,8 @@ class DateStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Date) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Date) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Date) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Date) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt index 62d52d9..135dfb3 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DoubleStrategy.kt @@ -15,8 +15,8 @@ class DoubleStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Double) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Double) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Double) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Double) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt index c5d455a..c35a847 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/DurationStrategy.kt @@ -16,8 +16,8 @@ class DurationStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Duration) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Duration) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Duration) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Duration) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt index ea727c9..65e7525 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/FloatStrategy.kt @@ -15,8 +15,8 @@ class FloatStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Float) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Float) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Float) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Float) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt index 4e50c22..95aff1f 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/InstantStrategy.kt @@ -16,8 +16,8 @@ class InstantStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Instant) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Instant) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Instant) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Instant) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt index a53c52a..fc8ceb1 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/IntStrategy.kt @@ -15,8 +15,8 @@ class IntStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as Int) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as Int) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as Int) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as Int) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt index aecadee..57e8ae2 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateStrategy.kt @@ -16,8 +16,8 @@ class LocalDateStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as LocalDate) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as LocalDate) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as LocalDate) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as LocalDate) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt index 0f1210a..18e691f 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalDateTimeStrategy.kt @@ -16,8 +16,8 @@ class LocalDateTimeStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as LocalDateTime) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as LocalDateTime) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as LocalDateTime) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as LocalDateTime) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt index 4f0fac6..998c8de 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/LocalTimeStrategy.kt @@ -16,8 +16,8 @@ class LocalTimeStrategy : ParsingStrategy { value: Any? ): Predicate? { return when (ops) { - SearchOperation.GREATER_THAN -> builder.greaterThan(path.get(fieldName), value as LocalTime) - SearchOperation.LESS_THAN -> builder.lessThan(path.get(fieldName), value as LocalTime) + SearchOperation.GREATER_THAN -> builder.greaterThan(path[fieldName], value as LocalTime) + SearchOperation.LESS_THAN -> builder.lessThan(path[fieldName], value as LocalTime) else -> super.buildPredicate(builder, path, fieldName, ops, value) } } diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt index a71298a..611abff 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/ParsingStrategy.kt @@ -47,11 +47,11 @@ interface ParsingStrategy { return when (ops) { SearchOperation.EQUALS -> builder.equal(path.get(fieldName), value) SearchOperation.NOT_EQUALS -> builder.notEqual(path.get(fieldName), value) - SearchOperation.STARTS_WITH -> builder.like(path.get(fieldName), "$value%") - SearchOperation.ENDS_WITH -> builder.like(path.get(fieldName), "%$value") + SearchOperation.STARTS_WITH -> builder.like(path[fieldName], "$value%") + SearchOperation.ENDS_WITH -> builder.like(path[fieldName], "%$value") SearchOperation.CONTAINS -> builder.like((path.get(fieldName).`as`(String::class.java)), "%$value%") - SearchOperation.DOESNT_START_WITH -> builder.notLike(path.get(fieldName), "$value%") - SearchOperation.DOESNT_END_WITH -> builder.notLike(path.get(fieldName), "%$value") + SearchOperation.DOESNT_START_WITH -> builder.notLike(path[fieldName], "$value%") + SearchOperation.DOESNT_END_WITH -> builder.notLike(path[fieldName], "%$value") SearchOperation.DOESNT_CONTAIN -> builder.notLike( (path.get(fieldName).`as`(String::class.java)), "%$value%" diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt index d038c28..683398c 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt @@ -17,7 +17,7 @@ class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { ): Predicate? { if (!searchSpecAnnotation.caseSensitiveFlag) { val lowerCasedValue = (value as String).lowercase(Locale.getDefault()) - val loweredFieldValue = builder.lower(path.get(fieldName)) + val loweredFieldValue = builder.lower(path[fieldName]) return when (ops) { SearchOperation.STARTS_WITH -> builder.like(loweredFieldValue, "$lowerCasedValue%") SearchOperation.ENDS_WITH -> builder.like(loweredFieldValue, "%$lowerCasedValue") From ebe7d222b42841f1a987a38f116d515c710b8c5c Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:46:08 +0100 Subject: [PATCH 05/23] refactor: replace null check and collection size check with "isNullOrEmpty()" --- .../springsearch/configuration/SearchSpecificationResolver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/configuration/SearchSpecificationResolver.kt b/src/main/kotlin/com/sipios/springsearch/configuration/SearchSpecificationResolver.kt index 578cac4..6ad160d 100644 --- a/src/main/kotlin/com/sipios/springsearch/configuration/SearchSpecificationResolver.kt +++ b/src/main/kotlin/com/sipios/springsearch/configuration/SearchSpecificationResolver.kt @@ -44,7 +44,7 @@ class SearchSpecificationResolver : HandlerMethodArgumentResolver { private fun buildSpecification(specClass: Class, search: String?, searchSpecAnnotation: SearchSpec): Specification? { logger.debug("Building specification for class {}", specClass) logger.debug("Search value found is {}", search) - if (search == null || search.isEmpty()) { + if (search.isNullOrEmpty()) { return null } val specBuilder = SpecificationsBuilder(searchSpecAnnotation) From 29bf5454c6179bc6ae896cbd090ebd41105fca0c Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:46:27 +0100 Subject: [PATCH 06/23] fix: fix typo --- src/main/kotlin/com/sipios/springsearch/anotation/SearchSpec.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/anotation/SearchSpec.kt b/src/main/kotlin/com/sipios/springsearch/anotation/SearchSpec.kt index ae51734..dd2a43d 100644 --- a/src/main/kotlin/com/sipios/springsearch/anotation/SearchSpec.kt +++ b/src/main/kotlin/com/sipios/springsearch/anotation/SearchSpec.kt @@ -14,7 +14,7 @@ annotation class SearchSpec( val searchParam: String = "search", /** - * A flag to indicate if the search needs to be case sensitive or not + * A flag to indicate if the search needs to be case-sensitive or not */ val caseSensitiveFlag: Boolean = true ) From 20c2e8c9f29e4613a8f7e5f936f34960c6edfad7 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:52:01 +0100 Subject: [PATCH 07/23] refactor: make searchSpecAnnotation private --- .../kotlin/com/sipios/springsearch/strategies/StringStrategy.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt index 683398c..6c73d10 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt @@ -7,7 +7,7 @@ import jakarta.persistence.criteria.Path import jakarta.persistence.criteria.Predicate import java.util.Locale -class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { +class StringStrategy(private var searchSpecAnnotation: SearchSpec) : ParsingStrategy { override fun buildPredicate( builder: CriteriaBuilder, path: Path<*>, From 23272f57a0d8206e84aa173a32db1e4faccb2b36 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:53:57 +0100 Subject: [PATCH 08/23] refactor: private property should not start with an uppercase letter --- src/main/kotlin/com/sipios/springsearch/QueryVisitorImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/sipios/springsearch/QueryVisitorImpl.kt b/src/main/kotlin/com/sipios/springsearch/QueryVisitorImpl.kt index ced091a..8eda3ce 100644 --- a/src/main/kotlin/com/sipios/springsearch/QueryVisitorImpl.kt +++ b/src/main/kotlin/com/sipios/springsearch/QueryVisitorImpl.kt @@ -6,7 +6,7 @@ import com.sipios.springsearch.grammar.QueryParser import org.springframework.data.jpa.domain.Specification class QueryVisitorImpl(private val searchSpecAnnotation: SearchSpec) : QueryBaseVisitor>() { - private val ValueRegExp = Regex(pattern = "^(\\*?)(.+?)(\\*?)$") + private val valueRegExp = Regex(pattern = "^(\\*?)(.+?)(\\*?)$") override fun visitOpQuery(ctx: QueryParser.OpQueryContext): Specification { val left = visit(ctx.left) val right = visit(ctx.right) @@ -43,7 +43,7 @@ class QueryVisitorImpl(private val searchSpecAnnotation: SearchSpec) : QueryB .replace("\\'", "'") } - val matchResult = this.ValueRegExp.find(value!!) + val matchResult = this.valueRegExp.find(value!!) val criteria = SearchCriteria( key, op, From 7352f21ce56b8968d116b829003f7dbd23457a56 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 13:58:39 +0100 Subject: [PATCH 09/23] refactor: use 'when' statement --- .../com/sipios/springsearch/SearchCriteria.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/sipios/springsearch/SearchCriteria.kt b/src/main/kotlin/com/sipios/springsearch/SearchCriteria.kt index dfaa1ee..e87ba7e 100644 --- a/src/main/kotlin/com/sipios/springsearch/SearchCriteria.kt +++ b/src/main/kotlin/com/sipios/springsearch/SearchCriteria.kt @@ -10,20 +10,19 @@ class SearchCriteria // Change EQUALS into ENDS_WITH, CONTAINS, STARTS_WITH base // Change EQUALS into ENDS_WITH, CONTAINS, STARTS_WITH based on the presence of * in the value val startsWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX) val endsWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX) - if (op === SearchOperation.EQUALS && startsWithAsterisk && endsWithAsterisk) { - op = SearchOperation.CONTAINS - } else if (op === SearchOperation.EQUALS && startsWithAsterisk) { - op = SearchOperation.ENDS_WITH - } else if (op === SearchOperation.EQUALS && endsWithAsterisk) { - op = SearchOperation.STARTS_WITH + op = when { + op === SearchOperation.EQUALS && startsWithAsterisk && endsWithAsterisk -> SearchOperation.CONTAINS + op === SearchOperation.EQUALS && startsWithAsterisk -> SearchOperation.ENDS_WITH + op === SearchOperation.EQUALS && endsWithAsterisk -> SearchOperation.STARTS_WITH + else -> op } + // Change NOT_EQUALS into DOESNT_END_WITH, DOESNT_CONTAIN, DOESNT_START_WITH based on the presence of * in the value - if (op === SearchOperation.NOT_EQUALS && startsWithAsterisk && endsWithAsterisk) { - op = SearchOperation.DOESNT_CONTAIN - } else if (op === SearchOperation.NOT_EQUALS && startsWithAsterisk) { - op = SearchOperation.DOESNT_END_WITH - } else if (op === SearchOperation.NOT_EQUALS && endsWithAsterisk) { - op = SearchOperation.DOESNT_START_WITH + op = when { + op === SearchOperation.NOT_EQUALS && startsWithAsterisk && endsWithAsterisk -> SearchOperation.DOESNT_CONTAIN + op === SearchOperation.NOT_EQUALS && startsWithAsterisk -> SearchOperation.DOESNT_END_WITH + op === SearchOperation.NOT_EQUALS && endsWithAsterisk -> SearchOperation.DOESNT_START_WITH + else -> op } } this.operation = op From 0698f63488689600f79ce070cdf5135c9066ed52 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 14:07:43 +0100 Subject: [PATCH 10/23] chore: update CircleCI config --- .circleci/config.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 72a0483..2438ce3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,12 +2,17 @@ version: 2.1 orbs: codecov: codecov/codecov@1.0.2 +parameters: + jdk-image: + type: string + default: cimg/openjdk:17.0 + jobs: test: environment: MAVEN_OPTS: -Xmx3200m docker: - - image: circleci/openjdk:11-jdk + - image: << pipeline.parameters.jdk-image >> working_directory: ~/project steps: - checkout From 68502155a0305acac14be1a7b7c229e5eae3f286 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 14:18:01 +0100 Subject: [PATCH 11/23] refactor: remove duplicate plugin and dependency declarations in pom --- pom.xml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 946df09..fc83731 100644 --- a/pom.xml +++ b/pom.xml @@ -52,10 +52,6 @@ org.jetbrains.kotlin kotlin-reflect - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - org.springframework.boot @@ -79,11 +75,6 @@ ${kotlin.version} test - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - @@ -112,10 +103,6 @@ ${project.build.directory}/generated-sources/antlr4/${grammar.directory} - - maven-compiler-plugin - 3.8.1 - org.jetbrains.kotlin kotlin-maven-plugin @@ -291,6 +278,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 compile From e2e84c2a7fc72ea5adc1213019ef373372ac3967 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 14:32:42 +0100 Subject: [PATCH 12/23] chore: bump antlr version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fc83731..295e226 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 17 1.9.22 - 4.9 + 4.13.1 com.sipios.springsearch.grammar com/sipios/springsearch/grammar 0.8.4 From f68a3530648c0564c249a4c58744e5a9127edc86 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 15:30:54 +0100 Subject: [PATCH 13/23] chore: add dependency-check to pom --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 295e226..5b6a06a 100644 --- a/pom.xml +++ b/pom.xml @@ -356,6 +356,18 @@ + + org.owasp + dependency-check-maven + 9.0.7 + + + + check + + + + From 5c4eecd6936b51494cb6f57ab43c9f50ba708c42 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 15:31:12 +0100 Subject: [PATCH 14/23] chore: bump h2 version to avoid vulnerability --- pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b6a06a..78f7ed6 100644 --- a/pom.xml +++ b/pom.xml @@ -16,10 +16,11 @@ 17 1.9.22 + 0.8.4 + 2.2.220 4.13.1 com.sipios.springsearch.grammar com/sipios/springsearch/grammar - 0.8.4 ${project.build.directory}/test-results @@ -32,6 +33,7 @@ com.h2database h2 + ${h2.version} test From 022aed0c1dea792f472c87cd7354b60b002612e4 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 15:53:12 +0100 Subject: [PATCH 15/23] chore: bump dependencies to avoid vulnerabilities --- pom.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78f7ed6..008ec7a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.1.7 com.sipios @@ -18,6 +18,8 @@ 1.9.22 0.8.4 2.2.220 + 2.16.0 + 2.0 4.13.1 com.sipios.springsearch.grammar com/sipios/springsearch/grammar @@ -46,6 +48,18 @@ spring-boot-starter-web provided + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + provided + + + org.yaml + snakeyaml + ${snakeyaml.version} + provided + com.fasterxml.jackson.module jackson-module-kotlin From 09ef5b54bf2cd3b51fa26ae755ad5aaaab35c53d Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Wed, 27 Dec 2023 10:07:45 +0100 Subject: [PATCH 16/23] chore: bump project version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 008ec7a..3644b24 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ com.sipios spring-search - 0.2.5 + 0.2.6 spring-search API for generating spring boot database queries From fd3a05416cf1a448c291af72500ae5b1c0e6e176 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Tue, 26 Dec 2023 15:59:33 +0100 Subject: [PATCH 17/23] chore: add variable for dependency-check-maven version in pom --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3644b24..cfe2f6b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ 2.2.220 2.16.0 2.0 + 9.0.7 4.13.1 com.sipios.springsearch.grammar com/sipios/springsearch/grammar @@ -375,7 +376,7 @@ org.owasp dependency-check-maven - 9.0.7 + ${dependency-check-maven.version} From 442dcd20d5a202484c3ef14dab006dec612cf2eb Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Thu, 28 Dec 2023 12:14:16 +0100 Subject: [PATCH 18/23] chore: update kotlin-maven-plugin compile phase Kotlin plugin should run before javac so Kotlin classes could be visible from Java --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cfe2f6b..fe27d4d 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,7 @@ compile - compile + process-sources compile From c7a34442a108d1e61b5c3335b01f56a8ee4c6c47 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Thu, 28 Dec 2023 12:15:18 +0100 Subject: [PATCH 19/23] chore: add .java-version file for jenv --- .java-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .java-version diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..03b6389 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17.0 From 7173228e61c1117550a8cbaec3350d696df47fe3 Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Thu, 28 Dec 2023 12:16:05 +0100 Subject: [PATCH 20/23] chore: make library available for applications running under jdk17 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fe27d4d..07cd64d 100644 --- a/pom.xml +++ b/pom.xml @@ -165,7 +165,7 @@ src/main/kotlin target/generated-sources/antlr4 - 21 + 17 From d6bd5199efefb2d915127b63c4653cd7f733db5c Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Thu, 28 Dec 2023 14:55:08 +0100 Subject: [PATCH 21/23] refactor: use data class --- .../kotlin/com/sipios/springsearch/strategies/StringStrategy.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt index 6c73d10..3498959 100644 --- a/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt +++ b/src/main/kotlin/com/sipios/springsearch/strategies/StringStrategy.kt @@ -7,7 +7,7 @@ import jakarta.persistence.criteria.Path import jakarta.persistence.criteria.Predicate import java.util.Locale -class StringStrategy(private var searchSpecAnnotation: SearchSpec) : ParsingStrategy { +data class StringStrategy(var searchSpecAnnotation: SearchSpec) : ParsingStrategy { override fun buildPredicate( builder: CriteriaBuilder, path: Path<*>, From 09d23485b147ff44d8b192bfe025f589e4d950ec Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Thu, 28 Dec 2023 15:37:59 +0100 Subject: [PATCH 22/23] chore: update README.md --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9142bad..9ad1e18 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Please note that providing such a feature on your API does not come without risk ## Getting Started -**Requirements** : JDK 8 or more. +**Requirements** : JDK 17 or more. To get a local copy up and running follow these simple steps. ### Installation @@ -91,7 +91,7 @@ Add the repo to your project inside your `pom.xml` file com.sipios spring-search - 0.2.0 + 0.3.0 ``` @@ -175,6 +175,40 @@ Request : `/cars?search=options.transmission:Auto` Request : `/cars?search=creationyear:2018 AND price<300000 AND (color:Yellow OR color:Blue) AND options.transmission:Auto` ![complex example](./docs/images/complex-example.gif) + +## Troubleshooting + +If you get the following error ⬇️ + +> No primary or default constructor found for interface org.springframework.data.jpa.domain.Specification + +You are free to opt for either of the two following solutions : +1. Add a `@Configuration` class to add our argument resolver to your project +```kotlin +// Kotlin +@Configuration +class SpringSearchResolverConf : WebMvcConfigurer { + override fun addArgumentResolvers(argumentResolvers: MutableList) { + argumentResolvers.add(SearchSpecificationResolver()) + } +} +``` +```java +// Java +@Configuration +public class SpringSearchResolverConf implements WebMvcConfigurer { + @Override + public void addArgumentResolvers(List argumentResolvers) { + argumentResolvers.add(new SearchSpecificationResolver()); + } +} +``` + +2. Add a `@ComponentScan` annotation to your project configuration class +```java +@ComponentScan(basePackages = {"com.your-application", "com.sipios.springsearch"}) +``` + ## Roadmap From abf051a243d1f0fdb8169c5aff2b461c11fa98dc Mon Sep 17 00:00:00 2001 From: Mahdi Lazraq Date: Fri, 29 Dec 2023 21:20:28 +0100 Subject: [PATCH 23/23] chore: bump maven-gpg-plugin version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 07cd64d..9e1929b 100644 --- a/pom.xml +++ b/pom.xml @@ -356,7 +356,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 3.1.0 sign-artifacts