From 0d57bee7853d19d18fee3538dcc18c7d5c764d7b Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 5 Dec 2022 16:50:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20pipline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitlab/context/domain/ExistContainer.java | 41 +++++++++++++++++++ .../context/domain/ExistsContainer.java | 40 ------------------ .../context/domain/entity/Pipeline.java | 3 +- .../context/service/DiscussionService.java | 4 +- .../context/service/MergeRequestsService.java | 4 +- .../gitlab/context/service/PersonService.java | 4 +- .../context/service/PipelineService.java | 4 +- .../context/service/ProjectService.java | 4 +- .../service/impl/DiscussionServiceImpl.java | 8 ++-- .../impl/MergeRequestsServiceImpl.java | 8 ++-- .../core/service/impl/PersonServiceImpl.java | 8 ++-- .../service/impl/PipelineServiceImpl.java | 16 ++++---- .../core/service/impl/ProjectServiceImpl.java | 8 ++-- .../core/service/parser/DiscussionParser.java | 8 ++-- .../service/parser/MergeRequestParser.java | 8 ++-- .../core/service/parser/PipelineParser.java | 12 +++--- .../core/service/parser/ProjectParser.java | 12 +++--- 17 files changed, 97 insertions(+), 95 deletions(-) create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistContainer.java delete mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistContainer.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistContainer.java new file mode 100644 index 0000000..f16664b --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistContainer.java @@ -0,0 +1,41 @@ +package dev.struchkov.bot.gitlab.context.domain; + +import lombok.NonNull; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +public class ExistContainer { + + protected final List container; + protected final boolean allFound; + protected final Set idNoFound; + + protected ExistContainer(List container, boolean allFound, Set idNoFound) { + this.container = container; + this.allFound = allFound; + this.idNoFound = idNoFound; + } + + public static ExistContainer allFind(@NonNull List container) { + return new ExistContainer<>(container, true, Collections.emptySet()); + } + + public static ExistContainer notAllFind(@NonNull List container, @NonNull Set idNoFound) { + return new ExistContainer<>(container, false, idNoFound); + } + + public List getContainer() { + return container; + } + + public boolean isAllFound() { + return allFound; + } + + public Set getIdNoFound() { + return idNoFound; + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java deleted file mode 100644 index be81a33..0000000 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/ExistsContainer.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.struchkov.bot.gitlab.context.domain; - -import lombok.NonNull; - -import java.util.Collection; -import java.util.Collections; - -public class ExistsContainer { - - protected final Collection container; - protected final boolean allFound; - protected final Collection idNoFound; - - protected ExistsContainer(Collection container, boolean allFound, Collection idNoFound) { - this.container = container; - this.allFound = allFound; - this.idNoFound = idNoFound; - } - - public static ExistsContainer allFind(@NonNull Collection container) { - return new ExistsContainer<>(container, true, Collections.emptyList()); - } - - public static ExistsContainer notAllFind(@NonNull Collection container, @NonNull Collection idNoFound) { - return new ExistsContainer<>(container, false, idNoFound); - } - - public Collection getContainer() { - return container; - } - - public boolean isAllFound() { - return allFound; - } - - public Collection getIdNoFound() { - return idNoFound; - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java index 2270802..5da5094 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Pipeline.java @@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -53,7 +54,7 @@ public class Pipeline { @JoinColumn(name = "project_id") private Project project; - @ManyToOne + @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}) @JoinColumn(name = "person_id") private Person person; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java index 11707a7..06663eb 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/DiscussionService.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import lombok.NonNull; import org.springframework.data.domain.Page; @@ -31,7 +31,7 @@ public interface DiscussionService { */ List getAllByMergeRequestId(@NonNull Long mergeRequestId); - ExistsContainer existsById(@NonNull Set discussionIds); + ExistContainer existsById(@NonNull Set discussionIds); List createAll(@NonNull List newDiscussions); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java index 1b42371..bc44bf0 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; @@ -32,7 +32,7 @@ public interface MergeRequestsService { Page getAll(@NonNull MergeRequestFilter filter, Pageable pagination); - ExistsContainer existsById(@NonNull Set mergeRequestIds); + ExistContainer existsById(@NonNull Set mergeRequestIds); List createAll(List newMergeRequests); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java index 2fd6772..0aa4d7a 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import lombok.NonNull; @@ -18,7 +18,7 @@ public interface PersonService { Person getByIdOrThrown(@NonNull Long personId); - ExistsContainer existsById(Set personIds); + ExistContainer existsById(Set personIds); List createAll(List newPersons); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java index f2ceacd..bd0a877 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PipelineService.java @@ -1,9 +1,9 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter; -import dev.struchkov.haiti.context.domain.ExistsContainer; import lombok.NonNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -25,7 +25,7 @@ public interface PipelineService { Page getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination); - ExistsContainer existsById(@NonNull Set pipelineIds); + ExistContainer existsById(@NonNull Set pipelineIds); void deleteAllById(Set pipelineIds); diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java index 8b23c4a..343e5c5 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/ProjectService.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import lombok.NonNull; import org.springframework.data.domain.Page; @@ -26,6 +26,6 @@ public interface ProjectService { boolean existsById(Long projectId); - ExistsContainer existsById(Set projectIds); + ExistContainer existsById(Set projectIds); } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java index 31d2084..863b50b 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; @@ -212,16 +212,16 @@ public class DiscussionServiceImpl implements DiscussionService { } @Override - public ExistsContainer existsById(@NonNull Set discussionIds) { + public ExistContainer existsById(@NonNull Set discussionIds) { final List existsEntity = repository.findAllById(discussionIds); final Set existsIds = existsEntity.stream().map(Discussion::getId).collect(Collectors.toSet()); if (existsIds.containsAll(discussionIds)) { - return dev.struchkov.bot.gitlab.context.domain.ExistsContainer.allFind(existsEntity); + return ExistContainer.allFind(existsEntity); } else { final Set noExistsId = discussionIds.stream() .filter(id -> !existsIds.contains(id)) .collect(Collectors.toSet()); - return ExistsContainer.notAllFind(existsEntity, noExistsId); + return ExistContainer.notAllFind(existsEntity, noExistsId); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index 312fdda..e39ed38 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; @@ -184,16 +184,16 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { } @Override - public ExistsContainer existsById(@NonNull Set mergeRequestIds) { + public ExistContainer existsById(@NonNull Set mergeRequestIds) { final List existsEntity = repository.findAllById(mergeRequestIds); final Set existsIds = existsEntity.stream().map(MergeRequest::getId).collect(Collectors.toSet()); if (existsIds.containsAll(mergeRequestIds)) { - return ExistsContainer.allFind(existsEntity); + return ExistContainer.allFind(existsEntity); } else { final Set noExistsId = mergeRequestIds.stream() .filter(id -> !existsIds.contains(id)) .collect(Collectors.toSet()); - return ExistsContainer.notAllFind(existsEntity, noExistsId); + return ExistContainer.notAllFind(existsEntity, noExistsId); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java index 0d8632a..15fc01c 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PersonServiceImpl.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.context.service.PersonService; @@ -40,16 +40,16 @@ public class PersonServiceImpl implements PersonService { } @Override - public ExistsContainer existsById(Set personIds) { + public ExistContainer existsById(Set personIds) { final List existsEntity = repository.findAllById(personIds); final Set existsIds = existsEntity.stream().map(Person::getId).collect(Collectors.toSet()); if (existsIds.containsAll(personIds)) { - return ExistsContainer.allFind(existsEntity); + return ExistContainer.allFind(existsEntity); } else { final Set noExistsId = personIds.stream() .filter(id -> !existsIds.contains(id)) .collect(Collectors.toSet()); - return ExistsContainer.notAllFind(existsEntity, noExistsId); + return ExistContainer.notAllFind(existsEntity, noExistsId); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java index 3d145fa..623ba15 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/PipelineServiceImpl.java @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Person; @@ -8,15 +9,14 @@ import dev.struchkov.bot.gitlab.context.domain.filter.PipelineFilter; import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotify; import dev.struchkov.bot.gitlab.context.repository.PipelineRepository; import dev.struchkov.bot.gitlab.context.service.NotifyService; -import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.PipelineService; import dev.struchkov.bot.gitlab.core.service.impl.filter.PipelineFilterService; -import dev.struchkov.haiti.context.domain.ExistsContainer; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Set; @@ -27,6 +27,7 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.FAILED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SKIPPED; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.SUCCESS; import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; /** * Реализация сервиса для работы с пайплайнами. @@ -42,14 +43,13 @@ public class PipelineServiceImpl implements PipelineService { private final NotifyService notifyService; private final PipelineRepository repository; - private final PersonService personService; private final PipelineFilterService pipelineFilterService; private final PersonInformation personInformation; @Override + @Transactional public Pipeline create(@NonNull Pipeline pipeline) { - personService.create(pipeline.getPerson()); final Pipeline newPipeline = repository.save(pipeline); notifyNewPipeline(pipeline, "n/a"); return newPipeline; @@ -87,7 +87,7 @@ public class PipelineServiceImpl implements PipelineService { private boolean isNeedNotifyNewPipeline(@NonNull Pipeline pipeline) { final Person personPipelineCreator = pipeline.getPerson(); return notificationStatus.contains(pipeline.getStatus()) // Пайплайн имеет статус необходимый для уведомления - && personPipelineCreator != null + && checkNotNull(personPipelineCreator) // Создатель пайплайна не null && personInformation.getId().equals(personPipelineCreator.getId()); // Пользователь приложения является инициатором пайплайна } @@ -102,16 +102,16 @@ public class PipelineServiceImpl implements PipelineService { } @Override - public ExistsContainer existsById(@NonNull Set pipelineIds) { + public ExistContainer existsById(@NonNull Set pipelineIds) { final List existsEntity = repository.findAllById(pipelineIds); final Set existsIds = existsEntity.stream().map(Pipeline::getId).collect(Collectors.toSet()); if (existsIds.containsAll(pipelineIds)) { - return ExistsContainer.allFind(existsEntity); + return ExistContainer.allFind(existsEntity); } else { final Set noExistsId = pipelineIds.stream() .filter(id -> !existsIds.contains(id)) .collect(Collectors.toSet()); - return ExistsContainer.notAllFind(existsEntity, noExistsId); + return ExistContainer.notAllFind(existsEntity, noExistsId); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java index cedd686..bdad5f4 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/ProjectServiceImpl.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.impl; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.notify.NewProjectNotify; @@ -78,16 +78,16 @@ public class ProjectServiceImpl implements ProjectService { } @Override - public ExistsContainer existsById(Set projectIds) { + public ExistContainer existsById(Set projectIds) { final List existsEntity = repository.findAllById(projectIds); final Set existsIds = existsEntity.stream().map(Project::getId).collect(Collectors.toSet()); if (existsIds.containsAll(projectIds)) { - return ExistsContainer.allFind(existsEntity); + return ExistContainer.allFind(existsEntity); } else { final Set noExistsId = projectIds.stream() .filter(id -> !existsIds.contains(id)) .collect(Collectors.toSet()); - return ExistsContainer.notAllFind(existsEntity, noExistsId); + return ExistContainer.notAllFind(existsEntity, noExistsId); } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java index b0b770e..346f36d 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Discussion; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; import dev.struchkov.bot.gitlab.context.domain.entity.Note; @@ -75,10 +75,10 @@ public class DiscussionParser { .map(DiscussionJson::getId) .collect(Collectors.toUnmodifiableSet()); - final ExistsContainer existsContainer = discussionService.existsById(discussionIds); - if (!existsContainer.isAllFound()) { + final ExistContainer existContainer = discussionService.existsById(discussionIds); + if (!existContainer.isAllFound()) { final List newDiscussions = discussionJson.stream() - .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .filter(json -> existContainer.getIdNoFound().contains(json.getId())) .map(json -> { final Discussion discussion = conversionService.convert(json, Discussion.class); discussion.setMergeRequest(mergeRequest); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java index 31a9aa4..61d171e 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr; import dev.struchkov.bot.gitlab.context.domain.MergeRequestState; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; @@ -96,10 +96,10 @@ public class MergeRequestParser { .map(MergeRequestJson::getId) .collect(Collectors.toSet()); - final ExistsContainer existsContainer = mergeRequestsService.existsById(jsonIds); - if (!existsContainer.isAllFound()) { + final ExistContainer existContainer = mergeRequestsService.existsById(jsonIds); + if (!existContainer.isAllFound()) { final List newMergeRequests = mergeRequestJsons.stream() - .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .filter(json -> existContainer.getIdNoFound().contains(json.getId())) .map(json -> { final MergeRequest mergeRequest = conversionService.convert(json, MergeRequest.class); parsingCommits(mergeRequest); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java index b195199..08d2b14 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/PipelineParser.java @@ -1,5 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.domain.entity.Project; @@ -9,7 +10,6 @@ import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty; import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty; import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.PipelineJson; -import dev.struchkov.haiti.context.domain.ExistsContainer; import dev.struchkov.haiti.utils.network.HttpParse; import lombok.RequiredArgsConstructor; import org.springframework.core.convert.ConversionService; @@ -19,7 +19,6 @@ import org.springframework.stereotype.Service; import java.text.MessageFormat; import java.time.LocalDateTime; -import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -31,6 +30,7 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PREPARING; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE; import static dev.struchkov.haiti.context.exception.ConvertException.convertException; +import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; /** @@ -75,17 +75,17 @@ public class PipelineParser { LocalDateTime newLastUpdate = LocalDateTime.now(); List pipelineJsons = getPipelineJsons(project.getId(), page, lastUpdate); - while (!pipelineJsons.isEmpty()) { + while (checkNotEmpty(pipelineJsons)) { final Set jsonIds = pipelineJsons.stream() .map(PipelineJson::getId) .collect(Collectors.toSet()); - final ExistsContainer existsContainer = pipelineService.existsById(jsonIds); + final ExistContainer existContainer = pipelineService.existsById(jsonIds); - if (!existsContainer.isAllFound()) { + if (!existContainer.isAllFound()) { - final Collection idsNotFound = existsContainer.getIdNoFound(); + final Set idsNotFound = existContainer.getIdNoFound(); for (Long newId : idsNotFound) { final Pipeline newPipeline = HttpParse.request( diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java index 6ff3738..25342f6 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/ProjectParser.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.core.service.parser; -import dev.struchkov.bot.gitlab.context.domain.ExistsContainer; +import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.service.PersonService; @@ -69,9 +69,9 @@ public class ProjectParser { createNewPersons(projectJsons); - final ExistsContainer existsContainer = projectService.existsById(projectIds); + final ExistContainer existContainer = projectService.existsById(projectIds); final List newProjects = projectJsons.stream() - .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .filter(json -> existContainer.getIdNoFound().contains(json.getId())) .map(json -> conversionService.convert(json, Project.class)) .toList(); @@ -102,10 +102,10 @@ public class ProjectParser { .map(ProjectJson::getCreatorId) .collect(Collectors.toSet()); - final ExistsContainer existsContainer = personService.existsById(personCreatorId); + final ExistContainer existContainer = personService.existsById(personCreatorId); - if (!existsContainer.isAllFound()) { - final Collection notFoundId = existsContainer.getIdNoFound(); + if (!existContainer.isAllFound()) { + final Collection notFoundId = existContainer.getIdNoFound(); final List newPersons = notFoundId.stream() .map(