Первая рабочая версия с меню в телеге
This commit is contained in:
parent
e71f767fce
commit
24008c7989
@ -2,8 +2,8 @@ package org.sadtech.bot.gitlab.app.scheduler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.bot.gitlab.app.service.parser.MergeRequestParser;
|
||||
import org.sadtech.bot.gitlab.app.service.parser.ProjectParser;
|
||||
import org.sadtech.bot.gitlab.core.service.parser.MergeRequestParser;
|
||||
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -20,11 +20,6 @@ public class SchedulerService {
|
||||
private final ProjectParser projectParser;
|
||||
private final MergeRequestParser mergeRequestParser;
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newProjectParse() {
|
||||
projectParser.parseNewProject();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newMergeRequest() {
|
||||
mergeRequestParser.parsingNewMergeRequest();
|
||||
|
@ -1,67 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.bot.gitlab.app.service.executor.DataScan;
|
||||
import org.sadtech.bot.gitlab.app.service.executor.Executor;
|
||||
import org.sadtech.bot.gitlab.app.service.executor.Seeker;
|
||||
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.CommentJson;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExecutorScanner implements Executor<DataScan, CommentJson> {
|
||||
|
||||
private final ExecutorService executorService;
|
||||
private List<Future<Optional<CommentJson>>> resultList = new ArrayList<>();
|
||||
private final GitlabProperty gitlabProperty;
|
||||
private final PersonProperty personProperty;
|
||||
|
||||
@Override
|
||||
public boolean registration(@NonNull List<DataScan> dataScans) {
|
||||
resultList.addAll(
|
||||
dataScans.stream()
|
||||
.map(dataScan -> new Seeker(dataScan, personProperty.getToken()))
|
||||
.map(executorService::submit)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommentJson> getResult() {
|
||||
while (!resultList.stream().allMatch(Future::isDone)) {
|
||||
|
||||
}
|
||||
final List<CommentJson> result = resultList.stream()
|
||||
.filter(Future::isDone)
|
||||
.map(this::getResultScan)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
resultList.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
private Optional<CommentJson> getResultScan(Future<Optional<CommentJson>> test) {
|
||||
try {
|
||||
return test.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service.executor;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DataScan {
|
||||
|
||||
private final String urlComment;
|
||||
private final Long pullRequestId;
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service.executor;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Executor<T, D> {
|
||||
|
||||
boolean registration(@NonNull List<T> seeker);
|
||||
|
||||
List<D> getResult();
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service.executor;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.CommentJson;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class ResultScan {
|
||||
|
||||
private final String commentApiUrl;
|
||||
private final Long pullRequestId;
|
||||
private final CommentJson commentJson;
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service.executor;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.CommentJson;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class Seeker implements Callable<Optional<CommentJson>> {
|
||||
|
||||
private final DataScan dataScan;
|
||||
private final String token;
|
||||
|
||||
@Override
|
||||
public Optional<CommentJson> call() {
|
||||
// return Utils.urlToJson(dataScan.getUrlComment(), token, CommentJson.class)
|
||||
// .map(
|
||||
// commentJson -> {
|
||||
// commentJson.setCustomPullRequestId(dataScan.getPullRequestId());
|
||||
// commentJson.setCustomCommentApiUrl(dataScan.getUrlComment());
|
||||
// return commentJson;
|
||||
// }
|
||||
// );
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
@ -1,213 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.app.service.parser;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.app.config.property.CommentSchedulerProperty;
|
||||
import org.sadtech.bot.gitlab.app.service.ExecutorScanner;
|
||||
import org.sadtech.bot.gitlab.app.service.executor.DataScan;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.service.CommentService;
|
||||
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.config.properties.InitProperty;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.CommentJson;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.Severity;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.core.page.PaginationImpl;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>Поиск новых комментариев и задач.</p>
|
||||
* <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p>
|
||||
*/
|
||||
//@Component
|
||||
public class CommentAndTaskParser {
|
||||
|
||||
private final CommentService commentService;
|
||||
private final MergeRequestsService mergeRequestsService;
|
||||
private final ExecutorScanner executorScanner;
|
||||
private final TaskService taskService;
|
||||
private final ConversionService conversionService;
|
||||
|
||||
private final GitlabProperty gitlabProperty;
|
||||
private final CommentSchedulerProperty commentSchedulerProperty;
|
||||
private final InitProperty initProperty;
|
||||
|
||||
private boolean initStart = false;
|
||||
|
||||
public CommentAndTaskParser(
|
||||
CommentService commentService,
|
||||
MergeRequestsService mergeRequestsService,
|
||||
ExecutorScanner executorScanner,
|
||||
TaskService taskService,
|
||||
ConversionService conversionService,
|
||||
GitlabProperty gitlabProperty,
|
||||
CommentSchedulerProperty commentSchedulerProperty,
|
||||
InitProperty initProperty
|
||||
) {
|
||||
this.commentService = commentService;
|
||||
this.mergeRequestsService = mergeRequestsService;
|
||||
this.executorScanner = executorScanner;
|
||||
this.taskService = taskService;
|
||||
this.conversionService = conversionService;
|
||||
this.gitlabProperty = gitlabProperty;
|
||||
this.commentSchedulerProperty = commentSchedulerProperty;
|
||||
this.initProperty = initProperty;
|
||||
}
|
||||
|
||||
public void scanNewCommentAndTask() {
|
||||
long commentId = getLastIdCommentOrTask() + 1;
|
||||
int count = 0;
|
||||
do {
|
||||
final List<DataScan> dataScans = generatingLinksToPossibleComments(commentId);
|
||||
executorScanner.registration(dataScans);
|
||||
final List<CommentJson> resultScans = executorScanner.getResult();
|
||||
if (!resultScans.isEmpty()) {
|
||||
final long commentMax = commentService.createAll(getCommentsByResultScan(resultScans)).stream()
|
||||
.mapToLong(Comment::getId)
|
||||
.max().orElse(0L);
|
||||
final long taskMax = taskService.createAll(getTaskByResultScan(resultScans)).stream()
|
||||
.mapToLong(Task::getId)
|
||||
.max().orElse(0L);
|
||||
commentId = Long.max(commentMax, taskMax) + 1;
|
||||
count = 0;
|
||||
}
|
||||
} while (count++ < commentSchedulerProperty.getNoCommentCount());
|
||||
}
|
||||
|
||||
private long getLastIdCommentOrTask() {
|
||||
Long commentStartId = Long.max(commentService.getLastCommentId(), taskService.getLastTaskId());
|
||||
if (initProperty != null && !initStart && (commentStartId == 0L || initProperty.isUse())) {
|
||||
commentStartId = initProperty.getStartCommentId();
|
||||
initStart = true;
|
||||
}
|
||||
return commentStartId;
|
||||
}
|
||||
|
||||
private List<DataScan> generatingLinksToPossibleComments(@NonNull Long commentId) {
|
||||
List<DataScan> commentUrls = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int page = 0;
|
||||
Sheet<MergeRequest> 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())
|
||||
);
|
||||
}
|
||||
commentId++;
|
||||
}
|
||||
return commentUrls;
|
||||
}
|
||||
|
||||
private List<Comment> getCommentsByResultScan(List<CommentJson> commentJsons) {
|
||||
return commentJsons.stream()
|
||||
.filter(json -> Severity.NORMAL.equals(json.getSeverity()))
|
||||
.map(resultScan -> conversionService.convert(resultScan, Comment.class))
|
||||
.peek(
|
||||
comment -> {
|
||||
final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId())
|
||||
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
||||
comment.setUrl(generateUrl(comment.getId(), mergeRequestMini.getWebUrl()));
|
||||
// comment.setResponsible(mergeRequestMini.getAuthor());
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<Task> getTaskByResultScan(List<CommentJson> commentJsons) {
|
||||
return commentJsons.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()));
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String generateUrl(@NonNull Long id, @NonNull String pullRequestUrl) {
|
||||
return MessageFormat.format("{0}/overview?commentId={1}", pullRequestUrl, Long.toString(id));
|
||||
}
|
||||
|
||||
private String getCommentUrl(long commentId, MergeRequest mergeRequest) {
|
||||
// return gitlabProperty.getUrlPullRequestComment()
|
||||
// .replace("{projectKey}", mergeRequest.getProjectKey())
|
||||
// .replace("{repositorySlug}", mergeRequest.getRepositorySlug())
|
||||
// .replace("{pullRequestId}", mergeRequest.getBitbucketId().toString())
|
||||
// .replace("{commentId}", String.valueOf(commentId));
|
||||
return null;
|
||||
}
|
||||
|
||||
public void scanOldComment() {
|
||||
// final List<Comment> comments = commentService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Comment oldComment : comments) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldComment.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.BLOCKER.equals(json.getSeverity())) {
|
||||
// taskService.convert(oldComment);
|
||||
// } else {
|
||||
// final Comment newComment = conversionService.convert(json, Comment.class);
|
||||
// commentService.update(newComment);
|
||||
// }
|
||||
// } else {
|
||||
// commentService.deleteById(oldComment.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void scanOldTask() {
|
||||
// final List<Task> tasks = taskService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Task oldTask : tasks) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldTask.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.NORMAL.equals(json.getSeverity())) {
|
||||
// commentService.convert(oldTask);
|
||||
// } else {
|
||||
// final Task newTask = conversionService.convert(json, Task.class);
|
||||
// taskService.update(newTask);
|
||||
// }
|
||||
// } else {
|
||||
// taskService.deleteById(oldTask.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
@ -32,10 +32,10 @@ gitlab-bot:
|
||||
telegram-id: ${TELEGRAM_PERSON_ID}
|
||||
token: ${GITLAB_PERSONAL_TOKEN}
|
||||
gitlab:
|
||||
url-project: ${GITLAB_URL}/api/v4/projects
|
||||
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
|
||||
url-pull-request-close: ${GITLAB_URL}
|
||||
url-pull-request-comment: ${GITLAB_URL}
|
||||
url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/19/merge_requests/8/notes
|
||||
url-pull-request: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}
|
||||
user-url: ${GITLAB_URL}/api/v4/user
|
||||
users-url: ${GITLAB_URL}/api/v4/users
|
||||
|
@ -0,0 +1,14 @@
|
||||
<databaseChangeLog
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<changeSet id="2020-01-16" author="uPagge">
|
||||
<insert tableName="app_setting">
|
||||
<column name="id" value="1"/>
|
||||
<column name="first_start" value="true"/>
|
||||
<column name="language" value="EN"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -3,6 +3,16 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<changeSet id="2020-01-16-create-table-app-setting" author="uPagge">
|
||||
<createTable tableName="app_setting">
|
||||
<column name="id" type="int">
|
||||
<constraints primaryKey="true"/>
|
||||
</column>
|
||||
<column name="language" type="varchar(10)"/>
|
||||
<column name="first_start" type="boolean"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2020-01-14-create-table-project" author="uPagge">
|
||||
<createTable tableName="project">
|
||||
<column name="id" type="int">
|
||||
@ -104,4 +114,35 @@
|
||||
<addUniqueConstraint tableName="merge_request_label" columnNames="merge_request_id, label"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2020-01-16-create-table-note" author="uPagge">
|
||||
<createTable tableName="note">
|
||||
<column name="id" type="int">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
<column name="type" type="varchar(100)"/>
|
||||
<column name="body" type="varchar(3000)"/>
|
||||
<column name="created_date" type="datetime">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="updated_date" type="datetime">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="author_id" type="int">
|
||||
<constraints nullable="false" foreignKeyName="merge_request_author_id_person_id"
|
||||
references="person(id)"/>
|
||||
</column>
|
||||
<column name="system" type="boolean">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="noteable_id" type="int"/>
|
||||
<column name="noteable_type" type="varchar(100)"/>
|
||||
<column name="resolvable" type="boolean"/>
|
||||
<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"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -4,5 +4,6 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<include file="liquibase/v.1.0.0/2021-01-14-create-tables.xml"/>
|
||||
<include file="liquibase/v.1.0.0/2020-01-16-app-setting.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
5
bot-app/src/main/resources/messages_en.properties
Normal file
5
bot-app/src/main/resources/messages_en.properties
Normal file
@ -0,0 +1,5 @@
|
||||
main.yes=Yes
|
||||
main.no=No
|
||||
ui.lang_changed=Language changed successfully
|
||||
ui.monitor_private_projects=Start tracking private projects?
|
||||
ui.monitor_project_private_success=Projects have been successfully added to tracking
|
5
bot-app/src/main/resources/messages_ru.properties
Normal file
5
bot-app/src/main/resources/messages_ru.properties
Normal file
@ -0,0 +1,5 @@
|
||||
main.yes=Да
|
||||
main.no=Нет
|
||||
ui.lang_changed=Язык успешно изменен
|
||||
ui.monitor_private_projects=Начать отслеживать приватные проекты?
|
||||
ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание
|
@ -0,0 +1,35 @@
|
||||
package org.sadtech.bot.gitlab.context.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.haiti.context.exception.NotFoundException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AppLocale {
|
||||
|
||||
RU("Русский"), EN("English");
|
||||
|
||||
private final String label;
|
||||
|
||||
public static AppLocale of(@NonNull String label) {
|
||||
return Arrays.stream(values())
|
||||
.filter(appLocale -> appLocale.getLabel().equals(label))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NotFoundException("Ошибка, локализация не найдена. Попробуйте снова."));
|
||||
}
|
||||
|
||||
public Locale getValue() {
|
||||
return Locale.forLanguageTag(name().toLowerCase());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package org.sadtech.bot.gitlab.context.domain.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.sadtech.bot.gitlab.context.domain.AppLocale;
|
||||
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name = "app_setting")
|
||||
public class AppSetting implements BasicEntity<Long> {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "language")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private AppLocale appLocale;
|
||||
|
||||
@Column(name = "first_start")
|
||||
private boolean firstStart;
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.context.domain.entity;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
//@Entity
|
||||
//@Table(name = "comment")
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class Comment implements BasicEntity<Long> {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@EqualsAndHashCode.Include
|
||||
private Long id;
|
||||
|
||||
@Column(name = "url_api")
|
||||
private String urlApi;
|
||||
|
||||
@Column(name = "url")
|
||||
private String url;
|
||||
|
||||
@Column(name = "pull_request_id")
|
||||
private Long pullRequestId;
|
||||
|
||||
@Column(name = "author_login")
|
||||
private String author;
|
||||
|
||||
@Column(name = "responsible_login")
|
||||
private String responsible;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Column(name = "create_date")
|
||||
private LocalDateTime createDate;
|
||||
|
||||
/**
|
||||
* Версия объекта в битбакет
|
||||
*/
|
||||
@Column(name = "bitbucket_version")
|
||||
private Integer bitbucketVersion;
|
||||
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "comment_tree", joinColumns = @JoinColumn(name = "parent_id"))
|
||||
@Column(name = "child_id")
|
||||
private Set<Long> answers;
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package org.sadtech.bot.gitlab.context.domain.entity;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "note")
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class Note implements BasicEntity<Long> {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
private Long id;
|
||||
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
@Column(name = "body")
|
||||
private String body;
|
||||
|
||||
@Column(name = "created_date")
|
||||
private LocalDateTime created;
|
||||
|
||||
@Column(name = "updated_date")
|
||||
private LocalDateTime updated;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "author_id")
|
||||
private Person author;
|
||||
|
||||
@Column(name = "system")
|
||||
private boolean system;
|
||||
|
||||
@Column(name = "noteable_id")
|
||||
private Long noteableId;
|
||||
|
||||
@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;
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.AppSetting;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
public interface AppSettingRepository extends SimpleManagerRepository<AppSetting, Long> {
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.bot.gitlab.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -14,13 +14,13 @@ import java.util.Set;
|
||||
*
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
public interface CommentRepository extends SimpleManagerRepository<Comment, Long> {
|
||||
public interface CommentRepository extends SimpleManagerRepository<Note, Long> {
|
||||
|
||||
Optional<Comment> findFirstByOrderByIdDesc();
|
||||
Optional<Note> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Comment> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<Note> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Comment> findAllById(@NonNull Set<Long> ids);
|
||||
List<Note> findAllById(@NonNull Set<Long> ids);
|
||||
|
||||
Set<Long> existsById(Set<Long> ids);
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.AppLocale;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
public interface AppSettingService {
|
||||
|
||||
boolean isFirstStart();
|
||||
|
||||
void disableFirstStart();
|
||||
|
||||
String getMessage(@NonNull String label);
|
||||
|
||||
String getMessage(@NonNull String label, String... params);
|
||||
|
||||
void setLocale(@NonNull AppLocale appLocale);
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.bot.gitlab.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
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;
|
||||
|
||||
@ -9,15 +9,15 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface CommentService extends SimpleManagerService<Comment, Long> {
|
||||
public interface NoteService extends SimpleManagerService<Note, Long> {
|
||||
|
||||
Long getLastCommentId();
|
||||
|
||||
List<Comment> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<Note> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
List<Comment> getAllById(@NonNull Set<Long> ids);
|
||||
List<Note> getAllById(@NonNull Set<Long> ids);
|
||||
|
||||
Comment convert(@NonNull Task task);
|
||||
Note convert(@NonNull Task task);
|
||||
|
||||
Set<Long> existsById(@NonNull Set<Long> ids);
|
||||
|
@ -2,7 +2,7 @@ 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.Comment;
|
||||
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;
|
||||
|
||||
@ -13,7 +13,7 @@ public interface TaskService extends SimpleManagerService<Task, Long> {
|
||||
|
||||
Long getLastTaskId();
|
||||
|
||||
Task convert(@NonNull Comment comment);
|
||||
Task convert(@NonNull Note note);
|
||||
|
||||
List<Task> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
|
@ -65,6 +65,16 @@
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech.haiti</groupId>
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech.bot.gitlab</groupId>
|
||||
<artifactId>gitlab-sdk</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.gitlab.app.service.convert;
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.gitlab.app.service.convert;
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Person;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.PersonJson;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.gitlab.app.service.convert;
|
||||
package org.sadtech.bot.gitlab.core.service.convert;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Project;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.ProjectJson;
|
@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.converter;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
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<Comment, Task> {
|
||||
|
||||
@Override
|
||||
public Task convert(Comment 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.converter;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
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, Comment> {
|
||||
|
||||
@Override
|
||||
public Comment convert(Task source) {
|
||||
final Comment comment = new Comment();
|
||||
comment.setId(source.getId());
|
||||
comment.setUrl(source.getUrl());
|
||||
comment.setUrlApi(source.getUrlApi());
|
||||
comment.setPullRequestId(source.getPullRequestId());
|
||||
comment.setBitbucketVersion(source.getBitbucketVersion());
|
||||
comment.setCreateDate(source.getCreateDate());
|
||||
comment.setMessage(source.getDescription());
|
||||
comment.setResponsible(source.getResponsible());
|
||||
comment.setAuthor(source.getAuthor());
|
||||
comment.setAnswers(source.getAnswers());
|
||||
return comment;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.context.domain.AppLocale;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.AppSetting;
|
||||
import org.sadtech.bot.gitlab.context.repository.AppSettingRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.AppSettingService;
|
||||
import org.sadtech.haiti.context.exception.NotFoundException;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AppSettingServiceImpl implements AppSettingService {
|
||||
|
||||
private static final Long KEY = 1L;
|
||||
private static final NotFoundException EXCEPTION = new NotFoundException("Ошибка, невозможно найти настройки приложения, проверьте базу данных.");
|
||||
private final AppSettingRepository appSettingRepository;
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
@Override
|
||||
public boolean isFirstStart() {
|
||||
return appSettingRepository.findById(KEY)
|
||||
.orElseThrow(() -> EXCEPTION)
|
||||
.isFirstStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableFirstStart() {
|
||||
final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(() -> EXCEPTION);
|
||||
appSetting.setFirstStart(false);
|
||||
appSettingRepository.save(appSetting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(@NonNull String label) {
|
||||
return messageSource.getMessage(
|
||||
label, null, appSettingRepository.findById(KEY)
|
||||
.orElseThrow(() -> EXCEPTION)
|
||||
.getAppLocale().getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage(@NonNull String label, String... params) {
|
||||
final Object[] paramsArray = Arrays.stream(params).toArray();
|
||||
return messageSource.getMessage(
|
||||
label,
|
||||
paramsArray,
|
||||
appSettingRepository.findById(KEY)
|
||||
.orElseThrow(() -> EXCEPTION)
|
||||
.getAppLocale().getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(@NonNull AppLocale appLocale) {
|
||||
final AppSetting appSetting = appSettingRepository.findById(KEY).orElseThrow(() -> EXCEPTION);
|
||||
appSetting.setAppLocale(appLocale);
|
||||
appSettingRepository.save(appSetting);
|
||||
}
|
||||
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.Answer;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Task;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.comment.AnswerCommentNotify;
|
||||
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.CommentService;
|
||||
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.sadtech.haiti.core.util.Assert;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//@Service
|
||||
public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Long> implements CommentService {
|
||||
|
||||
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 CommentServiceImpl(
|
||||
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(Comment::getId).orElse(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Comment> getAllBetweenDate(@NonNull LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
return commentRepository.findByCreateDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment create(@NonNull Comment comment) {
|
||||
Assert.isNotNull(comment.getId(), "При создании объекта должен быть установлен идентификатор");
|
||||
comment.getAnswers().clear();
|
||||
final Comment newComment = commentRepository.save(comment);
|
||||
notificationPersonal(comment);
|
||||
return newComment;
|
||||
}
|
||||
|
||||
private void notificationPersonal(@NonNull Comment comment) {
|
||||
Matcher matcher = PATTERN.matcher(comment.getMessage());
|
||||
Set<String> recipientsLogins = new HashSet<>();
|
||||
while (matcher.find()) {
|
||||
final String login = matcher.group(0).replace("@", "");
|
||||
recipientsLogins.add(login);
|
||||
}
|
||||
notifyService.send(
|
||||
CommentNotify.builder()
|
||||
.authorName(comment.getAuthor())
|
||||
.url(comment.getUrl())
|
||||
.message(comment.getMessage())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment update(Comment comment) {
|
||||
final Comment oldComment = commentRepository.findById(comment.getId())
|
||||
.orElseThrow(() -> new NotFoundException("Комментарий не найден"));
|
||||
|
||||
if (oldComment.getBitbucketVersion().equals(comment.getBitbucketVersion())) {
|
||||
oldComment.setBitbucketVersion(comment.getBitbucketVersion());
|
||||
oldComment.setMessage(oldComment.getMessage());
|
||||
}
|
||||
updateAnswer(oldComment, comment);
|
||||
|
||||
return commentRepository.save(oldComment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Comment> getAllById(@NonNull Set<Long> ids) {
|
||||
return commentRepository.findAllById(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment convert(@NonNull Task task) {
|
||||
taskService.deleteById(task.getId());
|
||||
final Comment comment = conversionService.convert(task, Comment.class);
|
||||
return commentRepository.save(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> existsById(@NonNull Set<Long> ids) {
|
||||
return commentRepository.existsById(ids);
|
||||
}
|
||||
|
||||
private void updateAnswer(Comment oldComment, Comment newComment) {
|
||||
final Set<Long> oldAnswerIds = oldComment.getAnswers();
|
||||
final Set<Long> newAnswerIds = newComment.getAnswers();
|
||||
if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds);
|
||||
final List<Comment> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream()
|
||||
.filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
.collect(Collectors.toList());
|
||||
oldComment.getAnswers().clear();
|
||||
oldComment.setAnswers(existsNewAnswersIds);
|
||||
if (!newAnswers.isEmpty()) {
|
||||
notifyService.send(
|
||||
AnswerCommentNotify.builder()
|
||||
.url(oldComment.getUrl())
|
||||
.youMessage(newComment.getMessage())
|
||||
.answers(
|
||||
newAnswers.stream()
|
||||
.map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExistsContainer<Comment, Long> existsById(@NonNull Collection<Long> collection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
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 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,19 +1,17 @@
|
||||
package org.sadtech.bot.gitlab.core.service.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.Answer;
|
||||
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
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.domain.notify.comment.AnswerCommentNotify;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.comment.CommentNotify;
|
||||
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.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.repository.TaskRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.CommentService;
|
||||
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
|
||||
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;
|
||||
@ -28,7 +26,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
//@Service
|
||||
public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> implements TaskService {
|
||||
@ -39,7 +36,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
|
||||
private final MergeRequestsService mergeRequestsService;
|
||||
private final NotifyService notifyService;
|
||||
private final CommentService commentService;
|
||||
private final NoteService noteService;
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
@ -47,14 +44,14 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
TaskRepository taskRepository,
|
||||
MergeRequestsService mergeRequestsService,
|
||||
NotifyService notifyService,
|
||||
CommentService commentService,
|
||||
NoteService noteService,
|
||||
ConversionService conversionService
|
||||
) {
|
||||
super(taskRepository);
|
||||
this.taskRepository = taskRepository;
|
||||
this.mergeRequestsService = mergeRequestsService;
|
||||
this.notifyService = notifyService;
|
||||
this.commentService = commentService;
|
||||
this.noteService = noteService;
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@ -114,29 +111,29 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
}
|
||||
|
||||
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 = commentService.existsById(newAnswerIds);
|
||||
final List<Comment> newAnswers = commentService.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()
|
||||
);
|
||||
}
|
||||
}
|
||||
// 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
|
||||
@ -145,9 +142,9 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task convert(@NonNull Comment comment) {
|
||||
commentService.deleteById(comment.getId());
|
||||
final Task task = conversionService.convert(comment, Task.class);
|
||||
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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.gitlab.app.service.parser;
|
||||
package org.sadtech.bot.gitlab.core.service.parser;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
@ -0,0 +1,191 @@
|
||||
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.service.MergeRequestsService;
|
||||
import org.sadtech.bot.gitlab.context.service.ProjectService;
|
||||
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.page.Sheet;
|
||||
import org.sadtech.haiti.core.page.PaginationImpl;
|
||||
import org.sadtech.haiti.utils.network.HttpParse;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>Поиск новых комментариев и задач.</p>
|
||||
* <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p>
|
||||
*/
|
||||
//@Component
|
||||
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;
|
||||
|
||||
public NoteParser(
|
||||
ProjectService projectService, MergeRequestsService mergeRequestsService,
|
||||
ConversionService conversionService,
|
||||
GitlabProperty gitlabProperty,
|
||||
InitProperty initProperty,
|
||||
PersonProperty personProperty) {
|
||||
this.projectService = projectService;
|
||||
this.mergeRequestsService = mergeRequestsService;
|
||||
this.conversionService = conversionService;
|
||||
this.gitlabProperty = gitlabProperty;
|
||||
this.initProperty = initProperty;
|
||||
this.personProperty = personProperty;
|
||||
}
|
||||
|
||||
public void scanNewCommentAndTask() {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private List<DataScan> generatingLinksToPossibleComments(@NonNull Long commentId) {
|
||||
// List<DataScan> commentUrls = new ArrayList<>();
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// int page = 0;
|
||||
// Sheet<MergeRequest> 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())
|
||||
// );
|
||||
// }
|
||||
// commentId++;
|
||||
// }
|
||||
// return commentUrls;
|
||||
// }
|
||||
|
||||
// private List<Note> getCommentsByResultScan(List<NoteJson> 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());
|
||||
// }
|
||||
// )
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
// private List<Task> getTaskByResultScan(List<NoteJson> 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()));
|
||||
// }
|
||||
// )
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
private String generateUrl(@NonNull Long id, @NonNull String pullRequestUrl) {
|
||||
return MessageFormat.format("{0}/overview?commentId={1}", pullRequestUrl, Long.toString(id));
|
||||
}
|
||||
|
||||
private String getCommentUrl(long commentId, MergeRequest mergeRequest) {
|
||||
// return gitlabProperty.getUrlPullRequestComment()
|
||||
// .replace("{projectKey}", mergeRequest.getProjectKey())
|
||||
// .replace("{repositorySlug}", mergeRequest.getRepositorySlug())
|
||||
// .replace("{pullRequestId}", mergeRequest.getBitbucketId().toString())
|
||||
// .replace("{commentId}", String.valueOf(commentId));
|
||||
return null;
|
||||
}
|
||||
|
||||
public void scanOldComment() {
|
||||
// final List<Comment> comments = commentService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Comment oldComment : comments) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldComment.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.BLOCKER.equals(json.getSeverity())) {
|
||||
// taskService.convert(oldComment);
|
||||
// } else {
|
||||
// final Comment newComment = conversionService.convert(json, Comment.class);
|
||||
// commentService.update(newComment);
|
||||
// }
|
||||
// } else {
|
||||
// commentService.deleteById(oldComment.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void scanOldTask() {
|
||||
// final List<Task> tasks = taskService.getAllBetweenDate(
|
||||
// LocalDateTime.now().minusDays(20), LocalDateTime.now()
|
||||
// );
|
||||
// for (Task oldTask : tasks) {
|
||||
// final Optional<CommentJson> optCommentJson = Utils.urlToJson(
|
||||
// oldTask.getUrlApi(),
|
||||
// gitlabProperty.getToken(),
|
||||
// CommentJson.class
|
||||
// );
|
||||
// if (optCommentJson.isPresent()) {
|
||||
// final CommentJson json = optCommentJson.get();
|
||||
// if (Severity.NORMAL.equals(json.getSeverity())) {
|
||||
// commentService.convert(oldTask);
|
||||
// } else {
|
||||
// final Task newTask = conversionService.convert(json, Task.class);
|
||||
// taskService.update(newTask);
|
||||
// }
|
||||
// } else {
|
||||
// taskService.deleteById(oldTask.getId());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package org.sadtech.bot.gitlab.app.service.parser;
|
||||
package org.sadtech.bot.gitlab.core.service.parser;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.bot.gitlab.app.config.property.CommentSchedulerProperty;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Person;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Project;
|
||||
import org.sadtech.bot.gitlab.context.service.PersonService;
|
||||
import org.sadtech.bot.gitlab.context.service.ProjectService;
|
||||
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.PersonJson;
|
||||
import org.sadtech.bot.gitlab.sdk.domain.ProjectJson;
|
||||
@ -17,12 +15,11 @@ import org.sadtech.haiti.context.exception.ConvertException;
|
||||
import org.sadtech.haiti.utils.network.HttpHeader;
|
||||
import org.sadtech.haiti.utils.network.HttpParse;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -40,6 +37,9 @@ import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectParser {
|
||||
|
||||
public static final String PRIVATE = "&visibility=private";
|
||||
public static final String OWNER = "&owned=true";
|
||||
|
||||
private final ProjectService projectService;
|
||||
private final PersonService personService;
|
||||
|
||||
@ -47,30 +47,38 @@ public class ProjectParser {
|
||||
|
||||
private final GitlabProperty gitlabProperty;
|
||||
private final PersonProperty personProperty;
|
||||
private final CommentSchedulerProperty commentSchedulerProperty;
|
||||
private final InitProperty initProperty;
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * *")
|
||||
public void parseNewProject() {
|
||||
final List<ProjectJson> projectJsons = HttpParse.request(gitlabProperty.getUrlProject())
|
||||
.header(ACCEPT)
|
||||
.header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken()))
|
||||
.executeList(ProjectJson.class);
|
||||
public void parseAllPrivateProject() {
|
||||
parseProjects(PRIVATE);
|
||||
}
|
||||
|
||||
final Set<Long> jsonIds = projectJsons.stream()
|
||||
.map(ProjectJson::getId)
|
||||
.collect(Collectors.toSet());
|
||||
public void parseAllProjectOwner() {
|
||||
parseProjects(OWNER);
|
||||
}
|
||||
|
||||
createNewPersons(projectJsons);
|
||||
private void parseProjects(String param) {
|
||||
int page = 0;
|
||||
List<ProjectJson> projectJsons = getProjectJsons(page, param);
|
||||
|
||||
final ExistsContainer<Project, Long> existsContainer = projectService.existsById(jsonIds);
|
||||
final List<Project> newProjects = projectJsons.stream()
|
||||
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
|
||||
.map(json -> conversionService.convert(json, Project.class))
|
||||
.collect(Collectors.toList());
|
||||
while (!projectJsons.isEmpty()) {
|
||||
|
||||
if (!newProjects.isEmpty()) {
|
||||
projectService.createAll(newProjects);
|
||||
final Set<Long> jsonIds = projectJsons.stream()
|
||||
.map(ProjectJson::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
createNewPersons(projectJsons);
|
||||
|
||||
final ExistsContainer<Project, Long> existsContainer = projectService.existsById(jsonIds);
|
||||
final List<Project> newProjects = projectJsons.stream()
|
||||
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
|
||||
.map(json -> conversionService.convert(json, Project.class))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!newProjects.isEmpty()) {
|
||||
projectService.createAll(newProjects);
|
||||
}
|
||||
|
||||
projectJsons = getProjectJsons(++page, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,16 +94,11 @@ public class ProjectParser {
|
||||
|
||||
final List<Person> newPersons = notFoundId.stream()
|
||||
.map(
|
||||
userId -> {
|
||||
final Optional<PersonJson> execute = HttpParse.request(gitlabProperty.getUsersUrl() + "/" + userId)
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(PersonJson.class);
|
||||
final Optional<Person> person = execute
|
||||
.map(json -> conversionService.convert(json, Person.class));
|
||||
return person
|
||||
.orElseThrow(() -> new ConvertException("Ошибка преобразования нового пользователя"));
|
||||
}
|
||||
userId -> HttpParse.request(gitlabProperty.getUsersUrl() + "/" + userId)
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(PersonJson.class)
|
||||
.map(json -> conversionService.convert(json, Person.class)).orElseThrow(() -> new ConvertException("Ошибка преобразования нового пользователя"))
|
||||
).collect(Collectors.toList());
|
||||
|
||||
personService.createAll(newPersons);
|
||||
@ -103,4 +106,13 @@ public class ProjectParser {
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProjectJson> getProjectJsons(int page, String... params) {
|
||||
String param = String.join("", params);
|
||||
final String url = MessageFormat.format(gitlabProperty.getUrlProject(), page);
|
||||
return HttpParse.request(url + param)
|
||||
.header(ACCEPT)
|
||||
.header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken()))
|
||||
.executeList(ProjectJson.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.AppSetting;
|
||||
import org.sadtech.bot.gitlab.context.repository.AppSettingRepository;
|
||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
@Repository
|
||||
public class AppSettingRepositoryImpl extends AbstractSimpleManagerRepository<AppSetting, Long> implements AppSettingRepository {
|
||||
|
||||
public AppSettingRepositoryImpl(JpaRepository<AppSetting, Long> jpaRepository) {
|
||||
super(jpaRepository);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.bot.gitlab.data.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
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;
|
||||
@ -17,7 +17,7 @@ import java.util.Set;
|
||||
* @author upagge 08.09.2020
|
||||
*/
|
||||
//@Repository
|
||||
public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Comment, Long> implements CommentRepository {
|
||||
public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Note, Long> implements CommentRepository {
|
||||
|
||||
private final CommentRepositoryJpa repositoryJpa;
|
||||
|
||||
@ -27,17 +27,17 @@ public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Comme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Comment> findFirstByOrderByIdDesc() {
|
||||
public Optional<Note> findFirstByOrderByIdDesc() {
|
||||
return repositoryJpa.findFirstByOrderByIdDesc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Comment> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
public List<Note> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo) {
|
||||
return repositoryJpa.findByCreateDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Comment> findAllById(@NonNull Set<Long> ids) {
|
||||
public List<Note> findAllById(@NonNull Set<Long> ids) {
|
||||
return repositoryJpa.findAllById(ids);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.AppSetting;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* // TODO: 16.01.2021 Добавить описание.
|
||||
*
|
||||
* @author upagge 16.01.2021
|
||||
*/
|
||||
public interface AppSettingJpaRepository extends JpaRepository<AppSetting, Long> {
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.bot.gitlab.data.jpa;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
@ -11,13 +11,13 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface CommentRepositoryJpa extends JpaRepository<Comment, Long> {
|
||||
public interface CommentRepositoryJpa extends JpaRepository<Note, Long> {
|
||||
|
||||
Optional<Comment> findFirstByOrderByIdDesc();
|
||||
Optional<Note> findFirstByOrderByIdDesc();
|
||||
|
||||
List<Comment> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<Note> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
|
||||
// @Query("SELECT c.id FROM Comment c WHERE c.id IN :ids")
|
||||
// @Query("SELECT c.id FROM Comment c WHERE c.id IN :ids")
|
||||
Set<Long> existsAllById(@NonNull Set<Long> ids);
|
||||
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package org.sadtech.bot.gitlab.sdk.domain;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import lombok.Data;
|
||||
import org.sadtech.bot.gitlab.sdk.utils.LocalDateTimeFromEpochDeserializer;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CommentJson {
|
||||
|
||||
private Long id;
|
||||
private Integer version;
|
||||
private String text;
|
||||
private UserJson author;
|
||||
private List<CommentJson> comments;
|
||||
|
||||
private Severity severity;
|
||||
|
||||
private CommentState state;
|
||||
|
||||
@JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
|
||||
private LocalDateTime createdDate;
|
||||
|
||||
@JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
|
||||
private LocalDateTime updatedDate;
|
||||
|
||||
private Long customPullRequestId;
|
||||
|
||||
private String customCommentApiUrl;
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.sadtech.bot.gitlab.sdk.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class NoteJson {
|
||||
|
||||
private Long id;
|
||||
private String type;
|
||||
private String body;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private LocalDateTime created;
|
||||
|
||||
@JsonProperty("updated_at")
|
||||
private LocalDateTime updated;
|
||||
|
||||
private PersonJson author;
|
||||
private boolean system;
|
||||
|
||||
@JsonProperty("noteable_id")
|
||||
private Long noteableId;
|
||||
|
||||
@JsonProperty("noteable_type")
|
||||
private String noteableType;
|
||||
|
||||
private Boolean resolveable;
|
||||
|
||||
private Boolean resolved;
|
||||
|
||||
@JsonProperty("resolved_by")
|
||||
private PersonJson resolvedBy;
|
||||
|
||||
@JsonProperty("noteable_iid")
|
||||
private Long noteableIid;
|
||||
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import org.sadtech.bot.godfather.telegram.listen.EventDistributor;
|
||||
import org.sadtech.bot.godfather.telegram.listen.EventDistributorImpl;
|
||||
import org.sadtech.bot.godfather.telegram.listen.TelegramConnect;
|
||||
import org.sadtech.bot.godfather.telegram.listen.TelegramSender;
|
||||
import org.sadtech.social.bot.domain.unit.AnswerText;
|
||||
import org.sadtech.social.bot.domain.unit.AnswerCheck;
|
||||
import org.sadtech.social.core.domain.content.Mail;
|
||||
import org.sadtech.social.core.repository.impl.local.MailRepositoryList;
|
||||
import org.sadtech.social.core.service.MailService;
|
||||
@ -45,10 +45,11 @@ public class TelegramBotConfig {
|
||||
public MessageAutoresponderTelegram messageAutoresponderTelegram(
|
||||
Sending sending,
|
||||
MessageService<Mail> messageService,
|
||||
UnitPointerRepository unitPointerRepository
|
||||
UnitPointerRepository unitPointerRepository,
|
||||
AnswerCheck checkFirstStart
|
||||
) {
|
||||
return new MessageAutoresponderTelegram(
|
||||
Collections.singleton(AnswerText.of("TEST")),
|
||||
Collections.singleton(checkFirstStart),
|
||||
sending,
|
||||
messageService,
|
||||
unitPointerRepository
|
||||
|
@ -3,8 +3,9 @@ package org.sadtech.bot.gitlab.telegram.scheduler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.godfather.telegram.autoresponder.MessageAutoresponderTelegram;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
//@Service
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CheckNewMessage {
|
||||
|
||||
|
@ -1,58 +1,47 @@
|
||||
package org.sadtech.bot.gitlab.telegram.unit;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
import org.sadtech.social.bot.domain.unit.AnswerProcessing;
|
||||
import org.sadtech.social.bot.domain.unit.AnswerText;
|
||||
import org.sadtech.social.core.domain.BoxAnswer;
|
||||
import org.sadtech.social.core.domain.content.Message;
|
||||
import org.sadtech.social.core.utils.KeyBoards;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* // TODO: 20.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 20.09.2020
|
||||
*/
|
||||
//@Configuration
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class NotifySettingUnit {
|
||||
|
||||
private final NotifyService notifyService;
|
||||
|
||||
@Bean
|
||||
public AnswerText notifySetting(
|
||||
AnswerProcessing<Message> disableNotifications
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(
|
||||
BoxAnswer.builder()
|
||||
.message("Вы можете полностью остановить уведомления от бота")
|
||||
.keyBoard(
|
||||
KeyBoards.verticalDuoMenuString(
|
||||
Arrays.stream(DisableMenu.values())
|
||||
.map(DisableMenu::getName)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
)
|
||||
.build()
|
||||
)
|
||||
.phrase("Уведомления")
|
||||
.nextUnit(disableNotifications)
|
||||
.build();
|
||||
}
|
||||
// @Bean
|
||||
// public AnswerText notifySetting(
|
||||
// AnswerProcessing<Message> disableNotifications
|
||||
// ) {
|
||||
// return AnswerText.builder()
|
||||
// .boxAnswer(
|
||||
// BoxAnswer.builder()
|
||||
// .message("Вы можете полностью остановить уведомления от бота")
|
||||
// .keyBoard(
|
||||
// KeyBoards.verticalDuoMenuString(
|
||||
// Arrays.stream(DisableMenu.values())
|
||||
// .map(DisableMenu::getName)
|
||||
// .collect(Collectors.toList())
|
||||
// )
|
||||
// )
|
||||
// .build()
|
||||
// )
|
||||
// .phrase("Уведомления")
|
||||
// .nextUnit(disableNotifications)
|
||||
// .build();
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public AnswerProcessing<Message> disableNotifications() {
|
||||
return AnswerProcessing.builder()
|
||||
.processingData(
|
||||
message -> {
|
||||
// @Bean
|
||||
// public AnswerProcessing<Message> disableNotifications() {
|
||||
// return AnswerProcessing.builder()
|
||||
// .processingData(
|
||||
// message -> {
|
||||
// final Person person = personService.getByTelegramId(message.getPersonId())
|
||||
// .orElseThrow(() -> new NotFoundException("Не найдено"));
|
||||
// final NotifySetting notifySetting = notifyService.getSetting(person.getLogin())
|
||||
@ -62,35 +51,35 @@ public class NotifySettingUnit {
|
||||
// );
|
||||
// notifyService.saveSettings(notifySetting);
|
||||
// return BoxAnswer.of("Настройки сохранены");
|
||||
return null;
|
||||
}
|
||||
)
|
||||
.build();
|
||||
}
|
||||
// return null;
|
||||
// }
|
||||
// )
|
||||
// .build();
|
||||
// }
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
private enum DisableMenu {
|
||||
|
||||
TURN_ON("Включить", 0),
|
||||
TURN_OFF("Выключить", 525600),
|
||||
DISABLE_15_MIN("15 мин", 15),
|
||||
DISABLE_2_HOUR("2 часа", 120),
|
||||
DISABLE_30_MIN("30 мин", 30),
|
||||
DISABLE_4_HOUR("4 часа", 240),
|
||||
DISABLE_60_MIN("60 мин", 60),
|
||||
DISABLE_8_HOUR("8 часов", 480);
|
||||
|
||||
private final String name;
|
||||
private final int minutes;
|
||||
|
||||
public static DisableMenu from(@NonNull String name) {
|
||||
return Arrays.stream(DisableMenu.values())
|
||||
.filter(disableMenu -> disableMenu.getName().equals(name))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NotFoundException("Не найдено"));
|
||||
}
|
||||
|
||||
}
|
||||
// @Getter
|
||||
// @RequiredArgsConstructor
|
||||
// private enum DisableMenu {
|
||||
//
|
||||
// TURN_ON("Включить", 0),
|
||||
// TURN_OFF("Выключить", 525600),
|
||||
// DISABLE_15_MIN("15 мин", 15),
|
||||
// DISABLE_2_HOUR("2 часа", 120),
|
||||
// DISABLE_30_MIN("30 мин", 30),
|
||||
// DISABLE_4_HOUR("4 часа", 240),
|
||||
// DISABLE_60_MIN("60 мин", 60),
|
||||
// DISABLE_8_HOUR("8 часов", 480);
|
||||
//
|
||||
// private final String name;
|
||||
// private final int minutes;
|
||||
//
|
||||
// public static DisableMenu from(@NonNull String name) {
|
||||
// return Arrays.stream(DisableMenu.values())
|
||||
// .filter(disableMenu -> disableMenu.getName().equals(name))
|
||||
// .findFirst()
|
||||
// .orElseThrow(() -> new NotFoundException("Не найдено"));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -1,93 +1,117 @@
|
||||
package org.sadtech.bot.gitlab.telegram.unit;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.sadtech.bot.gitlab.telegram.service.unit.TaskProcessing;
|
||||
import org.sadtech.bot.gitlab.telegram.utils.GeneratorKeyBoards;
|
||||
import org.sadtech.bot.gitlab.context.domain.AppLocale;
|
||||
import org.sadtech.bot.gitlab.context.service.AppSettingService;
|
||||
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.Message;
|
||||
import org.sadtech.social.core.utils.KeyBoards;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
*
|
||||
* @author upagge [30.01.2020]
|
||||
*/
|
||||
//@Configuration
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class UnitConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public AnswerText menu(
|
||||
AnswerProcessing<Message> getTasks,
|
||||
AnswerText menuPullRequest,
|
||||
AnswerText settings
|
||||
public AnswerCheck checkFirstStart(
|
||||
AppSettingService settingService,
|
||||
AnswerText textCheckLanguage
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(
|
||||
BoxAnswer.builder()
|
||||
.message("Привет, выбери пункт меню!")
|
||||
.keyBoard(GeneratorKeyBoards.menu())
|
||||
.build()
|
||||
return AnswerCheck.builder()
|
||||
.check(
|
||||
message -> settingService.isFirstStart()
|
||||
)
|
||||
.nextUnit(getTasks)
|
||||
.nextUnit(menuPullRequest)
|
||||
.nextUnit(settings)
|
||||
.unitTrue(textCheckLanguage)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerText settings(
|
||||
AnswerText notifySetting
|
||||
public AnswerText textCheckLanguage(
|
||||
AnswerProcessing checkLanguage
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(
|
||||
BoxAnswer.builder()
|
||||
.message("Здесь вы можете персонализировать бота")
|
||||
.keyBoard(
|
||||
KeyBoards.verticalMenuString("Уведомления")
|
||||
)
|
||||
.message("Hi :)\n\nLet's choose a language for.")
|
||||
.keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English"))
|
||||
.build()
|
||||
)
|
||||
.phrase("Настройки")
|
||||
.nextUnit(notifySetting)
|
||||
.nextUnit(checkLanguage)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerProcessing<Message> getTasks(
|
||||
TaskProcessing taskProcessing
|
||||
public AnswerProcessing checkLanguage(
|
||||
AppSettingService settingService,
|
||||
AnswerText textParserPrivateProject
|
||||
) {
|
||||
return AnswerProcessing
|
||||
.builder()
|
||||
.processingData(
|
||||
message -> {
|
||||
final AppLocale appLocale = AppLocale.of(message.getText());
|
||||
settingService.setLocale(appLocale);
|
||||
return BoxAnswer.of(
|
||||
settingService.getMessage("ui.lang_changed")
|
||||
);
|
||||
}
|
||||
)
|
||||
.nextUnit(textParserPrivateProject)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerText textParserPrivateProject(
|
||||
AnswerCheck checkParserPrivateProject,
|
||||
AppSettingService settingService
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(
|
||||
BoxAnswer.builder()
|
||||
.message(settingService.getMessage("ui.monitor_private_projects"))
|
||||
.keyBoard(KeyBoards.verticalDuoMenuString(
|
||||
settingService.getMessage("main.yes"), settingService.getMessage("main.no")
|
||||
))
|
||||
.build()
|
||||
)
|
||||
.activeType(UnitActiveType.AFTER)
|
||||
.nextUnit(checkParserPrivateProject)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerCheck checkParserPrivateProject(
|
||||
AppSettingService appSettingService,
|
||||
AnswerProcessing parserPrivateProject
|
||||
) {
|
||||
return AnswerCheck.builder()
|
||||
.check(
|
||||
message -> appSettingService.getMessage("main.yes").equalsIgnoreCase(message.getText())
|
||||
)
|
||||
.unitTrue(parserPrivateProject)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerProcessing parserPrivateProject(
|
||||
ProjectParser projectParser,
|
||||
AppSettingService settingService
|
||||
) {
|
||||
return AnswerProcessing.builder()
|
||||
.processingData(taskProcessing)
|
||||
.phrase("Мои задачи")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerProcessing<Mail> noRegister() {
|
||||
return AnswerProcessing.<Mail>builder()
|
||||
.processingData(message ->
|
||||
BoxAnswer.builder()
|
||||
.message("Привет :)\nЭтот бот сообщает о появлении новых ПР и об изменениях в старых\n\n" +
|
||||
"Теперь когда ты знаешь правду, ты просто обязан отправь POST запрос на адрес " +
|
||||
"http://192.168.236.164:8018/api/user/reg\n\n" +
|
||||
"В теле запроса укажи следующее:\n\n" +
|
||||
"{\n" +
|
||||
"\t\"telegramId\": " + message.getPersonId() + ",\n" +
|
||||
"\t\"login\": \"apetrov\",\n" +
|
||||
"\t\"token\": \"token value\"\n" +
|
||||
"}" +
|
||||
"\n\n" +
|
||||
"ВНИМАНИЕ!!!\ntelegramId не менять; login как в bitbucket; токен получать [тут](http://192.168.236.164:7990/plugins/servlet/access-tokens/manage)" +
|
||||
"\n-- -- --\n" +
|
||||
"По всем вопросам обращаться к @uPagge")
|
||||
.build()
|
||||
)
|
||||
.processingData(message -> {
|
||||
projectParser.parseAllPrivateProject();
|
||||
return BoxAnswer.of(settingService.getMessage("ui.monitor_project_private_success"));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user