From 0473dd13277edb9dbfa03d9f1e2a0c2bef76ef71 Mon Sep 17 00:00:00 2001 From: Yves MENGELLE Date: Thu, 21 Mar 2024 16:20:00 +0100 Subject: [PATCH] feat(isnull-operator): implement ISNULL operator --- querydsl-postgrest/pom.xml | 5 ++-- .../postgrest/mappers/IsNullMapper.java | 18 +++++++++++++++ .../querydsl/postgrest/mappers/Operators.java | 4 ++++ .../postgrest/mappers/IsNullMapperTest.java | 23 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapper.java create mode 100644 querydsl-postgrest/src/test/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapperTest.java diff --git a/querydsl-postgrest/pom.xml b/querydsl-postgrest/pom.xml index ff22b0a..b69bfb3 100644 --- a/querydsl-postgrest/pom.xml +++ b/querydsl-postgrest/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 fr.ouestfrance.querydsl @@ -13,7 +14,7 @@ fr.ouestfrance.querydsl querydsl - 1.2.0 + 1.3.0-SNAPSHOT diff --git a/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapper.java b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapper.java new file mode 100644 index 0000000..d65613d --- /dev/null +++ b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapper.java @@ -0,0 +1,18 @@ +package fr.ouestfrance.querydsl.postgrest.mappers; + +import fr.ouestfrance.querydsl.FilterOperation; +import fr.ouestfrance.querydsl.postgrest.model.Filter; +import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter; + +public class IsNullMapper extends AbstractMapper { + + @Override + public Filter getFilter(String field, Object value) { + return QueryFilter.of(field, Boolean.TRUE.equals(value) ? Operators.IS : Operators.IS_NOT, null); + } + + @Override + public Class operation() { + return FilterOperation.ISNULL.class; + } +} diff --git a/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/Operators.java b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/Operators.java index 91d4132..86f2688 100644 --- a/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/Operators.java +++ b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/Operators.java @@ -56,6 +56,10 @@ public final class Operators { * is operation */ public static final String IS = "is"; + /** + * is not operation + */ + public static final String IS_NOT = "not.is"; /** * Contains operation for JSON/Range datatype */ diff --git a/querydsl-postgrest/src/test/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapperTest.java b/querydsl-postgrest/src/test/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapperTest.java new file mode 100644 index 0000000..4e73a0e --- /dev/null +++ b/querydsl-postgrest/src/test/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapperTest.java @@ -0,0 +1,23 @@ +package fr.ouestfrance.querydsl.postgrest.mappers; + +import fr.ouestfrance.querydsl.FilterOperation; +import fr.ouestfrance.querydsl.model.SimpleFilter; +import fr.ouestfrance.querydsl.postgrest.builders.QueryFilterVisitor; +import fr.ouestfrance.querydsl.postgrest.model.Filter; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class IsNullMapperTest { + + @Test + void shouldMapIsNull() { + IsNullMapper mapper = new IsNullMapper(); + assertNotNull(mapper.operation()); + Filter result = mapper.map(new SimpleFilter("name", FilterOperation.ISNULL.class, false, null), Boolean.TRUE); + assertNotNull(result); + QueryFilterVisitor visitor = new QueryFilterVisitor(); + result.accept(visitor); + assertNotNull(visitor.getValue()); + } +}