diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java index 5eda83a..91ad68a 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java @@ -44,7 +44,7 @@ public class Discussion { joinColumns = @JoinColumn(name = "discussion_id"), inverseJoinColumns = @JoinColumn(name = "merge_request_id") ) - private MergeRequest mergeRequest; + private MergeRequestForDiscussion mergeRequest; @OneToMany( mappedBy = "discussion", diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestMini.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestForDiscussion.java similarity index 57% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestMini.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestForDiscussion.java index 612263d..d6deef4 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestMini.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequestForDiscussion.java @@ -4,11 +4,12 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.Table; /** @@ -19,27 +20,30 @@ import javax.persistence.Table; @Entity @Table(name = "merge_request") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class MergeRequestMini { +public class MergeRequestForDiscussion { /** * Идентификатор */ @Id @Column(name = "id") - @GeneratedValue(strategy = GenerationType.IDENTITY) @EqualsAndHashCode.Include private Long id; - /** - * Адрес ПР - */ + @Column(name = "two_id") + private Long twoId; + + @Column(name = "project_id") + private Long projectId; + + @Column(name = "title") + private String title; + + @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn(name = "author_id") + private Person author; + @Column(name = "web_url") private String webUrl; - /** - * Автор ПР - */ - @Column(name = "author_id") - private Long author; - } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java index 8a73e52..8a360a5 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java @@ -3,6 +3,7 @@ package dev.struchkov.bot.gitlab.context.repository; 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; +import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import lombok.NonNull; import java.util.List; @@ -17,7 +18,7 @@ public interface MergeRequestRepository { Optional findById(Long mergeRequestId); - List findAll(); + List findAllForDiscussion(); List findAllById(Set mergeRequestIds); 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 67823e0..36cdd0e 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 @@ -4,6 +4,7 @@ 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; +import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import lombok.NonNull; import java.util.List; @@ -25,14 +26,12 @@ public interface MergeRequestsService { */ Set getAllId(Set statuses); - List getAll(); + List getAllForDiscussion(); ExistContainer existsById(@NonNull Set mergeRequestIds); List createAll(List newMergeRequests); - void deleteAllById(@NonNull Set mergeRequestIds); - List getAllByReviewerId(@NonNull Long personId); void cleanOld(); 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 0ae876e..67bc75e 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 @@ -3,7 +3,7 @@ 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.entity.Discussion; -import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest; +import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify; @@ -88,7 +88,7 @@ public class DiscussionServiceImpl implements DiscussionService { final Note firstNote = discussion.getFirstNote(); final List notes = discussion.getNotes(); - final MergeRequest mergeRequest = discussion.getMergeRequest(); + final MergeRequestForDiscussion mergeRequest = discussion.getMergeRequest(); final DiscussionNewNotify.DiscussionNewNotifyBuilder notifyBuilder = DiscussionNewNotify.builder() .mrName(mergeRequest.getTitle()) .authorName(firstNote.getAuthor().getName()) @@ -117,6 +117,7 @@ public class DiscussionServiceImpl implements DiscussionService { } @Override + @Transactional public Discussion update(@NonNull Discussion discussion) { final Discussion oldDiscussion = repository.findById(discussion.getId()) .orElseThrow(notFoundException("Дискуссия не найдена")); @@ -212,7 +213,7 @@ public class DiscussionServiceImpl implements DiscussionService { private void updateTask(Note note, Note oldNote) { if (isResolved(note, oldNote)) { - final MergeRequest mergeRequest = oldNote.getDiscussion().getMergeRequest(); + final MergeRequestForDiscussion mergeRequest = oldNote.getDiscussion().getMergeRequest(); final List discussions = getAllByMergeRequestId(mergeRequest.getId()) .stream() .filter(discussion -> Objects.nonNull(discussion.getResponsible())) @@ -247,7 +248,7 @@ public class DiscussionServiceImpl implements DiscussionService { public void answer(@NonNull String discussionId, @NonNull String text) { final Discussion discussion = repository.findById(discussionId) .orElseThrow(notFoundException("Дисскусия {0} не найдена", discussionId)); - final MergeRequest mergeRequest = discussion.getMergeRequest(); + final MergeRequestForDiscussion mergeRequest = discussion.getMergeRequest(); final Long projectId = mergeRequest.getProjectId(); final String requestUrl = MessageFormat.format(gitlabProperty.getNewNoteUrl(), projectId, mergeRequest.getTwoId(), discussion.getId(), text); 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 0bfd1f6..c255fff 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 @@ -8,6 +8,7 @@ import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.domain.ReviewerChanged; 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.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictPrNotify; @@ -212,8 +213,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { } @Override - public List getAll() { - return repository.findAll(); + public List getAllForDiscussion() { + return repository.findAllForDiscussion(); } @Override @@ -237,12 +238,6 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .toList(); } - @Override - @Transactional - public void deleteAllById(@NonNull Set mergeRequestIds) { - repository.deleteByIds(mergeRequestIds); - } - @Override public List getAllByReviewerId(@NonNull Long personId) { return repository.findAllByReviewerId(personId); 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 eab26ca..346f92e 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 @@ -2,7 +2,7 @@ package dev.struchkov.bot.gitlab.core.service.parser; 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.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.service.DiscussionService; @@ -73,16 +73,16 @@ public class DiscussionParser { */ public void scanNewDiscussion() { log.debug("Старт обработки новых дискуссий"); - final List mergeRequests = mergeRequestsService.getAll(); + final List mergeRequests = mergeRequestsService.getAllForDiscussion(); - for (MergeRequest mergeRequest : mergeRequests) { + for (MergeRequestForDiscussion mergeRequest : mergeRequests) { processingMergeRequest(mergeRequest); } log.debug("Конец обработки новых дискуссий"); } - private void processingMergeRequest(MergeRequest mergeRequest) { + private void processingMergeRequest(MergeRequestForDiscussion mergeRequest) { int page = 1; List discussionJson = getDiscussionJson(mergeRequest, page); @@ -94,7 +94,7 @@ public class DiscussionParser { } } - private void createNewDiscussion(List discussionJson, MergeRequest mergeRequest) { + private void createNewDiscussion(List discussionJson, MergeRequestForDiscussion mergeRequest) { final Set discussionIds = discussionJson.stream() .map(DiscussionJson::getId) .collect(Collectors.toUnmodifiableSet()); @@ -200,14 +200,14 @@ public class DiscussionParser { ); } - private List getDiscussionJson(MergeRequest mergeRequest, int page) { + private List getDiscussionJson(MergeRequestForDiscussion mergeRequest, int page) { return HttpParse.request(MessageFormat.format(gitlabProperty.getDiscussionsUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId(), page)) .header(ACCEPT) .header(H_PRIVATE_TOKEN, personProperty.getToken()) .executeList(DiscussionJson.class); } - private Consumer createNoteLink(MergeRequest mergeRequest) { + private Consumer createNoteLink(MergeRequestForDiscussion mergeRequest) { return note -> { final String url = MessageFormat.format( gitlabProperty.getNoteUrl(), diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java index c1a2737..c925fd0 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java @@ -3,7 +3,9 @@ package dev.struchkov.bot.gitlab.data.impl; 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; +import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository; +import dev.struchkov.bot.gitlab.data.jpa.MergeRequestForDiscussionJpaRepository; import dev.struchkov.bot.gitlab.data.jpa.MergeRequestJpaRepository; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -18,6 +20,7 @@ import java.util.Set; public class MergeRequestRepositoryImpl implements MergeRequestRepository { private final MergeRequestJpaRepository jpaRepository; + private final MergeRequestForDiscussionJpaRepository forDiscussionJpaRepository; @Override public Set findAllIdByStateIn(@NonNull Set statuses) { @@ -35,8 +38,8 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository { } @Override - public List findAll() { - return jpaRepository.findAll(); + public List findAllForDiscussion() { + return forDiscussionJpaRepository.findAll(); } @Override diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestForDiscussionJpaRepository.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestForDiscussionJpaRepository.java new file mode 100644 index 0000000..c621d8e --- /dev/null +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestForDiscussionJpaRepository.java @@ -0,0 +1,12 @@ +package dev.struchkov.bot.gitlab.data.jpa; + +import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; +import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; + +/** + * @author upagge [31.01.2020] + */ + +public interface MergeRequestForDiscussionJpaRepository extends JpaRepositoryImplementation { + +}