delete lombok
This commit is contained in:
parent
491138cd70
commit
40803049a4
@ -46,7 +46,6 @@
|
||||
|
||||
<javax.persisttence.api.ver>2.2</javax.persisttence.api.ver>
|
||||
<elasticsearch.ver>7.16.3</elasticsearch.ver>
|
||||
<lombok.ver>1.18.22</lombok.ver>
|
||||
<slf4j.ver>1.7.33</slf4j.ver>
|
||||
|
||||
<plugin.nexus.staging.ver>1.6.8</plugin.nexus.staging.ver>
|
||||
@ -94,12 +93,6 @@
|
||||
<version>${haiti.utils.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
@ -145,11 +138,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${plugin.maven.compiler.ver}</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@ -175,6 +163,15 @@
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>${plugin.maven.gpg.ver}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${plugin.maven.compiler.ver}</version>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
@ -31,15 +31,18 @@
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-exception</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
|
@ -1,16 +1,14 @@
|
||||
package dev.struchkov.haiti.context.domain;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* // TODO: 14.01.2021 Добавить описание.
|
||||
* Базовая класс для сущностей.
|
||||
*
|
||||
* @author upagge 14.01.2021
|
||||
*/
|
||||
public interface BasicEntity<K> {
|
||||
public interface BasicEntity<Key> {
|
||||
|
||||
K getId();
|
||||
Key getId();
|
||||
|
||||
void setId(@NonNull K id);
|
||||
void setId(Key id);
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package dev.struchkov.haiti.context.domain;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@ -14,20 +10,37 @@ import java.util.Collections;
|
||||
*
|
||||
* @author upagge 11.01.2021
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class ExistsContainer<T, K> implements Serializable {
|
||||
public class ExistsContainer<Entity, Key> {
|
||||
|
||||
protected final Collection<T> container;
|
||||
protected final Collection<Entity> container;
|
||||
protected final boolean allFound;
|
||||
protected final Collection<K> idNoFound;
|
||||
protected final Collection<Key> idNoFound;
|
||||
|
||||
public static <T, K> ExistsContainer<T, K> allFind(@NonNull Collection<T> container) {
|
||||
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) {
|
||||
Assert.isNotNull(container);
|
||||
return new ExistsContainer<>(container, true, Collections.emptyList());
|
||||
}
|
||||
|
||||
public static <T, K> ExistsContainer<T, K> notAllFind(@NonNull Collection<T> container, @NonNull Collection<K> idNoFound) {
|
||||
public static <T, K> ExistsContainer<T, K> notAllFind(Collection<T> container, Collection<K> idNoFound) {
|
||||
Assert.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;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ public interface Pagination {
|
||||
|
||||
Integer getSize();
|
||||
|
||||
Set<? extends Sort> getSorts();
|
||||
Set<? extends Sort> getSorts();
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package dev.struchkov.haiti.context.page;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface Sheet<T> {
|
||||
public interface Sheet<Entity> {
|
||||
|
||||
int getNumber();
|
||||
|
||||
@ -13,10 +13,10 @@ public interface Sheet<T> {
|
||||
|
||||
int getTotalPage();
|
||||
|
||||
List<T> getContent();
|
||||
List<Entity> getContent();
|
||||
|
||||
boolean hasContent();
|
||||
|
||||
<U> Sheet<U> map(Function<? super T, ? extends U> converter);
|
||||
<NewEntity> Sheet<NewEntity> map(Function<? super Entity, ? extends NewEntity> converter);
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,9 @@ package dev.struchkov.haiti.context.page.impl;
|
||||
|
||||
import dev.struchkov.haiti.context.page.Pagination;
|
||||
import dev.struchkov.haiti.context.page.Sort;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class PaginationImpl implements Pagination {
|
||||
|
||||
private final Integer page;
|
||||
@ -32,4 +30,18 @@ public class PaginationImpl implements Pagination {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package dev.struchkov.haiti.context.page.impl;
|
||||
|
||||
import dev.struchkov.haiti.context.page.Sheet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -11,19 +8,24 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class SheetImpl<T> implements Sheet<T> {
|
||||
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<T> content;
|
||||
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 T, ? extends U> function) {
|
||||
public <U> Sheet<U> map(Function<? super Entity, ? extends U> function) {
|
||||
return new SheetImpl<>(
|
||||
this.number,
|
||||
this.size,
|
||||
@ -43,8 +45,8 @@ public class SheetImpl<T> implements Sheet<T> {
|
||||
);
|
||||
}
|
||||
|
||||
public Sheet<T> filter(Predicate<? super T> predicate) {
|
||||
final List<T> filterContent = content.stream().filter(predicate).collect(Collectors.toList());
|
||||
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,
|
||||
@ -58,4 +60,29 @@ public class SheetImpl<T> implements Sheet<T> {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,20 +2,32 @@ package dev.struchkov.haiti.context.page.impl;
|
||||
|
||||
import dev.struchkov.haiti.context.enums.TypeSort;
|
||||
import dev.struchkov.haiti.context.page.Sort;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
import static dev.struchkov.haiti.utils.Assert.isNotNull;
|
||||
|
||||
public class SortImpl implements Sort {
|
||||
|
||||
private final TypeSort type;
|
||||
private final String field;
|
||||
|
||||
public static Sort of(@NonNull TypeSort type, 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
package dev.struchkov.haiti.context.repository.simple;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Контракт для реализации объекта, который будет взаимодействовать с хранилищем данных.
|
||||
*
|
||||
* @param <T> Класс сущности
|
||||
* @param <K> Класс идентификатора
|
||||
* @param <Entity> Класс сущности
|
||||
* @param <Key> Класс идентификатора
|
||||
* @author upagge
|
||||
*/
|
||||
public interface CrudOperation<T, K> {
|
||||
public interface CrudOperation<Entity, Key> {
|
||||
|
||||
/**
|
||||
* Сохраняет сущность в базу данных. Не проверяет на наличие в хранилище.
|
||||
@ -20,12 +18,12 @@ public interface CrudOperation<T, K> {
|
||||
* @param entity Сущность для сохранения
|
||||
* @return Сохраненная сущность
|
||||
*/
|
||||
T save(@NonNull T entity);
|
||||
Entity save(Entity entity);
|
||||
|
||||
Optional<T> findById(@NonNull K primaryKey);
|
||||
Optional<Entity> findById(Key id);
|
||||
|
||||
boolean existsById(@NonNull K primaryKey);
|
||||
boolean existsById(Key id);
|
||||
|
||||
void deleteById(@NonNull K primaryKey);
|
||||
void deleteById(Key id);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.struchkov.haiti.context.repository.simple;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.haiti.context.domain.BasicEntity;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -8,10 +7,10 @@ import java.util.List;
|
||||
|
||||
public interface MultipleOperation<T extends BasicEntity<K>, K> {
|
||||
|
||||
List<T> saveAll(@NonNull Collection<T> entities);
|
||||
List<T> saveAll(Collection<T> entities);
|
||||
|
||||
void deleteAllById(@NonNull Collection<K> primaryKeys);
|
||||
void deleteAllById(Collection<K> primaryKeys);
|
||||
|
||||
List<T> findAllById(@NonNull Collection<K> ids);
|
||||
List<T> findAllById(Collection<K> ids);
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
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<T> {
|
||||
|
||||
Sheet<T> findAll(@NonNull Pagination pagination);
|
||||
Sheet<T> findAll(Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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<T extends BasicEntity<K>, K> extends SimpleService<T, K>, MultipleService<T, K>, PagingService<T> {
|
||||
public interface SimpleManagerService<Entity extends BasicEntity<Key>, Key>
|
||||
extends SimpleService<Entity, Key>, MultipleService<Entity, Key>, PagingService<Entity> {
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
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<T, F> {
|
||||
public interface FilterService<Entity, Filter> {
|
||||
|
||||
/**
|
||||
* Получить все элементы по заданному фильтру.
|
||||
@ -14,27 +13,27 @@ public interface FilterService<T, F> {
|
||||
* @param filter Фильтр
|
||||
* @param pagination Пагинация
|
||||
*/
|
||||
Sheet<T> getAll(@NonNull F filter, @NonNull Pagination pagination);
|
||||
Sheet<Entity> getAll(Filter filter, Pagination pagination);
|
||||
|
||||
/**
|
||||
* Возвращает первый найденный объект по фильтру.
|
||||
*
|
||||
* @param filter Объект фильтра
|
||||
*/
|
||||
Optional<T> getFirst(@NonNull F filter);
|
||||
Optional<Entity> getFirst(Filter filter);
|
||||
|
||||
/**
|
||||
* Проверка на наличие хотя бы одной сущности, которая удовлетворяет определенному набору параметров.
|
||||
*
|
||||
* @param filter Набор параметров
|
||||
*/
|
||||
boolean exists(@NonNull F filter);
|
||||
boolean exists(Filter filter);
|
||||
|
||||
/**
|
||||
* Получить количество сущностей, которые удовлетворяют определенному набору параметров.
|
||||
*
|
||||
* @param filter Набор параметров
|
||||
*/
|
||||
long count(@NonNull F filter);
|
||||
long count(Filter filter);
|
||||
|
||||
}
|
||||
|
@ -2,19 +2,18 @@ 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<T extends BasicEntity<K>, K> {
|
||||
public interface MultipleService<Entity extends BasicEntity<Key>, Key> {
|
||||
|
||||
List<T> createAll(@NonNull Collection<T> entities);
|
||||
List<Entity> createAll(Collection<Entity> entities);
|
||||
|
||||
List<T> updateAll(@NonNull Collection<T> entities);
|
||||
List<Entity> updateAll(Collection<Entity> entities);
|
||||
|
||||
void deleteAllById(@NonNull Collection<K> ids);
|
||||
void deleteAllById(Collection<Key> ids);
|
||||
|
||||
ExistsContainer<T, K> existsById(@NonNull Collection<K> ids);
|
||||
ExistsContainer<Entity, Key> existsById(Collection<Key> ids);
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
package dev.struchkov.haiti.context.service.simple;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.haiti.context.page.Pagination;
|
||||
import dev.struchkov.haiti.context.page.Sheet;
|
||||
|
||||
/**
|
||||
* Расширение базового контракта сервисов с добавлением пагинации.
|
||||
*
|
||||
* @param <T> Сущность сервиса.
|
||||
* @param <Entity> Сущность сервиса.
|
||||
* @author upagge 26.05.20
|
||||
*/
|
||||
public interface PagingService<T> {
|
||||
public interface PagingService<Entity> {
|
||||
|
||||
Sheet<T> getAll(@NonNull Pagination pagination);
|
||||
Sheet<Entity> getAll(Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -1,26 +1,24 @@
|
||||
package dev.struchkov.haiti.context.service.simple;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Базовый контракт для сервисов.
|
||||
*
|
||||
* @param <T> Сущность сервиса.
|
||||
* @param <Entity> Сущность сервиса.
|
||||
*/
|
||||
public interface SimpleService<T, K> {
|
||||
public interface SimpleService<Entity, Key> {
|
||||
|
||||
T create(@NonNull T entity);
|
||||
Entity create(Entity entity);
|
||||
|
||||
T update(@NonNull T entity);
|
||||
Entity update(Entity entity);
|
||||
|
||||
Optional<T> getById(@NonNull K primaryKey);
|
||||
Optional<Entity> getById(Key id);
|
||||
|
||||
T getByIdOrThrow(@NonNull K primaryKey);
|
||||
Entity getByIdOrThrow(Key id);
|
||||
|
||||
boolean existsById(@NonNull K primaryKey);
|
||||
boolean existsById(Key id);
|
||||
|
||||
void deleteById(@NonNull K primaryKey);
|
||||
void deleteById(Key id);
|
||||
|
||||
}
|
||||
|
9
haiti-context/src/main/java/module-info.java
Normal file
9
haiti-context/src/main/java/module-info.java
Normal file
@ -0,0 +1,9 @@
|
||||
module haiti.context {
|
||||
exports dev.struchkov.haiti.context.service.simple;
|
||||
exports dev.struchkov.haiti.context.repository.simple;
|
||||
exports dev.struchkov.haiti.context.repository;
|
||||
exports dev.struchkov.haiti.context.domain;
|
||||
exports dev.struchkov.haiti.context.service;
|
||||
exports dev.struchkov.haiti.context.page;
|
||||
requires transitive haiti.utils;
|
||||
}
|
@ -32,11 +32,6 @@
|
||||
<artifactId>haiti-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-filter</artifactId>
|
||||
@ -45,6 +40,10 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
|
@ -4,7 +4,7 @@ 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 lombok.NonNull;
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -13,13 +13,16 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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(@NonNull T accessTarget) {
|
||||
public T save(T accessTarget) {
|
||||
Assert.isNotNull(accessTarget);
|
||||
accessTarget.setId(key);
|
||||
map.put(key, accessTarget);
|
||||
key++;
|
||||
@ -27,42 +30,48 @@ public class SimpleManagerRepositoryMap<T extends BasicEntity<Long>> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> findById(@NonNull Long id) {
|
||||
public Optional<T> findById(Long id) {
|
||||
Assert.isNotNull(id);
|
||||
return Optional.ofNullable(map.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(@NonNull Long id) {
|
||||
public boolean existsById(Long id) {
|
||||
Assert.isNotNull(id);
|
||||
return map.containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(@NonNull Long id) {
|
||||
public void deleteById(Long id) {
|
||||
Assert.isNotNull(id);
|
||||
map.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> saveAll(@NonNull Collection<T> accessTargets) {
|
||||
public List<T> saveAll(Collection<T> accessTargets) {
|
||||
Assert.isNotNull(accessTargets);
|
||||
return accessTargets.stream()
|
||||
.map(this::save)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllById(@NonNull Collection<Long> accessTargets) {
|
||||
public void deleteAllById(Collection<Long> accessTargets) {
|
||||
Assert.isNotNull(accessTargets);
|
||||
accessTargets.forEach(map::remove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findAllById(@NonNull Collection<Long> ids) {
|
||||
public List<T> findAllById(Collection<Long> ids) {
|
||||
Assert.isNotNull(ids);
|
||||
return ids.stream()
|
||||
.map(map::get)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<T> findAll(@NonNull Pagination pagination) {
|
||||
return null;
|
||||
public Sheet<T> findAll(Pagination pagination) {
|
||||
throw new IllegalStateException(ERR_OPERATION_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,36 +5,42 @@ 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 dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractFilterService<T, F> implements FilterService<T, F> {
|
||||
public abstract class AbstractFilterService<Entity, F> implements FilterService<Entity, F> {
|
||||
|
||||
protected final FilterOperation<T> filterOperation;
|
||||
protected final FilterOperation<Entity> filterOperation;
|
||||
|
||||
protected AbstractFilterService(FilterOperation<Entity> filterOperation) {
|
||||
this.filterOperation = filterOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<T> getAll(@NonNull F filter, Pagination pagination) {
|
||||
public Sheet<Entity> getAll(F filter, Pagination pagination) {
|
||||
Assert.isNotNull(filter);
|
||||
return filterOperation.findAll(createFilter(filter), pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> getFirst(@NonNull F filter) {
|
||||
public Optional<Entity> getFirst(F filter) {
|
||||
Assert.isNotNull(filter);
|
||||
return filterOperation.findFirst(createFilter(filter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(@NonNull F filter) {
|
||||
public boolean exists(F filter) {
|
||||
Assert.isNotNull(filter);
|
||||
return filterOperation.exists(createFilter(filter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count(@NonNull F filter) {
|
||||
public long count(F filter) {
|
||||
Assert.isNotNull(filter);
|
||||
return filterOperation.count(createFilter(filter));
|
||||
}
|
||||
|
||||
protected abstract Filter createFilter(@NonNull F filter);
|
||||
protected abstract Filter createFilter(F filter);
|
||||
|
||||
}
|
||||
|
@ -6,36 +6,43 @@ 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 dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractMultipleService<T extends BasicEntity<K>, K> implements MultipleService<T, K> {
|
||||
public abstract class AbstractMultipleService<Entity extends BasicEntity<Key>, Key> implements MultipleService<Entity, Key> {
|
||||
|
||||
private final SimpleService<T, K> simpleService;
|
||||
private final MultipleOperation<T, K> multipleOperation;
|
||||
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(@NonNull Collection<K> ids) {
|
||||
public void deleteAllById(Collection<Key> ids) {
|
||||
Assert.isNotNull(ids);
|
||||
multipleOperation.deleteAllById(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> createAll(@NonNull Collection<T> entities) {
|
||||
public List<Entity> createAll(Collection<Entity> entities) {
|
||||
Assert.isNotNull(entities);
|
||||
return entities.stream().map(simpleService::create).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> updateAll(@NonNull Collection<T> entities) {
|
||||
public List<Entity> updateAll(Collection<Entity> entities) {
|
||||
Assert.isNotNull(entities);
|
||||
return entities.stream().map(simpleService::update).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExistsContainer<T, K> existsById(@NonNull Collection<K> ids) {
|
||||
public ExistsContainer<Entity, Key> existsById(Collection<Key> ids) {
|
||||
Assert.isNotNull(ids);
|
||||
return ServiceOperation.existsContainerById(multipleOperation, ids);
|
||||
}
|
||||
|
||||
|
@ -4,16 +4,19 @@ 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 dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
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(@NonNull Pagination pagination) {
|
||||
public Sheet<T> getAll(Pagination pagination) {
|
||||
Assert.isNotNull(pagination);
|
||||
return pagingOperation.findAll(pagination);
|
||||
}
|
||||
|
||||
|
@ -8,61 +8,72 @@ 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 dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractSimpleManagerService<T extends BasicEntity<K>, K> implements SimpleManagerService<T, K> {
|
||||
public abstract class AbstractSimpleManagerService<Entity extends BasicEntity<Key>, Key> implements SimpleManagerService<Entity, Key> {
|
||||
|
||||
protected final SimpleManagerRepository<T, K> repository;
|
||||
protected final SimpleManagerRepository<Entity, Key> repository;
|
||||
|
||||
@Override
|
||||
public void deleteAllById(@NonNull Collection<K> primaryKeys) {
|
||||
ServiceOperation.deleteAllById(repository, primaryKeys);
|
||||
protected AbstractSimpleManagerService(SimpleManagerRepository<Entity, Key> repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<T> getAll(@NonNull Pagination pagination) {
|
||||
public void deleteAllById(Collection<Key> ids) {
|
||||
Assert.isNotNull(ids);
|
||||
ServiceOperation.deleteAllById(repository, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<Entity> getAll(Pagination pagination) {
|
||||
Assert.isNotNull(pagination);
|
||||
return ServiceOperation.getAll(repository, pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> getById(@NonNull K primaryKey) {
|
||||
return ServiceOperation.getById(repository, primaryKey);
|
||||
public Optional<Entity> getById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
return ServiceOperation.getById(repository, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getByIdOrThrow(@NonNull K primaryKey) {
|
||||
return getById(primaryKey).orElseThrow(NotFoundException.supplier("Объект не найден. Идентификатор: ", primaryKey));
|
||||
public Entity getByIdOrThrow(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
return getById(id).orElseThrow(NotFoundException.supplier("Объект не найден. Идентификатор: ", id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(@NonNull K primaryKey) {
|
||||
return ServiceOperation.existsById(repository, primaryKey);
|
||||
public boolean existsById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
return ServiceOperation.existsById(repository, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(@NonNull K primaryKey) {
|
||||
ServiceOperation.deleteById(repository, primaryKey);
|
||||
public void deleteById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
ServiceOperation.deleteById(repository, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> createAll(@NonNull Collection<T> entities) {
|
||||
public List<Entity> createAll(Collection<Entity> entities) {
|
||||
Assert.isNotNull(entities);
|
||||
return entities.stream().map(this::create).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> updateAll(@NonNull Collection<T> entities) {
|
||||
public List<Entity> updateAll(Collection<Entity> entities) {
|
||||
Assert.isNotNull(entities);
|
||||
return entities.stream().map(this::update).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExistsContainer<T, K> existsById(@NonNull Collection<K> ids) {
|
||||
public ExistsContainer<Entity, Key> existsById(Collection<Key> ids) {
|
||||
Assert.isNotNull(ids);
|
||||
return ServiceOperation.existsContainerById(repository, ids);
|
||||
}
|
||||
|
||||
|
@ -3,29 +3,34 @@ 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 dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractSimpleService<T, K> implements SimpleService<T, K> {
|
||||
public abstract class AbstractSimpleService<Entity, Key> implements SimpleService<Entity, Key> {
|
||||
|
||||
private final CrudOperation<T, K> crudOperation;
|
||||
private final CrudOperation<Entity, Key> crudOperation;
|
||||
|
||||
@Override
|
||||
public Optional<T> getById(@NonNull K primaryKey) {
|
||||
return ServiceOperation.getById(crudOperation, primaryKey);
|
||||
protected AbstractSimpleService(CrudOperation<Entity, Key> crudOperation) {
|
||||
this.crudOperation = crudOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(@NonNull K primaryKey) {
|
||||
return ServiceOperation.existsById(crudOperation, primaryKey);
|
||||
public Optional<Entity> getById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
return ServiceOperation.getById(crudOperation, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(@NonNull K primaryKey) {
|
||||
ServiceOperation.deleteById(crudOperation, primaryKey);
|
||||
public boolean existsById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
return ServiceOperation.existsById(crudOperation, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(Key id) {
|
||||
Assert.isNotNull(id);
|
||||
ServiceOperation.deleteById(crudOperation, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ 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;
|
||||
@ -15,27 +14,32 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
public final class ServiceOperation {
|
||||
|
||||
public static <T extends BasicEntity<K>, K> void deleteAllById(MultipleOperation<T, K> repository, Collection<K> primaryKeys) {
|
||||
repository.deleteAllById(primaryKeys);
|
||||
private ServiceOperation() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static <T> Sheet<T> getAll(PagingOperation<T> repository, Pagination pagination) {
|
||||
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 <T, K> Optional<T> getById(CrudOperation<T, K> repository, K primaryKey) {
|
||||
return repository.findById(primaryKey);
|
||||
public static <Entity, Key> Optional<Entity> getById(CrudOperation<Entity, Key> repository, Key id) {
|
||||
return repository.findById(id);
|
||||
}
|
||||
|
||||
public static <T, K> boolean existsById(CrudOperation<T, K> repository, K primaryKey) {
|
||||
return repository.existsById(primaryKey);
|
||||
public static <Entity, Key> boolean existsById(CrudOperation<Entity, Key> repository, Key id) {
|
||||
return repository.existsById(id);
|
||||
}
|
||||
|
||||
public static <T, K> void deleteById(CrudOperation<T, K> repository, K primaryKey) {
|
||||
repository.deleteById(primaryKey);
|
||||
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) {
|
||||
@ -52,4 +56,5 @@ public final class ServiceOperation {
|
||||
return ExistsContainer.notAllFind(existsEntity, noExistsId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
5
haiti-core/src/main/java/module-info.java
Normal file
5
haiti-core/src/main/java/module-info.java
Normal file
@ -0,0 +1,5 @@
|
||||
module haiti.core {
|
||||
requires haiti.context;
|
||||
requires haiti.exception;
|
||||
requires haiti.filter;
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
|
||||
<properties>
|
||||
<skip.deploy>false</skip.deploy>
|
||||
|
||||
<java.version>11</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
@ -27,6 +28,10 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
|
3
haiti-exception/src/main/java/module-info.java
Normal file
3
haiti-exception/src/main/java/module-info.java
Normal file
@ -0,0 +1,3 @@
|
||||
module haiti.exception {
|
||||
exports dev.struchkov.haiti.context.exception;
|
||||
}
|
@ -27,11 +27,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-context</artifactId>
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.struchkov.haiti.filter;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.haiti.context.page.Pagination;
|
||||
import dev.struchkov.haiti.context.page.Sheet;
|
||||
|
||||
@ -8,12 +7,12 @@ import java.util.Optional;
|
||||
|
||||
public interface FilterOperation<T> {
|
||||
|
||||
Sheet<T> findAll(@NonNull Filter filter, @NonNull Pagination pagination);
|
||||
Sheet<T> findAll(Filter filter, Pagination pagination);
|
||||
|
||||
Optional<T> findFirst(@NonNull Filter filter);
|
||||
Optional<T> findFirst(Filter filter);
|
||||
|
||||
boolean exists(@NonNull Filter filter);
|
||||
boolean exists(Filter filter);
|
||||
|
||||
long count(@NonNull Filter filter);
|
||||
long count(Filter filter);
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package dev.struchkov.haiti.filter;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface FilterQuery {
|
||||
@ -13,11 +11,11 @@ public interface FilterQuery {
|
||||
* @param from Начало интервала
|
||||
* @param to Конец интервала
|
||||
*/
|
||||
<Y extends Comparable<? super Y>> FilterQuery between(@NonNull String field, Y from, Y to);
|
||||
<Y extends Comparable<? super Y>> FilterQuery between(String field, Y from, Y to);
|
||||
|
||||
<Y extends Comparable<? super Y>> FilterQuery greaterThan(@NonNull String field, Y value);
|
||||
<Y extends Comparable<? super Y>> FilterQuery greaterThan(String field, Y value);
|
||||
|
||||
<Y extends Comparable<? super Y>> FilterQuery lessThan(@NonNull String field, Y value);
|
||||
<Y extends Comparable<? super Y>> FilterQuery lessThan(String field, Y value);
|
||||
|
||||
/**
|
||||
* Добавляет в запрос проверку по значению поля
|
||||
@ -25,7 +23,7 @@ public interface FilterQuery {
|
||||
* @param field Название поля
|
||||
* @param value Значение поля для проверки
|
||||
*/
|
||||
FilterQuery matchPhrase(@NonNull String field, Object value);
|
||||
FilterQuery matchPhrase(String field, Object value);
|
||||
|
||||
/**
|
||||
* Добавляет в запрос проверку по нескольким значениям одного поля
|
||||
@ -33,7 +31,7 @@ public interface FilterQuery {
|
||||
* @param field Название поля
|
||||
* @param value Значения поля
|
||||
*/
|
||||
<U> FilterQuery matchPhrase(@NonNull String field, Set<U> value);
|
||||
<U> FilterQuery matchPhrase(String field, Set<U> value);
|
||||
|
||||
/**
|
||||
* Добавляет в запрос проверку на NULL значение поля
|
||||
@ -48,7 +46,7 @@ public interface FilterQuery {
|
||||
* @param field Названия поля
|
||||
* @param value Часть искомого значения
|
||||
*/
|
||||
FilterQuery like(@NonNull String field, String value, boolean ignoreCase);
|
||||
FilterQuery like(String field, String value, boolean ignoreCase);
|
||||
|
||||
/**
|
||||
* Добавляет в запрос поиск по флагу, который конвертируется в диапазон
|
||||
@ -56,7 +54,7 @@ public interface FilterQuery {
|
||||
* @param flag Значение флага
|
||||
* @param field Поле для проверки
|
||||
*/
|
||||
FilterQuery checkBoolInt(@NonNull String field, Boolean flag);
|
||||
FilterQuery checkBoolInt(String field, Boolean flag);
|
||||
|
||||
<Q> Q build();
|
||||
|
||||
|
@ -3,7 +3,7 @@ package dev.struchkov.haiti.filter.exception;
|
||||
import dev.struchkov.haiti.context.exception.BasicException;
|
||||
|
||||
/**
|
||||
* // TODO: 09.11.2020 Добавить описание.
|
||||
* Исключения связанные с работой фильтров.
|
||||
*
|
||||
* @author upagge 09.11.2020
|
||||
*/
|
||||
|
6
haiti-filter/src/main/java/module-info.java
Normal file
6
haiti-filter/src/main/java/module-info.java
Normal file
@ -0,0 +1,6 @@
|
||||
module haiti.filter {
|
||||
exports dev.struchkov.haiti.filter;
|
||||
|
||||
requires haiti.exception;
|
||||
requires haiti.context;
|
||||
}
|
@ -31,15 +31,14 @@
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-exception</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
|
@ -1,21 +1,22 @@
|
||||
package dev.struchkov.haiti.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* // TODO: 06.09.2020 Добавить описание.
|
||||
* Утилитарный класс для различных проверок.
|
||||
*
|
||||
* @author upagge 06.09.2020
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class Assert {
|
||||
|
||||
public Assert() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка на null значение с возвращением исключения, если объект не null.
|
||||
*
|
||||
@ -46,6 +47,30 @@ public final class Assert {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка на null значение с возвращением исключения, если объект null.
|
||||
*
|
||||
* @param object Проверяемый объект
|
||||
*/
|
||||
public static void isNotNull(Object object) {
|
||||
if (object == null) {
|
||||
throw new NullPointerException("Object cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка на null значение с возвращением исключения, если объект null.
|
||||
*
|
||||
* @param objects Проверяемый объект
|
||||
*/
|
||||
public static void isNotNull(Object... objects) {
|
||||
for (Object o : objects) {
|
||||
if (o == null) {
|
||||
throw new NullPointerException("Object cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка на true значение с возвращением исключения, если flag не true.
|
||||
*
|
||||
@ -70,9 +95,13 @@ public final class Assert {
|
||||
}
|
||||
}
|
||||
|
||||
@UtilityClass
|
||||
|
||||
public static final class Utils {
|
||||
|
||||
public Utils() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static Supplier<NullPointerException> nullPointer(String fieldName) {
|
||||
return () -> new NullPointerException(fieldName + " is marked non-null but is null");
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package dev.struchkov.haiti.utils;
|
||||
|
||||
public final class Exceptions {
|
||||
|
||||
public static final IllegalStateException UTILITY_CLASS = new IllegalStateException(Strings.ERR_UTILITY_CLASS);
|
||||
|
||||
private Exceptions() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static void utilityClass() {
|
||||
throw Exceptions.UTILITY_CLASS;
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
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;
|
||||
@ -14,14 +12,19 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* // TODO: 07.03.2021 Добавить описание.
|
||||
* Утилитарный класс для работы с классами и объектами.
|
||||
*
|
||||
* @author upagge 07.03.2021
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ObjectUtils {
|
||||
|
||||
private ObjectUtils() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Позволяет получить значение вложенного в объект поля по названию поля.</p>
|
||||
* <p></p>
|
||||
@ -33,7 +36,8 @@ public class ObjectUtils {
|
||||
* @param object Объект
|
||||
* @return Значение поля из объекта
|
||||
*/
|
||||
public static Object getFieldValue(@NonNull Object object, @NonNull String fieldName) {
|
||||
public static Object getFieldValue(Object object, String fieldName) {
|
||||
Assert.isNotNull(object, fieldName);
|
||||
int firstNameIndex = fieldName.indexOf(".");
|
||||
String firstName;
|
||||
if (firstNameIndex != -1) {
|
||||
@ -58,7 +62,8 @@ public class ObjectUtils {
|
||||
throw new ConvertException("Метод у объекта не найден");
|
||||
}
|
||||
|
||||
public static void setFieldValue(@NonNull Object object, @NonNull String fieldName, Object fieldValue) {
|
||||
public static void setFieldValue(Object object, String fieldName, Object fieldValue) {
|
||||
Assert.isNotNull(object, fieldName);
|
||||
int firstNameIndex = fieldName.indexOf(".");
|
||||
if (firstNameIndex != -1) {
|
||||
final String[] split = fieldName.split("\\.");
|
||||
@ -118,7 +123,8 @@ public class ObjectUtils {
|
||||
* @param method Метод
|
||||
* @return true если метод является геттером для fieldName, false в противном случае
|
||||
*/
|
||||
public static boolean isGetMethod(@NonNull String fieldName, Method method) {
|
||||
public static boolean isGetMethod(String fieldName, Method method) {
|
||||
Assert.isNotNull(fieldName);
|
||||
return (method.getName().startsWith("get"))
|
||||
&& (method.getName().length() == (fieldName.length() + 3))
|
||||
&& method.getName().toLowerCase().endsWith(fieldName.toLowerCase());
|
||||
@ -131,7 +137,8 @@ public class ObjectUtils {
|
||||
* @param method Метод
|
||||
* @return true если метод является сеттером для fieldName, false в противном случае
|
||||
*/
|
||||
public static boolean isSetMethod(@NonNull String fieldName, Method method) {
|
||||
public static boolean isSetMethod(String fieldName, Method method) {
|
||||
Assert.isNotNull(fieldName);
|
||||
return (method.getName().startsWith("set"))
|
||||
&& (method.getName().length() == (fieldName.length() + 3))
|
||||
&& method.getName().toLowerCase().endsWith(fieldName.toLowerCase());
|
||||
|
@ -1,15 +1,20 @@
|
||||
package dev.struchkov.haiti.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* // TODO: 07.03.2021 Добавить описание.
|
||||
* Утилитарный класс для работы со строками.
|
||||
*
|
||||
* @author upagge 07.03.2021
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Strings {
|
||||
public final class Strings {
|
||||
|
||||
private Strings() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static final String EMPTY = "";
|
||||
public static final String ERR_UTILITY_CLASS = "Нельзя создать объект утилитарного класса";
|
||||
public static final String ERR_OPERATION_NOT_SUPPORTED = "Операция не поддерживается";
|
||||
|
||||
}
|
||||
|
6
haiti-utils/src/main/java/module-info.java
Normal file
6
haiti-utils/src/main/java/module-info.java
Normal file
@ -0,0 +1,6 @@
|
||||
module haiti.utils {
|
||||
requires haiti.exception;
|
||||
|
||||
exports dev.struchkov.haiti.utils;
|
||||
|
||||
}
|
25
pom.xml
25
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti</artifactId>
|
||||
<version>${haiti.ver}</version>
|
||||
<version>0.0.3</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Haiti Framework</name>
|
||||
@ -24,12 +24,12 @@
|
||||
</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>
|
||||
<module>haiti-bom</module>
|
||||
<module>haiti-utils</module>
|
||||
<module>haiti-exception</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
@ -39,7 +39,6 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<haiti.ver>0.0.3</haiti.ver>
|
||||
<haiti.bom.ver>0.0.3</haiti.bom.ver>
|
||||
<haiti.exception.ver>0.0.3</haiti.exception.ver>
|
||||
<haiti.context.ver>0.0.3</haiti.context.ver>
|
||||
@ -49,6 +48,7 @@
|
||||
<haiti.database.ver>0.0.3</haiti.database.ver>
|
||||
<haiti.utils.ver>0.0.3</haiti.utils.ver>
|
||||
|
||||
<plugin.maven.compiler.ver>3.9.0</plugin.maven.compiler.ver>
|
||||
<plugin.nexus.staging.ver>1.6.8</plugin.nexus.staging.ver>
|
||||
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
|
||||
<plugin.maven.javadoc.ver>3.3.1</plugin.maven.javadoc.ver>
|
||||
@ -120,11 +120,14 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
<configuration>
|
||||
<gpgArguments>
|
||||
<gpgArgument>--pinentry-mode</gpgArgument>
|
||||
<gpgArgument>loopback</gpgArgument>
|
||||
</gpgArguments>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@ -134,10 +137,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
Loading…
Reference in New Issue
Block a user