release-0.0.1
This commit is contained in:
parent
31f59fc0d5
commit
167843d8b2
@ -3,7 +3,7 @@ package org.sadtech.bot.gitlab.app.scheduler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.bot.gitlab.core.service.parser.MergeRequestParser;
|
||||
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
|
||||
import org.sadtech.bot.gitlab.core.service.parser.NoteParser;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -17,8 +17,8 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class SchedulerService {
|
||||
|
||||
private final ProjectParser projectParser;
|
||||
private final MergeRequestParser mergeRequestParser;
|
||||
private final NoteParser noteParser;
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newMergeRequest() {
|
||||
@ -30,4 +30,9 @@ public class SchedulerService {
|
||||
mergeRequestParser.parsingOldMergeRequest();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newNoteParser() {
|
||||
noteParser.scanNewCommentAndTask();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,14 +32,15 @@ gitlab-bot:
|
||||
telegram-id: ${TELEGRAM_PERSON_ID}
|
||||
token: ${GITLAB_PERSONAL_TOKEN}
|
||||
gitlab:
|
||||
url-project: ${GITLAB_URL}/api/v4/projects?page={0}&per_page=100
|
||||
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened&page={1}&per_page=100
|
||||
url-project: ${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100
|
||||
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests?state=opened&page={1, number, integer}&per_page=100
|
||||
url-pull-request-close: ${GITLAB_URL}
|
||||
url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}/notes
|
||||
url-pull-request: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}?page={2}&per_page=100
|
||||
url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests/{1}/notes
|
||||
url-pull-request: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests/{1, number, integer}?page={2, number, integer}&per_page=100
|
||||
url-merge-request-add: ${GITLAB_URL}/api/v4/projects/{0}%2F{1}
|
||||
user-url: ${GITLAB_URL}/api/v4/user
|
||||
users-url: ${GITLAB_URL}/api/v4/users
|
||||
url-note: "{0}#note_{1,number,#}"
|
||||
teamcity:
|
||||
token: ${TEAMCITY_ADMIN_TOKEN}
|
||||
project-url: ${TEAMCITY_URL}/app/rest/projects
|
||||
|
@ -94,6 +94,9 @@
|
||||
<column name="target_branch" type="varchar(100)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="notification" type="boolean">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
@ -136,13 +139,31 @@
|
||||
</column>
|
||||
<column name="noteable_id" type="int"/>
|
||||
<column name="noteable_type" type="varchar(100)"/>
|
||||
<column name="resolvable" type="boolean"/>
|
||||
<column name="resolvable" type="varchar(6)"/>
|
||||
<column name="resolved" type="boolean"/>
|
||||
<column name="resolved_id" type="int">
|
||||
<constraints foreignKeyName="note_resolved_by_person_id" references="person(id)"/>
|
||||
</column>
|
||||
<column name="noteable_iid" type="int"/>
|
||||
<column name="web_url" type="varchar(300)"/>
|
||||
<column name="responsible_id" type="integer">
|
||||
<constraints foreignKeyName="note_responsible_id_person_id" references="person(id)"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2020-01-17-create-link-note" author="uPagge">
|
||||
<createTable tableName="merge_request_notes">
|
||||
<column name="merge_request_id" type="int">
|
||||
<constraints nullable="false" foreignKeyName="merge_request_notes_merge_request_id"
|
||||
references="note(id)" deleteCascade="true"/>
|
||||
</column>
|
||||
<column name="notes_id" type="int">
|
||||
<constraints nullable="false" foreignKeyName="merge_request_notes_note_id" references="note(id)"/>
|
||||
</column>
|
||||
</createTable>
|
||||
|
||||
<addPrimaryKey tableName="merge_request_notes" columnNames="merge_request_id, notes_id"/>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -15,7 +15,7 @@ menu.add_project_success=Project added successfully
|
||||
ui.menu.setting.text=This is the settings menu
|
||||
ui.menu.setting.language=Language settings
|
||||
ui.menu.setting.language.text=Choose your language
|
||||
notify.pr.new={0} *New PullRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
|
||||
notify.pr.new={0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
|
||||
notify.pr.forgotten={0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2})
|
||||
notify.pr.conflict={0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3})
|
||||
notify.pr.smart={0} *MergeRequest Reminder | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5}
|
||||
|
@ -15,7 +15,7 @@ menu.add_project_success=Проект успешно добавлен
|
||||
ui.menu.setting.text=Это меню настроек
|
||||
ui.menu.setting.language=Настройки языка
|
||||
ui.menu.setting.language.text=Выберете язык
|
||||
notify.pr.new={0} *Новый PullRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
|
||||
notify.pr.new={0} *Новый MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
|
||||
notify.pr.forgotten={0} *Напоминание о просмотре PullRequest | {4}*{3}[{1}]({2})
|
||||
notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3})
|
||||
notify.pr.smart={0} *Напоминание о MergeRequest | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.context.domain;
|
||||
|
||||
public enum TaskStatus {
|
||||
|
||||
OPEN,
|
||||
RESOLVED
|
||||
|
||||
}
|
@ -12,12 +12,17 @@ import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -79,9 +84,16 @@ public class MergeRequest implements BasicEntity<Long> {
|
||||
@Column(name = "source_branch")
|
||||
private String sourceBranch;
|
||||
|
||||
@Column(name = "notification")
|
||||
private Boolean notification;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "merge_request_label", joinColumns = @JoinColumn(name = "merge_request_id"))
|
||||
@Column(name = "label")
|
||||
private Set<String> labels = new HashSet<>();
|
||||
|
||||
@JoinTable
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
private List<Note> notes = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ import java.time.LocalDateTime;
|
||||
@Table(name = "note")
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type")
|
||||
@DiscriminatorValue("null")
|
||||
@DiscriminatorColumn(name = "resolvable")
|
||||
@DiscriminatorValue("false")
|
||||
public class Note implements BasicEntity<Long> {
|
||||
|
||||
@Id
|
||||
@ -56,17 +56,10 @@ public class Note implements BasicEntity<Long> {
|
||||
@Column(name = "noteable_type")
|
||||
private String noteableType;
|
||||
|
||||
@Column(name = "resolveable")
|
||||
private Boolean resolveable;
|
||||
|
||||
@Column(name = "resolved")
|
||||
private Boolean resolved;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "resolved_id")
|
||||
private Person resolvedBy;
|
||||
|
||||
@Column(name = "noteable_iid")
|
||||
private Long noteableIid;
|
||||
|
||||
@Column(name = "web_url")
|
||||
private String webUrl;
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,31 @@
|
||||
package org.sadtech.bot.gitlab.context.domain.entity;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
//@Entity
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
//@Table(name = "task")
|
||||
@DiscriminatorValue("true")
|
||||
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
public class Task extends Note {
|
||||
|
||||
@Column(name = "resolved")
|
||||
private Boolean resolved;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "resolved_id")
|
||||
private Person resolvedBy;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "responsible_id")
|
||||
private Person responsible;
|
||||
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
public interface CommentRepository extends SimpleManagerRepository<Note, Long> {
|
||||
|
||||
Optional<Note> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Note> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Note> findAllById(@NonNull Set<Long> ids);
|
||||
|
||||
Set<Long> existsById(Set<Long> ids);
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
public interface NoteRepository extends SimpleManagerRepository<Note, Long> {
|
||||
|
||||
}
|
@ -1,20 +1,8 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TaskRepository extends SimpleManagerRepository<Task, Long> {
|
||||
|
||||
Optional<Task> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Task> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo);
|
||||
|
||||
List<Task> findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status);
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,8 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface NoteService extends SimpleManagerService<Note, Long> {
|
||||
|
||||
Long getLastCommentId();
|
||||
|
||||
List<Note> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Note> getAllById(@NonNull Set<Long> ids);
|
||||
|
||||
Note convert(@NonNull Task task);
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,8 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskService extends SimpleManagerService<Task, Long> {
|
||||
|
||||
Long getLastTaskId();
|
||||
|
||||
Task convert(@NonNull Note note);
|
||||
|
||||
List<Task> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Task> getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus open);
|
||||
|
||||
}
|
||||
|
@ -44,4 +44,6 @@ public class GitlabProperty {
|
||||
|
||||
private String urlMergeRequestAdd;
|
||||
|
||||
private String urlNote;
|
||||
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* // TODO: 12.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
@Component
|
||||
public class CommentToTaskConvert implements Converter<Note, Task> {
|
||||
|
||||
@Override
|
||||
public Task convert(Note source) {
|
||||
final Task task = new Task();
|
||||
// task.setId(source.getId());
|
||||
// task.setUrl(source.getUrl());
|
||||
// task.setUrlApi(source.getUrlApi());
|
||||
// task.setResponsible(source.getResponsible());
|
||||
// task.setStatus(TaskStatus.OPEN);
|
||||
// task.setPullRequestId(source.getPullRequestId());
|
||||
// task.setBitbucketVersion(source.getBitbucketVersion());
|
||||
// task.setCreateDate(source.getCreateDate());
|
||||
// task.setDescription(source.getMessage());
|
||||
// task.setAuthor(source.getAuthor());
|
||||
// task.setAnswers(source.getAnswers());
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.NoteJson;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* // TODO: 12.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NoteJsonConvert implements Converter<NoteJson, Note> {
|
||||
|
||||
private final PersonJsonConverter personConverter;
|
||||
|
||||
@Override
|
||||
public Note convert(NoteJson source) {
|
||||
final Note note = new Note();
|
||||
note.setAuthor(personConverter.convert(source.getAuthor()));
|
||||
note.setId(source.getId());
|
||||
note.setBody(source.getBody());
|
||||
note.setType(source.getType());
|
||||
note.setNoteableType(source.getNoteableType());
|
||||
note.setCreated(source.getCreated());
|
||||
note.setUpdated(source.getUpdated());
|
||||
note.setNoteableId(source.getNoteableId());
|
||||
note.setNoteableIid(source.getNoteableIid());
|
||||
note.setSystem(source.isSystem());
|
||||
return note;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.NoteJson;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* // TODO: 12.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NoteJsonToTaskConvert implements Converter<NoteJson, Task> {
|
||||
|
||||
private final PersonJsonConverter personConverter;
|
||||
|
||||
@Override
|
||||
public Task convert(NoteJson source) {
|
||||
final Task task = new Task();
|
||||
task.setAuthor(personConverter.convert(source.getAuthor()));
|
||||
task.setId(source.getId());
|
||||
task.setBody(source.getBody());
|
||||
task.setType(source.getType());
|
||||
task.setNoteableType(source.getNoteableType());
|
||||
task.setCreated(source.getCreated());
|
||||
task.setUpdated(source.getUpdated());
|
||||
task.setNoteableId(source.getNoteableId());
|
||||
task.setNoteableIid(source.getNoteableIid());
|
||||
task.setSystem(source.isSystem());
|
||||
|
||||
task.setResolved(source.getResolved());
|
||||
if (source.getResolvedBy() != null) {
|
||||
task.setResolvedBy(personConverter.convert(source.getResolvedBy()));
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* // TODO: 12.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
@Component
|
||||
public class TaskToCommentConvert implements Converter<Task, Note> {
|
||||
|
||||
@Override
|
||||
public Note convert(Task source) {
|
||||
final Note note = new Note();
|
||||
// note.setId(source.getId());
|
||||
// note.setUrl(source.getUrl());
|
||||
// note.setUrlApi(source.getUrlApi());
|
||||
// note.setPullRequestId(source.getPullRequestId());
|
||||
// note.setBitbucketVersion(source.getBitbucketVersion());
|
||||
// note.setCreateDate(source.getCreateDate());
|
||||
// note.setMessage(source.getDescription());
|
||||
// note.setResponsible(source.getResponsible());
|
||||
// note.setAuthor(source.getAuthor());
|
||||
// note.setAnswers(source.getAnswers());
|
||||
return note;
|
||||
}
|
||||
|
||||
}
|
@ -62,6 +62,8 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
personService.create(mergeRequest.getAuthor());
|
||||
personService.create(mergeRequest.getAssignee());
|
||||
|
||||
mergeRequest.setNotification(true);
|
||||
|
||||
final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest);
|
||||
|
||||
// if (!settingService.isFirstStart()) {
|
||||
@ -98,13 +100,19 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
||||
|
||||
// forgottenNotification(oldMergeRequest);
|
||||
|
||||
if (mergeRequest.getNotification() == null) {
|
||||
mergeRequest.setNotification(oldMergeRequest.getNotification());
|
||||
}
|
||||
|
||||
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())) {
|
||||
final Project project = projectService.getById(mergeRequest.getProjectId())
|
||||
.orElseThrow(() -> new NotFoundException("Проект не найден"));
|
||||
|
||||
notifyStatus(oldMergeRequest, mergeRequest, project);
|
||||
notifyConflict(oldMergeRequest, mergeRequest, project);
|
||||
notifyUpdate(oldMergeRequest, mergeRequest, project);
|
||||
if (Boolean.TRUE.equals(oldMergeRequest.getNotification())) {
|
||||
notifyStatus(oldMergeRequest, mergeRequest, project);
|
||||
notifyConflict(oldMergeRequest, mergeRequest, project);
|
||||
notifyUpdate(oldMergeRequest, mergeRequest, project);
|
||||
}
|
||||
|
||||
return mergeRequestRepository.save(mergeRequest);
|
||||
}
|
||||
|
@ -1,141 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.comment.CommentNotify;
|
||||
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.repository.CommentRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.NoteService;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.bot.gitlab.context.service.TaskService;
|
||||
import org.sadtech.haiti.context.domain.ExistsContainer;
|
||||
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> implements NoteService {
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("@[\\w]+");
|
||||
|
||||
private final CommentRepository commentRepository;
|
||||
private final NotifyService notifyService;
|
||||
private final TaskService taskService;
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
public NoteServiceImpl(
|
||||
CommentRepository commentRepository,
|
||||
NotifyService notifyService,
|
||||
@Lazy TaskService taskService,
|
||||
ConversionService conversionService
|
||||
) {
|
||||
super(commentRepository);
|
||||
this.commentRepository = commentRepository;
|
||||
this.notifyService = notifyService;
|
||||
this.taskService = taskService;
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastCommentId() {
|
||||
return commentRepository.findFirstByOrderByIdDesc().map(Note::getId).orElse(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> getAllBetweenDate(@NonNull LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
return commentRepository.findByCreateDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Note create(@NonNull Note note) {
|
||||
final Note newNote = commentRepository.save(note);
|
||||
notificationPersonal(note);
|
||||
return newNote;
|
||||
}
|
||||
|
||||
private void notificationPersonal(@NonNull Note note) {
|
||||
Matcher matcher = PATTERN.matcher(note.getBody());
|
||||
Set<String> recipientsLogins = new HashSet<>();
|
||||
while (matcher.find()) {
|
||||
final String login = matcher.group(0).replace("@", "");
|
||||
recipientsLogins.add(login);
|
||||
}
|
||||
notifyService.send(
|
||||
CommentNotify.builder()
|
||||
// .authorName(note.getAuthor())
|
||||
// .url(note.getUrl())
|
||||
// .message(note.getMessage())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Note update(Note note) {
|
||||
final Note oldNote = commentRepository.findById(note.getId())
|
||||
.orElseThrow(() -> new NotFoundException("Комментарий не найден"));
|
||||
|
||||
updateAnswer(oldNote, note);
|
||||
|
||||
return commentRepository.save(oldNote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> getAllById(@NonNull Set<Long> ids) {
|
||||
return commentRepository.findAllById(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Note convert(@NonNull Task task) {
|
||||
taskService.deleteById(task.getId());
|
||||
final Note note = conversionService.convert(task, Note.class);
|
||||
return commentRepository.save(note);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> existsById(@NonNull Set<Long> ids) {
|
||||
return commentRepository.existsById(ids);
|
||||
}
|
||||
|
||||
private void updateAnswer(Note oldNote, Note newNote) {
|
||||
// final Set<Long> oldAnswerIds = oldNote.getAnswers();
|
||||
// final Set<Long> newAnswerIds = newNote.getAnswers();
|
||||
// if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
// final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds);
|
||||
// final List<Note> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream()
|
||||
// .filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
// .collect(Collectors.toList());
|
||||
// oldNote.getAnswers().clear();
|
||||
// oldNote.setAnswers(existsNewAnswersIds);
|
||||
// if (!newAnswers.isEmpty()) {
|
||||
// notifyService.send(
|
||||
// AnswerCommentNotify.builder()
|
||||
// .url(oldNote.getUrl())
|
||||
// .youMessage(newNote.getMessage())
|
||||
// .answers(
|
||||
// newAnswers.stream()
|
||||
// .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
|
||||
// .collect(Collectors.toList())
|
||||
// )
|
||||
// .build()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExistsContainer<Note, Long> existsById(@NonNull Collection<Long> collection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl;
|
||||
|
||||
//@Service
|
||||
//public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> implements TaskService {
|
||||
//
|
||||
// private static final Pattern PATTERN = Pattern.compile("@[\\w]+");
|
||||
//
|
||||
// private final TaskRepository taskRepository;
|
||||
//
|
||||
// private final MergeRequestsService mergeRequestsService;
|
||||
// private final NotifyService notifyService;
|
||||
// private final NoteService noteService;
|
||||
//
|
||||
// private final ConversionService conversionService;
|
||||
//
|
||||
// public TaskServiceImpl(
|
||||
// TaskRepository taskRepository,
|
||||
// MergeRequestsService mergeRequestsService,
|
||||
// NotifyService notifyService,
|
||||
// NoteService noteService,
|
||||
// ConversionService conversionService
|
||||
// ) {
|
||||
// super(taskRepository);
|
||||
// this.taskRepository = taskRepository;
|
||||
// this.mergeRequestsService = mergeRequestsService;
|
||||
// this.notifyService = notifyService;
|
||||
// this.noteService = noteService;
|
||||
// this.conversionService = conversionService;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Task create(@NonNull Task task) {
|
||||
// Assert.isNotNull(task.getId(), "При создании объекта должен быть установлен идентификатор");
|
||||
// task.getAnswers().clear();
|
||||
// final Task newTask = taskRepository.save(task);
|
||||
// notifyNewTask(task);
|
||||
// notificationPersonal(task);
|
||||
// return newTask;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Task update(@NonNull Task task) {
|
||||
// final Task oldTask = taskRepository.findById(task.getId())
|
||||
// .orElseThrow(() -> new NotFoundException("Задача не найдена"));
|
||||
//
|
||||
// if (!task.getBitbucketVersion().equals(oldTask.getBitbucketVersion())) {
|
||||
// oldTask.setDescription(task.getDescription());
|
||||
// oldTask.setBitbucketVersion(task.getBitbucketVersion());
|
||||
// }
|
||||
// updateAnswer(oldTask, task);
|
||||
// updateStatus(oldTask, task);
|
||||
// oldTask.setStatus(task.getStatus());
|
||||
// return taskRepository.save(oldTask);
|
||||
// }
|
||||
//
|
||||
// private void updateStatus(Task oldTask, Task task) {
|
||||
// final TaskStatus oldStatus = oldTask.getStatus();
|
||||
// final TaskStatus newStatus = task.getStatus();
|
||||
// if (!oldStatus.equals(newStatus)) {
|
||||
// switch (newStatus) {
|
||||
// case OPEN:
|
||||
// notifyService.send(
|
||||
// TaskNewNotify.builder()
|
||||
// .messageTask(task.getDescription())
|
||||
// .authorName(oldTask.getAuthor())
|
||||
// .url(oldTask.getUrl())
|
||||
// .build()
|
||||
// );
|
||||
// break;
|
||||
// case RESOLVED:
|
||||
// notifyService.send(
|
||||
// TaskCloseNotify.builder()
|
||||
// .messageTask(oldTask.getDescription())
|
||||
// .authorName(oldTask.getAuthor())
|
||||
// .url(oldTask.getUrl())
|
||||
// .build()
|
||||
// );
|
||||
// break;
|
||||
// default:
|
||||
// throw new NotFoundException("Обработчика типа не существует");
|
||||
// }
|
||||
// oldTask.setStatus(newStatus);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void updateAnswer(Task oldTask, Task task) {
|
||||
//// final Set<Long> oldAnswerIds = oldTask.getAnswers();
|
||||
//// final Set<Long> newAnswerIds = task.getAnswers();
|
||||
//// if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
//// final Set<Long> existsNewAnswersIds = noteService.existsById(newAnswerIds);
|
||||
//// final List<Note> newAnswers = noteService.getAllById(existsNewAnswersIds).stream()
|
||||
//// .filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
//// .collect(Collectors.toList());
|
||||
//// oldTask.getAnswers().clear();
|
||||
//// oldTask.setAnswers(existsNewAnswersIds);
|
||||
//// if (!newAnswers.isEmpty()) {
|
||||
//// notifyService.send(
|
||||
//// AnswerCommentNotify.builder()
|
||||
//// .url(oldTask.getUrl())
|
||||
//// .youMessage(oldTask.getDescription())
|
||||
//// .answers(
|
||||
//// newAnswers.stream()
|
||||
//// .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
|
||||
//// .collect(Collectors.toList())
|
||||
//// )
|
||||
//// .build()
|
||||
//// );
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Long getLastTaskId() {
|
||||
// return taskRepository.findFirstByOrderByIdDesc().map(Task::getId).orElse(0L);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Task convert(@NonNull Note note) {
|
||||
// noteService.deleteById(note.getId());
|
||||
// final Task task = conversionService.convert(note, Task.class);
|
||||
// final Task newTask = taskRepository.save(task);
|
||||
// notifyNewTask(newTask);
|
||||
// return newTask;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Task> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||
// return taskRepository.findByCreateDateBetween(dateFrom, dateTo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Task> getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus status) {
|
||||
// return taskRepository.findAllByResponsibleAndStatus(login, status);
|
||||
// }
|
||||
//
|
||||
// private void notifyNewTask(Task task) {
|
||||
// final MergeRequest mergeRequest = mergeRequestsService.getById(task.getPullRequestId())
|
||||
// .orElseThrow(() -> new NotFoundException("ПР не найден"));
|
||||
//
|
||||
// notifyService.send(
|
||||
// TaskNewNotify.builder()
|
||||
// .authorName(task.getAuthor())
|
||||
// .messageTask(task.getDescription())
|
||||
// .url(task.getUrl())
|
||||
//// .recipients(Collections.singleton(mergeRequest.getAuthor().getId()))
|
||||
// .build()
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// private void notificationPersonal(@NonNull Task task) {
|
||||
// Matcher matcher = PATTERN.matcher(task.getDescription());
|
||||
// Set<String> recipientsLogins = new HashSet<>();
|
||||
// while (matcher.find()) {
|
||||
// final String login = matcher.group(0).replace("@", "");
|
||||
// recipientsLogins.add(login);
|
||||
// }
|
||||
// notifyService.send(
|
||||
// CommentNotify.builder()
|
||||
// .authorName(task.getAuthor())
|
||||
// .url(task.getUrl())
|
||||
// .message(task.getDescription())
|
||||
// .build()
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deleteById(@NonNull Long id) {
|
||||
// super.deleteById(id);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ExistsContainer<Task, Long> existsById(@NonNull Collection<Long> collection) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,56 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl.note;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.comment.CommentNotify;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* // TODO: 17.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 17.01.2021
|
||||
*/
|
||||
public abstract class AbstractNoteService<T extends Note> extends AbstractSimpleManagerService<T, Long> {
|
||||
|
||||
protected static final Pattern PATTERN = Pattern.compile("@[\\w]+");
|
||||
|
||||
private final NotifyService notifyService;
|
||||
private final PersonInformation personInformation;
|
||||
|
||||
protected AbstractNoteService(
|
||||
SimpleManagerRepository<T, Long> repository,
|
||||
NotifyService notifyService,
|
||||
PersonInformation personInformation
|
||||
) {
|
||||
super(repository);
|
||||
this.notifyService = notifyService;
|
||||
this.personInformation = personInformation;
|
||||
}
|
||||
|
||||
protected void notificationPersonal(@NonNull Note note) {
|
||||
Matcher matcher = PATTERN.matcher(note.getBody());
|
||||
Set<String> recipientsLogins = new HashSet<>();
|
||||
while (matcher.find()) {
|
||||
final String login = matcher.group(0).replace("@", "");
|
||||
recipientsLogins.add(login);
|
||||
}
|
||||
if (recipientsLogins.contains(personInformation.getUsername())) {
|
||||
notifyService.send(
|
||||
CommentNotify.builder()
|
||||
.authorName(note.getAuthor().getName())
|
||||
.message(note.getBody())
|
||||
.url(note.getWebUrl())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl.note;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.repository.NoteRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.NoteService;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class NoteServiceImpl extends AbstractNoteService<Note> implements NoteService {
|
||||
|
||||
private final NoteRepository noteRepository;
|
||||
|
||||
public NoteServiceImpl(
|
||||
NoteRepository noteRepository,
|
||||
NotifyService notifyService,
|
||||
PersonInformation personInformation
|
||||
) {
|
||||
super(noteRepository, notifyService, personInformation);
|
||||
this.noteRepository = noteRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Note create(@NonNull Note note) {
|
||||
final Note newNote = noteRepository.save(note);
|
||||
notificationPersonal(note);
|
||||
return newNote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Note update(@NonNull Note note) {
|
||||
final Note oldNote = noteRepository.findById(note.getId())
|
||||
.orElseThrow(() -> new NotFoundException("Комментарий не найден"));
|
||||
|
||||
if (!oldNote.getUpdated().equals(note.getUpdated())) {
|
||||
note.setWebUrl(oldNote.getWebUrl());
|
||||
return noteRepository.save(oldNote);
|
||||
}
|
||||
// updateAnswer(oldNote, note);
|
||||
|
||||
return oldNote;
|
||||
}
|
||||
|
||||
private void updateAnswer(Note oldNote, Note newNote) {
|
||||
// final Set<Long> oldAnswerIds = oldNote.getAnswers();
|
||||
// final Set<Long> newAnswerIds = newNote.getAnswers();
|
||||
// if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
// final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds);
|
||||
// final List<Note> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream()
|
||||
// .filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
// .collect(Collectors.toList());
|
||||
// oldNote.getAnswers().clear();
|
||||
// oldNote.setAnswers(existsNewAnswersIds);
|
||||
// if (!newAnswers.isEmpty()) {
|
||||
// notifyService.send(
|
||||
// AnswerCommentNotify.builder()
|
||||
// .url(oldNote.getUrl())
|
||||
// .youMessage(newNote.getMessage())
|
||||
// .answers(
|
||||
// newAnswers.stream()
|
||||
// .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
|
||||
// .collect(Collectors.toList())
|
||||
// )
|
||||
// .build()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl.note;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.task.TaskNewNotify;
|
||||
import org.sadtech.bot.gitlab.context.repository.TaskRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.bot.gitlab.context.service.TaskService;
|
||||
import org.sadtech.haiti.context.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TaskServiceImpl extends AbstractNoteService<Task> implements TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
private final NotifyService notifyService;
|
||||
private final PersonInformation personInformation;
|
||||
|
||||
public TaskServiceImpl(
|
||||
TaskRepository taskRepository,
|
||||
NotifyService notifyService,
|
||||
PersonInformation personInformation) {
|
||||
super(taskRepository, notifyService, personInformation);
|
||||
this.taskRepository = taskRepository;
|
||||
this.notifyService = notifyService;
|
||||
this.personInformation = personInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task create(@NonNull Task task) {
|
||||
final Task newTask = taskRepository.save(task);
|
||||
notifyNewTask(task);
|
||||
notificationPersonal(task);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task update(@NonNull Task task) {
|
||||
final Task oldTask = taskRepository.findById(task.getId())
|
||||
.orElseThrow(() -> new NotFoundException("Задача не найдена"));
|
||||
|
||||
if (oldTask.getUpdated().equals(task.getUpdated())) {
|
||||
|
||||
task.setWebUrl(oldTask.getWebUrl());
|
||||
task.setResponsible(oldTask.getResponsible());
|
||||
|
||||
notifyUpdateStatus(oldTask, task);
|
||||
|
||||
return taskRepository.save(oldTask);
|
||||
}
|
||||
return oldTask;
|
||||
}
|
||||
|
||||
private void notifyUpdateStatus(Task oldTask, Task task) {
|
||||
if (
|
||||
personInformation.getId().equals(oldTask.getAuthor().getId())
|
||||
&& !personInformation.getId().equals(oldTask.getResolvedBy().getId())
|
||||
|
||||
) {
|
||||
final boolean oldStatus = oldTask.getResolved();
|
||||
final boolean newStatus = task.getResolved();
|
||||
if (!oldStatus && newStatus) {
|
||||
notifyService.send(
|
||||
TaskCloseNotify.builder()
|
||||
.authorName(task.getAuthor().getName())
|
||||
.messageTask(task.getBody())
|
||||
.url(task.getWebUrl())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyNewTask(Task task) {
|
||||
if (personInformation.getId().equals(task.getResponsible().getId())
|
||||
&& !personInformation.getId().equals(task.getAuthor().getId())) {
|
||||
notifyService.send(
|
||||
TaskNewNotify.builder()
|
||||
.authorName(task.getAuthor().getName())
|
||||
.messageTask(task.getBody())
|
||||
.url(task.getWebUrl())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,11 +3,11 @@ package org.sadtech.bot.gitlab.core.service.parser;
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
|
||||
import org.sadtech.bot.gitlab.context.service.NoteService;
|
||||
import org.sadtech.bot.gitlab.context.service.ProjectService;
|
||||
import org.sadtech.bot.gitlab.context.service.TaskService;
|
||||
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
|
||||
import org.sadtech.bot.gitlab.core.config.properties.InitProperty;
|
||||
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.NoteJson;
|
||||
import org.sadtech.haiti.context.domain.ExistsContainer;
|
||||
@ -35,50 +35,40 @@ public class NoteParser {
|
||||
|
||||
public static final int COUNT = 100;
|
||||
|
||||
private final ProjectService projectService;
|
||||
private final MergeRequestsService mergeRequestsService;
|
||||
private final ConversionService conversionService;
|
||||
|
||||
private final GitlabProperty gitlabProperty;
|
||||
private final InitProperty initProperty;
|
||||
private final PersonProperty personProperty;
|
||||
private final NoteService noteService;
|
||||
private final TaskService taskService;
|
||||
|
||||
public NoteParser(
|
||||
ProjectService projectService, MergeRequestsService mergeRequestsService,
|
||||
MergeRequestsService mergeRequestsService,
|
||||
ConversionService conversionService,
|
||||
GitlabProperty gitlabProperty,
|
||||
InitProperty initProperty,
|
||||
PersonProperty personProperty,
|
||||
NoteService noteService
|
||||
NoteService noteService,
|
||||
TaskService taskService
|
||||
) {
|
||||
this.projectService = projectService;
|
||||
this.mergeRequestsService = mergeRequestsService;
|
||||
this.conversionService = conversionService;
|
||||
this.gitlabProperty = gitlabProperty;
|
||||
this.initProperty = initProperty;
|
||||
this.personProperty = personProperty;
|
||||
this.noteService = noteService;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
public void scanNewCommentAndTask() {
|
||||
int page = 1;
|
||||
int page = 0;
|
||||
Sheet<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
|
||||
|
||||
while (mergeRequestSheet.hasContent()) {
|
||||
|
||||
final List<MergeRequest> mergeRequests = mergeRequestSheet.getContent();
|
||||
for (MergeRequest mergeRequest : mergeRequests) {
|
||||
final List<NoteJson> noteJsons = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestComment(), mergeRequest.getProjectId(), mergeRequest.getTwoId()))
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.executeList(NoteJson.class)
|
||||
.stream()
|
||||
.filter(noteJson -> !noteJson.isSystem())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
createNewComment(noteJsons);
|
||||
createNewTask(noteJsons);
|
||||
processingMergeRequest(mergeRequest);
|
||||
|
||||
}
|
||||
|
||||
@ -87,7 +77,56 @@ public class NoteParser {
|
||||
|
||||
}
|
||||
|
||||
private void createNewComment(List<NoteJson> noteJsons) {
|
||||
private void processingMergeRequest(MergeRequest mergeRequest) {
|
||||
int page = 1;
|
||||
List<NoteJson> noteJsons = getNoteJson(mergeRequest, page);
|
||||
|
||||
while (!noteJsons.isEmpty()) {
|
||||
|
||||
createNewComment(noteJsons, mergeRequest);
|
||||
createNewTask(noteJsons, mergeRequest);
|
||||
|
||||
noteJsons = getNoteJson(mergeRequest, ++page);
|
||||
}
|
||||
}
|
||||
|
||||
private List<NoteJson> getNoteJson(MergeRequest mergeRequest, int page) {
|
||||
return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestComment(), mergeRequest.getProjectId(), mergeRequest.getTwoId(), page))
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.executeList(NoteJson.class)
|
||||
.stream()
|
||||
.filter(noteJson -> !noteJson.isSystem())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void createNewTask(List<NoteJson> noteJsons, MergeRequest mergeRequest) {
|
||||
final List<NoteJson> newJsons = noteJsons.stream()
|
||||
.filter(json -> json.getType() != null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final Set<Long> jsonIds = newJsons.stream()
|
||||
.map(NoteJson::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final ExistsContainer<Task, Long> existsContainer = taskService.existsById(jsonIds);
|
||||
|
||||
if (!existsContainer.isAllFound()) {
|
||||
final List<Task> newNotes = newJsons.stream()
|
||||
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
|
||||
.map(json -> conversionService.convert(json, Task.class))
|
||||
.peek(task -> {
|
||||
task.setWebUrl(MessageFormat.format(gitlabProperty.getUrlNote(), mergeRequest.getWebUrl(), task.getId()));
|
||||
task.setResponsible(mergeRequest.getAuthor());
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
taskService.createAll(newNotes);
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewComment(List<NoteJson> noteJsons, MergeRequest mergeRequest) {
|
||||
final List<NoteJson> newJsons = noteJsons.stream()
|
||||
.filter(json -> json.getType() == null)
|
||||
.collect(Collectors.toList());
|
||||
@ -102,6 +141,9 @@ public class NoteParser {
|
||||
final List<Note> newNotes = newJsons.stream()
|
||||
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
|
||||
.map(json -> conversionService.convert(json, Note.class))
|
||||
.peek(note -> note.setWebUrl(
|
||||
MessageFormat.format(gitlabProperty.getUrlNote(), mergeRequest.getWebUrl(), note.getId()))
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
noteService.createAll(newNotes);
|
||||
|
@ -1,49 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.repository.CommentRepository;
|
||||
import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa;
|
||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
//@Repository
|
||||
public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Note, Long> implements CommentRepository {
|
||||
|
||||
private final CommentRepositoryJpa repositoryJpa;
|
||||
|
||||
public CommentRepositoryImpl(CommentRepositoryJpa repositoryJpa) {
|
||||
super(repositoryJpa);
|
||||
this.repositoryJpa = repositoryJpa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Note> findFirstByOrderByIdDesc() {
|
||||
return repositoryJpa.findFirstByOrderByIdDesc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
return repositoryJpa.findByCreateDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> findAllById(@NonNull Set<Long> ids) {
|
||||
return repositoryJpa.findAllById(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> existsById(Set<Long> ids) {
|
||||
return repositoryJpa.existsAllById(ids);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.repository.NoteRepository;
|
||||
import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa;
|
||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
@Repository
|
||||
public class NoteRepositoryImpl extends AbstractSimpleManagerRepository<Note, Long> implements NoteRepository {
|
||||
|
||||
private final CommentRepositoryJpa repositoryJpa;
|
||||
|
||||
public NoteRepositoryImpl(CommentRepositoryJpa repositoryJpa) {
|
||||
super(repositoryJpa);
|
||||
this.repositoryJpa = repositoryJpa;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.repository.TaskRepository;
|
||||
import org.sadtech.bot.gitlab.data.jpa.TaskRepositoryJpa;
|
||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
//@Repository
|
||||
@Repository
|
||||
public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Long> implements TaskRepository {
|
||||
|
||||
private final TaskRepositoryJpa taskRepositoryJpa;
|
||||
@ -21,19 +16,4 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Lo
|
||||
this.taskRepositoryJpa = taskRepositoryJpa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Task> findFirstByOrderByIdDesc() {
|
||||
return taskRepositoryJpa.findFirstByOrderByIdDesc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
return taskRepositoryJpa.findByCreateDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Task> findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status) {
|
||||
return taskRepositoryJpa.findAllByResponsibleAndStatus(responsibleLogin, status);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,8 @@
|
||||
package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface CommentRepositoryJpa extends JpaRepository<Note, Long> {
|
||||
|
||||
Optional<Note> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Note> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
// @Query("SELECT c.id FROM Comment c WHERE c.id IN :ids")
|
||||
Set<Long> existsAllById(@NonNull Set<Long> ids);
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,8 @@
|
||||
package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface TaskRepositoryJpa extends JpaRepository<Task, Long> {
|
||||
|
||||
Optional<Task> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Task> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Task> findAllByResponsibleAndStatus(String login, TaskStatus taskStatus);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package org.sadtech.bot.gitlab.sdk.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -12,9 +16,13 @@ public class NoteJson {
|
||||
private String type;
|
||||
private String body;
|
||||
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonProperty("created_at")
|
||||
private LocalDateTime created;
|
||||
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonProperty("updated_at")
|
||||
private LocalDateTime updated;
|
||||
|
||||
@ -27,7 +35,7 @@ public class NoteJson {
|
||||
@JsonProperty("noteable_type")
|
||||
private String noteableType;
|
||||
|
||||
private Boolean resolveable;
|
||||
private Boolean resolvable;
|
||||
|
||||
private Boolean resolved;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user