Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
App Blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Genesys PGR
App Blocks
Commits
cdbb5f44
Commit
cdbb5f44
authored
Apr 25, 2020
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Querydsl does not allow `null` predicate for `findAll()`
parent
1c924ed7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
6 deletions
+89
-6
core/pom.xml
core/pom.xml
+17
-0
core/src/main/java/org/genesys/blocks/model/filters/SuperModelFilter.java
...va/org/genesys/blocks/model/filters/SuperModelFilter.java
+3
-1
core/src/test/java/org/genesys/blocks/model/VersionedEntityFilter.java
.../java/org/genesys/blocks/model/VersionedEntityFilter.java
+42
-0
core/src/test/java/org/genesys/blocks/persistence/VersionedEntityRepository.java
...genesys/blocks/persistence/VersionedEntityRepository.java
+2
-1
core/src/test/java/org/genesys/blocks/tests/model/VersionedModelTest.java
...va/org/genesys/blocks/tests/model/VersionedModelTest.java
+25
-4
No files found.
core/pom.xml
View file @
cdbb5f44
...
...
@@ -39,6 +39,8 @@
<version>
1.1.3
</version>
<executions>
<execution>
<id>
generate-source-entities
</id>
<phase>
generate-sources
</phase>
<goals>
<goal>
process
</goal>
</goals>
...
...
@@ -51,6 +53,21 @@
<processor>
com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
</configuration>
</execution>
<execution>
<id>
generate-test-entities
</id>
<phase>
generate-test-sources
</phase>
<goals>
<goal>
test-process
</goal>
</goals>
<configuration>
<includes>
<!-- List packages to be processed -->
<include>
org.genesys.blocks.model
</include>
</includes>
<outputDirectory>
target/generated-test-sources/querydsl
</outputDirectory>
<processor>
com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
...
...
core/src/main/java/org/genesys/blocks/model/filters/SuperModelFilter.java
View file @
cdbb5f44
...
...
@@ -39,6 +39,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.fasterxml.jackson.databind.deser.ContextualDeserializer
;
import
com.querydsl.core.BooleanBuilder
;
import
com.querydsl.core.types.ExpressionUtils
;
import
com.querydsl.core.types.Predicate
;
import
com.querydsl.core.types.dsl.CollectionPathBase
;
...
...
@@ -84,7 +85,8 @@ public abstract class SuperModelFilter<T extends SuperModelFilter<T, R>, R> {
* @return the predicate
*/
public
Predicate
buildPredicate
()
{
return
ExpressionUtils
.
allOf
(
collectPredicates
());
Predicate
collected
=
ExpressionUtils
.
allOf
(
collectPredicates
());
return
collected
==
null
?
new
BooleanBuilder
()
:
collected
;
}
/**
...
...
core/src/test/java/org/genesys/blocks/model/VersionedEntityFilter.java
0 → 100644
View file @
cdbb5f44
/*
* Copyright 2020 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys.blocks.model
;
import
java.util.List
;
import
org.genesys.blocks.model.filters.StringFilter
;
import
org.genesys.blocks.model.filters.VersionedModelFilter
;
import
com.querydsl.core.types.Predicate
;
public
class
VersionedEntityFilter
extends
VersionedModelFilter
<
VersionedEntityFilter
,
VersionedEntity
>
{
public
StringFilter
name
;
public
List
<
Predicate
>
collectPredicates
()
{
return
collectPredicates
(
QVersionedEntity
.
versionedEntity
);
}
public
List
<
Predicate
>
collectPredicates
(
QVersionedEntity
versionedEntity
)
{
final
List
<
Predicate
>
predicates
=
super
.
collectPredicates
(
versionedEntity
,
versionedEntity
.
_super
.
_super
);
if
(
name
!=
null
)
{
predicates
.
add
(
name
.
buildQuery
(
versionedEntity
.
name
));
}
return
predicates
;
}
}
core/src/test/java/org/genesys/blocks/persistence/VersionedEntityRepository.java
View file @
cdbb5f44
...
...
@@ -17,10 +17,11 @@ package org.genesys.blocks.persistence;
import
org.genesys.blocks.model.VersionedEntity
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.querydsl.QuerydslPredicateExecutor
;
/**
* The Interface VersionedEntityRepository.
*/
public
interface
VersionedEntityRepository
extends
JpaRepository
<
VersionedEntity
,
Long
>
{
public
interface
VersionedEntityRepository
extends
JpaRepository
<
VersionedEntity
,
Long
>
,
QuerydslPredicateExecutor
<
VersionedEntity
>
{
}
core/src/test/java/org/genesys/blocks/tests/model/VersionedModelTest.java
View file @
cdbb5f44
...
...
@@ -15,14 +15,15 @@
*/
package
org.genesys.blocks.tests.model
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
org.genesys.blocks.model.VersionedEntity
;
import
org.genesys.blocks.model.VersionedEntityFilter
;
import
org.genesys.blocks.tests.ServiceTest
;
import
org.junit.Test
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.transaction.annotation.Transactional
;
/**
...
...
@@ -75,6 +76,26 @@ public class VersionedModelTest extends ServiceTest {
assertThat
(
entity
.
isActive
(),
is
(
false
));
}
@Test
public
void
testEmptyFilter
()
{
VersionedEntityFilter
filter
=
new
VersionedEntityFilter
();
Page
<
VersionedEntity
>
page
=
versionedEntityRepository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
10
));
assertThat
(
page
,
not
(
nullValue
()));
}
@Test
public
void
testStringFilter
()
{
VersionedEntity
entity
=
versionedEntityRepository
.
save
(
createEntity
());
VersionedEntityFilter
filter
=
new
VersionedEntityFilter
();
filter
.
id
().
add
(
entity
.
getId
());
Page
<
VersionedEntity
>
page
=
versionedEntityRepository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
10
));
assertThat
(
page
,
not
(
nullValue
()));
assertThat
(
page
.
getContent
().
size
(),
is
(
1
));
assertThat
(
page
.
getContent
().
get
(
0
),
is
(
entity
));
}
/**
* Creates the entity.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment