From 34e72edbe0722bf544d87d1bb5e15e1252f260fb Mon Sep 17 00:00:00 2001 From: uPagge Date: Thu, 12 Nov 2020 02:03:10 +0300 Subject: [PATCH] Init Commit --- .gitignore | 51 ++++++++ haiti-context/.gitignore | 51 ++++++++ haiti-context/pom.xml | 22 ++++ .../haiti/context/anotation/Marker.java | 18 +++ .../sadtech/haiti/context/enums/TypeSort.java | 12 ++ .../context/exception/AccessException.java | 13 ++ .../context/exception/BasicException.java | 18 +++ .../context/exception/ConvertException.java | 16 +++ .../context/exception/NotFoundException.java | 14 +++ .../haiti/context/page/Pagination.java | 15 +++ .../org/sadtech/haiti/context/page/Sheet.java | 22 ++++ .../repository/SimpleManagerRepository.java | 8 ++ .../repository/simple/CrudOperation.java | 31 +++++ .../repository/simple/MultipleOperation.java | 14 +++ .../repository/simple/PagingOperation.java | 11 ++ .../context/service/SimpleManagerService.java | 9 ++ .../service/simple/MultipleService.java | 16 +++ .../context/service/simple/PagingService.java | 17 +++ .../context/service/simple/SimpleService.java | 24 ++++ haiti-core/.gitignore | 51 ++++++++ haiti-core/pom.xml | 32 +++++ .../haiti/core/page/PaginationImpl.java | 35 ++++++ .../sadtech/haiti/core/page/SheetImpl.java | 40 +++++++ .../core/service/AbstractFilterService.java | 40 +++++++ .../core/service/AbstractMultipleService.java | 34 ++++++ .../core/service/AbstractPagingService.java | 20 ++++ .../service/AbstractSimpleManagerService.java | 56 +++++++++ .../core/service/AbstractSimpleService.java | 30 +++++ .../org/sadtech/haiti/core/util/Assert.java | 23 ++++ .../haiti/core/util/ServiceOperation.java | 37 ++++++ haiti-database/.gitignore | 51 ++++++++ haiti-database/pom.xml | 37 ++++++ .../haiti/database/entity/BasicEntity.java | 24 ++++ .../repository/AbstractCrudOperation.java | 35 ++++++ .../repository/AbstractFilterOperation.java | 38 ++++++ .../repository/AbstractMultipleOperation.java | 26 ++++ .../repository/AbstractPagingOperation.java | 20 ++++ .../database/repository/OperationJpa.java | 73 +++++++++++ .../AbstractSimpleManagerRepository.java | 55 +++++++++ .../manager/FilterManagerRepository.java | 59 +++++++++ .../haiti/database/util/Converter.java | 41 +++++++ pom.xml | 113 ++++++++++++++++++ 42 files changed, 1352 insertions(+) create mode 100644 .gitignore create mode 100644 haiti-context/.gitignore create mode 100644 haiti-context/pom.xml create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java create mode 100644 haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java create mode 100644 haiti-core/.gitignore create mode 100644 haiti-core/pom.xml create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java create mode 100644 haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java create mode 100644 haiti-database/.gitignore create mode 100644 haiti-database/pom.xml create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/entity/BasicEntity.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractCrudOperation.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractFilterOperation.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractMultipleOperation.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractPagingOperation.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/OperationJpa.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/AbstractSimpleManagerRepository.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/FilterManagerRepository.java create mode 100644 haiti-database/src/main/java/org/sadtech/haiti/database/util/Converter.java create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..58ae9ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,51 @@ +# Created by .ignore support plugin (hsz.mobi) +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser diff --git a/haiti-context/.gitignore b/haiti-context/.gitignore new file mode 100644 index 0000000..58ae9ed --- /dev/null +++ b/haiti-context/.gitignore @@ -0,0 +1,51 @@ +# Created by .ignore support plugin (hsz.mobi) +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser diff --git a/haiti-context/pom.xml b/haiti-context/pom.xml new file mode 100644 index 0000000..0ca9a26 --- /dev/null +++ b/haiti-context/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + org.sadtech.haiti + haiti + 0.0.1-SNAPSHOT + + + haiti-context + 0.0.1-SNAPSHOT + + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java b/haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java new file mode 100644 index 0000000..4f237f8 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/anotation/Marker.java @@ -0,0 +1,18 @@ +package org.sadtech.haiti.context.anotation; + +/** + * Маркер для разграничения политик валидации. + * + * @author upagge 26.05.20 + */ +public interface Marker { + + interface Create { + + } + + interface Update { + + } + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java b/haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java new file mode 100644 index 0000000..73fb1e1 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/enums/TypeSort.java @@ -0,0 +1,12 @@ +package org.sadtech.haiti.context.enums; + +/** + * Допустимые типы сортировки. + * + * @author upagge 28.01.2020 + */ +public enum TypeSort { + + ASC, DESC + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java new file mode 100644 index 0000000..baccb74 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/AccessException.java @@ -0,0 +1,13 @@ +package org.sadtech.haiti.context.exception; + +/** + * Исключения связанные с доступом. + */ +public class AccessException extends BasicException { + + public AccessException(String message) { + super(message); + } + +} + diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java new file mode 100644 index 0000000..ecced4d --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/BasicException.java @@ -0,0 +1,18 @@ +package org.sadtech.haiti.context.exception; + +/** + * Общий класс для всех ошибок приложения. + * + * @author upagge 17.12.2019 + */ +public abstract class BasicException extends RuntimeException { + + protected BasicException(String message) { + super(message); + } + + protected BasicException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java new file mode 100644 index 0000000..6e0aa42 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/ConvertException.java @@ -0,0 +1,16 @@ +package org.sadtech.haiti.context.exception; + +/** + * Исключение при конвертации. + */ +public class ConvertException extends BasicException { + + public ConvertException(String message) { + super(message); + } + + public ConvertException(String message, Throwable cause) { + super(message, cause); + } + +} 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 new file mode 100644 index 0000000..138dc53 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/exception/NotFoundException.java @@ -0,0 +1,14 @@ +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/page/Pagination.java b/haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java new file mode 100644 index 0000000..0f75d74 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/page/Pagination.java @@ -0,0 +1,15 @@ +package org.sadtech.haiti.context.page; + +import org.sadtech.haiti.context.enums.TypeSort; + +public interface Pagination { + + int getPage(); + + int getSize(); + + TypeSort getTypeSort(); + + String getFieldSort(); + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java b/haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java new file mode 100644 index 0000000..0b90f94 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/page/Sheet.java @@ -0,0 +1,22 @@ +package org.sadtech.haiti.context.page; + +import java.util.List; +import java.util.function.Function; + +public interface Sheet { + + int getNumber(); + + int getSize(); + + long getTotalElement(); + + int getTotalPage(); + + List getContent(); + + boolean hasContent(); + + Sheet map(Function converter); + +} 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 new file mode 100644 index 0000000..24f1e67 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/SimpleManagerRepository.java @@ -0,0 +1,8 @@ +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/CrudOperation.java b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java new file mode 100644 index 0000000..8127821 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/CrudOperation.java @@ -0,0 +1,31 @@ +package org.sadtech.haiti.context.repository.simple; + +import lombok.NonNull; + +import java.util.Optional; + +/** + * Контракт для реализации объекта, который будет взаимодействовать с хранилищем данных. + * + * @param Класс сущности + * @param Класс идентификатора + * @author upagge + */ +public interface CrudOperation { + + /** + * Сохраняет сущность в базу данных. Не проверяет на наличие в хранилище. + * Если сущность с подобным идентификатором уже есть, то необходимо ее перезаписать. + * + * @param entity Сущность для сохранения + * @return Сохраненная сущность + */ + T save(@NonNull T entity); + + Optional findById(@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/repository/simple/MultipleOperation.java b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java new file mode 100644 index 0000000..772f57b --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/MultipleOperation.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..f9f412e --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/repository/simple/PagingOperation.java @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..4431c01 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/service/SimpleManagerService.java @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..30bb5df --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/MultipleService.java @@ -0,0 +1,16 @@ +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-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java new file mode 100644 index 0000000..d545331 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/PagingService.java @@ -0,0 +1,17 @@ +package org.sadtech.haiti.context.service.simple; + +import lombok.NonNull; +import org.sadtech.haiti.context.page.Pagination; +import org.sadtech.haiti.context.page.Sheet; + +/** + * Расширение базового контракта сервисов с добавлением пагинации. + * + * @param Сущность сервиса. + * @author upagge 26.05.20 + */ +public interface PagingService { + + Sheet getAll(@NonNull Pagination pagination); + +} diff --git a/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java new file mode 100644 index 0000000..b037335 --- /dev/null +++ b/haiti-context/src/main/java/org/sadtech/haiti/context/service/simple/SimpleService.java @@ -0,0 +1,24 @@ +package org.sadtech.haiti.context.service.simple; + +import lombok.NonNull; + +import java.util.Optional; + +/** + * Базовый контракт для сервисов. + * + * @param Сущность сервиса. + */ +public interface SimpleService { + + T create(@NonNull T entity); + + T update(@NonNull T entity); + + Optional getById(@NonNull K primaryKey); + + boolean existsById(@NonNull K primaryKey); + + void deleteById(@NonNull K primaryKey); + +} diff --git a/haiti-core/.gitignore b/haiti-core/.gitignore new file mode 100644 index 0000000..58ae9ed --- /dev/null +++ b/haiti-core/.gitignore @@ -0,0 +1,51 @@ +# Created by .ignore support plugin (hsz.mobi) +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser diff --git a/haiti-core/pom.xml b/haiti-core/pom.xml new file mode 100644 index 0000000..0e58a91 --- /dev/null +++ b/haiti-core/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + org.sadtech.haiti + haiti + 0.0.1-SNAPSHOT + + + haiti-core + 0.0.1-SNAPSHOT + + + + org.sadtech.haiti + haiti-context + + + + org.sadtech.haiti.filter + filter-api + + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java b/haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java new file mode 100644 index 0000000..4049f20 --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/page/PaginationImpl.java @@ -0,0 +1,35 @@ +package org.sadtech.haiti.core.page; + +import lombok.Getter; +import org.sadtech.haiti.context.enums.TypeSort; +import org.sadtech.haiti.context.page.Pagination; + +@Getter +public class PaginationImpl implements Pagination { + + private final int page; + private final int size; + private String fieldSort; + private TypeSort typeSort; + + private PaginationImpl(int page, int size) { + this.page = page; + this.size = size; + } + + public PaginationImpl(int page, int size, String fieldSort, TypeSort typeSort) { + this.page = page; + this.size = size; + this.fieldSort = fieldSort; + this.typeSort = typeSort; + } + + public static Pagination of(int page, int size) { + return new PaginationImpl(page, size); + } + + public static Pagination of(int page, int size, String fieldSort, TypeSort typeSort) { + return new PaginationImpl(page, size, fieldSort, typeSort); + } + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java b/haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java new file mode 100644 index 0000000..5ff8e38 --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/page/SheetImpl.java @@ -0,0 +1,40 @@ +package org.sadtech.haiti.core.page; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import org.sadtech.haiti.context.page.Sheet; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Getter +@Builder +@AllArgsConstructor +public class SheetImpl implements Sheet { + + private final int number; + private final int size; + private final long totalElement; + 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<>( + this.number, + this.size, + this.totalElement, + this.totalPage, + this.content.stream().map(function).collect(Collectors.toList()) + ); + } + + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java new file mode 100644 index 0000000..29852ab --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractFilterService.java @@ -0,0 +1,40 @@ +package org.sadtech.haiti.core.service; + +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; + + @Override + public Sheet getAll(@NonNull F filter, Pagination pagination) { + return filterOperation.findAll(createFilter(filter), pagination); + } + + @Override + public Optional getFirst(@NonNull F filter) { + return filterOperation.findFirst(createFilter(filter)); + } + + @Override + public boolean exists(@NonNull F filter) { + return filterOperation.exists(createFilter(filter)); + } + + @Override + public long count(@NonNull F filter) { + return filterOperation.count(createFilter(filter)); + } + + protected abstract Filter createFilter(@NonNull F filter); + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java new file mode 100644 index 0000000..1efba9d --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractMultipleService.java @@ -0,0 +1,34 @@ +package org.sadtech.haiti.core.service; + +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 { + + private final SimpleService simpleService; + private final MultipleOperation multipleOperation; + + @Override + public void deleteAllById(@NonNull Collection ids) { + multipleOperation.deleteAllById(ids); + } + + @Override + public List createAll(@NonNull Collection entities) { + return entities.stream().map(simpleService::create).collect(Collectors.toList()); + } + + @Override + public List updateAll(@NonNull Collection entities) { + return entities.stream().map(simpleService::update).collect(Collectors.toList()); + } + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java new file mode 100644 index 0000000..6e3b298 --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractPagingService.java @@ -0,0 +1,20 @@ +package org.sadtech.haiti.core.service; + +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 { + + private final PagingOperation pagingOperation; + + @Override + public Sheet getAll(@NonNull Pagination pagination) { + return pagingOperation.findAll(pagination); + } + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java new file mode 100644 index 0000000..f4cf0bb --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleManagerService.java @@ -0,0 +1,56 @@ +package org.sadtech.haiti.core.service; + +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; +import java.util.Optional; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +public abstract class AbstractSimpleManagerService implements SimpleManagerService { + + private final SimpleManagerRepository repository; + + @Override + public void deleteAllById(@NonNull Collection primaryKeys) { + ServiceOperation.deleteAllById(repository, primaryKeys); + } + + @Override + public Sheet getAll(@NonNull Pagination pagination) { + return ServiceOperation.getAll(repository, pagination); + } + + @Override + public Optional getById(@NonNull K primaryKey) { + return ServiceOperation.getById(repository, primaryKey); + } + + @Override + public boolean existsById(@NonNull K primaryKey) { + return ServiceOperation.existsById(repository, primaryKey); + } + + @Override + public void deleteById(@NonNull K primaryKey) { + ServiceOperation.deleteById(repository, primaryKey); + } + + @Override + public List createAll(@NonNull Collection entities) { + return entities.stream().map(this::create).collect(Collectors.toList()); + } + + @Override + public List updateAll(@NonNull Collection entities) { + return entities.stream().map(this::update).collect(Collectors.toList()); + } + +} diff --git a/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java new file mode 100644 index 0000000..1c0b295 --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/service/AbstractSimpleService.java @@ -0,0 +1,30 @@ +package org.sadtech.haiti.core.service; + +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; + +@RequiredArgsConstructor +public abstract class AbstractSimpleService implements SimpleService { + + private final CrudOperation crudOperation; + + @Override + public Optional getById(@NonNull K primaryKey) { + return crudOperation.findById(primaryKey); + } + + @Override + public boolean existsById(@NonNull K primaryKey) { + return crudOperation.existsById(primaryKey); + } + + @Override + public void deleteById(@NonNull K primaryKey) { + crudOperation.deleteById(primaryKey); + } + +} 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 new file mode 100644 index 0000000..c96ea9f --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/util/Assert.java @@ -0,0 +1,23 @@ +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 new file mode 100644 index 0000000..6f92746 --- /dev/null +++ b/haiti-core/src/main/java/org/sadtech/haiti/core/util/ServiceOperation.java @@ -0,0 +1,37 @@ +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-database/.gitignore b/haiti-database/.gitignore new file mode 100644 index 0000000..58ae9ed --- /dev/null +++ b/haiti-database/.gitignore @@ -0,0 +1,51 @@ +# Created by .ignore support plugin (hsz.mobi) +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser diff --git a/haiti-database/pom.xml b/haiti-database/pom.xml new file mode 100644 index 0000000..d9db6a3 --- /dev/null +++ b/haiti-database/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + org.sadtech.haiti + haiti + 0.0.1-SNAPSHOT + + + haiti-database + 0.0.1-SNAPSHOT + + + + org.projectlombok + lombok + + + + org.sadtech.haiti + haiti-core + + + + org.sadtech.haiti.filter + criteria-filter + + + + org.springframework.data + spring-data-jpa + + + + \ No newline at end of file diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/entity/BasicEntity.java b/haiti-database/src/main/java/org/sadtech/haiti/database/entity/BasicEntity.java new file mode 100644 index 0000000..1312634 --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/entity/BasicEntity.java @@ -0,0 +1,24 @@ +package org.sadtech.haiti.database.entity; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@Getter +@Setter +@MappedSuperclass +@EqualsAndHashCode(of = "id") +public abstract class BasicEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false, nullable = false) + protected Long id; + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractCrudOperation.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractCrudOperation.java new file mode 100644 index 0000000..dffe2de --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractCrudOperation.java @@ -0,0 +1,35 @@ +package org.sadtech.haiti.database.repository; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.haiti.context.repository.simple.CrudOperation; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +@RequiredArgsConstructor +public abstract class AbstractCrudOperation implements CrudOperation { + + private final JpaRepository jpaRepository; + + @Override + public T save(@NonNull T entity) { + return OperationJpa.save(jpaRepository, entity); + } + + @Override + public Optional findById(@NonNull K primaryKey) { + return OperationJpa.findById(jpaRepository, primaryKey); + } + + @Override + public boolean existsById(@NonNull K primaryKey) { + return OperationJpa.existsById(jpaRepository, primaryKey); + } + + @Override + public void deleteById(@NonNull K primaryKey) { + OperationJpa.deleteById(jpaRepository, primaryKey); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractFilterOperation.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractFilterOperation.java new file mode 100644 index 0000000..08601e7 --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractFilterOperation.java @@ -0,0 +1,38 @@ +package org.sadtech.haiti.database.repository; + +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.springframework.data.jpa.repository.support.JpaRepositoryImplementation; + +import java.util.Optional; + +@RequiredArgsConstructor +public abstract class AbstractFilterOperation implements FilterOperation { + + private final JpaRepositoryImplementation jpaRepository; + + @Override + public Sheet findAll(@NonNull Filter filter, @NonNull Pagination pagination) { + return OperationJpa.findAll(jpaRepository, filter.build(), pagination); + } + + @Override + public Optional findFirst(@NonNull Filter filter) { + return OperationJpa.findFirst(jpaRepository, filter.build()); + } + + @Override + public boolean exists(@NonNull Filter filter) { + return OperationJpa.exists(jpaRepository, filter.build()); + } + + @Override + public long count(@NonNull Filter filter) { + return OperationJpa.count(jpaRepository, filter.build()); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractMultipleOperation.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractMultipleOperation.java new file mode 100644 index 0000000..6dc19eb --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractMultipleOperation.java @@ -0,0 +1,26 @@ +package org.sadtech.haiti.database.repository; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.haiti.context.repository.simple.MultipleOperation; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Collection; +import java.util.List; + +@RequiredArgsConstructor +public abstract class AbstractMultipleOperation implements MultipleOperation { + + private final JpaRepository jpaRepository; + + @Override + public List saveAll(@NonNull Collection entities) { + return OperationJpa.saveAll(jpaRepository, entities); + } + + @Override + public void deleteAllById(@NonNull Collection primaryKeys) { + OperationJpa.deleteAllById(jpaRepository, primaryKeys); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractPagingOperation.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractPagingOperation.java new file mode 100644 index 0000000..1546170 --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/AbstractPagingOperation.java @@ -0,0 +1,20 @@ +package org.sadtech.haiti.database.repository; + +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.springframework.data.jpa.repository.JpaRepository; + +@RequiredArgsConstructor +public abstract class AbstractPagingOperation implements PagingOperation { + + private final JpaRepository jpaRepository; + + @Override + public Sheet findAll(@NonNull Pagination pagination) { + return OperationJpa.findAll(jpaRepository, pagination); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/OperationJpa.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/OperationJpa.java new file mode 100644 index 0000000..d625f6a --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/OperationJpa.java @@ -0,0 +1,73 @@ +package org.sadtech.haiti.database.repository; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.sadtech.haiti.context.page.Pagination; +import org.sadtech.haiti.context.page.Sheet; +import org.sadtech.haiti.database.util.Converter; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class OperationJpa { + + public static T save(JpaRepository jpaRepository, T entity) { + return jpaRepository.save(entity); + } + + public static Optional findById(JpaRepository jpaRepository, K primaryKey) { + return jpaRepository.findById(primaryKey); + } + + public static boolean existsById(JpaRepository jpaRepository, K primaryKey) { + return jpaRepository.existsById(primaryKey); + } + + public static void deleteById(JpaRepository jpaRepository, K primaryKey) { + jpaRepository.deleteById(primaryKey); + } + + public static Sheet findAll(JpaRepository jpaRepository, Pagination pagination) { + return Converter.page( + jpaRepository.findAll( + Converter.pagination(pagination) + ) + ); + } + + public static List saveAll(JpaRepository jpaRepository, Collection entities) { + return jpaRepository.saveAll(entities); + } + + public static void deleteAllById(JpaRepository jpaRepository, Collection primaryKeys) { + primaryKeys.forEach(jpaRepository::deleteById); + } + + public static Optional findFirst(JpaRepositoryImplementation jpaRepository, Specification specification) { + return jpaRepository.findOne(specification); + } + + public static boolean exists(JpaRepositoryImplementation jpaRepository, Specification specification) { + return jpaRepository.count(specification) > 0; + } + + public static List findAll(JpaRepositoryImplementation jpaRepository, Specification specification) { + return jpaRepository.findAll(specification); + } + + public static Sheet findAll(JpaRepositoryImplementation jpaRepository, Specification specification, Pagination pagination) { + return Converter.page( + jpaRepository.findAll(specification, Converter.pagination(pagination)) + ); + } + + public static long count(JpaRepositoryImplementation jpaRepository, Specification specification) { + return jpaRepository.count(specification); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/AbstractSimpleManagerRepository.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/AbstractSimpleManagerRepository.java new file mode 100644 index 0000000..67b083f --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/AbstractSimpleManagerRepository.java @@ -0,0 +1,55 @@ +package org.sadtech.haiti.database.repository.manager; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.haiti.database.repository.OperationJpa; +import org.sadtech.haiti.context.page.Pagination; +import org.sadtech.haiti.context.page.Sheet; +import org.sadtech.haiti.context.repository.SimpleManagerRepository; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +@RequiredArgsConstructor +public abstract class AbstractSimpleManagerRepository implements SimpleManagerRepository { + + private final JpaRepository jpaRepository; + + @Override + public T save(@NonNull T entity) { + return OperationJpa.save(jpaRepository, entity); + } + + @Override + public Optional findById(@NonNull K primaryKey) { + return OperationJpa.findById(jpaRepository, primaryKey); + } + + @Override + public boolean existsById(@NonNull K primaryKey) { + return OperationJpa.existsById(jpaRepository, primaryKey); + } + + @Override + public void deleteById(@NonNull K primaryKey) { + OperationJpa.deleteById(jpaRepository, primaryKey); + } + + @Override + public List saveAll(@NonNull Collection entities) { + return OperationJpa.saveAll(jpaRepository, entities); + } + + @Override + public void deleteAllById(@NonNull Collection primaryKeys) { + OperationJpa.deleteAllById(jpaRepository, primaryKeys); + } + + @Override + public Sheet findAll(@NonNull Pagination pagination) { + return OperationJpa.findAll(jpaRepository, pagination); + } + +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/FilterManagerRepository.java b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/FilterManagerRepository.java new file mode 100644 index 0000000..f71db8c --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/repository/manager/FilterManagerRepository.java @@ -0,0 +1,59 @@ +package org.sadtech.haiti.database.repository.manager; + +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import org.sadtech.haiti.context.page.Pagination; +import org.sadtech.haiti.context.page.Sheet; +import org.sadtech.haiti.database.repository.OperationJpa; +import org.sadtech.haiti.filter.Filter; +import org.sadtech.haiti.filter.FilterOperation; +import org.springframework.dao.InvalidDataAccessResourceUsageException; +import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; + +import java.util.Optional; + +@Slf4j +public abstract class FilterManagerRepository extends AbstractSimpleManagerRepository implements FilterOperation { + + private final JpaRepositoryImplementation jpaRepositoryImplementation; + + public FilterManagerRepository(JpaRepositoryImplementation jpaRepository) { + super(jpaRepository); + this.jpaRepositoryImplementation = jpaRepository; + } + + @Override + public Sheet findAll(@NonNull Filter filter, @NonNull Pagination pagination) { + return OperationJpa.findAll(jpaRepositoryImplementation, filter.build(), pagination); + } + + @Override + public Optional findFirst(@NonNull Filter filter) { + try { + return OperationJpa.findFirst(jpaRepositoryImplementation, filter.build()); + } catch (InvalidDataAccessResourceUsageException e) { + log.error(e.getMessage()); + } + return Optional.empty(); + } + + @Override + public boolean exists(@NonNull Filter filter) { + try { + return OperationJpa.exists(jpaRepositoryImplementation, filter.build()); + } catch (InvalidDataAccessResourceUsageException e) { + log.error(e.getMessage()); + } + return false; + } + + @Override + public long count(@NonNull Filter filter) { + try { + return OperationJpa.count(jpaRepositoryImplementation, filter.build()); + } catch (InvalidDataAccessResourceUsageException e) { + log.error(e.getMessage()); + } + return 0; + } +} diff --git a/haiti-database/src/main/java/org/sadtech/haiti/database/util/Converter.java b/haiti-database/src/main/java/org/sadtech/haiti/database/util/Converter.java new file mode 100644 index 0000000..abfbdef --- /dev/null +++ b/haiti-database/src/main/java/org/sadtech/haiti/database/util/Converter.java @@ -0,0 +1,41 @@ +package org.sadtech.haiti.database.util; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.sadtech.haiti.context.enums.TypeSort; +import org.sadtech.haiti.context.page.Pagination; +import org.sadtech.haiti.context.page.Sheet; +import org.sadtech.haiti.core.page.SheetImpl; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class Converter { + + public static Pageable pagination(@NonNull Pagination pagination) { + if (pagination.getTypeSort() != null) { + return PageRequest.of( + pagination.getPage(), + pagination.getSize(), + TypeSort.ASC.equals(pagination.getTypeSort()) ? Sort.Direction.ASC : Sort.Direction.DESC, + pagination.getFieldSort() + ); + } + return PageRequest.of(pagination.getPage(), pagination.getSize()); + } + + public static Sheet page(@NonNull Page page) { + return SheetImpl.builder() + .totalPage(page.getTotalPages()) + .totalElement(page.getTotalElements()) + .size(page.getSize()) + .number(page.getNumber()) + .content(page.getContent()) + .build(); + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..028a73d --- /dev/null +++ b/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + org.sadtech.haiti + haiti + 0.0.1-SNAPSHOT + pom + + + haiti-context + haiti-core + haiti-database + + + + 1.8 + 1.8 + 1.8 + + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + 0.0.1-SNAPSHOT + + 4.1.0 + 2.4.0 + 2.4.0 + + 7.9.3 + 1.18.16 + + + + + + org.sadtech.haiti + haiti-context + ${sadtech.haiti.context.version} + + + + org.sadtech.haiti + haiti-core + ${sadtech.haiti.core.version} + + + + org.sadtech.haiti.filter + criteria-filter + ${sadtech.haiti.filter.criteria.version} + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.sadtech.haiti.filter + filter-api + ${sadtech.haiti.filter.api.version} + + + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + + + + javax.persistence + javax.persistence-api + 2.2 + + + + + org.springframework.data + spring-data-elasticsearch + ${spring.data.elasticsearch.version} + + + + org.springframework.data + spring-data-commons + ${spring.data.commons.version} + + + + org.springframework.data + spring-data-jpa + ${spring.data.jpa.version} + + + + + + + + uPagge + Struchkov Mark + upagge@ya.ru + SADTECH + https://t.me/uPagge + + + + \ No newline at end of file