рефакторинг

This commit is contained in:
Struchkov Mark 2022-12-09 21:03:41 +03:00
parent 6b8c430dbb
commit 7907a80f77
44 changed files with 171 additions and 1269 deletions

View File

@ -9,7 +9,7 @@
<version>1.5.0</version>
<packaging>pom</packaging>
<name>Haiti BOM</name>
<name>Haiti Dependencies</name>
<description>Current versions of the framework dependencies</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<licenses>
@ -38,11 +38,11 @@
<haiti.filter.api.ver>${haiti.ver}</haiti.filter.api.ver>
<haiti.utils.ver>${haiti.ver}</haiti.utils.ver>
<haiti.database.ver>0.0.4</haiti.database.ver>
<haiti.database.ver>1.4.0</haiti.database.ver>
<haiti.filter.criteria.ver>0.0.4</haiti.filter.criteria.ver>
<haiti.utils.network.ver>0.0.4</haiti.utils.network.ver>
<haiti.utils.field.constants>0.0.1</haiti.utils.field.constants>
<haiti.utils.field.constants>0.0.5</haiti.utils.field.constants>
<spring.data.elasticsearch.ver>4.3.1</spring.data.elasticsearch.ver>
<spring.data.jpa.ver>2.6.1</spring.data.jpa.ver>
@ -181,8 +181,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.maven.compiler.ver}</version>
<configuration>
<source>11</source>
<target>11</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
@ -218,19 +218,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${plugin.maven.javadoc.ver}</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>

View File

@ -1,51 +0,0 @@
# 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

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
</parent>
<artifactId>haiti-context</artifactId>
<version>${haiti.context.ver}</version>
<name>Haiti Context</name>
<description>Basic framework general classes</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-exception</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-utils</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,18 +0,0 @@
package dev.struchkov.haiti.context.anotation;
/**
* Маркер для разграничения политик валидации.
*
* @author upagge 26.05.20
*/
public interface Marker {
interface Create {
}
interface Update {
}
}

View File

@ -1,14 +0,0 @@
package dev.struchkov.haiti.context.domain;
/**
* Базовая класс для сущностей.
*
* @author upagge 14.01.2021
*/
public interface BasicEntity<Key> {
Key getId();
void setId(Key id);
}

View File

@ -1,47 +0,0 @@
package dev.struchkov.haiti.context.domain;
import java.util.Collection;
import java.util.Collections;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
/**
* Контейнер для возврата результата сервисных методов exists.
*
* @author upagge 11.01.2021
*/
public class ExistsContainer<Entity, Key> {
protected final Collection<Entity> container;
protected final boolean allFound;
protected final Collection<Key> idNoFound;
protected ExistsContainer(Collection<Entity> container, boolean allFound, Collection<Key> idNoFound) {
this.container = container;
this.allFound = allFound;
this.idNoFound = idNoFound;
}
public static <T, K> ExistsContainer<T, K> allFind(Collection<T> container) {
isNotNull(container);
return new ExistsContainer<>(container, true, Collections.emptyList());
}
public static <T, K> ExistsContainer<T, K> notAllFind(Collection<T> container, Collection<K> idNoFound) {
isNotNull(container, idNoFound);
return new ExistsContainer<>(container, false, idNoFound);
}
public Collection<Entity> getContainer() {
return container;
}
public boolean isAllFound() {
return allFound;
}
public Collection<Key> getIdNoFound() {
return idNoFound;
}
}

View File

@ -1,12 +0,0 @@
package dev.struchkov.haiti.context.enums;
/**
* Допустимые типы сортировки.
*
* @author upagge 28.01.2020
*/
public enum TypeSort {
ASC, DESC
}

View File

@ -1,13 +0,0 @@
package dev.struchkov.haiti.context.page;
import java.util.Set;
public interface Pagination {
Integer getPage();
Integer getSize();
Set<? extends Sort> getSorts();
}

View File

@ -1,22 +0,0 @@
package dev.struchkov.haiti.context.page;
import java.util.List;
import java.util.function.Function;
public interface Sheet<Entity> {
int getNumber();
int getSize();
long getTotalElement();
int getTotalPage();
List<Entity> getContent();
boolean hasContent();
<NewEntity> Sheet<NewEntity> map(Function<? super Entity, ? extends NewEntity> converter);
}

View File

@ -1,11 +0,0 @@
package dev.struchkov.haiti.context.page;
import dev.struchkov.haiti.context.enums.TypeSort;
public interface Sort {
TypeSort getType();
String getField();
}

View File

@ -1,47 +0,0 @@
package dev.struchkov.haiti.context.page.impl;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sort;
import java.util.Set;
public class PaginationImpl implements Pagination {
private final Integer page;
private final Integer size;
private Set<? extends Sort> sorts;
private PaginationImpl(int page, int size) {
this.page = page;
this.size = size;
}
public PaginationImpl(int page, int size, Set<? extends Sort> sorts) {
this.page = page;
this.size = size;
this.sorts = sorts;
}
public static Pagination of(int page, int size) {
return new PaginationImpl(page, size);
}
public static Pagination of(int page, int size, Set<? extends Sort> sorts) {
return new PaginationImpl(page, size, sorts);
}
@Override
public Integer getPage() {
return page;
}
@Override
public Integer getSize() {
return size;
}
@Override
public Set<? extends Sort> getSorts() {
return sorts;
}
}

View File

@ -1,88 +0,0 @@
package dev.struchkov.haiti.context.page.impl;
import dev.struchkov.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;
public class SheetImpl<Entity> implements Sheet<Entity> {
private final int number;
private final int size;
private final long totalElement;
private final int totalPage;
private final List<Entity> content;
public SheetImpl(int number, int size, long totalElement, int totalPage, List<Entity> content) {
this.number = number;
this.size = size;
this.totalElement = totalElement;
this.totalPage = totalPage;
this.content = content;
}
@Override
public <U> Sheet<U> map(Function<? super Entity, ? extends U> function) {
return new SheetImpl<>(
this.number,
this.size,
this.totalElement,
this.totalPage,
this.content.stream().map(function).collect(Collectors.toList())
);
}
public static <T> Sheet<T> empty() {
return new SheetImpl<>(
0,
0,
0L,
0,
Collections.emptyList()
);
}
public Sheet<Entity> filter(Predicate<? super Entity> predicate) {
final List<Entity> 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();
}
@Override
public int getNumber() {
return number;
}
@Override
public int getSize() {
return size;
}
@Override
public long getTotalElement() {
return totalElement;
}
@Override
public int getTotalPage() {
return totalPage;
}
@Override
public List<Entity> getContent() {
return content;
}
}

View File

@ -1,33 +0,0 @@
package dev.struchkov.haiti.context.page.impl;
import dev.struchkov.haiti.context.enums.TypeSort;
import dev.struchkov.haiti.context.page.Sort;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class SortImpl implements Sort {
private final TypeSort type;
private final String field;
private SortImpl(TypeSort type, String field) {
this.type = type;
this.field = field;
}
public static Sort of(TypeSort type, String field) {
isNotNull(type);
return new SortImpl(type, field);
}
@Override
public TypeSort getType() {
return type;
}
@Override
public String getField() {
return field;
}
}

View File

@ -1,11 +0,0 @@
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<T extends BasicEntity<K>, K>
extends CrudOperation<T, K>, MultipleOperation<T, K>, PagingOperation<T> {
}

View File

@ -1,29 +0,0 @@
package dev.struchkov.haiti.context.repository.simple;
import java.util.Optional;
/**
* Контракт для реализации объекта, который будет взаимодействовать с хранилищем данных.
*
* @param <Entity> Класс сущности
* @param <Key> Класс идентификатора
* @author upagge
*/
public interface CrudOperation<Entity, Key> {
/**
* Сохраняет сущность в базу данных. Не проверяет на наличие в хранилище.
* Если сущность с подобным идентификатором уже есть, то необходимо ее перезаписать.
*
* @param entity Сущность для сохранения
* @return Сохраненная сущность
*/
Entity save(Entity entity);
Optional<Entity> findById(Key id);
boolean existsById(Key id);
void deleteById(Key id);
}

View File

@ -1,16 +0,0 @@
package dev.struchkov.haiti.context.repository.simple;
import dev.struchkov.haiti.context.domain.BasicEntity;
import java.util.Collection;
import java.util.List;
public interface MultipleOperation<T extends BasicEntity<K>, K> {
List<T> saveAll(Collection<T> entities);
void deleteAllById(Collection<K> primaryKeys);
List<T> findAllById(Collection<K> ids);
}

View File

@ -1,10 +0,0 @@
package dev.struchkov.haiti.context.repository.simple;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sheet;
public interface PagingOperation<T> {
Sheet<T> findAll(Pagination pagination);
}

View File

@ -1,11 +0,0 @@
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<Entity extends BasicEntity<Key>, Key>
extends SimpleService<Entity, Key>, MultipleService<Entity, Key>, PagingService<Entity> {
}

View File

@ -1,39 +0,0 @@
package dev.struchkov.haiti.context.service.simple;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sheet;
import java.util.Optional;
public interface FilterService<Entity, Filter> {
/**
* Получить все элементы по заданному фильтру.
*
* @param filter Фильтр
* @param pagination Пагинация
*/
Sheet<Entity> getAll(Filter filter, Pagination pagination);
/**
* Возвращает первый найденный объект по фильтру.
*
* @param filter Объект фильтра
*/
Optional<Entity> getFirst(Filter filter);
/**
* Проверка на наличие хотя бы одной сущности, которая удовлетворяет определенному набору параметров.
*
* @param filter Набор параметров
*/
boolean exists(Filter filter);
/**
* Получить количество сущностей, которые удовлетворяют определенному набору параметров.
*
* @param filter Набор параметров
*/
long count(Filter filter);
}

View File

@ -1,19 +0,0 @@
package dev.struchkov.haiti.context.service.simple;
import dev.struchkov.haiti.context.domain.BasicEntity;
import dev.struchkov.haiti.context.domain.ExistsContainer;
import java.util.Collection;
import java.util.List;
public interface MultipleService<Entity extends BasicEntity<Key>, Key> {
List<Entity> createAll(Collection<Entity> entities);
List<Entity> updateAll(Collection<Entity> entities);
void deleteAllById(Collection<Key> ids);
ExistsContainer<Entity, Key> existsById(Collection<Key> ids);
}

View File

@ -1,16 +0,0 @@
package dev.struchkov.haiti.context.service.simple;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sheet;
/**
* Расширение базового контракта сервисов с добавлением пагинации.
*
* @param <Entity> Сущность сервиса.
* @author upagge 26.05.20
*/
public interface PagingService<Entity> {
Sheet<Entity> getAll(Pagination pagination);
}

View File

@ -1,24 +0,0 @@
package dev.struchkov.haiti.context.service.simple;
import java.util.Optional;
/**
* Базовый контракт для сервисов.
*
* @param <Entity> Сущность сервиса.
*/
public interface SimpleService<Entity, Key> {
Entity create(Entity entity);
Entity update(Entity entity);
Optional<Entity> getById(Key id);
Entity getByIdOrThrow(Key id);
boolean existsById(Key id);
void deleteById(Key id);
}

View File

@ -1,12 +0,0 @@
module haiti.context {
exports dev.struchkov.haiti.context.service.simple;
exports dev.struchkov.haiti.context.repository.simple;
exports dev.struchkov.haiti.context.page.impl;
exports dev.struchkov.haiti.context.repository;
exports dev.struchkov.haiti.context.domain;
exports dev.struchkov.haiti.context.service;
exports dev.struchkov.haiti.context.page;
exports dev.struchkov.haiti.context.enums;
requires transitive haiti.utils;
}

51
haiti-core/.gitignore vendored
View File

@ -1,51 +0,0 @@
# 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

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
</parent>
<artifactId>haiti-core</artifactId>
<version>${haiti.core.ver}</version>
<name>Haiti Core</name>
<description>Implementation of the main classes of the framework</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-context</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-filter</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,77 +0,0 @@
package dev.struchkov.haiti.core.repository;
import dev.struchkov.haiti.context.domain.BasicEntity;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sheet;
import dev.struchkov.haiti.context.repository.SimpleManagerRepository;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
import static dev.struchkov.haiti.utils.Strings.ERR_OPERATION_NOT_SUPPORTED;
public class SimpleManagerRepositoryMap<T extends BasicEntity<Long>> implements SimpleManagerRepository<T, Long> {
protected final Map<Long, T> map = new HashMap<>();
protected long key = 0;
@Override
public T save(T accessTarget) {
isNotNull(accessTarget);
accessTarget.setId(key);
map.put(key, accessTarget);
key++;
return accessTarget;
}
@Override
public Optional<T> findById(Long id) {
isNotNull(id);
return Optional.ofNullable(map.get(id));
}
@Override
public boolean existsById(Long id) {
isNotNull(id);
return map.containsKey(id);
}
@Override
public void deleteById(Long id) {
isNotNull(id);
map.remove(id);
}
@Override
public List<T> saveAll(Collection<T> accessTargets) {
isNotNull(accessTargets);
return accessTargets.stream()
.map(this::save)
.collect(Collectors.toList());
}
@Override
public void deleteAllById(Collection<Long> accessTargets) {
isNotNull(accessTargets);
accessTargets.forEach(map::remove);
}
@Override
public List<T> findAllById(Collection<Long> ids) {
isNotNull(ids);
return ids.stream()
.map(map::get)
.collect(Collectors.toList());
}
@Override
public Sheet<T> findAll(Pagination pagination) {
throw new IllegalStateException(ERR_OPERATION_NOT_SUPPORTED);
}
}

View File

@ -1,46 +0,0 @@
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 dev.struchkov.haiti.utils.Inspector;
import java.util.Optional;
public abstract class AbstractFilterService<Entity, F> implements FilterService<Entity, F> {
protected final FilterOperation<Entity> filterOperation;
protected AbstractFilterService(FilterOperation<Entity> filterOperation) {
this.filterOperation = filterOperation;
}
@Override
public Sheet<Entity> getAll(F filter, Pagination pagination) {
Inspector.isNotNull(filter);
return filterOperation.findAll(createFilter(filter), pagination);
}
@Override
public Optional<Entity> getFirst(F filter) {
Inspector.isNotNull(filter);
return filterOperation.findFirst(createFilter(filter));
}
@Override
public boolean exists(F filter) {
Inspector.isNotNull(filter);
return filterOperation.exists(createFilter(filter));
}
@Override
public long count(F filter) {
Inspector.isNotNull(filter);
return filterOperation.count(createFilter(filter));
}
protected abstract Filter createFilter(F filter);
}

View File

@ -1,49 +0,0 @@
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 dev.struchkov.haiti.utils.Inspector;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public abstract class AbstractMultipleService<Entity extends BasicEntity<Key>, Key> implements MultipleService<Entity, Key> {
private final SimpleService<Entity, Key> simpleService;
private final MultipleOperation<Entity, Key> multipleOperation;
protected AbstractMultipleService(SimpleService<Entity, Key> simpleService, MultipleOperation<Entity, Key> multipleOperation) {
this.simpleService = simpleService;
this.multipleOperation = multipleOperation;
}
@Override
public void deleteAllById(Collection<Key> ids) {
Inspector.isNotNull(ids);
multipleOperation.deleteAllById(ids);
}
@Override
public List<Entity> createAll(Collection<Entity> entities) {
Inspector.isNotNull(entities);
return entities.stream().map(simpleService::create).collect(Collectors.toList());
}
@Override
public List<Entity> updateAll(Collection<Entity> entities) {
Inspector.isNotNull(entities);
return entities.stream().map(simpleService::update).collect(Collectors.toList());
}
@Override
public ExistsContainer<Entity, Key> existsById(Collection<Key> ids) {
Inspector.isNotNull(ids);
return ServiceOperation.existsContainerById(multipleOperation, ids);
}
}

View File

@ -1,23 +0,0 @@
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 dev.struchkov.haiti.utils.Inspector;
public abstract class AbstractPagingService<T> implements PagingService<T> {
private final PagingOperation<T> pagingOperation;
protected AbstractPagingService(PagingOperation<T> pagingOperation) {
this.pagingOperation = pagingOperation;
}
@Override
public Sheet<T> getAll(Pagination pagination) {
Inspector.isNotNull(pagination);
return pagingOperation.findAll(pagination);
}
}

View File

@ -1,81 +0,0 @@
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.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 dev.struchkov.haiti.utils.Inspector;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
public abstract class AbstractSimpleManagerService<Entity extends BasicEntity<Key>, Key> implements SimpleManagerService<Entity, Key> {
protected final SimpleManagerRepository<Entity, Key> repository;
protected AbstractSimpleManagerService(SimpleManagerRepository<Entity, Key> repository) {
this.repository = repository;
}
@Override
public void deleteAllById(Collection<Key> ids) {
Inspector.isNotNull(ids);
ServiceOperation.deleteAllById(repository, ids);
}
@Override
public Sheet<Entity> getAll(Pagination pagination) {
Inspector.isNotNull(pagination);
return ServiceOperation.getAll(repository, pagination);
}
@Override
public Optional<Entity> getById(Key id) {
Inspector.isNotNull(id);
return ServiceOperation.getById(repository, id);
}
@Override
public Entity getByIdOrThrow(Key id) {
Inspector.isNotNull(id);
return getById(id).orElseThrow(notFoundException("Объект не найден. Идентификатор: ", id));
}
@Override
public boolean existsById(Key id) {
Inspector.isNotNull(id);
return ServiceOperation.existsById(repository, id);
}
@Override
public void deleteById(Key id) {
Inspector.isNotNull(id);
ServiceOperation.deleteById(repository, id);
}
@Override
public List<Entity> createAll(Collection<Entity> entities) {
Inspector.isNotNull(entities);
return entities.stream().map(this::create).collect(Collectors.toList());
}
@Override
public List<Entity> updateAll(Collection<Entity> entities) {
Inspector.isNotNull(entities);
return entities.stream().map(this::update).collect(Collectors.toList());
}
@Override
public ExistsContainer<Entity, Key> existsById(Collection<Key> ids) {
Inspector.isNotNull(ids);
return ServiceOperation.existsContainerById(repository, ids);
}
}

View File

@ -1,36 +0,0 @@
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 dev.struchkov.haiti.utils.Inspector;
import java.util.Optional;
public abstract class AbstractSimpleService<Entity, Key> implements SimpleService<Entity, Key> {
private final CrudOperation<Entity, Key> crudOperation;
protected AbstractSimpleService(CrudOperation<Entity, Key> crudOperation) {
this.crudOperation = crudOperation;
}
@Override
public Optional<Entity> getById(Key id) {
Inspector.isNotNull(id);
return ServiceOperation.getById(crudOperation, id);
}
@Override
public boolean existsById(Key id) {
Inspector.isNotNull(id);
return ServiceOperation.existsById(crudOperation, id);
}
@Override
public void deleteById(Key id) {
Inspector.isNotNull(id);
ServiceOperation.deleteById(crudOperation, id);
}
}

View File

@ -1,60 +0,0 @@
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 java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public final class ServiceOperation {
private ServiceOperation() {
utilityClass();
}
public static <Entity extends BasicEntity<Key>, Key> void deleteAllById(MultipleOperation<Entity, Key> repository, Collection<Key> ids) {
repository.deleteAllById(ids);
}
public static <Entity> Sheet<Entity> getAll(PagingOperation<Entity> repository, Pagination pagination) {
return repository.findAll(pagination);
}
public static <Entity, Key> Optional<Entity> getById(CrudOperation<Entity, Key> repository, Key id) {
return repository.findById(id);
}
public static <Entity, Key> boolean existsById(CrudOperation<Entity, Key> repository, Key id) {
return repository.existsById(id);
}
public static <Entity, Key> void deleteById(CrudOperation<Entity, Key> repository, Key id) {
repository.deleteById(id);
}
public static <K, T extends BasicEntity<K>> ExistsContainer<T, K> existsContainerById(MultipleOperation<T, K> multipleOperation, Collection<K> ids) {
final List<T> existsEntity = multipleOperation.findAllById(ids);
final Set<K> existsIds = existsEntity.stream()
.map(BasicEntity::getId)
.collect(Collectors.toSet());
if (existsIds.containsAll(ids)) {
return ExistsContainer.allFind(existsEntity);
} else {
final Set<K> noExistsId = ids.stream()
.filter(id -> !existsIds.contains(id))
.collect(Collectors.toSet());
return ExistsContainer.notAllFind(existsEntity, noExistsId);
}
}
}

View File

@ -1,5 +0,0 @@
module haiti.core {
requires haiti.context;
requires haiti.exception;
requires haiti.filter;
}

View File

@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
<artifactId>haiti-dependencies</artifactId>
<version>2.0.0</version>
</parent>
<artifactId>haiti-exception</artifactId>
@ -16,12 +16,4 @@
<description>General exceptions for the haiti project</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>

147
haiti-external-bom/pom.xml Normal file
View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-external-bom</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
<name>Haiti External Dependencies</name>
<description>External dependencies required for Haiti components</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/haiti-projects/haiti-framework/issues</url>
</issueManagement>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver>
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
<plugin.maven.gpg.ver>3.0.1</plugin.maven.gpg.ver>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.maven.compiler.ver}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${plugin.nexus.staging.ver}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${plugin.maven.source.ver}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${plugin.maven.gpg.ver}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<scm>
<connection>scm:git:https://github.com/haiti-projects/haiti-framework.git</connection>
<url>https://github.com/haiti-projects/haiti-framework</url>
<developerConnection>scm:git:https://github.com/haiti-projects/haiti-framework.git</developerConnection>
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<developers>
<developer>
<id>uPagge</id>
<name>Struchkov Mark</name>
<email>mark@struchkov.dev</email>
<url>https://mark.struchkov.dev</url>
</developer>
</developers>
</project>

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
</parent>
<artifactId>haiti-filter</artifactId>
<version>${haiti.filter.api.ver}</version>
<name>Haiti Filter</name>
<description>Fast and convenient filtering requests to data warehouses.</description>
<url>https://github.com/haiti-projects/haiti-framework</url>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-context</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,21 +0,0 @@
package dev.struchkov.haiti.filter;
import java.util.function.Consumer;
public interface Filter {
Filter and(FilterQuery filterQuery);
Filter and(Consumer<FilterQuery> query);
Filter or(FilterQuery filterQuery);
Filter or(Consumer<FilterQuery> query);
Filter not(FilterQuery filterQuery);
Filter not(Consumer<FilterQuery> query);
<Q> Q build();
}

View File

@ -1,18 +0,0 @@
package dev.struchkov.haiti.filter;
import dev.struchkov.haiti.context.page.Pagination;
import dev.struchkov.haiti.context.page.Sheet;
import java.util.Optional;
public interface FilterOperation<T> {
Sheet<T> findAll(Filter filter, Pagination pagination);
Optional<T> findFirst(Filter filter);
boolean exists(Filter filter);
long count(Filter filter);
}

View File

@ -1,61 +0,0 @@
package dev.struchkov.haiti.filter;
import java.util.Set;
public interface FilterQuery {
/**
* Добавляет в запрос поиск по диапазону.
*
* @param field Название поля в elasticsearch
* @param from Начало интервала
* @param to Конец интервала
*/
<Y extends Comparable<? super Y>> FilterQuery between(String field, Y from, Y to);
<Y extends Comparable<? super Y>> FilterQuery greaterThan(String field, Y value);
<Y extends Comparable<? super Y>> FilterQuery lessThan(String field, Y value);
/**
* Добавляет в запрос проверку по значению поля
*
* @param field Название поля
* @param value Значение поля для проверки
*/
FilterQuery matchPhrase(String field, Object value);
/**
* Добавляет в запрос проверку по нескольким значениям одного поля
*
* @param field Название поля
* @param value Значения поля
*/
<U> FilterQuery matchPhrase(String field, Set<U> value);
/**
* Добавляет в запрос проверку на NULL значение поля
*
* @param field Наименование поля
*/
FilterQuery exists(String field);
/**
* Поиск подстрок
*
* @param field Названия поля
* @param value Часть искомого значения
*/
FilterQuery like(String field, String value, boolean ignoreCase);
/**
* Добавляет в запрос поиск по флагу, который конвертируется в диапазон
*
* @param flag Значение флага
* @param field Поле для проверки
*/
FilterQuery checkBoolInt(String field, Boolean flag);
<Q> Q build();
}

View File

@ -1,9 +0,0 @@
package dev.struchkov.haiti.filter.exception;
public class BadFilterConstructorException extends FilterException {
public BadFilterConstructorException(String s) {
super(s);
}
}

View File

@ -1,20 +0,0 @@
package dev.struchkov.haiti.filter.exception;
import dev.struchkov.haiti.context.exception.BasicException;
/**
* Исключения связанные с работой фильтров.
*
* @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);
}
}

View File

@ -1,6 +0,0 @@
module haiti.filter {
exports dev.struchkov.haiti.filter;
requires haiti.exception;
requires haiti.context;
}

View File

@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
<artifactId>haiti-dependencies</artifactId>
<version>2.0.0</version>
</parent>
<name>Haiti Utils</name>
@ -16,14 +16,6 @@
<artifactId>haiti-utils</artifactId>
<version>${haiti.utils.ver}</version>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>

29
pom.xml
View File

@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.5.0</version>
<artifactId>haiti-dependencies</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
<name>Haiti Framework</name>
@ -24,12 +24,8 @@
</issueManagement>
<modules>
<module>haiti-bom</module>
<module>haiti-exception</module>
<module>haiti-utils</module>
<module>haiti-context</module>
<module>haiti-core</module>
<module>haiti-filter</module>
</modules>
<properties>
@ -39,15 +35,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<haiti.ver>${project.version}</haiti.ver>
<haiti.bom.ver>${haiti.ver}</haiti.bom.ver>
<haiti.ver>2.0.0</haiti.ver>
<haiti.exception.ver>${haiti.ver}</haiti.exception.ver>
<haiti.context.ver>${haiti.ver}</haiti.context.ver>
<haiti.core.ver>${haiti.ver}</haiti.core.ver>
<haiti.filter.api.ver>${haiti.ver}</haiti.filter.api.ver>
<haiti.filter.criteria.ver>${haiti.ver}</haiti.filter.criteria.ver>
<haiti.database.ver>${haiti.ver}</haiti.database.ver>
<haiti.utils.ver>${haiti.ver}</haiti.utils.ver>
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
@ -61,11 +52,21 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-bom</artifactId>
<version>${haiti.bom.ver}</version>
<artifactId>haiti-external-bom</artifactId>
<version>${haiti.ver}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-exception</artifactId>
<version>${haiti.exception.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-utils</artifactId>
<version>${haiti.utils.ver}</version>
</dependency>
</dependencies>
</dependencyManagement>