From cf68f1738e206c2e6ce00de79f941667287c6c9c Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Wed, 20 Oct 2021 21:22:45 +0300 Subject: [PATCH] dev.struchkov --- haiti-bom/pom.xml | 163 +++++++++++++++--- haiti-context/pom.xml | 21 +-- .../haiti/context/anotation/Marker.java | 2 +- .../haiti/context/domain/BasicEntity.java | 12 ++ .../haiti/context/domain/ExistsContainer.java | 33 ++++ .../haiti/context/enums/TypeSort.java | 2 +- .../context/exception/AccessException.java | 2 +- .../context/exception/BasicException.java | 2 +- .../context/exception/ConvertException.java | 2 +- .../context/exception/CreateException.java | 19 ++ .../context/exception/NotFoundException.java | 21 +++ .../haiti/context/page/Pagination.java | 4 +- .../struchkov}/haiti/context/page/Sheet.java | 2 +- .../repository/SimpleManagerRepository.java | 11 ++ .../repository/simple/CrudOperation.java | 2 +- .../repository/simple/MultipleOperation.java | 17 ++ .../repository/simple/PagingOperation.java | 11 ++ .../context/service/SimpleManagerService.java | 10 ++ .../context/service/simple/FilterService.java | 40 +++++ .../service/simple/MultipleService.java | 20 +++ .../context/service/simple/PagingService.java | 6 +- .../context/service/simple/SimpleService.java | 4 +- .../context/exception/NotFoundException.java | 14 -- .../repository/SimpleManagerRepository.java | 8 - .../repository/simple/MultipleOperation.java | 14 -- .../repository/simple/PagingOperation.java | 11 -- .../context/service/SimpleManagerService.java | 9 - .../service/simple/MultipleService.java | 16 -- haiti-core/pom.xml | 33 ++-- .../haiti/core/page/PaginationImpl.java | 6 +- .../struchkov}/haiti/core/page/SheetImpl.java | 35 +++- .../core/service/AbstractFilterService.java | 14 +- .../core/service/AbstractMultipleService.java | 18 +- .../core/service/AbstractPagingService.java | 10 +- .../service/AbstractSimpleManagerService.java | 29 +++- .../core/service/AbstractSimpleService.java | 13 +- .../haiti/core/util/ServiceOperation.java | 55 ++++++ .../org/sadtech/haiti/core/util/Assert.java | 23 --- .../haiti/core/util/ServiceOperation.java | 37 ---- haiti-filter/pom.xml | 23 +-- .../dev/struchkov/haiti/filter/Filter.java | 13 ++ .../haiti/filter/FilterOperation.java | 19 ++ .../struchkov/haiti/filter/FilterQuery.java | 63 +++++++ .../BadFilterConstructorException.java | 9 + .../filter/exception/FilterException.java | 20 +++ haiti-utils/pom.xml | 42 +++++ .../dev/struchkov/haiti/utils/Assert.java | 72 ++++++++ .../struchkov/haiti/utils/ObjectUtils.java | 155 +++++++++++++++++ .../dev/struchkov/haiti/utils/Strings.java | 15 ++ pom.xml | 23 +-- 50 files changed, 934 insertions(+), 271 deletions(-) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/anotation/Marker.java (82%) create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/domain/BasicEntity.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/domain/ExistsContainer.java rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/enums/TypeSort.java (76%) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/exception/AccessException.java (81%) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/exception/BasicException.java (88%) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/exception/ConvertException.java (86%) create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/exception/CreateException.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/exception/NotFoundException.java rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/page/Pagination.java (58%) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/page/Sheet.java (88%) create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/repository/SimpleManagerRepository.java rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/repository/simple/CrudOperation.java (94%) create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/MultipleOperation.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/PagingOperation.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/service/SimpleManagerService.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/FilterService.java create mode 100644 haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/MultipleService.java rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/service/simple/PagingService.java (68%) rename haiti-context/src/main/java/{org/sadtech => dev/struchkov}/haiti/context/service/simple/SimpleService.java (81%) delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java delete mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/page/PaginationImpl.java (84%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/page/SheetImpl.java (54%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/service/AbstractFilterService.java (69%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/service/AbstractMultipleService.java (52%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/service/AbstractPagingService.java (56%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/service/AbstractSimpleManagerService.java (53%) rename haiti-core/src/main/java/{org/sadtech => dev/struchkov}/haiti/core/service/AbstractSimpleService.java (52%) create mode 100644 haiti-core/src/main/java/dev/struchkov/haiti/core/util/ServiceOperation.java delete mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java delete mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java create mode 100644 haiti-filter/src/main/java/dev/struchkov/haiti/filter/Filter.java create mode 100644 haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterOperation.java create mode 100644 haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterQuery.java create mode 100644 haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/BadFilterConstructorException.java create mode 100644 haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/FilterException.java create mode 100644 haiti-utils/pom.xml create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/Assert.java create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/ObjectUtils.java create mode 100644 haiti-utils/src/main/java/dev/struchkov/haiti/utils/Strings.java diff --git a/haiti-bom/pom.xml b/haiti-bom/pom.xml index 6d233f0..54dbfc3 100644 --- a/haiti-bom/pom.xml +++ b/haiti-bom/pom.xml @@ -4,64 +4,110 @@ 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-bom - 0.0.1-RELEASE + 0.0.1-SNAPSHOT pom Haiti BOM Current versions of the framework dependencies https://github.com/haiti-projects/haiti-framework + + + 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 + Struchkov Inc. + https://mark.struchkov.dev - - 1.8 - 1.8 - 1.8 + + scm:git:https://github.com/haiti-projects/haiti-framework.git + https://github.com/haiti-projects/haiti-framework + scm:git:https://github.com/haiti-projects/haiti-framework.git + - 0.0.1-RELEASE - 0.0.1-RELEASE - 0.0.1-RELEASE - 0.0.1-RELEASE - 0.0.1-RELEASE - 0.0.1-RELEASE + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + GitHub + https://github.com/haiti-projects/haiti-framework/issues + + + + 16 + 16 + 16 + + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + 0.0.1-RELEASE + 0.0.1-SNAPSHOT 4.1.0 2.4.0 2.4.0 7.9.3 - 1.18.16 + 1.18.22 - org.sadtech.haiti + dev.struchkov.haiti haiti-context - ${sadtech.haiti.context.version} + ${haiti.context.version} - org.sadtech.haiti + dev.struchkov.haiti haiti-core - ${sadtech.haiti.core.version} + ${haiti.core.version} - org.sadtech.haiti + dev.struchkov.haiti haiti-filter - ${sadtech.haiti.filter.api.version} + ${haiti.filter.api.version} - org.sadtech.haiti + dev.struchkov.haiti.filter haiti-filter-criteria - 0.0.1-RELEASE + ${haiti.filter.criteria.version} + + + + dev.struchkov.haiti + haiti-utils + ${haiti.utils.version} @@ -105,6 +151,67 @@ + + + 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 + + + + + + + + + @@ -123,12 +230,12 @@ uPagge Struchkov Mark - upagge@ya.ru - SADTECH - https://sadtech.org - https://uPagge.sadtech.org + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev - Project lead + Project Lead +3 diff --git a/haiti-context/pom.xml b/haiti-context/pom.xml index 7345479..7941cb1 100644 --- a/haiti-context/pom.xml +++ b/haiti-context/pom.xml @@ -4,23 +4,18 @@ 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.1-RELEASE + 0.0.1-SNAPSHOT haiti-context - 0.0.1-RELEASE + 0.0.1-SNAPSHOT Haiti Context Basic framework classes https://github.com/haiti-projects/haiti-framework - - SADTECH - https://sadtech.org - - org.projectlombok @@ -32,12 +27,12 @@ uPagge Struchkov Mark - upagge@ya.ru - SADTECH - https://sadtech.org - https://uPagge.sadtech.org + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev - Project lead + Project Lead +3 diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/anotation/Marker.java similarity index 82% rename from haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/anotation/Marker.java index 4f237f8..f0c6d84 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/anotation/Marker.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.anotation; +package dev.struchkov.haiti.context.anotation; /** * Маркер для разграничения политик валидации. diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/BasicEntity.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/BasicEntity.java new file mode 100644 index 0000000..6367c66 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/BasicEntity.java @@ -0,0 +1,12 @@ +package dev.struchkov.haiti.context.domain; + +/** + * // TODO: 14.01.2021 Добавить описание. + * + * @author upagge 14.01.2021 + */ +public interface BasicEntity { + + K getId(); + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/ExistsContainer.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/ExistsContainer.java new file mode 100644 index 0000000..5d95cbf --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/domain/ExistsContainer.java @@ -0,0 +1,33 @@ +package dev.struchkov.haiti.context.domain; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Collections; + +/** + * Контейнер для возврата результата сервисных методов exists. + * + * @author upagge 11.01.2021 + */ +@Getter +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class ExistsContainer implements Serializable { + + protected final Collection container; + protected final boolean allFound; + protected final Collection idNoFound; + + public static ExistsContainer allFind(@NonNull Collection container) { + return new ExistsContainer<>(container, true, Collections.emptyList()); + } + + public static ExistsContainer notAllFind(@NonNull Collection container, @NonNull Collection idNoFound) { + return new ExistsContainer<>(container, false, idNoFound); + } + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/enums/TypeSort.java similarity index 76% rename from haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/enums/TypeSort.java index 73fb1e1..bafb82b 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/enums/TypeSort.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.enums; +package dev.struchkov.haiti.context.enums; /** * Допустимые типы сортировки. diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/AccessException.java similarity index 81% rename from haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/exception/AccessException.java index baccb74..b9b4fe6 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/AccessException.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.exception; +package dev.struchkov.haiti.context.exception; /** * Исключения связанные с доступом. diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/BasicException.java similarity index 88% rename from haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/exception/BasicException.java index ecced4d..26bcd9f 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/BasicException.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.exception; +package dev.struchkov.haiti.context.exception; /** * Общий класс для всех ошибок приложения. diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/ConvertException.java similarity index 86% rename from haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/exception/ConvertException.java index 6e0aa42..fe6f4b7 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/ConvertException.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.exception; +package dev.struchkov.haiti.context.exception; /** * Исключение при конвертации. diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/CreateException.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/CreateException.java new file mode 100644 index 0000000..479f6f0 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/CreateException.java @@ -0,0 +1,19 @@ +package dev.struchkov.haiti.context.exception; + +import java.text.MessageFormat; +import java.util.function.Supplier; + +/** + * @author upagge 17.12.2019 + */ +public class CreateException extends BasicException { + + public CreateException(String message) { + super(message); + } + + public static Supplier supplier(String message, Object... objects) { + return () -> new CreateException(MessageFormat.format(message, objects)); + } + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/NotFoundException.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/NotFoundException.java new file mode 100644 index 0000000..e4ca595 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/exception/NotFoundException.java @@ -0,0 +1,21 @@ +package dev.struchkov.haiti.context.exception; + +import java.text.MessageFormat; +import java.util.function.Supplier; + +/** + * Исключения, возникающие, когда необходимые данные не были найдены. + * + * @author upagge 17.12.2019 + */ +public class NotFoundException extends BasicException { + + public NotFoundException(String message) { + super(message); + } + + public static Supplier supplier(String message, Object... objects) { + return () -> new NotFoundException(MessageFormat.format(message, objects)); + } + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/page/Pagination.java similarity index 58% rename from haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/page/Pagination.java index 0f75d74..f152219 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/page/Pagination.java @@ -1,6 +1,6 @@ -package org.sadtech.haiti.context.page; +package dev.struchkov.haiti.context.page; -import org.sadtech.haiti.context.enums.TypeSort; +import dev.struchkov.haiti.context.enums.TypeSort; public interface Pagination { diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/page/Sheet.java similarity index 88% rename from haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/page/Sheet.java index 0b90f94..e0cbd72 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/page/Sheet.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.page; +package dev.struchkov.haiti.context.page; import java.util.List; import java.util.function.Function; diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/SimpleManagerRepository.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/SimpleManagerRepository.java new file mode 100644 index 0000000..cd09938 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/SimpleManagerRepository.java @@ -0,0 +1,11 @@ +package dev.struchkov.haiti.context.repository; + +import dev.struchkov.haiti.context.repository.simple.CrudOperation; +import dev.struchkov.haiti.context.repository.simple.MultipleOperation; +import dev.struchkov.haiti.context.repository.simple.PagingOperation; +import dev.struchkov.haiti.context.domain.BasicEntity; + +public interface SimpleManagerRepository, K> + extends CrudOperation, MultipleOperation, PagingOperation { + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/CrudOperation.java similarity index 94% rename from haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/CrudOperation.java index 8127821..ced2806 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/CrudOperation.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.repository.simple; +package dev.struchkov.haiti.context.repository.simple; import lombok.NonNull; diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/MultipleOperation.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/MultipleOperation.java new file mode 100644 index 0000000..137e01e --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/MultipleOperation.java @@ -0,0 +1,17 @@ +package dev.struchkov.haiti.context.repository.simple; + +import lombok.NonNull; +import dev.struchkov.haiti.context.domain.BasicEntity; + +import java.util.Collection; +import java.util.List; + +public interface MultipleOperation, K> { + + List saveAll(@NonNull Collection entities); + + void deleteAllById(@NonNull Collection primaryKeys); + + List findAllById(@NonNull Collection ids); + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/PagingOperation.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/PagingOperation.java new file mode 100644 index 0000000..7e32492 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/repository/simple/PagingOperation.java @@ -0,0 +1,11 @@ +package dev.struchkov.haiti.context.repository.simple; + +import lombok.NonNull; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; + +public interface PagingOperation { + + Sheet findAll(@NonNull Pagination pagination); + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/service/SimpleManagerService.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/SimpleManagerService.java new file mode 100644 index 0000000..b1eba11 --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/SimpleManagerService.java @@ -0,0 +1,10 @@ +package dev.struchkov.haiti.context.service; + +import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.context.service.simple.MultipleService; +import dev.struchkov.haiti.context.service.simple.PagingService; +import dev.struchkov.haiti.context.service.simple.SimpleService; + +public interface SimpleManagerService, K> extends SimpleService, MultipleService, PagingService { + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/FilterService.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/FilterService.java new file mode 100644 index 0000000..9ff7f4f --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/FilterService.java @@ -0,0 +1,40 @@ +package dev.struchkov.haiti.context.service.simple; + +import lombok.NonNull; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; + +import java.util.Optional; + +public interface FilterService { + + /** + * Получить все элементы по заданному фильтру. + * + * @param filter Фильтр + * @param pagination Пагинация + */ + Sheet getAll(@NonNull F filter, @NonNull Pagination pagination); + + /** + * Возвращает первый найденный объект по фильтру. + * + * @param filter Объект фильтра + */ + Optional getFirst(@NonNull F filter); + + /** + * Проверка на наличие хотя бы одной сущности, которая удовлетворяет определенному набору параметров. + * + * @param filter Набор параметров + */ + boolean exists(@NonNull F filter); + + /** + * Получить количество сущностей, которые удовлетворяют определенному набору параметров. + * + * @param filter Набор параметров + */ + long count(@NonNull F filter); + +} diff --git a/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/MultipleService.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/MultipleService.java new file mode 100644 index 0000000..f63ac3d --- /dev/null +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/MultipleService.java @@ -0,0 +1,20 @@ +package dev.struchkov.haiti.context.service.simple; + +import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.context.domain.ExistsContainer; +import lombok.NonNull; + +import java.util.Collection; +import java.util.List; + +public interface MultipleService, K> { + + List createAll(@NonNull Collection entities); + + List updateAll(@NonNull Collection entities); + + void deleteAllById(@NonNull Collection ids); + + ExistsContainer existsById(@NonNull Collection ids); + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/PagingService.java similarity index 68% rename from haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/PagingService.java index d545331..5f8596b 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/PagingService.java @@ -1,8 +1,8 @@ -package org.sadtech.haiti.context.service.simple; +package dev.struchkov.haiti.context.service.simple; import lombok.NonNull; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; /** * Расширение базового контракта сервисов с добавлением пагинации. diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/SimpleService.java similarity index 81% rename from haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java rename to haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/SimpleService.java index b037335..2f869f1 100644 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java +++ b/haiti-context/src/main/java/dev/struchkov/haiti/context/service/simple/SimpleService.java @@ -1,4 +1,4 @@ -package org.sadtech.haiti.context.service.simple; +package dev.struchkov.haiti.context.service.simple; import lombok.NonNull; @@ -17,6 +17,8 @@ public interface SimpleService { Optional getById(@NonNull K primaryKey); + T getByIdOrThrow(@NonNull K primaryKey); + boolean existsById(@NonNull K primaryKey); void deleteById(@NonNull K primaryKey); diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java deleted file mode 100644 index 138dc53..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.haiti.context.exception; - -/** - * Исключения, возникающиек, когда необходимые данные не были найдены. - * - * @author upagge 17.12.2019 - */ -public class NotFoundException extends BasicException { - - public NotFoundException(String message) { - super(message); - } - -} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java deleted file mode 100644 index 24f1e67..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.haiti.context.repository; - -import org.sadtech.haiti.context.repository.simple.CrudOperation; -import org.sadtech.haiti.context.repository.simple.MultipleOperation; -import org.sadtech.haiti.context.repository.simple.PagingOperation; - -public interface SimpleManagerRepository extends CrudOperation, MultipleOperation, PagingOperation { -} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java deleted file mode 100644 index 772f57b..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.haiti.context.repository.simple; - -import lombok.NonNull; - -import java.util.Collection; -import java.util.List; - -public interface MultipleOperation { - - List saveAll(@NonNull Collection entities); - - void deleteAllById(@NonNull Collection primaryKeys); - -} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java deleted file mode 100644 index f9f412e..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sadtech.haiti.context.repository.simple; - -import lombok.NonNull; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; - -public interface PagingOperation { - - Sheet findAll(@NonNull Pagination pagination); - -} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java b/haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java deleted file mode 100644 index 4431c01..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.haiti.context.service; - -import org.sadtech.haiti.context.service.simple.MultipleService; -import org.sadtech.haiti.context.service.simple.PagingService; -import org.sadtech.haiti.context.service.simple.SimpleService; - -public interface SimpleManagerService extends SimpleService, MultipleService, PagingService { - -} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java deleted file mode 100644 index 30bb5df..0000000 --- a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.haiti.context.service.simple; - -import lombok.NonNull; - -import java.util.Collection; -import java.util.List; - -public interface MultipleService { - - List createAll(@NonNull Collection entities); - - List updateAll(@NonNull Collection entities); - - void deleteAllById(@NonNull Collection ids); - -} diff --git a/haiti-core/pom.xml b/haiti-core/pom.xml index 88f6b2a..162d58b 100644 --- a/haiti-core/pom.xml +++ b/haiti-core/pom.xml @@ -4,50 +4,45 @@ 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.1-RELEASE + 0.0.1-SNAPSHOT haiti-core - 0.0.1-RELEASE + 0.0.1-SNAPSHOT Haiti Core Implementation of the main classes of the framework https://github.com/haiti-projects/haiti-framework - - SADTECH - https://sadtech.org - - - org.sadtech.haiti + dev.struchkov.haiti haiti-context - - org.sadtech.haiti - haiti-filter - - org.projectlombok lombok + + + dev.struchkov.haiti + haiti-filter + uPagge Struchkov Mark - upagge@ya.ru - SADTECH - https://sadtech.org - https://uPagge.sadtech.org + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev - Project lead + Project Lead +3 diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/page/PaginationImpl.java similarity index 84% rename from haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/page/PaginationImpl.java index 4049f20..5afddd0 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/page/PaginationImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.haiti.core.page; +package dev.struchkov.haiti.core.page; +import dev.struchkov.haiti.context.enums.TypeSort; +import dev.struchkov.haiti.context.page.Pagination; import lombok.Getter; -import org.sadtech.haiti.context.enums.TypeSort; -import org.sadtech.haiti.context.page.Pagination; @Getter public class PaginationImpl implements Pagination { diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/page/SheetImpl.java similarity index 54% rename from haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/page/SheetImpl.java index 5ff8e38..0a591ec 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/page/SheetImpl.java @@ -1,12 +1,14 @@ -package org.sadtech.haiti.core.page; +package dev.struchkov.haiti.core.page; +import dev.struchkov.haiti.context.page.Sheet; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import org.sadtech.haiti.context.page.Sheet; +import java.util.Collections; import java.util.List; import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Collectors; @Getter @@ -20,11 +22,6 @@ public class SheetImpl implements Sheet { private final int totalPage; private final List content; - @Override - public boolean hasContent() { - return content != null && !content.isEmpty(); - } - @Override public Sheet map(Function function) { return new SheetImpl<>( @@ -36,5 +33,29 @@ public class SheetImpl implements Sheet { ); } + public static Sheet empty() { + return new SheetImpl<>( + 0, + 0, + 0L, + 0, + Collections.emptyList() + ); + } + + public Sheet filter(Predicate predicate) { + final List filterContent = content.stream().filter(predicate).collect(Collectors.toList()); + return new SheetImpl<>( + this.number, + this.size, + this.totalElement, + this.totalPage, + filterContent + ); + } + + public boolean hasContent() { + return content != null && !content.isEmpty(); + } } diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractFilterService.java similarity index 69% rename from haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractFilterService.java index 29852ab..b21d58c 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractFilterService.java @@ -1,19 +1,19 @@ -package org.sadtech.haiti.core.service; +package dev.struchkov.haiti.core.service; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; +import dev.struchkov.haiti.context.service.simple.FilterService; +import dev.struchkov.haiti.filter.Filter; +import dev.struchkov.haiti.filter.FilterOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; -import org.sadtech.haiti.filter.Filter; -import org.sadtech.haiti.filter.FilterOperation; -import org.sadtech.haiti.filter.FilterService; import java.util.Optional; @RequiredArgsConstructor public abstract class AbstractFilterService implements FilterService { - private final FilterOperation filterOperation; + protected final FilterOperation filterOperation; @Override public Sheet getAll(@NonNull F filter, Pagination pagination) { diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractMultipleService.java similarity index 52% rename from haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractMultipleService.java index 1efba9d..5c4e14c 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractMultipleService.java @@ -1,17 +1,20 @@ -package org.sadtech.haiti.core.service; +package dev.struchkov.haiti.core.service; +import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.context.domain.ExistsContainer; +import dev.struchkov.haiti.context.repository.simple.MultipleOperation; +import dev.struchkov.haiti.context.service.simple.MultipleService; +import dev.struchkov.haiti.context.service.simple.SimpleService; +import dev.struchkov.haiti.core.util.ServiceOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.haiti.context.repository.simple.MultipleOperation; -import org.sadtech.haiti.context.service.simple.MultipleService; -import org.sadtech.haiti.context.service.simple.SimpleService; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @RequiredArgsConstructor -public abstract class AbstractMultipleService implements MultipleService { +public abstract class AbstractMultipleService, K> implements MultipleService { private final SimpleService simpleService; private final MultipleOperation multipleOperation; @@ -31,4 +34,9 @@ public abstract class AbstractMultipleService implements MultipleService existsById(@NonNull Collection ids) { + return ServiceOperation.existsContainerById(multipleOperation, ids); + } + } diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractPagingService.java similarity index 56% rename from haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractPagingService.java index 6e3b298..644da40 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractPagingService.java @@ -1,11 +1,11 @@ -package org.sadtech.haiti.core.service; +package dev.struchkov.haiti.core.service; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; +import dev.struchkov.haiti.context.repository.simple.PagingOperation; +import dev.struchkov.haiti.context.service.simple.PagingService; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; -import org.sadtech.haiti.context.repository.simple.PagingOperation; -import org.sadtech.haiti.context.service.simple.PagingService; @RequiredArgsConstructor public abstract class AbstractPagingService implements PagingService { diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java similarity index 53% rename from haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java index f4cf0bb..d757711 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleManagerService.java @@ -1,12 +1,15 @@ -package org.sadtech.haiti.core.service; +package dev.struchkov.haiti.core.service; +import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.context.domain.ExistsContainer; +import dev.struchkov.haiti.context.exception.NotFoundException; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; +import dev.struchkov.haiti.context.repository.SimpleManagerRepository; +import dev.struchkov.haiti.context.service.SimpleManagerService; +import dev.struchkov.haiti.core.util.ServiceOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; -import org.sadtech.haiti.context.repository.SimpleManagerRepository; -import org.sadtech.haiti.context.service.SimpleManagerService; -import org.sadtech.haiti.core.util.ServiceOperation; import java.util.Collection; import java.util.List; @@ -14,9 +17,9 @@ import java.util.Optional; import java.util.stream.Collectors; @RequiredArgsConstructor -public abstract class AbstractSimpleManagerService implements SimpleManagerService { +public abstract class AbstractSimpleManagerService, K> implements SimpleManagerService { - private final SimpleManagerRepository repository; + protected final SimpleManagerRepository repository; @Override public void deleteAllById(@NonNull Collection primaryKeys) { @@ -33,6 +36,11 @@ public abstract class AbstractSimpleManagerService implements SimpleManage return ServiceOperation.getById(repository, primaryKey); } + @Override + public T getByIdOrThrow(@NonNull K primaryKey) { + return getById(primaryKey).orElseThrow(NotFoundException.supplier("Объект не найден. Идентификатор: ", primaryKey)); + } + @Override public boolean existsById(@NonNull K primaryKey) { return ServiceOperation.existsById(repository, primaryKey); @@ -53,4 +61,9 @@ public abstract class AbstractSimpleManagerService implements SimpleManage return entities.stream().map(this::update).collect(Collectors.toList()); } + @Override + public ExistsContainer existsById(@NonNull Collection ids) { + return ServiceOperation.existsContainerById(repository, ids); + } + } diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleService.java similarity index 52% rename from haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java rename to haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleService.java index 1c0b295..98117d9 100644 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/service/AbstractSimpleService.java @@ -1,9 +1,10 @@ -package org.sadtech.haiti.core.service; +package dev.struchkov.haiti.core.service; +import dev.struchkov.haiti.context.repository.simple.CrudOperation; +import dev.struchkov.haiti.context.service.simple.SimpleService; +import dev.struchkov.haiti.core.util.ServiceOperation; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.haiti.context.repository.simple.CrudOperation; -import org.sadtech.haiti.context.service.simple.SimpleService; import java.util.Optional; @@ -14,17 +15,17 @@ public abstract class AbstractSimpleService implements SimpleService @Override public Optional getById(@NonNull K primaryKey) { - return crudOperation.findById(primaryKey); + return ServiceOperation.getById(crudOperation, primaryKey); } @Override public boolean existsById(@NonNull K primaryKey) { - return crudOperation.existsById(primaryKey); + return ServiceOperation.existsById(crudOperation, primaryKey); } @Override public void deleteById(@NonNull K primaryKey) { - crudOperation.deleteById(primaryKey); + ServiceOperation.deleteById(crudOperation, primaryKey); } } diff --git a/haiti-core/src/main/java/dev/struchkov/haiti/core/util/ServiceOperation.java b/haiti-core/src/main/java/dev/struchkov/haiti/core/util/ServiceOperation.java new file mode 100644 index 0000000..2050e10 --- /dev/null +++ b/haiti-core/src/main/java/dev/struchkov/haiti/core/util/ServiceOperation.java @@ -0,0 +1,55 @@ +package dev.struchkov.haiti.core.util; + +import dev.struchkov.haiti.context.domain.BasicEntity; +import dev.struchkov.haiti.context.domain.ExistsContainer; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; +import dev.struchkov.haiti.context.repository.simple.CrudOperation; +import dev.struchkov.haiti.context.repository.simple.MultipleOperation; +import dev.struchkov.haiti.context.repository.simple.PagingOperation; +import lombok.experimental.UtilityClass; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +@UtilityClass +public final class ServiceOperation { + + public static , K> void deleteAllById(MultipleOperation repository, Collection primaryKeys) { + repository.deleteAllById(primaryKeys); + } + + public static Sheet getAll(PagingOperation repository, Pagination pagination) { + return repository.findAll(pagination); + } + + public static Optional getById(CrudOperation repository, K primaryKey) { + return repository.findById(primaryKey); + } + + public static boolean existsById(CrudOperation repository, K primaryKey) { + return repository.existsById(primaryKey); + } + + public static void deleteById(CrudOperation repository, K primaryKey) { + repository.deleteById(primaryKey); + } + + public static > ExistsContainer existsContainerById(MultipleOperation multipleOperation, Collection ids) { + final List existsEntity = multipleOperation.findAllById(ids); + final Set existsIds = existsEntity.stream() + .map(BasicEntity::getId) + .collect(Collectors.toSet()); + if (existsIds.containsAll(ids)) { + return ExistsContainer.allFind(existsEntity); + } else { + final Set noExistsId = ids.stream() + .filter(id -> !existsIds.contains(id)) + .collect(Collectors.toSet()); + return ExistsContainer.notAllFind(existsEntity, noExistsId); + } + } +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java b/haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java deleted file mode 100644 index c96ea9f..0000000 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sadtech.haiti.core.util; - -/** - * // TODO: 06.09.2020 Добавить описание. - * - * @author upagge 06.09.2020 - */ - -public final class Assert { - - public static void isNull(Object object, String message) { - if (object != null) { - throw new IllegalStateException(message); - } - } - - public static void isNotNull(Object object, String message) { - if (object == null) { - throw new IllegalStateException(message); - } - } - -} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java b/haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java deleted file mode 100644 index 6f92746..0000000 --- a/haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.sadtech.haiti.core.util; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.sadtech.haiti.context.page.Pagination; -import org.sadtech.haiti.context.page.Sheet; -import org.sadtech.haiti.context.repository.simple.CrudOperation; -import org.sadtech.haiti.context.repository.simple.MultipleOperation; -import org.sadtech.haiti.context.repository.simple.PagingOperation; - -import java.util.Collection; -import java.util.Optional; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ServiceOperation { - - public static void deleteAllById(MultipleOperation repository, Collection primaryKeys) { - repository.deleteAllById(primaryKeys); - } - - public static Sheet getAll(PagingOperation repository, Pagination pagination) { - return repository.findAll(pagination); - } - - public static Optional getById(CrudOperation repository, K primaryKey) { - return repository.findById(primaryKey); - } - - public static boolean existsById(CrudOperation repository, K primaryKey) { - return repository.existsById(primaryKey); - } - - public static void deleteById(CrudOperation repository, K primaryKey) { - repository.deleteById(primaryKey); - } - -} diff --git a/haiti-filter/pom.xml b/haiti-filter/pom.xml index 4e24494..d1071b4 100644 --- a/haiti-filter/pom.xml +++ b/haiti-filter/pom.xml @@ -4,23 +4,18 @@ 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.1-RELEASE + 0.0.1-SNAPSHOT haiti-filter - 0.0.1-RELEASE + 0.0.1-SNAPSHOT Haiti Filter Fast and convenient filtering requests to data warehouses. https://github.com/haiti-projects/haiti-framework - - SADTECH - https://sadtech.org - - org.projectlombok @@ -28,7 +23,7 @@ - org.sadtech.haiti + dev.struchkov.haiti haiti-context @@ -37,12 +32,12 @@ uPagge Struchkov Mark - upagge@ya.ru - SADTECH - https://sadtech.org - https://uPagge.sadtech.org + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev - Project lead + Project Lead +3 diff --git a/haiti-filter/src/main/java/dev/struchkov/haiti/filter/Filter.java b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/Filter.java new file mode 100644 index 0000000..f656049 --- /dev/null +++ b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/Filter.java @@ -0,0 +1,13 @@ +package dev.struchkov.haiti.filter; + +public interface Filter { + + Filter and(FilterQuery filterQuery); + + Filter or(FilterQuery filterQuery); + + Filter not(FilterQuery filterQuery); + + Q build(); + +} diff --git a/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterOperation.java b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterOperation.java new file mode 100644 index 0000000..54a27f9 --- /dev/null +++ b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterOperation.java @@ -0,0 +1,19 @@ +package dev.struchkov.haiti.filter; + +import lombok.NonNull; +import dev.struchkov.haiti.context.page.Pagination; +import dev.struchkov.haiti.context.page.Sheet; + +import java.util.Optional; + +public interface FilterOperation { + + Sheet findAll(@NonNull Filter filter, @NonNull Pagination pagination); + + Optional findFirst(@NonNull Filter filter); + + boolean exists(@NonNull Filter filter); + + long count(@NonNull Filter filter); + +} diff --git a/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterQuery.java b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterQuery.java new file mode 100644 index 0000000..67944a5 --- /dev/null +++ b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/FilterQuery.java @@ -0,0 +1,63 @@ +package dev.struchkov.haiti.filter; + +import lombok.NonNull; + +import java.util.Set; + +public interface FilterQuery { + + /** + * Добавляет в запрос поиск по диапазону. + * + * @param field Название поля в elasticsearch + * @param from Начало интервала + * @param to Конец интервала + */ + > FilterQuery between(@NonNull String field, Y from, Y to); + + > FilterQuery greaterThan(@NonNull String field, Y value); + + > FilterQuery lessThan(@NonNull String field, Y value); + + /** + * Добавляет в запрос проверку по значению поля + * + * @param field Название поля + * @param value Значение поля для проверки + */ + FilterQuery matchPhrase(@NonNull String field, Object value); + + /** + * Добавляет в запрос проверку по нескольким значениям одного поля + * + * @param field Название поля + * @param value Значения поля + */ + FilterQuery matchPhrase(@NonNull String field, Set value); + + /** + * Добавляет в запрос проверку на NULL значение поля + * + * @param field Наименование поля + */ + FilterQuery exists(String field); + + /** + * Поиск подстрок + * + * @param field Названия поля + * @param value Часть искомого значения + */ + FilterQuery like(@NonNull String field, String value, boolean ignoreCase); + + /** + * Добавляет в запрос поиск по флагу, который конвертируется в диапазон + * + * @param flag Значение флага + * @param field Поле для проверки + */ + FilterQuery checkBoolInt(@NonNull String field, Boolean flag); + + Q build(); + +} diff --git a/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/BadFilterConstructorException.java b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/BadFilterConstructorException.java new file mode 100644 index 0000000..380bff6 --- /dev/null +++ b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/BadFilterConstructorException.java @@ -0,0 +1,9 @@ +package dev.struchkov.haiti.filter.exception; + +public class BadFilterConstructorException extends FilterException { + + public BadFilterConstructorException(String s) { + super(s); + } + +} diff --git a/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/FilterException.java b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/FilterException.java new file mode 100644 index 0000000..f38edf4 --- /dev/null +++ b/haiti-filter/src/main/java/dev/struchkov/haiti/filter/exception/FilterException.java @@ -0,0 +1,20 @@ +package dev.struchkov.haiti.filter.exception; + +import dev.struchkov.haiti.context.exception.BasicException; + +/** + * // TODO: 09.11.2020 Добавить описание. + * + * @author upagge 09.11.2020 + */ +public class FilterException extends BasicException { + + protected FilterException(String message) { + super(message); + } + + protected FilterException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/haiti-utils/pom.xml b/haiti-utils/pom.xml new file mode 100644 index 0000000..e0c3a96 --- /dev/null +++ b/haiti-utils/pom.xml @@ -0,0 +1,42 @@ + + + + dev.struchkov.haiti + haiti + 0.0.1-SNAPSHOT + + 4.0.0 + + haiti-utils + 0.0.1-SNAPSHOT + + + + org.projectlombok + lombok + + + + dev.struchkov.haiti + haiti-context + + + + + + uPagge + Struchkov Mark + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev + + Project Lead + + +3 + + + + \ No newline at end of file diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Assert.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Assert.java new file mode 100644 index 0000000..b24372f --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Assert.java @@ -0,0 +1,72 @@ +package dev.struchkov.haiti.utils; + +import lombok.experimental.UtilityClass; + +import java.util.function.Supplier; + +/** + * // TODO: 06.09.2020 Добавить описание. + * + * @author upagge 06.09.2020 + */ +@UtilityClass +public final class Assert { + + /** + * Проверка на null значение с возвращением исключения, если объект не null. + * + * @param object Проверяемый объект + * @param exception Возвращаемое исключение + */ + public static void isNull(Object object, Supplier exception) { + if (object != null) { + throw exception.get(); + } + } + + /** + * Проверка на null значение с возвращением исключения, если объект null. + * + * @param object Проверяемый объект + * @param exception Возвращаемое исключение + */ + public static void isNotNull(Object object, Supplier exception) { + if (object == null) { + throw exception.get(); + } + } + + /** + * Проверка на true значение с возвращением исключения, если flag не true. + * + * @param flag Проверяемое значение + * @param exception Возвращаемое исключение + */ + public static void isTrue(boolean flag, Supplier exception) { + if (!flag) { + throw exception.get(); + } + } + + /** + * Проверка на false значение с возвращением исключения, если flag не false. + * + * @param flag Проверяемое значение + * @param exception Возвращаемое исключение + */ + public static void isFalse(boolean flag, Supplier exception) { + if (flag) { + throw exception.get(); + } + } + + @UtilityClass + public static final class Utils { + + public static Supplier nullPointer(String fieldName) { + return () -> new NullPointerException(fieldName + " is marked non-null but is null"); + } + + } + +} diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/ObjectUtils.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/ObjectUtils.java new file mode 100644 index 0000000..b310a39 --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/ObjectUtils.java @@ -0,0 +1,155 @@ +package dev.struchkov.haiti.utils; + +import dev.struchkov.haiti.context.exception.ConvertException; +import lombok.NonNull; +import lombok.experimental.UtilityClass; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * // TODO: 07.03.2021 Добавить описание. + * + * @author upagge 07.03.2021 + */ +@UtilityClass +public class ObjectUtils { + + /** + *

Позволяет получить значение вложенного в объект поля по названию поля.

+ *

+ *

При этом у поля должен быть доступен get-метод

+ *

+ *

Поддерживаются воженные объекты, чтобы задать такой объект, необходимо прописать путь до него от переданного объекта через '.'. У всех объектов на пути должны быть get-методы.

+ * + * @param fieldName Имя поля в объекте или цепь имен + * @param object Объект + * @return Значение поля из объекта + */ + public static Object getFieldValue(@NonNull Object object, @NonNull String fieldName) { + int firstNameIndex = fieldName.indexOf("."); + String firstName; + if (firstNameIndex != -1) { + firstName = fieldName.substring(0, firstNameIndex); + } else { + firstName = fieldName; + } + for (Method method : object.getClass().getMethods()) { + if (isGetMethod(firstName, method)) { + try { + final Object invoke = method.invoke(object); + if (firstNameIndex == -1) { + return invoke; + } else { + return getFieldValue(invoke, fieldName.substring(firstNameIndex + 1)); + } + } catch (IllegalAccessException | InvocationTargetException e) { + throw new ConvertException("Не удалось определить метод " + method.getName()); + } + } + } + throw new ConvertException("Метод у объекта не найден"); + } + + public static void setFieldValue(@NonNull Object object, @NonNull String fieldName, Object fieldValue) { + int firstNameIndex = fieldName.indexOf("."); + if (firstNameIndex != -1) { + final String[] split = fieldName.split("\\."); + final String fieldNameToObject = String.join(".", Arrays.copyOf(split, split.length - 1)); + fieldName = split[split.length - 1]; + object = getFieldValue(object, fieldNameToObject); + } + + boolean flag = true; + for (Method method : object.getClass().getMethods()) { + if (isSetMethod(fieldName, method)) { + try { + Class parameterType = method.getParameterTypes()[0]; + method.invoke(object, convertFieldValue(fieldValue, parameterType)); + flag = false; + break; + } catch (IllegalAccessException | InvocationTargetException e) { + throw new ConvertException("Не удалось определить метод " + method.getName()); + } + } + } + Assert.isFalse(flag, () -> new ConvertException("Метод у объекта не найден")); + } + + private static Object convertFieldValue(Object fieldValue, Class parameterType) { + if (String.class.equals(fieldValue.getClass())) { + final String value = (String) fieldValue; + if ("null".equalsIgnoreCase(value)) { + return null; + } + if (Long.class.equals(parameterType)) { + return Long.valueOf(value); + } + if (Integer.class.equals(parameterType)) { + return Integer.valueOf(value); + } + if (Double.class.equals(parameterType)) { + return Double.valueOf(value); + } + if (Float.class.equals(parameterType)) { + return Float.valueOf(value); + } + if (BigDecimal.class.equals(parameterType)) { + return BigDecimal.valueOf(Long.parseLong(value)); + } + if (BigInteger.class.equals(parameterType)) { + return BigInteger.valueOf(Long.parseLong(value)); + } + } + return fieldValue; + } + + /** + * Определяет что метод является геттером поля. + * + * @param fieldName Поле + * @param method Метод + * @return true если метод является геттером для fieldName, false в противном случае + */ + public static boolean isGetMethod(@NonNull String fieldName, Method method) { + return (method.getName().startsWith("get")) + && (method.getName().length() == (fieldName.length() + 3)) + && method.getName().toLowerCase().endsWith(fieldName.toLowerCase()); + } + + /** + * Определяет что метод является сеттером поля. + * + * @param fieldName Поле + * @param method Метод + * @return true если метод является сеттером для fieldName, false в противном случае + */ + public static boolean isSetMethod(@NonNull String fieldName, Method method) { + return (method.getName().startsWith("set")) + && (method.getName().length() == (fieldName.length() + 3)) + && method.getName().toLowerCase().endsWith(fieldName.toLowerCase()); + } + + public static Collection toCollect(T... t) { + return Arrays.stream(t).collect(Collectors.toList()); + } + + public static Collection toCollect(Collection collection, T... t) { + return Stream.concat( + collection.stream(), Arrays.stream(t) + ).collect(Collectors.toList()); + } + + public static Collection toCollect(Collection collectionOne, Collection collectionTwo) { + return Stream.concat( + collectionOne.stream(), collectionTwo.stream() + ).collect(Collectors.toList()); + } + +} diff --git a/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Strings.java b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Strings.java new file mode 100644 index 0000000..af31e5e --- /dev/null +++ b/haiti-utils/src/main/java/dev/struchkov/haiti/utils/Strings.java @@ -0,0 +1,15 @@ +package dev.struchkov.haiti.utils; + +import lombok.experimental.UtilityClass; + +/** + * // TODO: 07.03.2021 Добавить описание. + * + * @author upagge 07.03.2021 + */ +@UtilityClass +public class Strings { + + public static final String EMPTY = ""; + +} diff --git a/pom.xml b/pom.xml index d017493..ccd54c0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ 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.1-RELEASE + 0.0.1-SNAPSHOT pom @@ -14,6 +14,7 @@ haiti-core haiti-filter haiti-bom + haiti-utils Haiti Framework @@ -43,8 +44,8 @@ - SADTECH - https://sadtech.org + Struchkov Inc. + https://mark.struchkov.dev @@ -129,9 +130,9 @@ - org.sadtech.haiti + dev.struchkov.haiti haiti-bom - 0.0.1-RELEASE + 0.0.1-SNAPSHOT pom import @@ -156,12 +157,12 @@ uPagge Struchkov Mark - upagge@ya.ru - SADTECH - https://sadtech.org - https://uPagge.sadtech.org + mark@struchkov.dev + Struchkov Inc. + https://struchkov.dev + https://mark.struchkov.dev - Project lead + Project Lead +3