getDiscussionJson(MergeRequest mergeRequest, int page) {
+ return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlDiscussion(), mergeRequest.getProjectId(), mergeRequest.getTwoId(), page))
+ .header(ACCEPT)
+ .header(AUTHORIZATION, BEARER + personProperty.getToken())
+ .executeList(DiscussionJson.class);
+ }
+
+}
diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java
index a9c5a33..5eaee28 100644
--- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java
+++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java
@@ -1,31 +1,7 @@
package org.sadtech.bot.gitlab.core.service.parser;
-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.TaskService;
-import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
-import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
-import org.sadtech.bot.gitlab.sdk.domain.NoteJson;
-import org.sadtech.haiti.context.domain.ExistsContainer;
-import org.sadtech.haiti.context.exception.ConvertException;
-import org.sadtech.haiti.context.page.Sheet;
-import org.sadtech.haiti.core.page.PaginationImpl;
-import org.sadtech.haiti.utils.network.HttpParse;
-import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Component;
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT;
-import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION;
-import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
-
/**
* Поиск новых комментариев и задач.
* К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом
@@ -33,216 +9,161 @@ import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
@Component
public class NoteParser {
- public static final int COUNT = 100;
-
- private final MergeRequestsService mergeRequestsService;
- private final ConversionService conversionService;
-
- private final GitlabProperty gitlabProperty;
- private final PersonProperty personProperty;
- private final NoteService noteService;
- private final TaskService taskService;
-
- public NoteParser(
- MergeRequestsService mergeRequestsService,
- ConversionService conversionService,
- GitlabProperty gitlabProperty,
- PersonProperty personProperty,
- NoteService noteService,
- TaskService taskService
- ) {
- this.mergeRequestsService = mergeRequestsService;
- this.conversionService = conversionService;
- this.gitlabProperty = gitlabProperty;
- this.personProperty = personProperty;
- this.noteService = noteService;
- this.taskService = taskService;
- }
-
- public void scanNewCommentAndTask() {
- int page = 0;
- Sheet mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
-
- while (mergeRequestSheet.hasContent()) {
-
- final List mergeRequests = mergeRequestSheet.getContent();
- for (MergeRequest mergeRequest : mergeRequests) {
-
- processingMergeRequest(mergeRequest);
-
- }
-
- mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT));
- }
-
- }
-
- private void processingMergeRequest(MergeRequest mergeRequest) {
- int page = 1;
- List noteJsons = getNoteJson(mergeRequest, page);
-
- while (!noteJsons.isEmpty()) {
-
- createNewComment(noteJsons, mergeRequest);
- createNewTask(noteJsons, mergeRequest);
-
- noteJsons = getNoteJson(mergeRequest, ++page);
- }
- }
-
- private List 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 noteJsons, MergeRequest mergeRequest) {
- final List newJsons = noteJsons.stream()
- .filter(json -> json.getType() != null)
- .collect(Collectors.toList());
-
- final Set jsonIds = newJsons.stream()
- .map(NoteJson::getId)
- .collect(Collectors.toSet());
-
- final ExistsContainer existsContainer = taskService.existsById(jsonIds);
-
- if (!existsContainer.isAllFound()) {
- final List 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());
-
- final Set newNoteIds = newNotes.stream().map(Task::getId).collect(Collectors.toSet());
-
- final ExistsContainer existsNoteContainer = noteService.existsById(newNoteIds);
-
- if (existsContainer.getContainer() != null && !existsContainer.getContainer().isEmpty()) {
- noteService.deleteAllById(existsNoteContainer.getContainer().stream().map(Note::getId).collect(Collectors.toSet()));
- }
-
- final List newTasks = taskService.createAll(newNotes);
- newTasks.forEach(task -> noteService.link(task.getId(), mergeRequest.getId()));
- }
- }
-
- private void createNewComment(List noteJsons, MergeRequest mergeRequest) {
- final List newJsons = noteJsons.stream()
- .filter(json -> json.getType() == null)
- .collect(Collectors.toList());
-
- final Set jsonIds = newJsons.stream()
- .map(NoteJson::getId)
- .collect(Collectors.toSet());
-
- final ExistsContainer existsContainer = noteService.existsById(jsonIds);
-
- if (!existsContainer.isAllFound()) {
- final List notes = 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());
-
- final List newNotes = noteService.createAll(notes);
- newNotes.forEach(note -> noteService.link(note.getId(), mergeRequest.getId()));
- }
-
- }
-
- public void scanOldTask() {
- int page = 0;
- Sheet taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(page, COUNT));
-
- while (taskSheet.hasContent()) {
- final List tasks = taskSheet.getContent();
-
- for (Task task : tasks) {
- final MergeRequest mergeRequest = task.getMergeRequest();
- final Task newTask = HttpParse.request(MessageFormat.format(
- gitlabProperty.getUrlNoteApi(),
- mergeRequest.getProjectId(),
- mergeRequest.getTwoId(),
- task.getId())
- )
- .header(ACCEPT)
- .header(AUTHORIZATION, BEARER + personProperty.getToken())
- .execute(NoteJson.class)
- .map(json -> conversionService.convert(json, Task.class))
- .orElseThrow(() -> new ConvertException("Ошибка обработки задачи id: " + task.getId()));
- taskService.update(newTask);
- }
-
- taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(++page, COUNT));
- }
-
- }
-
-// private List generatingLinksToPossibleComments(@NonNull Long commentId) {
-// List commentUrls = new ArrayList<>();
-// for (int i = 0; i < 5; i++) {
-// int page = 0;
-// Sheet pullRequestPage = mergeRequestsService.getAll(
-// PaginationImpl.of(page, commentSchedulerProperty.getCommentCount())
-// );
-// while (pullRequestPage.hasContent()) {
-// long finalCommentId = commentId;
-// commentUrls.addAll(pullRequestPage.getContent().stream()
-// .map(
-// pullRequest -> new DataScan(
-// getCommentUrl(finalCommentId, pullRequest),
-// pullRequest.getId()
-// )
-// )
-// .collect(Collectors.toList()));
-// pullRequestPage = mergeRequestsService.getAll(
-// PaginationImpl.of(++page, commentSchedulerProperty.getCommentCount())
-// );
+// public static final int COUNT = 100;
+//
+// private final MergeRequestsService mergeRequestsService;
+// private final ConversionService conversionService;
+//
+// private final GitlabProperty gitlabProperty;
+// private final PersonProperty personProperty;
+// private final NoteService noteService;
+//
+// public NoteParser(
+// MergeRequestsService mergeRequestsService,
+// ConversionService conversionService,
+// GitlabProperty gitlabProperty,
+// PersonProperty personProperty,
+// NoteService noteService
+// ) {
+// this.mergeRequestsService = mergeRequestsService;
+// this.conversionService = conversionService;
+// this.gitlabProperty = gitlabProperty;
+// this.personProperty = personProperty;
+// this.noteService = noteService;
+// }
+//
+// public void scanNewCommentAndTask() {
+// int page = 0;
+// Sheet mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
+//
+// while (mergeRequestSheet.hasContent()) {
+//
+// final List mergeRequests = mergeRequestSheet.getContent();
+// for (MergeRequest mergeRequest : mergeRequests) {
+//
+// processingMergeRequest(mergeRequest);
+//
// }
-// commentId++;
+//
+// mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT));
// }
-// return commentUrls;
+//
// }
-
-// private List getCommentsByResultScan(List noteJsons) {
-// return noteJsons.stream()
-// .filter(json -> Severity.NORMAL.equals(json.getSeverity()))
-// .map(resultScan -> conversionService.convert(resultScan, Note.class))
-// .peek(
-// comment -> {
-// final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId())
-// .orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
-// comment.setUrl(generateUrl(comment.getId(), mergeRequestMini.getWebUrl()));
-// comment.setResponsible(mergeRequestMini.getAuthor());
-// }
-// )
+//
+// private void processingMergeRequest(MergeRequest mergeRequest) {
+// int page = 1;
+// List noteJsons = getNoteJson(mergeRequest, page);
+//
+// while (!noteJsons.isEmpty()) {
+//
+// createNewComment(noteJsons, mergeRequest);
+//
+// noteJsons = getNoteJson(mergeRequest, ++page);
+// }
+// }
+//
+// private List 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 List getTaskByResultScan(List noteJsons) {
-// return noteJsons.stream()
-// .filter(json -> Severity.BLOCKER.equals(json.getSeverity()))
-// .map(resultScan -> conversionService.convert(resultScan, Task.class))
-// .peek(
-// task -> {
-// final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(task.getPullRequestId())
-// .orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
-// task.setResponsible(mergeRequestMini.getAuthorLogin());
-// task.setUrl(generateUrl(task.getId(), mergeRequestMini.getWebUrl()));
-// }
-// )
+// private void createNewTask(List noteJsons, MergeRequest mergeRequest) {
+// final List newJsons = noteJsons.stream()
+// .filter(json -> json.getType() != null)
// .collect(Collectors.toList());
+//
+// final Set jsonIds = newJsons.stream()
+// .map(NoteJson::getId)
+// .collect(Collectors.toSet());
+//
+// final ExistsContainer existsContainer = taskService.existsById(jsonIds);
+//
+// if (!existsContainer.isAllFound()) {
+// final List 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());
+//
+// final Set newNoteIds = newNotes.stream().map(Task::getId).collect(Collectors.toSet());
+//
+// final ExistsContainer existsNoteContainer = noteService.existsById(newNoteIds);
+//
+// if (existsContainer.getContainer() != null && !existsContainer.getContainer().isEmpty()) {
+// noteService.deleteAllById(existsNoteContainer.getContainer().stream().map(Note::getId).collect(Collectors.toSet()));
+// }
+//
+// final List newTasks = taskService.createAll(newNotes);
+// newTasks.forEach(task -> noteService.link(task.getId(), mergeRequest.getId()));
+// }
+// }
+//
+// private void createNewComment(List noteJsons, MergeRequest mergeRequest) {
+// final List newJsons = noteJsons.stream()
+// .filter(json -> json.getType() == null)
+// .collect(Collectors.toList());
+//
+// final Set jsonIds = newJsons.stream()
+// .map(NoteJson::getId)
+// .collect(Collectors.toSet());
+//
+// final ExistsContainer existsContainer = noteService.existsById(jsonIds);
+//
+// if (!existsContainer.isAllFound()) {
+// final List notes = 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());
+//
+// final List newNotes = noteService.createAll(notes);
+// newNotes.forEach(note -> noteService.link(note.getId(), mergeRequest.getId()));
+// }
+
+// }
+
+// public void scanOldTask() {
+// int page = 0;
+// Sheet taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(page, COUNT));
+//
+// while (taskSheet.hasContent()) {
+// final List tasks = taskSheet.getContent();
+//
+// for (Task task : tasks) {
+// final MergeRequest mergeRequest = task.getMergeRequest();
+// // FIXME: 11.02.2021 Костыль, исправить в будущем
+// if (mergeRequest!=null) {
+// final Task newTask = HttpParse.request(MessageFormat.format(
+// gitlabProperty.getUrlNoteApi(),
+// mergeRequest.getProjectId(),
+// mergeRequest.getTwoId(),
+// task.getId())
+// )
+// .header(ACCEPT)
+// .header(AUTHORIZATION, BEARER + personProperty.getToken())
+// .execute(NoteJson.class)
+// .map(json -> conversionService.convert(json, Task.class))
+// .orElseThrow(() -> new ConvertException("Ошибка обработки задачи id: " + task.getId()));
+// taskService.update(newTask);
+// } else {
+// taskService.deleteById(task.getId());
+// }
+// }
+//
+// taskSheet = taskService.getAllByResolved(false, PaginationImpl.of(++page, COUNT));
+// }
+//
// }
}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/DiscussionRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/DiscussionRepositoryImpl.java
new file mode 100644
index 0000000..3dd01d3
--- /dev/null
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/DiscussionRepositoryImpl.java
@@ -0,0 +1,21 @@
+package org.sadtech.bot.gitlab.data.impl;
+
+import org.sadtech.bot.gitlab.context.domain.entity.Discussion;
+import org.sadtech.bot.gitlab.context.repository.DiscussionRepository;
+import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * // TODO: 11.02.2021 Добавить описание.
+ *
+ * @author upagge 11.02.2021
+ */
+@Repository
+public class DiscussionRepositoryImpl extends AbstractSimpleManagerRepository implements DiscussionRepository {
+
+ public DiscussionRepositoryImpl(JpaRepository jpaRepository) {
+ super(jpaRepository);
+ }
+
+}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NoteRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NoteRepositoryImpl.java
index 71aba22..29d1e7a 100644
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NoteRepositoryImpl.java
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NoteRepositoryImpl.java
@@ -3,10 +3,15 @@ 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.NoteRepository;
-import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa;
+import org.sadtech.bot.gitlab.data.jpa.NoteRepositoryJpa;
+import org.sadtech.haiti.context.page.Pagination;
+import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
+import org.sadtech.haiti.database.util.Converter;
import org.springframework.stereotype.Repository;
+import java.util.List;
+
/**
* // TODO: 08.09.2020 Добавить описание.
*
@@ -15,16 +20,23 @@ import org.springframework.stereotype.Repository;
@Repository
public class NoteRepositoryImpl extends AbstractSimpleManagerRepository implements NoteRepository {
- private final CommentRepositoryJpa repositoryJpa;
+ private final NoteRepositoryJpa repositoryJpa;
- public NoteRepositoryImpl(CommentRepositoryJpa repositoryJpa) {
+ public NoteRepositoryImpl(NoteRepositoryJpa repositoryJpa) {
super(repositoryJpa);
this.repositoryJpa = repositoryJpa;
}
@Override
- public void link(@NonNull Long noteId, @NonNull Long mergeRequestId) {
- repositoryJpa.link(noteId, mergeRequestId);
+ public Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination) {
+ return Converter.page(
+ repositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
+ );
+ }
+
+ @Override
+ public List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
+ return repositoryJpa.findAllByResponsibleIdAndResolved(userId, resolved);
}
}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java
deleted file mode 100644
index 7c618da..0000000
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/TaskRepositoryImpl.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.sadtech.bot.gitlab.data.impl;
-
-import lombok.NonNull;
-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.context.page.Pagination;
-import org.sadtech.haiti.context.page.Sheet;
-import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
-import org.sadtech.haiti.database.util.Converter;
-import org.springframework.stereotype.Repository;
-
-import java.util.List;
-
-@Repository
-public class TaskRepositoryImpl extends AbstractSimpleManagerRepository implements TaskRepository {
-
- private final TaskRepositoryJpa taskRepositoryJpa;
-
- public TaskRepositoryImpl(TaskRepositoryJpa taskRepositoryJpa) {
- super(taskRepositoryJpa);
- this.taskRepositoryJpa = taskRepositoryJpa;
- }
-
- @Override
- public Sheet findAllByResolved(boolean resolved, @NonNull Pagination pagination) {
- return Converter.page(
- taskRepositoryJpa.findAllByResolved(resolved, Converter.pagination(pagination))
- );
- }
-
- @Override
- public List findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
- return taskRepositoryJpa.findAllByResponsibleIdAndResolved(userId, resolved);
- }
-}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/CommentRepositoryJpa.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/CommentRepositoryJpa.java
deleted file mode 100644
index 76c0bbf..0000000
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/CommentRepositoryJpa.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.sadtech.bot.gitlab.data.jpa;
-
-import org.sadtech.bot.gitlab.context.domain.entity.Note;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
-import org.springframework.transaction.annotation.Transactional;
-
-public interface CommentRepositoryJpa extends JpaRepository {
-
- @Modifying
- @Transactional
- @Query(value = "INSERT INTO gitlab_bot.public.merge_request_notes(merge_request_id, notes_id) values (:mergeRequestId, :noteId)", nativeQuery = true)
- void link(@Param("noteId") Long noteId, @Param("mergeRequestId") Long mergeRequestId);
-
-}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/DiscussionJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/DiscussionJpaRepository.java
new file mode 100644
index 0000000..525b69c
--- /dev/null
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/DiscussionJpaRepository.java
@@ -0,0 +1,13 @@
+package org.sadtech.bot.gitlab.data.jpa;
+
+import org.sadtech.bot.gitlab.context.domain.entity.Discussion;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * // TODO: 11.02.2021 Добавить описание.
+ *
+ * @author upagge 11.02.2021
+ */
+public interface DiscussionJpaRepository extends JpaRepository {
+
+}
diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/NoteRepositoryJpa.java
similarity index 51%
rename from bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java
rename to bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/NoteRepositoryJpa.java
index 69b9534..c9e04fc 100644
--- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/TaskRepositoryJpa.java
+++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/NoteRepositoryJpa.java
@@ -1,16 +1,16 @@
package org.sadtech.bot.gitlab.data.jpa;
-import org.sadtech.bot.gitlab.context.domain.entity.Task;
+import org.sadtech.bot.gitlab.context.domain.entity.Note;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
-public interface TaskRepositoryJpa extends JpaRepository {
+public interface NoteRepositoryJpa extends JpaRepository {
- Page findAllByResolved(boolean resolved, Pageable pageable);
+ Page findAllByResolved(boolean resolved, Pageable pageable);
- List findAllByResponsibleIdAndResolved(Long responsibleId, boolean resolved);
+ List findAllByResponsibleIdAndResolved(Long responsibleId, boolean resolved);
}
diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/DiscussionJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/DiscussionJson.java
new file mode 100644
index 0000000..8ff2e7b
--- /dev/null
+++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/DiscussionJson.java
@@ -0,0 +1,20 @@
+package org.sadtech.bot.gitlab.sdk.domain;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * // TODO: 11.02.2021 Добавить описание.
+ *
+ * @author upagge 11.02.2021
+ */
+@Getter
+@Setter
+public class DiscussionJson {
+
+ private String id;
+ private List notes;
+
+}
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java
index 8c1c394..4781848 100644
--- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java
+++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java
@@ -1,25 +1,18 @@
package org.sadtech.bot.gitlab.telegram.service.unit;
-import lombok.RequiredArgsConstructor;
-import org.sadtech.bot.gitlab.context.domain.entity.Task;
-import org.sadtech.bot.gitlab.context.service.TaskService;
-import org.sadtech.social.core.domain.BoxAnswer;
-import org.sadtech.social.core.domain.ProcessingData;
-import org.sadtech.social.core.domain.content.Message;
-
/**
* // TODO: 17.09.2020 Добавить описание.
*
* @author upagge 17.09.2020
*/
//@Component
-@RequiredArgsConstructor
-public class TaskProcessing implements ProcessingData {
-
- private final TaskService taskService;
-
- @Override
- public BoxAnswer processing(Message message) {
+//@RequiredArgsConstructor
+//public class TaskProcessing implements ProcessingData {
+//
+// private final TaskService taskService;
+//
+// @Override
+// public BoxAnswer processing(Message message) {
// final Person person = personService.getByTelegramId(message.getPersonId())
// .orElseThrow(() -> new NotFoundException("Ошибочка"));
// final List tasks = taskService.getAllByResponsibleAndStatus(person.getLogin(), TaskStatus.OPEN);
@@ -36,15 +29,15 @@ public class TaskProcessing implements ProcessingData {
// );
// }
// return BoxAnswer.of(messageText);
- return null;
- }
-
- private String createTaskString(Task task) {
+// return null;
+// }
+//
+// private String createTaskString(Task task) {
// return MessageFormat.format(
// "- [{0}]({1})",
// task.getDescription(), task.getUrl()
// );
- return null;
- }
-
-}
+// return null;
+// }
+//
+//}
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
index 0cd1a6f..5de18e5 100644
--- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
+++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java
@@ -3,11 +3,10 @@ package org.sadtech.bot.gitlab.telegram.unit;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
-import org.sadtech.bot.gitlab.context.domain.entity.Task;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
+import org.sadtech.bot.gitlab.context.service.DiscussionService;
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
-import org.sadtech.bot.gitlab.context.service.TaskService;
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
import org.sadtech.haiti.context.page.Sheet;
@@ -130,7 +129,7 @@ public class MenuConfig {
@Bean
public AnswerText getTasks(
- TaskService taskService,
+ DiscussionService discussionService,
AppSettingService settingService,
PersonInformation personInformation
) {
@@ -138,21 +137,22 @@ public class MenuConfig {
.boxAnswer(message ->
{
final Long userId = personInformation.getId();
- final String text = taskService.getAllPersonTask(userId, false).stream()
- .collect(Collectors.groupingBy(Task::getMergeRequest))
- .entrySet()
- .stream()
- .map(node -> {
- final String mrTitle = node.getKey().getTitle();
- final String mrUrl = node.getKey().getWebUrl();
-
- final String taskText = node.getValue().stream()
- .map(task -> MessageFormat.format("[{0}]({1})", task.getBody(), task.getWebUrl()))
- .collect(Collectors.joining("\n"));
-
- return MessageFormat.format("- [{0}]({1}):\n{2}", mrTitle, mrUrl, taskText);
- })
- .collect(Collectors.joining("\n\n"));
+ final String text = "test";
+// taskService.getAllPersonTask(userId, false).stream()
+// .collect(Collectors.groupingBy(Task::getMergeRequest))
+// .entrySet()
+// .stream()
+// .map(node -> {
+// final String mrTitle = node.getKey().getTitle();
+// final String mrUrl = node.getKey().getWebUrl();
+//
+// final String taskText = node.getValue().stream()
+// .map(task -> MessageFormat.format("[{0}]({1})", task.getBody(), task.getWebUrl()))
+// .collect(Collectors.joining("\n"));
+//
+// return MessageFormat.format("- [{0}]({1}):\n{2}", mrTitle, mrUrl, taskText);
+// })
+// .collect(Collectors.joining("\n\n"));
return BoxAnswer.of("".equals(text) ? settingService.getMessage("ui.answer.no_task") : text);
})
.phrase(settingService.getMessage("ui.menu.task"))
diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java
index 1907cc3..6ece51f 100644
--- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java
+++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java
@@ -3,16 +3,25 @@ package org.sadtech.bot.gitlab.telegram.unit;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.AppLocale;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
+import org.sadtech.bot.gitlab.context.service.NoteService;
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
import org.sadtech.social.bot.domain.unit.AnswerCheck;
import org.sadtech.social.bot.domain.unit.AnswerProcessing;
import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.bot.domain.unit.UnitActiveType;
import org.sadtech.social.core.domain.BoxAnswer;
+import org.sadtech.social.core.domain.content.Mail;
+import org.sadtech.social.core.domain.content.attachment.Attachment;
+import org.sadtech.social.core.domain.content.attachment.AttachmentType;
+import org.sadtech.social.core.domain.content.attachment.Link;
import org.sadtech.social.core.utils.KeyBoards;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* TODO: Добавить описание класса.
*
@@ -22,21 +31,72 @@ import org.springframework.context.annotation.Configuration;
@RequiredArgsConstructor
public class UnitConfig {
+ private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$");
+
@Bean
public AnswerCheck checkFirstStart(
AppSettingService settingService,
AnswerText textCheckLanguage,
- AnswerText menu
+ AnswerCheck checkMenuOrAnswer
) {
return AnswerCheck.builder()
.check(
message -> settingService.isFirstStart()
)
- .unitFalse(menu)
+ .unitFalse(checkMenuOrAnswer)
.unitTrue(textCheckLanguage)
.build();
}
+ @Bean
+ public AnswerCheck checkMenuOrAnswer(
+ AnswerText menu,
+ AnswerText answerNote
+ ) {
+ return AnswerCheck.builder()
+ .check(
+ message -> {
+ Mail mail = (Mail) message;
+ final List forwardMails = mail.getForwardMail();
+ if (forwardMails.size() == 1) {
+ final Mail forwardMail = forwardMails.get(0);
+ return forwardMail.getAttachments().stream()
+ .anyMatch(attachment -> AttachmentType.LINK.equals(attachment.getType()));
+ }
+ return false;
+ }
+ )
+ .unitTrue(answerNote)
+ .unitFalse(menu)
+ .build();
+ }
+
+ @Bean
+ public AnswerText answerNote(
+ NoteService noteService
+ ) {
+ return AnswerText.builder()
+ .boxAnswer(
+ message -> {
+ final List attachments = ((Mail) message).getForwardMail().get(0).getAttachments();
+ for (Attachment attachment : attachments) {
+ if (AttachmentType.LINK.equals(attachment.getType())) {
+ final String url = ((Link) attachment).getUrl();
+ Matcher matcher = NOTE_LINK.matcher(url);
+ if (matcher.find()) {
+ final String note = url.substring(matcher.start(), matcher.end());
+ Long noteId = Long.valueOf(note.replaceAll("#note_", ""));
+// noteService.answer(noteId, message.getText());
+ }
+ return BoxAnswer.of("Победа");
+ }
+ }
+ return BoxAnswer.of("Ошибка");
+ }
+ )
+ .build();
+ }
+
@Bean
public AnswerText textCheckLanguage(
AnswerProcessing checkLanguage