diff --git a/pom.xml b/pom.xml
index ca0f0d0..90a3020 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,14 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- org.sadtech.haiti
+ dev.struchkov.haiti
haiti
- 0.0.2-SNAPSHOT
+ 0.0.4
- org.sadtech.haiti.filter
+ dev.struchkov.haiti.filter
haiti-filter-criteria
- 0.0.3-SNAPSHOT
+ 0.0.4
Haiti Filter Criteria
Fast creation of filtering requests using the Criteria Api wrapper.
@@ -20,57 +20,43 @@
Apache License, Version 2.0
https://www.apache.org/licenses/LICENSE-2.0
-
- Copyright 2010 the original author or authors.
-
- 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
-
- https://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.
-
-
-
- SADTECH
- https://sadtech.org
-
-
-
- scm:git:https://github.com/haiti-projects/haiti-filter-criteria.git
- https://github.com/haiti-projects/haiti-filter-criteria
- scm:git:https://github.com/haiti-projects/haiti-filter-criteria.git
-
-
-
-
- ossrh
- https://oss.sonatype.org/content/repositories/snapshots
-
-
-
GitHub
https://github.com/haiti-projects/haiti-framework/issues
+
+ 11
+ ${java.version}
+ ${java.version}
+ UTF-8
+ UTF-8
+
+ 0.0.4
+ 1.0.1
+
+ 3.9.0
+ 1.6.8
+ 3.2.1
+ 3.3.1
+ 3.0.1
+
+
- org.sadtech.haiti
+ dev.struchkov.haiti
haiti-filter
+
+ dev.struchkov.haiti
+ haiti-utils
+
- org.projectlombok
- lombok
+ com.google.auto.service
+ auto-service
@@ -85,98 +71,35 @@
org.hibernate
hibernate-core
- 5.4.29.Final
-
-
- release
-
-
-
- org.sonatype.plugins
- nexus-staging-maven-plugin
- 1.6.7
- true
-
- ossrh
- https://oss.sonatype.org/
- true
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.2.1
-
-
- attach-sources
-
- jar-no-fork
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9.1
-
-
- attach-javadocs
-
- jar
-
-
-
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
- 1.5
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
- 3.8.0
-
- 8
+
+
+ com.google.auto.service
+ auto-service
+ 1.0.1
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+
-
-
- uPagge
- Struchkov Mark
- upagge@ya.ru
- SADTECH
- https://sadtech.org
- https://uPagge.sadtech.org
-
- Project lead
-
- +3
-
-
+
+ scm:git:https://github.com/haiti-projects/haiti-filter-criteria.git
+ https://github.com/haiti-projects/haiti-filter-criteria
+ scm:git:https://github.com/haiti-projects/haiti-filter-criteria.git
+
\ No newline at end of file
diff --git a/src/main/java/org/sadtech/haiti/filter/criteria/Container.java b/src/main/java/dev/struchkov/haiti/filter/criteria/Container.java
similarity index 54%
rename from src/main/java/org/sadtech/haiti/filter/criteria/Container.java
rename to src/main/java/dev/struchkov/haiti/filter/criteria/Container.java
index 5733632..a86fa47 100644
--- a/src/main/java/org/sadtech/haiti/filter/criteria/Container.java
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/Container.java
@@ -1,8 +1,5 @@
-package org.sadtech.haiti.filter.criteria;
+package dev.struchkov.haiti.filter.criteria;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
import org.springframework.data.jpa.domain.Specification;
import java.util.List;
@@ -13,9 +10,6 @@ import java.util.UUID;
*
* @author upagge 09.11.2020
*/
-@Getter
-@Setter
-@NoArgsConstructor
public class Container {
private final String uuid = UUID.randomUUID().toString();
@@ -31,4 +25,24 @@ public class Container {
return new Container<>(joinTables);
}
+ public List getJoinTables() {
+ return joinTables;
+ }
+
+ public void setJoinTables(List joinTables) {
+ this.joinTables = joinTables;
+ }
+
+ public Specification getSpecification() {
+ return specification;
+ }
+
+ public void setSpecification(Specification specification) {
+ this.specification = specification;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
}
diff --git a/src/main/java/org/sadtech/haiti/filter/criteria/CriteriaFilter.java b/src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaFilter.java
similarity index 72%
rename from src/main/java/org/sadtech/haiti/filter/criteria/CriteriaFilter.java
rename to src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaFilter.java
index c4d61e3..82c16be 100644
--- a/src/main/java/org/sadtech/haiti/filter/criteria/CriteriaFilter.java
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaFilter.java
@@ -1,24 +1,25 @@
-package org.sadtech.haiti.filter.criteria;
+package dev.struchkov.haiti.filter.criteria;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.sadtech.haiti.filter.Filter;
-import org.sadtech.haiti.filter.FilterQuery;
+import dev.struchkov.haiti.filter.Filter;
+import dev.struchkov.haiti.filter.FilterQuery;
import org.springframework.data.jpa.domain.Specification;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CriteriaFilter implements Filter {
private final List> andSpecifications = new ArrayList<>();
private final List> orSpecifications = new ArrayList<>();
private final List> notSpecifications = new ArrayList<>();
+ private CriteriaFilter() {
+ }
+
public static Filter create() {
return new CriteriaFilter();
}
@@ -29,18 +30,46 @@ public class CriteriaFilter implements Filter {
return this;
}
+ @Override
+ public Filter and(Consumer query) {
+ final FilterQuery criteriaQuery = CriteriaQuery.create();
+ query.accept(criteriaQuery);
+ andSpecifications.addAll(getSpecification(criteriaQuery));
+ return this;
+ }
+
@Override
public Filter or(FilterQuery filterQuery) {
orSpecifications.addAll(getSpecification(filterQuery));
return this;
}
+ @Override
+ public Filter or(Consumer query) {
+ final FilterQuery criteriaQuery = CriteriaQuery.create();
+ query.accept(criteriaQuery);
+ orSpecifications.addAll(getSpecification(criteriaQuery));
+ return this;
+ }
+
@Override
public Filter not(FilterQuery filterQuery) {
notSpecifications.addAll(
getSpecification(filterQuery).stream()
.map(Specification::not)
- .collect(Collectors.toList())
+ .collect(Collectors.toUnmodifiableList())
+ );
+ return this;
+ }
+
+ @Override
+ public Filter not(Consumer query) {
+ final FilterQuery criteriaQuery = CriteriaQuery.create();
+ query.accept(criteriaQuery);
+ notSpecifications.addAll(
+ getSpecification(criteriaQuery).stream()
+ .map(Specification::not)
+ .collect(Collectors.toUnmodifiableList())
);
return this;
}
diff --git a/src/main/java/org/sadtech/haiti/filter/criteria/CriteriaQuery.java b/src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaQuery.java
similarity index 74%
rename from src/main/java/org/sadtech/haiti/filter/criteria/CriteriaQuery.java
rename to src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaQuery.java
index acc025a..10b0e9a 100644
--- a/src/main/java/org/sadtech/haiti/filter/criteria/CriteriaQuery.java
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/CriteriaQuery.java
@@ -1,9 +1,7 @@
-package org.sadtech.haiti.filter.criteria;
+package dev.struchkov.haiti.filter.criteria;
-import lombok.AccessLevel;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-import org.sadtech.haiti.filter.FilterQuery;
+
+import dev.struchkov.haiti.filter.FilterQuery;
import java.util.ArrayList;
import java.util.Arrays;
@@ -11,14 +9,22 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+import static dev.struchkov.haiti.utils.Assert.Utils.nullPointer;
+import static dev.struchkov.haiti.utils.Assert.isNotNull;
+
public class CriteriaQuery implements FilterQuery {
private static final CriteriaQuery> EMPTY = new CriteriaQuery<>(new ArrayList<>());
+ public static final String FIELD_NAME = "field";
+
private final List> containers;
private List joinTables = new ArrayList<>();
private final SimpleCriteriaQuery simpleCriteriaQuery = new SimpleCriteriaQuery();
+ public CriteriaQuery(List> containers) {
+ this.containers = containers;
+ }
+
public static FilterQuery create() {
return new CriteriaQuery(new ArrayList<>());
}
@@ -29,20 +35,23 @@ public class CriteriaQuery implements FilterQuery {
*
* @param fieldName Имя поля сущности, которое отвечает за название таблицы.
*/
- public CriteriaQuery join(@NonNull String... fieldName) {
+ public CriteriaQuery join(String... fieldName) {
+ isNotNull(fieldName, nullPointer("fieldName"));
joinTables = Arrays.stream(fieldName)
.map(JoinTable::of)
.collect(Collectors.toList());
return this;
}
- public CriteriaQuery join(@NonNull JoinTable... joinTables) {
+ public CriteriaQuery join(JoinTable... joinTables) {
+ isNotNull(joinTables, nullPointer("joinTables"));
this.joinTables = Arrays.stream(joinTables).collect(Collectors.toList());
return this;
}
@Override
- public > FilterQuery between(@NonNull String field, Y from, Y to) {
+ public > FilterQuery between(String field, Y from, Y to) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (from != null && to != null) {
containers.add(simpleCriteriaQuery.between(joinTables, field, from, to));
}
@@ -50,7 +59,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public > FilterQuery greaterThan(@NonNull String field, Y value) {
+ public > FilterQuery greaterThan(String field, Y value) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (value != null) {
containers.add(simpleCriteriaQuery.greaterThan(joinTables, field, value));
}
@@ -58,7 +68,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public > FilterQuery lessThan(@NonNull String field, Y value) {
+ public > FilterQuery lessThan(String field, Y value) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (value != null) {
containers.add(simpleCriteriaQuery.lessThan(joinTables, field, value));
}
@@ -66,7 +77,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public FilterQuery matchPhrase(@NonNull String field, Object value) {
+ public FilterQuery matchPhrase(String field, Object value) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (value != null) {
containers.add(simpleCriteriaQuery.matchPhrase(joinTables, field, value));
}
@@ -74,7 +86,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public FilterQuery matchPhrase(@NonNull String field, Set values) {
+ public FilterQuery matchPhrase(String field, Set values) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (values != null && !values.isEmpty()) {
containers.addAll(
values.stream()
@@ -105,7 +118,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public FilterQuery like(@NonNull String field, String value, boolean ignoreCase) {
+ public FilterQuery like(String field, String value, boolean ignoreCase) {
+ isNotNull(field, nullPointer(FIELD_NAME));
containers.add(
ignoreCase
? simpleCriteriaQuery.likeIgnoreCase(joinTables, field, value)
@@ -115,7 +129,8 @@ public class CriteriaQuery implements FilterQuery {
}
@Override
- public FilterQuery checkBoolInt(@NonNull String field, Boolean flag) {
+ public FilterQuery checkBoolInt(String field, Boolean flag) {
+ isNotNull(field, nullPointer(FIELD_NAME));
if (flag != null) {
containers.add(
simpleCriteriaQuery.between(joinTables, field, 0, Integer.MAX_VALUE)
diff --git a/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTable.java b/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTable.java
new file mode 100644
index 0000000..3bef8df
--- /dev/null
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTable.java
@@ -0,0 +1,37 @@
+package dev.struchkov.haiti.filter.criteria;
+
+import dev.struchkov.haiti.utils.Assert;
+
+import static dev.struchkov.haiti.utils.Assert.Utils.nullPointer;
+
+/**
+ * @author upagge 15.04.2021
+ */
+public class JoinTable {
+
+ private final String tableName;
+ private final JoinTypeOperation joinTypeOperation;
+
+ private JoinTable(String tableName, JoinTypeOperation joinTypeOperation) {
+ this.tableName = tableName;
+ this.joinTypeOperation = joinTypeOperation;
+ }
+
+ public static JoinTable of(String tableName) {
+ Assert.isNotNull(tableName, nullPointer("tableName"));
+ return new JoinTable(tableName, JoinTypeOperation.LEFT);
+ }
+
+ public static JoinTable of(String tableName, JoinTypeOperation joinType) {
+ Assert.isNotNull(tableName, nullPointer("tableName"));
+ return new JoinTable(tableName, joinType);
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public JoinTypeOperation getJoinTypeOperation() {
+ return joinTypeOperation;
+ }
+}
diff --git a/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTypeOperation.java b/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTypeOperation.java
new file mode 100644
index 0000000..a6e1f85
--- /dev/null
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/JoinTypeOperation.java
@@ -0,0 +1,22 @@
+package dev.struchkov.haiti.filter.criteria;
+
+import javax.persistence.criteria.JoinType;
+
+/**
+ * @author upagge 15.04.2021
+ */
+public enum JoinTypeOperation {
+
+ LEFT(JoinType.LEFT),
+ INNER(JoinType.INNER);
+
+ private final JoinType criteriaType;
+
+ JoinTypeOperation(JoinType criteriaType) {
+ this.criteriaType = criteriaType;
+ }
+
+ public JoinType getCriteriaType() {
+ return criteriaType;
+ }
+}
diff --git a/src/main/java/org/sadtech/haiti/filter/criteria/SimpleCriteriaQuery.java b/src/main/java/dev/struchkov/haiti/filter/criteria/SimpleCriteriaQuery.java
similarity index 81%
rename from src/main/java/org/sadtech/haiti/filter/criteria/SimpleCriteriaQuery.java
rename to src/main/java/dev/struchkov/haiti/filter/criteria/SimpleCriteriaQuery.java
index d090e4a..3ea1294 100644
--- a/src/main/java/org/sadtech/haiti/filter/criteria/SimpleCriteriaQuery.java
+++ b/src/main/java/dev/struchkov/haiti/filter/criteria/SimpleCriteriaQuery.java
@@ -1,6 +1,6 @@
-package org.sadtech.haiti.filter.criteria;
+package dev.struchkov.haiti.filter.criteria;
-import lombok.NonNull;
+import dev.struchkov.haiti.utils.Assert;
import org.hibernate.query.criteria.internal.path.PluralAttributeJoinSupport;
import javax.persistence.criteria.From;
@@ -15,13 +15,20 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import static dev.struchkov.haiti.utils.Assert.Utils.nullPointer;
+
public class SimpleCriteriaQuery {
+ public static final String FIELD = "field";
+
private From