Первая версия синхронизации проектов

This commit is contained in:
uPagge 2021-01-14 21:47:12 +03:00
parent 418b7c9f80
commit 073bb0e3d9
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
88 changed files with 898 additions and 1169 deletions

View File

@ -95,6 +95,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -2,10 +2,14 @@ package org.sadtech.bot.gitlab.app.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import java.util.Arrays;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -33,4 +37,11 @@ public class AppConfig {
return Executors.newFixedThreadPool(3); return Executors.newFixedThreadPool(3);
} }
@Bean
public ConversionService conversionService(Converter... converters) {
final DefaultConversionService defaultConversionService = new DefaultConversionService();
Arrays.stream(converters).forEach(defaultConversionService::addConverter);
return defaultConversionService;
}
} }

View File

@ -1,29 +1,27 @@
package org.sadtech.bot.gitlab.app.scheduler; package org.sadtech.bot.gitlab.app.scheduler;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.app.service.CommentAndTaskParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class CommentAndTaskScheduler { public class CommentAndTaskScheduler {
//
private final CommentAndTaskParser commentAndTaskParser; // private final CommentAndTaskParser commentAndTaskParser;
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void scanNewCommentAndTask() { // public void scanNewCommentAndTask() {
commentAndTaskParser.scanNewCommentAndTask(); // commentAndTaskParser.scanNewCommentAndTask();
} // }
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void scanOldComment() { // public void scanOldComment() {
commentAndTaskParser.scanOldComment(); // commentAndTaskParser.scanOldComment();
} // }
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void scanOldTask() { // public void scanOldTask() {
commentAndTaskParser.scanOldTask(); // commentAndTaskParser.scanOldTask();
} // }
} }

View File

@ -2,8 +2,6 @@ package org.sadtech.bot.gitlab.app.scheduler;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vsc.context.service.PullRequestParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -16,16 +14,16 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PullRequestParserScheduler { public class PullRequestParserScheduler {
private final PullRequestParser pullRequestParser; // private final PullRequestParser pullRequestParser;
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void parsingOldPullRequest() { // public void parsingOldPullRequest() {
pullRequestParser.parsingOldPullRequest(); // pullRequestParser.parsingOldPullRequest();
} // }
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void parsingNewPullRequest() { // public void parsingNewPullRequest() {
pullRequestParser.parsingNewPullRequest(); // pullRequestParser.parsingNewPullRequest();
} // }
} }

View File

@ -0,0 +1,26 @@
package org.sadtech.bot.gitlab.app.scheduler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.gitlab.app.service.parser.ProjectParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class SchedulerService {
private final ProjectParser projectParser;
@Scheduled(cron = "0 */1 * * * *")
public void newProjectParse() {
projectParser.parseNewProject();
}
}

View File

@ -0,0 +1,27 @@
package org.sadtech.bot.gitlab.app.service.convert;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.bot.gitlab.sdk.domain.ProjectJson;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Component
public class ProjectJsonConverter implements Converter<ProjectJson, Project> {
@Override
public Project convert(ProjectJson source) {
final Project project = new Project();
project.setId(source.getId());
project.setCreatedDate(source.getCreatedDate());
project.setCreatorId(source.getCreatorId());
project.setDescription(source.getDescription());
project.setName(source.getName());
return project;
}
}

View File

@ -14,14 +14,15 @@ public class Seeker implements Callable<Optional<CommentJson>> {
@Override @Override
public Optional<CommentJson> call() { public Optional<CommentJson> call() {
return Utils.urlToJson(dataScan.getUrlComment(), token, CommentJson.class) // return Utils.urlToJson(dataScan.getUrlComment(), token, CommentJson.class)
.map( // .map(
commentJson -> { // commentJson -> {
commentJson.setCustomPullRequestId(dataScan.getPullRequestId()); // commentJson.setCustomPullRequestId(dataScan.getPullRequestId());
commentJson.setCustomCommentApiUrl(dataScan.getUrlComment()); // commentJson.setCustomCommentApiUrl(dataScan.getUrlComment());
return commentJson; // return commentJson;
} // }
); // );
return Optional.empty();
} }
} }

View File

@ -1,7 +1,8 @@
package org.sadtech.bot.gitlab.app.service; package org.sadtech.bot.gitlab.app.service.parser;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.app.config.property.CommentSchedulerProperty; 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.app.service.executor.DataScan;
import org.sadtech.bot.gitlab.context.domain.entity.Comment; import org.sadtech.bot.gitlab.context.domain.entity.Comment;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
@ -18,20 +19,17 @@ import org.sadtech.bot.gitlab.sdk.domain.Severity;
import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.core.page.PaginationImpl;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* <p>Поиск новых комментариев и задач.</p> * <p>Поиск новых комментариев и задач.</p>
* <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p> * <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p>
*/ */
@Component //@Component
public class CommentAndTaskParser { public class CommentAndTaskParser {
private final CommentService commentService; private final CommentService commentService;
@ -164,51 +162,51 @@ public class CommentAndTaskParser {
} }
public void scanOldComment() { public void scanOldComment() {
final List<Comment> comments = commentService.getAllBetweenDate( // final List<Comment> comments = commentService.getAllBetweenDate(
LocalDateTime.now().minusDays(20), LocalDateTime.now() // LocalDateTime.now().minusDays(20), LocalDateTime.now()
); // );
for (Comment oldComment : comments) { // for (Comment oldComment : comments) {
final Optional<CommentJson> optCommentJson = Utils.urlToJson( // final Optional<CommentJson> optCommentJson = Utils.urlToJson(
oldComment.getUrlApi(), // oldComment.getUrlApi(),
gitlabProperty.getToken(), // gitlabProperty.getToken(),
CommentJson.class // CommentJson.class
); // );
if (optCommentJson.isPresent()) { // if (optCommentJson.isPresent()) {
final CommentJson json = optCommentJson.get(); // final CommentJson json = optCommentJson.get();
if (Severity.BLOCKER.equals(json.getSeverity())) { // if (Severity.BLOCKER.equals(json.getSeverity())) {
taskService.convert(oldComment); // taskService.convert(oldComment);
} else { // } else {
final Comment newComment = conversionService.convert(json, Comment.class); // final Comment newComment = conversionService.convert(json, Comment.class);
commentService.update(newComment); // commentService.update(newComment);
} // }
} else { // } else {
commentService.deleteById(oldComment.getId()); // commentService.deleteById(oldComment.getId());
} // }
} // }
} }
public void scanOldTask() { public void scanOldTask() {
final List<Task> tasks = taskService.getAllBetweenDate( // final List<Task> tasks = taskService.getAllBetweenDate(
LocalDateTime.now().minusDays(20), LocalDateTime.now() // LocalDateTime.now().minusDays(20), LocalDateTime.now()
); // );
for (Task oldTask : tasks) { // for (Task oldTask : tasks) {
final Optional<CommentJson> optCommentJson = Utils.urlToJson( // final Optional<CommentJson> optCommentJson = Utils.urlToJson(
oldTask.getUrlApi(), // oldTask.getUrlApi(),
gitlabProperty.getToken(), // gitlabProperty.getToken(),
CommentJson.class // CommentJson.class
); // );
if (optCommentJson.isPresent()) { // if (optCommentJson.isPresent()) {
final CommentJson json = optCommentJson.get(); // final CommentJson json = optCommentJson.get();
if (Severity.NORMAL.equals(json.getSeverity())) { // if (Severity.NORMAL.equals(json.getSeverity())) {
commentService.convert(oldTask); // commentService.convert(oldTask);
} else { // } else {
final Task newTask = conversionService.convert(json, Task.class); // final Task newTask = conversionService.convert(json, Task.class);
taskService.update(newTask); // taskService.update(newTask);
} // }
} else { // } else {
taskService.deleteById(oldTask.getId()); // taskService.deleteById(oldTask.getId());
} // }
} // }
} }
} }

View File

@ -0,0 +1,66 @@
package org.sadtech.bot.gitlab.app.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.Project;
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.sdk.domain.ProjectJson;
import org.sadtech.haiti.context.domain.ExistsContainer;
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.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;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ProjectParser {
private final ProjectService projectService;
private final ConversionService conversionService;
private final GitlabProperty gitlabProperty;
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 + gitlabProperty.getToken()))
.executeList(ProjectJson.class);
final Set<Long> jsonIds = projectJsons.stream()
.map(ProjectJson::getId)
.collect(Collectors.toSet());
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);
}
}
}

View File

@ -2,17 +2,14 @@ package org.sadtech.bot.gitlab.app.service.parser;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
import org.sadtech.bot.gitlab.core.utils.Pair; import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson;
import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.service.PullRequestParser; import org.sadtech.bot.vsc.context.service.PullRequestParser;
import org.sadtech.haiti.utils.network.HttpHeader; import org.sadtech.haiti.utils.network.HttpHeader;
import org.sadtech.haiti.utils.network.HttpParse; import org.sadtech.haiti.utils.network.HttpParse;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -24,7 +21,7 @@ import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION;
import static org.sadtech.haiti.utils.network.HttpParse.BEARER; import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
@Slf4j @Slf4j
@Service //@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class PullRequestBitbucketParser implements PullRequestParser { public class PullRequestBitbucketParser implements PullRequestParser {
@ -41,23 +38,22 @@ public class PullRequestBitbucketParser implements PullRequestParser {
@Override @Override
public void parsingNewPullRequest() { public void parsingNewPullRequest() {
final List<MergeRequestJson> mergeRequestJsons = HttpParse.request(gitlabProperty.getUrlPullRequestOpen())
final List<PullRequestJson> pullRequestJsons = HttpParse.request(gitlabProperty.getUrlPullRequestOpen())
.header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken())) .header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken()))
.header(ACCEPT) .header(ACCEPT)
.executeList(PullRequestJson.class); .executeList(MergeRequestJson.class);
while (pullRequestJsons != null && !pullRequestJsons.isEmpty()) { // while (mergeRequestJsons != null && !mergeRequestJsons.isEmpty()) {
final List<PullRequest> newPullRequest = pullRequestJsons.stream() // final List<PullRequest> newPullRequest = mergeRequestJsons.stream()
.collect(Collectors.toMap(pullRequestJson -> new Pair<>(pullRequestJson.getId(), pullRequestJson.getFromRef().getRepository().getId()), pullRequestJson -> pullRequestJson)) // .collect(Collectors.toMap(mergeRequestJson -> new Pair<>(mergeRequestJson.getId(), mergeRequestJson.getFromRef().getRepository().getId()), mergeRequestJson -> mergeRequestJson))
.values() // .values()
.stream() // .stream()
// .filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson))) // .filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson)))
.map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class)) // .map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class))
.collect(Collectors.toList()); // .collect(Collectors.toList());
//
pullRequestsService.createAll(newPullRequest); // pullRequestsService.createAll(newPullRequest);
} // }
} }
// private Set<Long> getExistsPullRequestIds(String bitbucketUrl) { // private Set<Long> getExistsPullRequestIds(String bitbucketUrl) {

View File

@ -32,11 +32,11 @@ gitlab-bot:
token: ${GITLAB_PERSONAL_TOKEN} token: ${GITLAB_PERSONAL_TOKEN}
username: ${GITLAB_USERNAME} username: ${GITLAB_USERNAME}
full-name: ${GITLAB_FULLNAME} full-name: ${GITLAB_FULLNAME}
url-pull-request-open: ${GITLAB_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN url-project: ${GITLAB_URL}/api/v4/projects
url-pull-request-close: ${GITLAB_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 url-pull-request-open: ${GITLAB_URL}/api/v4/projects/18/merge_requests?state=opened
url-pull-request-comment: ${GITLAB_URL}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} url-pull-request-close: ${GITLAB_URL}
url-pull-request: ${GITLAB_URL}/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/overview url-pull-request-comment: ${GITLAB_URL}
url-users: ${GITLAB_URL}/rest/api/1.0/admin/users url-pull-request: ${GITLAB_URL}
teamcity: teamcity:
token: ${TEAMCITY_ADMIN_TOKEN} token: ${TEAMCITY_ADMIN_TOKEN}
project-url: ${TEAMCITY_URL}/app/rest/projects project-url: ${TEAMCITY_URL}/app/rest/projects

View File

@ -3,7 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="liquibase/v.2.0.0/2020-09-06-cumulative.xml"/> <include file="liquibase/v.1.0.0/cumulative.xml"/>
<include file="liquibase/v.3.0.0/cumulative.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -1,191 +0,0 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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-09-06-create-table-person" author="upagge">
<createTable tableName="person">
<column name="login" type="varchar(64)">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="full_name" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="bitbucket_token" type="varchar(200)"/>
<column name="telegram_id" type="integer">
<constraints unique="true"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-06-create-table-pull-request" author="upagge">
<createTable tableName="pull_request">
<column name="id" type="integer" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="bitbucket_id" type="integer">
<constraints nullable="false"/>
</column>
<column name="repository_id" type="integer"/>
<column name="project_key" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="repository_slug" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="title" type="varchar(100)"/>
<column name="description" type="varchar(300)"/>
<column name="author_login" type="varchar(64)">
<constraints nullable="false"
foreignKeyName="pull_request_author_login_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="status" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="url" type="varchar(500)">
<constraints nullable="false"/>
</column>
<column name="conflict" type="boolean">
<constraints nullable="false"/>
</column>
<column name="bitbucket_version" type="int">
<constraints nullable="false"/>
</column>
<column name="create_date" type="datetime">
<constraints nullable="false"/>
</column>
<column name="update_date" type="datetime">
<constraints nullable="false"/>
</column>
</createTable>
<addUniqueConstraint tableName="pull_request" columnNames="bitbucket_id, repository_id"/>
</changeSet>
<changeSet id="2020-09-06-create-table-pull-request-reviewer" author="upagge">
<createTable tableName="reviewer">
<column name="id" type="integer" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="pull_request_id" type="integer">
<constraints nullable="false" foreignKeyName="reviewer_pull_request_id_pull_request_id"
references="pull_request(id)" deleteCascade="true"/>
</column>
<column name="person_login" type="varchar(64)">
<constraints nullable="false"
foreignKeyName="reviewer_person_login_id_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="status" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
<addUniqueConstraint tableName="reviewer" columnNames="pull_request_id, person_login"/>
</changeSet>
<changeSet id="2020-09-06-create-table-comments" author="upagge">
<createTable tableName="comment">
<column name="id" type="int">
<constraints primaryKey="true"/>
</column>
<column name="url" type="varchar(300)">
<constraints nullable="false" unique="true"/>
</column>
<column name="url_api" type="varchar(300)">
<constraints nullable="false" unique="true"/>
</column>
<column name="author_login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="task_author_login_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="responsible_login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="comment_responsible_login_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="pull_request_id" type="integer">
<constraints nullable="false" foreignKeyName="comment_pull_request_id_pull_request_id"
references="pull_request(id)" deleteCascade="true"/>
</column>
<column name="message" type="varchar(500)"/>
<column name="create_date" type="datetime">
<constraints nullable="false"/>
</column>
<column name="bitbucket_version" type="int">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-06-create-table-comment-tree" author="upagge">
<createTable tableName="comment_tree">
<column name="parent_id" type="int">
<constraints foreignKeyName="comment_tree_parent_id_comment_id"
references="comment(id)" nullable="false"
deleteCascade="true"/>
</column>
<column name="child_id" type="int">
<constraints foreignKeyName="comment_tree_child_id_comment_id"
references="comment(id)" nullable="false"
deleteCascade="true"/>
</column>
</createTable>
<addPrimaryKey tableName="comment_tree" columnNames="parent_id, child_id"/>
</changeSet>
<changeSet id="2020-09-06-create-table-task" author="upagge">
<createTable tableName="task">
<column name="id" type="integer" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="description" type="varchar(500)">
<constraints nullable="false"/>
</column>
<column name="status" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="url" type="varchar(300)">
<constraints nullable="false" unique="true"/>
</column>
<column name="url_api" type="varchar(300)">
<constraints nullable="false" unique="true"/>
</column>
<column name="author_login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="task_author_login_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="responsible_login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="task_responsible_login_person_login"
references="person(login)" deleteCascade="true"/>
</column>
<column name="pull_request_id" type="int">
<constraints nullable="true" foreignKeyName="task_pull_request_id_pull_request_id"
references="pull_request(id)" deleteCascade="true"/>
</column>
<column name="create_date" type="datetime">
<constraints nullable="false"/>
</column>
<column name="bitbucket_version" type="int">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-08-create-table-task-comments" author="upagge">
<createTable tableName="task_comments">
<column name="task_id" type="integer">
<constraints nullable="false" foreignKeyName="task_comments_task_id_task_id" references="task(id)"/>
</column>
<column name="comment_id" type="integer">
<constraints nullable="false" foreignKeyName="task_comments_comment_id_comment_id"
references="comment(id)"/>
</column>
</createTable>
<addPrimaryKey tableName="task_comments" columnNames="task_id, comment_id"/>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,20 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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-14-create-table-project" author="uPagge">
<createTable tableName="project">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="name" type="varchar(200)">
<constraints nullable="false"/>
</column>
<column name="description" type="varchar(1000)"/>
<column name="created_date" type="datetime"/>
<column name="creator_id" type="int"/>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -1,8 +1,8 @@
<databaseChangeLog <databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="liquibase/v.3.0.0/2020-10-31-add-new-columns-pr.xml"/> <include file="liquibase/v.1.0.0/2021-01-14-create-tables.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -1,16 +0,0 @@
<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">
<include file="liquibase/v.2.0.0/2020-09-06-create-table.xml"/>
<include file="liquibase/v.2.0.0/2020-09-15-fix-task-comments.xml"/>
<include file="liquibase/v.2.0.0/2020-09-20-setting-notify.xml"/>
<include file="liquibase/v.2.0.0/2020-09-20-teamcity.xml"/>
<include file="liquibase/v.2.0.0/2020-10-01-rating.xml"/>
<include file="liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml"/>
<include file="liquibase/v.2.0.0/2020-10-07-add-colum-reviewer-date.xml"/>
<include file="liquibase/v.2.0.0/2020-10-11-teamcity-refactoring.xml"/>
<include file="liquibase/v.2.0.0/2020-10-11-new-colum-reviewer.xml"/>
</databaseChangeLog>

View File

@ -1,24 +0,0 @@
<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-09-15-drop-constraint-task-comments" author="upagge">
<dropForeignKeyConstraint baseTableName="task_comments" constraintName="task_comments_comment_id_comment_id"/>
<dropForeignKeyConstraint baseTableName="task_comments" constraintName="task_comments_task_id_task_id"/>
</changeSet>
<changeSet id="2020-09-15-create-constraint-task-comments" author="upagge">
<addNotNullConstraint tableName="task_comments" columnName="comment_id"/>
<addNotNullConstraint tableName="task_comments" columnName="task_id"/>
<addForeignKeyConstraint baseTableName="task_comments" baseColumnNames="comment_id"
constraintName="task_comments_comment_id_comment_id"
referencedTableName="comment"
referencedColumnNames="id" onDelete="CASCADE"/>
<addForeignKeyConstraint baseTableName="task_comments" baseColumnNames="task_id"
constraintName="task_comments_task_id_task_id"
referencedTableName="task"
referencedColumnNames="id" onDelete="CASCADE"/>
</changeSet>
</databaseChangeLog>

View File

@ -1,18 +0,0 @@
<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-09-20-create-table-setting-notify" author="upagge">
<createTable tableName="setting_notify">
<column name="login" type="varchar(64)">
<constraints primaryKey="true" nullable="false" deleteCascade="true" references="person(login)"
foreignKeyName="setting_notify_login_person_login"/>
</column>
<column name="start_receiving" type="datetime">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -1,72 +0,0 @@
<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-09-21-create-table-teamcity_project" author="upagge">
<createTable tableName="teamcity_project">
<column name="id" type="varchar(64)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(300)">
<constraints nullable="true"/>
</column>
<column name="description" type="varchar(400)"/>
<column name="url" type="varchar(300)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-20-create-table-teamcity-setting" author="upagge">
<createTable tableName="teamcity_setting">
<column name="id" type="integer" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="chat_id" type="integer">
<constraints nullable="false"/>
</column>
<column name="project_id" type="varchar(64)">
<constraints nullable="false" foreignKeyName="teamcity_setting_project_id_teamcity_project_id"
references="teamcity_project(id)" deleteCascade="true"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-20-create-table-teamcity-build" author="upagge">
<createTable tableName="teamcity_build">
<column name="id" type="integer">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="project_id" type="varchar(64)">
<constraints nullable="false" foreignKeyName="teamcity_build_project_id_teamcity_project_id"
references="teamcity_project(id)" deleteCascade="true"/>
</column>
<column name="number" type="integer"/>
<column name="status" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="state" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="branch_name" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="api_url" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="url" type="varchar(300)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-09-22-add-column-build-type-id" author="upagge">
<addColumn tableName="teamcity_build">
<column name="build_type_id" type="varchar(200)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -1,44 +0,0 @@
<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-10-01-create-table-rating-history" author="upagge">
<createTable tableName="rating_history">
<column name="id" type="integer" autoIncrement="true">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="rating_history_login_person_login"
references="person(login)"/>
</column>
<column name="points" type="integer">
<constraints nullable="false"/>
</column>
<column name="type" type="varchar(64)"/>
<column name="date_add" type="datetime">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-10-01-create-table-rating-list" author="upagge">
<createTable tableName="rating_list">
<column name="login" type="varchar(64)">
<constraints nullable="false" foreignKeyName="rating_list_login_person_login"
references="person(login)"/>
</column>
<column name="number" type="integer">
<constraints nullable="false" unique="true"/>
</column>
<column name="points" type="integer">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="2020-10-01-delete-unique" author="upagge">
<dropUniqueConstraint tableName="rating_list" constraintName="rating_list_number_key"/>
</changeSet>
</databaseChangeLog>

View File

@ -1,19 +0,0 @@
<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-10-02" author="upagge">
<addColumn tableName="teamcity_setting">
<column name="success" type="boolean">
<constraints nullable="false"/>
</column>
</addColumn>
<addColumn tableName="teamcity_setting">
<column name="failure" type="boolean">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -1,12 +0,0 @@
<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-10-07" author="upagge">
<addColumn tableName="reviewer">
<column name="date_change" type="datetime"/>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -1,12 +0,0 @@
<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-10-11-add-column-reviewer" author="upagge">
<addColumn tableName="reviewer">
<column name="date_smart_notify" type="datetime"/>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -1,40 +0,0 @@
<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-10-11-drop-column-teamcity-setting-chat-id" author="upagge">
<dropColumn tableName="teamcity_setting" columnName="chat_id"/>
</changeSet>
<changeSet id="2020-10-11-create-table-chat" author="upagge">
<createTable tableName="chat">
<column name="key" type="varchar(64)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="telegram_id" type="int">
<constraints unique="true" nullable="false"/>
</column>
<column name="description" type="varchar(200)"/>
</createTable>
</changeSet>
<changeSet id="2020-10-11-add-column-teamcity" author="upagge">
<addColumn tableName="teamcity_setting">
<column name="build_type_id" type="varchar(200)"/>
</addColumn>
<addColumn tableName="teamcity_setting">
<column name="recipient_id" type="varchar(64)">
<constraints nullable="false"/>
</column>
</addColumn>
<addColumn tableName="teamcity_setting">
<column name="recipient_type" type="varchar(20)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -1,20 +0,0 @@
<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-10-31-add-columns-pull-request" author="upagge">
<addColumn tableName="pull_request">
<column name="resolved_task_count" type="integer">
<constraints nullable="false"/>
</column>
<column name="comment_count" type="integer">
<constraints nullable="false"/>
</column>
<column name="open_task_count" type="integer">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -3,11 +3,10 @@ package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table;
/** /**
* // TODO: 11.10.2020 Добавить описание. * // TODO: 11.10.2020 Добавить описание.
@ -16,17 +15,24 @@ import javax.persistence.Table;
*/ */
@Getter @Getter
@Setter @Setter
@Entity //@Entity
@Table(name = "chat") //@Table(name = "chat")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Chat { public class Chat extends BasicEntity<String> {
@Id
@Column(name = "key")
@EqualsAndHashCode.Include
private String key;
@Column(name = "telegram_id") @Column(name = "telegram_id")
private Long telegramId; private Long telegramId;
@Override
@Id
@Column(name = "key")
@EqualsAndHashCode.Include
public String getId() {
return super.getId();
}
@Override
public void setId(String id) {
super.setId(id);
}
} }

View File

@ -3,32 +3,23 @@ package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Set; import java.util.Set;
@Getter @Getter
@Setter @Setter
@Entity //@Entity
@Table(name = "comment") //@Table(name = "comment")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class Comment { public class Comment extends BasicEntity<Long> {
/**
* Идентификатор
*/
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
private Long id;
@Column(name = "url_api") @Column(name = "url_api")
private String urlApi; private String urlApi;
@ -62,4 +53,16 @@ public class Comment {
@Column(name = "child_id") @Column(name = "child_id")
private Set<Long> answers; private Set<Long> answers;
@Override
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
} }

View File

@ -3,11 +3,10 @@ package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -17,18 +16,10 @@ import java.time.LocalDateTime;
*/ */
@Getter @Getter
@Setter @Setter
@Entity //@Entity
@Table(name = "setting_notify") //@Table(name = "setting_notify")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class NotifySetting { public class NotifySetting extends BasicEntity<String> {
/**
* Логин пользователя, которому принадлежат настройки
*/
@Id
@Column(name = "login")
@EqualsAndHashCode.Include
private String login;
/** /**
* Дата, после которой пользователю будут поступать уведомления. * Дата, после которой пользователю будут поступать уведомления.
@ -36,4 +27,16 @@ public class NotifySetting {
@Column(name = "start_receiving") @Column(name = "start_receiving")
private LocalDateTime startReceiving; private LocalDateTime startReceiving;
@Override
@Id
@Column(name = "login")
@EqualsAndHashCode.Include
public String getId() {
return super.getId();
}
@Override
public void setId(String id) {
super.setId(id);
}
} }

View File

@ -0,0 +1,49 @@
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.Table;
import java.time.LocalDateTime;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Getter
@Setter
@Entity
@Table(name = "project")
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class Project extends BasicEntity<Long> {
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "created_date")
private LocalDateTime createdDate;
@Column(name = "creator_id")
private Integer creatorId;
@Id
@Column(name = "id")
@Override
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
}

View File

@ -4,10 +4,10 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
@ -15,7 +15,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -27,19 +26,10 @@ import java.util.List;
*/ */
@Getter @Getter
@Setter @Setter
@Entity //@Entity
@Table(name = "pull_request") //@Table(name = "pull_request")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class PullRequest { public class PullRequest extends BasicEntity<Long> {
/**
* Идентификатор
*/
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;
/** /**
* Идентификатор на стороне битбакета * Идентификатор на стороне битбакета
@ -140,4 +130,17 @@ public class PullRequest {
this.reviewers = reviewers; this.reviewers = reviewers;
} }
@Id
@Override
@Column(name = "id")
@EqualsAndHashCode.Include
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
} }

View File

@ -5,11 +5,9 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table;
/** /**
* // TODO: 12.09.2020 Добавить описание. * // TODO: 12.09.2020 Добавить описание.
@ -18,8 +16,8 @@ import javax.persistence.Table;
*/ */
@Getter @Getter
@Setter @Setter
@Entity //@Entity
@Table(name = "pull_request") //@Table(name = "pull_request")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class PullRequestMini { public class PullRequestMini {

View File

@ -7,7 +7,6 @@ import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
@ -16,7 +15,6 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -24,10 +22,10 @@ import java.time.LocalDateTime;
* *
* @author upagge [01.02.2020] * @author upagge [01.02.2020]
*/ */
@Entity //@Entity
@Getter @Getter
@Setter @Setter
@Table(name = "reviewer") //@Table(name = "reviewer")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Reviewer { public class Reviewer {

View File

@ -4,35 +4,26 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.bot.gitlab.context.domain.TaskStatus; import org.sadtech.bot.gitlab.context.domain.TaskStatus;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.Table;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@Entity //@Entity
@Getter @Getter
@Setter @Setter
@Table(name = "task") //@Table(name = "task")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class Task { public class Task extends BasicEntity<Long> {
/**
* Идентификатор
*/
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
private Long id;
/** /**
* Описание задачи * Описание задачи
@ -73,4 +64,16 @@ public class Task {
@Column(name = "comment_id") @Column(name = "comment_id")
private Set<Long> answers = new HashSet<>(); private Set<Long> answers = new HashSet<>();
@Override
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
} }

View File

@ -0,0 +1,13 @@
package org.sadtech.bot.gitlab.context.repository;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
public interface ProjectRepository extends SimpleManagerRepository<Project, Long> {
}

View File

@ -0,0 +1,14 @@
package org.sadtech.bot.gitlab.context.service;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.haiti.context.service.SimpleManagerService;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
public interface ProjectService extends SimpleManagerService<Project, Long> {
}

View File

@ -42,4 +42,6 @@ public class GitlabProperty {
*/ */
private String urlPullRequest; private String urlPullRequest;
private String urlProject;
} }

View File

@ -1,98 +1,70 @@
package org.sadtech.bot.gitlab.core.scheduler; package org.sadtech.bot.gitlab.core.scheduler;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.EntityType;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.domain.notify.GoodMorningNotify;
import org.sadtech.bot.gitlab.context.domain.notify.SimpleTextNotify;
import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.gitlab.context.utils.Smile;
import org.sadtech.bot.gitlab.core.config.properties.AppProperty;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class NotificationScheduler { public class NotificationScheduler {
//
private static final Set<String> tksLoginNotify = new HashSet<>(Arrays.asList( // private final PullRequestsService pullRequestsService;
"mstruchkov", "emukhin", "imescheryakov", "kkeglev" // private final NotifyService notifyService;
)); // private final AppProperty appProperty;
//
private final PullRequestsService pullRequestsService; // // Утреннее сообщение
// @Scheduled(cron = "0 15 8 * * MON-FRI")
private final NotifyService notifyService; // public void goodMorning() {
// List<Person> allRegister = personService.getAllRegister();
private final AppProperty appProperty; // for (Person user : allRegister) {
// List<PullRequest> pullRequestsReviews = pullRequestsService.getAllByReviewerAndStatuses(
// Утреннее сообщение // user.getLogin(),
@Scheduled(cron = "0 15 8 * * MON-FRI") // ReviewerStatus.NEEDS_WORK,
public void goodMorning() { // Collections.singleton(PullRequestStatus.OPEN)
List<Person> allRegister = personService.getAllRegister(); // );
for (Person user : allRegister) { // List<PullRequest> pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED);
List<PullRequest> pullRequestsReviews = pullRequestsService.getAllByReviewerAndStatuses( // notifyService.send(
user.getLogin(), // GoodMorningNotify.builder()
ReviewerStatus.NEEDS_WORK, // .personName(user.getFullName())
Collections.singleton(PullRequestStatus.OPEN) // .pullRequestsNeedWork(pullRequestsNeedWork)
); // .pullRequestsReviews(pullRequestsReviews)
List<PullRequest> pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED); // .recipients(Collections.singleton(user.getLogin()))
notifyService.send( // .version(appProperty.getVersion())
GoodMorningNotify.builder() // .build()
.personName(user.getFullName()) // );
.pullRequestsNeedWork(pullRequestsNeedWork) // }
.pullRequestsReviews(pullRequestsReviews) // }
.recipients(Collections.singleton(user.getLogin())) //
.version(appProperty.getVersion()) // @Scheduled(cron = "0 44 10 * * MON-FRI")
.build() // public void tks() {
); // notifyService.send(
} // SimpleTextNotify
} // .builder()
// .recipients(
@Scheduled(cron = "0 44 10 * * MON-FRI") // usersTks.stream()
public void tks() { // .map(Person::getLogin)
List<Person> usersTks = personService.getAllRegister().stream() // .collect(Collectors.toSet())
.filter(user -> tksLoginNotify.contains(user.getLogin())) // )
.collect(Collectors.toList()); // .message("☎️ Внимание созвон" + Smile.HR + "https://meet.google.com/avj-cdyy-enu")
notifyService.send( // .build()
SimpleTextNotify // );
.builder() // }
.recipients( //
usersTks.stream() // @Scheduled(cron = "0 0 18 * * FRI")
.map(Person::getLogin) // public void goodWeekEnd() {
.collect(Collectors.toSet()) // List<Person> allRegister = personService.getAllRegister();
) // notifyService.send(
.message("☎️ Внимание созвон" + Smile.HR + "https://meet.google.com/avj-cdyy-enu") // SimpleTextNotify.builder()
.build() // .entityType(EntityType.PERSON)
); // .message("Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR +
// "До понедельника" + Smile.BUY + Smile.TWO_BR)
} // .recipients(
// allRegister.stream()
@Scheduled(cron = "0 0 18 * * FRI") // .map(Person::getLogin)
public void goodWeekEnd() { // .collect(Collectors.toSet())
List<Person> allRegister = personService.getAllRegister(); // )
notifyService.send( // .build()
SimpleTextNotify.builder() // );
.entityType(EntityType.PERSON) // }
.message("Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR +
"До понедельника" + Smile.BUY + Smile.TWO_BR)
.recipients(
allRegister.stream()
.map(Person::getLogin)
.collect(Collectors.toSet())
)
.build()
);
}
} }

View File

@ -4,7 +4,6 @@ import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.repository.ChatRepository; import org.sadtech.bot.gitlab.context.repository.ChatRepository;
import org.sadtech.bot.gitlab.context.service.ChatService; import org.sadtech.bot.gitlab.context.service.ChatService;
import org.springframework.stereotype.Service;
import java.util.Set; import java.util.Set;
@ -13,7 +12,7 @@ import java.util.Set;
* *
* @author upagge 11.10.2020 * @author upagge 11.10.2020
*/ */
@Service //@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class ChatServiceImpl implements ChatService { public class ChatServiceImpl implements ChatService {

View File

@ -2,7 +2,6 @@ package org.sadtech.bot.gitlab.core.service.impl;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.Answer; import org.sadtech.bot.gitlab.context.domain.Answer;
import org.sadtech.bot.gitlab.context.domain.PointType;
import org.sadtech.bot.gitlab.context.domain.entity.Comment; 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.entity.Task;
import org.sadtech.bot.gitlab.context.domain.notify.comment.AnswerCommentNotify; import org.sadtech.bot.gitlab.context.domain.notify.comment.AnswerCommentNotify;
@ -12,13 +11,14 @@ import org.sadtech.bot.gitlab.context.repository.CommentRepository;
import org.sadtech.bot.gitlab.context.service.CommentService; import org.sadtech.bot.gitlab.context.service.CommentService;
import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.TaskService; 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.service.AbstractSimpleManagerService;
import org.sadtech.haiti.core.util.Assert; import org.sadtech.haiti.core.util.Assert;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -27,7 +27,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service //@Service
public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Long> implements CommentService { public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Long> implements CommentService {
private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); private static final Pattern PATTERN = Pattern.compile("@[\\w]+");
@ -35,7 +35,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
private final CommentRepository commentRepository; private final CommentRepository commentRepository;
private final NotifyService notifyService; private final NotifyService notifyService;
private final TaskService taskService; private final TaskService taskService;
private final RatingService ratingService;
private final ConversionService conversionService; private final ConversionService conversionService;
@ -43,14 +42,12 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
CommentRepository commentRepository, CommentRepository commentRepository,
NotifyService notifyService, NotifyService notifyService,
@Lazy TaskService taskService, @Lazy TaskService taskService,
RatingService ratingService,
ConversionService conversionService ConversionService conversionService
) { ) {
super(commentRepository); super(commentRepository);
this.commentRepository = commentRepository; this.commentRepository = commentRepository;
this.notifyService = notifyService; this.notifyService = notifyService;
this.taskService = taskService; this.taskService = taskService;
this.ratingService = ratingService;
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@ -69,15 +66,10 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
Assert.isNotNull(comment.getId(), "При создании объекта должен быть установлен идентификатор"); Assert.isNotNull(comment.getId(), "При создании объекта должен быть установлен идентификатор");
comment.getAnswers().clear(); comment.getAnswers().clear();
final Comment newComment = commentRepository.save(comment); final Comment newComment = commentRepository.save(comment);
ratingCreateComment(comment.getAuthor());
notificationPersonal(comment); notificationPersonal(comment);
return newComment; return newComment;
} }
private void ratingCreateComment(String author) {
ratingService.addRating(author, PointType.COMMENT_ADD, PointType.COMMENT_ADD.getPoints());
}
private void notificationPersonal(@NonNull Comment comment) { private void notificationPersonal(@NonNull Comment comment) {
Matcher matcher = PATTERN.matcher(comment.getMessage()); Matcher matcher = PATTERN.matcher(comment.getMessage());
Set<String> recipientsLogins = new HashSet<>(); Set<String> recipientsLogins = new HashSet<>();
@ -118,9 +110,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
public Comment convert(@NonNull Task task) { public Comment convert(@NonNull Task task) {
taskService.deleteById(task.getId()); taskService.deleteById(task.getId());
final Comment comment = conversionService.convert(task, Comment.class); final Comment comment = conversionService.convert(task, Comment.class);
final Comment newComment = commentRepository.save(comment); return commentRepository.save(comment);
ratingService.addRating(newComment.getAuthor(), PointType.COMMENT_ADD, PointType.COMMENT_ADD.getPoints());
return newComment;
} }
@Override @Override
@ -156,10 +146,8 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
} }
@Override @Override
public void deleteById(@NonNull Long id) { public ExistsContainer<Comment, Long> existsById(@NonNull Collection<Long> collection) {
final Comment comment = commentRepository.findById(id) return null;
.orElseThrow(() -> new NotFoundException("Комментарий не найден"));
ratingService.addRating(comment.getAuthor(), PointType.COMMENT_DELETE, PointType.COMMENT_DELETE.getPoints());
super.deleteById(id);
} }
} }

View File

@ -8,12 +8,11 @@ import org.sadtech.bot.gitlab.context.domain.notify.Notify;
import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository; import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository;
import org.sadtech.bot.gitlab.context.service.MessageSendService; import org.sadtech.bot.gitlab.context.service.MessageSendService;
import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.springframework.stereotype.Service;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@Service //@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class NotifyServiceImpl implements NotifyService { public class NotifyServiceImpl implements NotifyService {

View File

@ -0,0 +1,36 @@
package org.sadtech.bot.gitlab.core.service.impl;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.bot.gitlab.context.repository.ProjectRepository;
import org.sadtech.bot.gitlab.context.service.ProjectService;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.springframework.stereotype.Service;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Service
public class ProjectServiceImpl extends AbstractSimpleManagerService<Project, Long> implements ProjectService {
private final ProjectRepository projectRepository;
public ProjectServiceImpl(SimpleManagerRepository<Project, Long> repository, ProjectRepository projectRepository) {
super(repository);
this.projectRepository = projectRepository;
}
@Override
public Project create(@NonNull Project project) {
return projectRepository.save(project);
}
@Override
public Project update(@NonNull Project project) {
return projectRepository.save(project);
}
}

View File

@ -2,7 +2,6 @@ package org.sadtech.bot.gitlab.core.service.impl;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.PointType;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini;
import org.sadtech.bot.gitlab.context.domain.entity.Reviewer; import org.sadtech.bot.gitlab.context.domain.entity.Reviewer;
@ -21,6 +20,7 @@ import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus; import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.context.page.Pagination; import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
@ -29,10 +29,10 @@ import org.sadtech.haiti.filter.FilterService;
import org.sadtech.haiti.filter.criteria.CriteriaFilter; import org.sadtech.haiti.filter.criteria.CriteriaFilter;
import org.sadtech.haiti.filter.criteria.CriteriaQuery; import org.sadtech.haiti.filter.criteria.CriteriaQuery;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -40,29 +40,23 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service //@Service
public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRequest, Long> implements PullRequestsService { public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRequest, Long> implements PullRequestsService {
protected final NotifyService notifyService; protected final NotifyService notifyService;
protected final PullRequestsRepository pullRequestsRepository; protected final PullRequestsRepository pullRequestsRepository;
protected final RatingService ratingService;
protected final FilterService<PullRequest, PullRequestFilter> filterService; protected final FilterService<PullRequest, PullRequestFilter> filterService;
protected final RatingProperty ratingProperty;
protected PullRequestsServiceImpl( protected PullRequestsServiceImpl(
PullRequestsRepository pullRequestsRepository, PullRequestsRepository pullRequestsRepository,
NotifyService notifyService, NotifyService notifyService,
RatingService ratingService, @Qualifier("pullRequestFilterService") FilterService<PullRequest, PullRequestFilter> pullRequestsFilterService
@Qualifier("pullRequestFilterService") FilterService<PullRequest, PullRequestFilter> pullRequestsFilterService,
RatingProperty ratingProperty
) { ) {
super(pullRequestsRepository); super(pullRequestsRepository);
this.notifyService = notifyService; this.notifyService = notifyService;
this.pullRequestsRepository = pullRequestsRepository; this.pullRequestsRepository = pullRequestsRepository;
this.ratingService = ratingService;
this.filterService = pullRequestsFilterService; this.filterService = pullRequestsFilterService;
this.ratingProperty = ratingProperty;
} }
@Override @Override
@ -75,8 +69,6 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
final PullRequest newPullRequest = pullRequestsRepository.save(pullRequest); final PullRequest newPullRequest = pullRequestsRepository.save(pullRequest);
addRatingCreate(newPullRequest.getAuthorLogin());
notifyService.send( notifyService.send(
NewPrNotify.builder() NewPrNotify.builder()
.author(newPullRequest.getAuthorLogin()) .author(newPullRequest.getAuthorLogin())
@ -96,12 +88,6 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
return newPullRequest; return newPullRequest;
} }
protected void addRatingCreate(@NonNull String login) {
if (ratingProperty.isEnabled()) {
ratingService.addRating(login, PointType.CREATE_PULL_REQUEST, PointType.CREATE_PULL_REQUEST.getPoints());
}
}
@Override @Override
public PullRequest update(@NonNull PullRequest pullRequest) { public PullRequest update(@NonNull PullRequest pullRequest) {
final PullRequest oldPullRequest = findAndFillId(pullRequest); final PullRequest oldPullRequest = findAndFillId(pullRequest);
@ -190,7 +176,6 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
final PullRequestStatus oldStatus = oldPullRequest.getStatus(); final PullRequestStatus oldStatus = oldPullRequest.getStatus();
final PullRequestStatus newStatus = newPullRequest.getStatus(); final PullRequestStatus newStatus = newPullRequest.getStatus();
if (!oldStatus.equals(newStatus)) { if (!oldStatus.equals(newStatus)) {
ratingStatus(oldPullRequest, newPullRequest);
notifyService.send( notifyService.send(
StatusPrNotify.builder() StatusPrNotify.builder()
.name(newPullRequest.getTitle()) .name(newPullRequest.getTitle())
@ -206,23 +191,6 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
} }
} }
protected void ratingStatus(PullRequest oldPullRequest, PullRequest newPullRequest) {
if (ratingProperty.isEnabled()) {
final String authorLogin = oldPullRequest.getAuthorLogin();
switch (newPullRequest.getStatus()) {
case OPEN:
ratingService.addRating(authorLogin, PointType.CREATE_PULL_REQUEST, PointType.CREATE_PULL_REQUEST.getPoints());
break;
case MERGED:
// TODO: 01.10.2020 Нужно продумать как расчитывать баллы при мерже.
break;
case DECLINED:
ratingService.addRating(authorLogin, PointType.DECLINE_PULL_REQUEST, PointType.DECLINE_PULL_REQUEST.getPoints());
break;
}
}
}
protected void updateReviewers(PullRequest oldPullRequest, PullRequest newPullRequest) { protected void updateReviewers(PullRequest oldPullRequest, PullRequest newPullRequest) {
final Map<String, Reviewer> oldReviewers = oldPullRequest.getReviewers().stream() final Map<String, Reviewer> oldReviewers = oldPullRequest.getReviewers().stream()
.collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer)); .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer));
@ -354,4 +322,9 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
).orElseThrow(() -> new UpdateException("ПР с таким id не существует")); ).orElseThrow(() -> new UpdateException("ПР с таким id не существует"));
} }
@Override
public ExistsContainer<PullRequest, Long> existsById(@NonNull Collection<Long> collection) {
return null;
}
} }

View File

@ -2,7 +2,6 @@ package org.sadtech.bot.gitlab.core.service.impl;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.Answer; import org.sadtech.bot.gitlab.context.domain.Answer;
import org.sadtech.bot.gitlab.context.domain.PointType;
import org.sadtech.bot.gitlab.context.domain.TaskStatus; 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.Comment;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
@ -17,12 +16,13 @@ import org.sadtech.bot.gitlab.context.service.CommentService;
import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.gitlab.context.service.TaskService; 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.service.AbstractSimpleManagerService;
import org.sadtech.haiti.core.util.Assert; import org.sadtech.haiti.core.util.Assert;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -31,7 +31,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service //@Service
public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> implements TaskService { public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> implements TaskService {
private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); private static final Pattern PATTERN = Pattern.compile("@[\\w]+");
@ -41,7 +41,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
private final PullRequestsService pullRequestsService; private final PullRequestsService pullRequestsService;
private final NotifyService notifyService; private final NotifyService notifyService;
private final CommentService commentService; private final CommentService commentService;
private final RatingService ratingService;
private final ConversionService conversionService; private final ConversionService conversionService;
@ -50,7 +49,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
PullRequestsService pullRequestsService, PullRequestsService pullRequestsService,
NotifyService notifyService, NotifyService notifyService,
CommentService commentService, CommentService commentService,
RatingService ratingService,
ConversionService conversionService ConversionService conversionService
) { ) {
super(taskRepository); super(taskRepository);
@ -58,7 +56,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
this.pullRequestsService = pullRequestsService; this.pullRequestsService = pullRequestsService;
this.notifyService = notifyService; this.notifyService = notifyService;
this.commentService = commentService; this.commentService = commentService;
this.ratingService = ratingService;
this.conversionService = conversionService; this.conversionService = conversionService;
} }
@ -69,7 +66,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
final Task newTask = taskRepository.save(task); final Task newTask = taskRepository.save(task);
notifyNewTask(task); notifyNewTask(task);
notificationPersonal(task); notificationPersonal(task);
ratingCreateTask(task.getAuthor(), task.getResponsible());
return newTask; return newTask;
} }
@ -204,19 +200,12 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
@Override @Override
public void deleteById(@NonNull Long id) { public void deleteById(@NonNull Long id) {
final Task task = taskRepository.findById(id).orElseThrow(() -> new NotFoundException("Задача не найдена"));
ratingDeleteTask(task.getAuthor(), task.getResponsible());
super.deleteById(id); super.deleteById(id);
} }
private void ratingCreateTask(String authorLogin, String responsibleLogin) { @Override
ratingService.addRating(authorLogin, PointType.TASK_CREATE, PointType.TASK_CREATE.getPoints()); public ExistsContainer<Task, Long> existsById(@NonNull Collection<Long> collection) {
ratingService.addRating(responsibleLogin, PointType.TASK_RECIPIENT, PointType.TASK_RECIPIENT.getPoints()); return null;
}
private void ratingDeleteTask(String authorLogin, String responsibleLogin) {
ratingService.addRating(authorLogin, PointType.TASK_DELETE, PointType.TASK_DELETE.getPoints());
ratingService.addRating(responsibleLogin, PointType.TASK_DELETE_RECIPIENT, PointType.TASK_DELETE_RECIPIENT.getPoints());
} }
} }

View File

@ -9,9 +9,8 @@ import org.sadtech.haiti.filter.Filter;
import org.sadtech.haiti.filter.FilterQuery; import org.sadtech.haiti.filter.FilterQuery;
import org.sadtech.haiti.filter.criteria.CriteriaFilter; import org.sadtech.haiti.filter.criteria.CriteriaFilter;
import org.sadtech.haiti.filter.criteria.CriteriaQuery; import org.sadtech.haiti.filter.criteria.CriteriaQuery;
import org.springframework.stereotype.Service;
@Service //@Service
public class PullRequestFilterService extends AbstractFilterService<PullRequest, PullRequestFilter> { public class PullRequestFilterService extends AbstractFilterService<PullRequest, PullRequestFilter> {
public PullRequestFilterService(PullRequestsRepository filterOperation) { public PullRequestFilterService(PullRequestsRepository filterOperation) {

View File

@ -5,7 +5,6 @@ import org.sadtech.bot.gitlab.context.domain.entity.Chat;
import org.sadtech.bot.gitlab.context.repository.ChatRepository; import org.sadtech.bot.gitlab.context.repository.ChatRepository;
import org.sadtech.bot.gitlab.data.jpa.ChatJpaRepository; import org.sadtech.bot.gitlab.data.jpa.ChatJpaRepository;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.springframework.stereotype.Repository;
import java.util.Set; import java.util.Set;
@ -14,7 +13,7 @@ import java.util.Set;
* *
* @author upagge 11.10.2020 * @author upagge 11.10.2020
*/ */
@Repository //@Repository
public class ChatRepositoryImpl extends AbstractSimpleManagerRepository<Chat, String> implements ChatRepository { public class ChatRepositoryImpl extends AbstractSimpleManagerRepository<Chat, String> implements ChatRepository {
private final ChatJpaRepository jpaRepository; private final ChatJpaRepository jpaRepository;

View File

@ -5,7 +5,6 @@ import org.sadtech.bot.gitlab.context.domain.entity.Comment;
import org.sadtech.bot.gitlab.context.repository.CommentRepository; import org.sadtech.bot.gitlab.context.repository.CommentRepository;
import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa; import org.sadtech.bot.gitlab.data.jpa.CommentRepositoryJpa;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -17,7 +16,7 @@ import java.util.Set;
* *
* @author upagge 08.09.2020 * @author upagge 08.09.2020
*/ */
@Repository //@Repository
public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Comment, Long> implements CommentRepository { public class CommentRepositoryImpl extends AbstractSimpleManagerRepository<Comment, Long> implements CommentRepository {
private final CommentRepositoryJpa repositoryJpa; private final CommentRepositoryJpa repositoryJpa;

View File

@ -5,7 +5,6 @@ import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting;
import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository; import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository;
import org.sadtech.bot.gitlab.data.jpa.NotifySettingJpaRepository; import org.sadtech.bot.gitlab.data.jpa.NotifySettingJpaRepository;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Set; import java.util.Set;
@ -15,7 +14,7 @@ import java.util.Set;
* *
* @author upagge 20.09.2020 * @author upagge 20.09.2020
*/ */
@Repository //@Repository
public class NotifySettingRepositoryImpl extends AbstractSimpleManagerRepository<NotifySetting, String> implements NotifySettingRepository { public class NotifySettingRepositoryImpl extends AbstractSimpleManagerRepository<NotifySetting, String> implements NotifySettingRepository {
private final NotifySettingJpaRepository jpaRepository; private final NotifySettingJpaRepository jpaRepository;

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.gitlab.data.impl;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.bot.gitlab.context.repository.ProjectRepository;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Repository
public class ProjectRepositoryImpl extends AbstractSimpleManagerRepository<Project, Long> implements ProjectRepository {
public ProjectRepositoryImpl(JpaRepository<Project, Long> jpaRepository) {
super(jpaRepository);
}
}

View File

@ -10,13 +10,12 @@ import org.sadtech.bot.gitlab.data.jpa.PullRequestsRepositoryJpa;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus; import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.haiti.database.repository.manager.FilterManagerRepository; import org.sadtech.haiti.database.repository.manager.FilterManagerRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@Repository //@Repository
public class PullRequestsRepositoryImpl extends FilterManagerRepository<PullRequest, Long> implements PullRequestsRepository { public class PullRequestsRepositoryImpl extends FilterManagerRepository<PullRequest, Long> implements PullRequestsRepository {
private final PullRequestsRepositoryJpa repositoryJpa; private final PullRequestsRepositoryJpa repositoryJpa;

View File

@ -6,13 +6,12 @@ import org.sadtech.bot.gitlab.context.domain.entity.Task;
import org.sadtech.bot.gitlab.context.repository.TaskRepository; import org.sadtech.bot.gitlab.context.repository.TaskRepository;
import org.sadtech.bot.gitlab.data.jpa.TaskRepositoryJpa; import org.sadtech.bot.gitlab.data.jpa.TaskRepositoryJpa;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@Repository //@Repository
public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Long> implements TaskRepository { public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Long> implements TaskRepository {
private final TaskRepositoryJpa taskRepositoryJpa; private final TaskRepositoryJpa taskRepositoryJpa;

View File

@ -2,7 +2,7 @@ package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.Chat; import org.sadtech.bot.gitlab.context.domain.entity.Chat;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.Set; import java.util.Set;
@ -12,9 +12,10 @@ import java.util.Set;
* *
* @author upagge 11.10.2020 * @author upagge 11.10.2020
*/ */
@NoRepositoryBean
public interface ChatJpaRepository extends JpaRepository<Chat, String> { public interface ChatJpaRepository extends JpaRepository<Chat, String> {
@Query("SELECT c.telegramId FROM Chat c WHERE c.key IN :keys AND c.telegramId IS NOT NULL") // @Query("SELECT c.telegramId FROM Chat c WHERE c.key IN :keys AND c.telegramId IS NOT NULL")
Set<Long> findAllTelegramIdByKey(@Param("keys") Set<String> keys); Set<Long> findAllTelegramIdByKey(@Param("keys") Set<String> keys);
} }

View File

@ -3,20 +3,21 @@ package org.sadtech.bot.gitlab.data.jpa;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.Comment; import org.sadtech.bot.gitlab.context.domain.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.NoRepositoryBean;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@NoRepositoryBean
public interface CommentRepositoryJpa extends JpaRepository<Comment, Long> { public interface CommentRepositoryJpa extends JpaRepository<Comment, Long> {
Optional<Comment> findFirstByOrderByIdDesc(); Optional<Comment> findFirstByOrderByIdDesc();
List<Comment> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); List<Comment> 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); Set<Long> existsAllById(@NonNull Set<Long> ids);
} }

View File

@ -2,7 +2,7 @@ package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -13,11 +13,13 @@ import java.util.Set;
* *
* @author upagge 20.09.2020 * @author upagge 20.09.2020
*/ */
@NoRepositoryBean
public interface NotifySettingJpaRepository extends JpaRepository<NotifySetting, String> { public interface NotifySettingJpaRepository extends JpaRepository<NotifySetting, String> {
boolean findByLoginAndStartReceivingAfter(String login, LocalDateTime date); boolean findByLoginAndStartReceivingAfter(String login, LocalDateTime date);
@Query("SELECT n.login FROM NotifySetting n WHERE n.login IN :logins AND n.startReceiving < :date") // @Query("SELECT n.login FROM NotifySetting n WHERE n.login IN :logins AND n.startReceiving < :date")
Set<String> findAllByLoginInAndStartReceivingAfter(@Param("logins") Set<String> logins, @Param("date") LocalDateTime date); Set<String> findAllByLoginInAndStartReceivingAfter(@Param("logins") Set<String> logins, @Param("date") LocalDateTime date);
} }

View File

@ -0,0 +1,13 @@
package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
public interface ProjectJpaRepository extends JpaRepository<Project, Long> {
}

View File

@ -2,12 +2,15 @@ package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
/** /**
* // TODO: 12.09.2020 Добавить описание. * // TODO: 12.09.2020 Добавить описание.
* *
* @author upagge 12.09.2020 * @author upagge 12.09.2020
*/ */
@NoRepositoryBean
public interface PullRequestMiniRepositoryJpa extends JpaRepository<PullRequestMini, Long> { public interface PullRequestMiniRepositoryJpa extends JpaRepository<PullRequestMini, Long> {
} }

View File

@ -4,8 +4,8 @@ import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus; import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.Collection; import java.util.Collection;
@ -16,30 +16,32 @@ import java.util.Set;
/** /**
* @author upagge [31.01.2020] * @author upagge [31.01.2020]
*/ */
@NoRepositoryBean
public interface PullRequestsRepositoryJpa extends JpaRepositoryImplementation<PullRequest, Long> { public interface PullRequestsRepositoryJpa extends JpaRepositoryImplementation<PullRequest, Long> {
Set<PullRequest> findAllByIdIn(Set<Long> ids); Set<PullRequest> findAllByIdIn(Set<Long> ids);
Boolean existsByBitbucketIdAndRepositoryId(Long bitbucketId, Long repositoryId); Boolean existsByBitbucketIdAndRepositoryId(Long bitbucketId, Long repositoryId);
@Query("SELECT p.id FROM PullRequest p WHERE p.bitbucketId=:bitbucketId AND p.repositoryId=:repositoryId") // @Query("SELECT p.id FROM PullRequest p WHERE p.bitbucketId=:bitbucketId AND p.repositoryId=:repositoryId")
Optional<Long> findIdByBitbucketIdAndRepositoryId(@Param("bitbucketId") Long bitbucketId, @Param("repositoryId") Long repositoryId); Optional<Long> findIdByBitbucketIdAndRepositoryId(@Param("bitbucketId") Long bitbucketId, @Param("repositoryId") Long repositoryId);
void deleteAllByIdIn(Collection<Long> id); void deleteAllByIdIn(Collection<Long> id);
@Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.personLogin=:reviewer AND r.status =:reviewerStatus AND p.status IN :pullRequestStatus") // @Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.personLogin=:reviewer AND r.status =:reviewerStatus AND p.status IN :pullRequestStatus")
List<PullRequest> findAllByReviewerAndStatuses(@Param("reviewer") String reviewer, @Param("reviewerStatus") ReviewerStatus reviewerStatus, @Param("pullRequestStatus") Set<PullRequestStatus> pullRequestStatus); List<PullRequest> findAllByReviewerAndStatuses(@Param("reviewer") String reviewer, @Param("reviewerStatus") ReviewerStatus reviewerStatus, @Param("pullRequestStatus") Set<PullRequestStatus> pullRequestStatus);
@Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE p.authorLogin=:author AND r.status=:reviewerStatus") // @Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE p.authorLogin=:author AND r.status=:reviewerStatus")
List<PullRequest> findAllByAuthorAndReviewerStatus(@Param("author") String author, @Param("reviewerStatus") ReviewerStatus reviewerStatus); List<PullRequest> findAllByAuthorAndReviewerStatus(@Param("author") String author, @Param("reviewerStatus") ReviewerStatus reviewerStatus);
// @Query("SELECT new org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses") // @Query("SELECT new org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses")
Set<IdAndStatusPr> findAllIdByStatusIn(@Param("statuses") Set<PullRequestStatus> statuses); Set<IdAndStatusPr> findAllIdByStatusIn(@Param("statuses") Set<PullRequestStatus> statuses);
@Query("SELECT p.id from PullRequest p") // @Query("SELECT p.id from PullRequest p")
Set<Long> findAllIds(); Set<Long> findAllIds();
@Query("SELECT p.authorLogin from PullRequest p WHERE p.id = :id") // @Query("SELECT p.authorLogin from PullRequest p WHERE p.id = :id")
Optional<String> findAuthorById(@Param("id") Long id); Optional<String> findAuthorById(@Param("id") Long id);
} }

View File

@ -4,11 +4,13 @@ import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.TaskStatus; import org.sadtech.bot.gitlab.context.domain.TaskStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.domain.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@NoRepositoryBean
public interface TaskRepositoryJpa extends JpaRepository<Task, Long> { public interface TaskRepositoryJpa extends JpaRepository<Task, Long> {
Optional<Task> findFirstByOrderByIdDesc(); Optional<Task> findFirstByOrderByIdDesc();

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.core.service.converter; package org.sadtech.bot.gitalb.core.service.converter;
import org.sadtech.bot.gitlab.context.domain.entity.Comment; import org.sadtech.bot.gitlab.context.domain.entity.Comment;
import org.sadtech.bot.gitlab.core.utils.StringUtils; import org.sadtech.bot.gitlab.core.utils.StringUtils;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.core.service.converter; package org.sadtech.bot.gitalb.core.service.converter;
import org.sadtech.bot.gitlab.context.domain.TaskStatus; import org.sadtech.bot.gitlab.context.domain.TaskStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.domain.entity.Task;

View File

@ -0,0 +1,61 @@
package org.sadtech.bot.gitalb.core.service.converter;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson;
import org.sadtech.bot.gitlab.sdk.domain.Outcome;
import org.sadtech.bot.gitlab.sdk.domain.Properties;
import org.sadtech.bot.gitlab.sdk.domain.PullRequestState;
import org.sadtech.bot.gitlab.sdk.domain.UserPullRequestStatus;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.haiti.context.exception.ConvertException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class PullRequestJsonConverter implements Converter<MergeRequestJson, PullRequest> {
public static PullRequestStatus convertPullRequestStatus(PullRequestState state) {
switch (state) {
case OPENED:
return PullRequestStatus.OPEN;
case MERGED:
return PullRequestStatus.MERGED;
case DECLINED:
return PullRequestStatus.DECLINED;
default:
throw new ConvertException("Неподдерживаемый тип ПР");
}
}
private static ReviewerStatus convertStatusReviewer(UserPullRequestStatus status) {
switch (status) {
case APPROVED:
return ReviewerStatus.APPROVED;
case NEEDS_WORK:
return ReviewerStatus.UNAPPROVED;
case UNAPPROVED:
return ReviewerStatus.NEEDS_WORK;
default:
throw new ConvertException("Неподдерживаемый статус ревьювера");
}
}
@Override
public PullRequest convert(MergeRequestJson json) {
final PullRequest pullRequest = new PullRequest();
return pullRequest;
}
private boolean convertConflict(Properties properties) {
return properties != null
&& properties.getMergeResult() != null
&& properties.getMergeResult().getOutcome() != null
&& Outcome.CONFLICTED.equals(properties.getMergeResult().getOutcome());
}
}

View File

@ -1,96 +0,0 @@
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.domain.entity.Reviewer;
import org.sadtech.bot.gitlab.core.utils.StringUtils;
import org.sadtech.bot.gitlab.sdk.domain.AuthorJson;
import org.sadtech.bot.gitlab.sdk.domain.Outcome;
import org.sadtech.bot.gitlab.sdk.domain.Properties;
import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson;
import org.sadtech.bot.gitlab.sdk.domain.PullRequestState;
import org.sadtech.bot.gitlab.sdk.domain.UserPullRequestStatus;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.haiti.context.exception.ConvertException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class PullRequestJsonConverter implements Converter<PullRequestJson, PullRequest> {
public static PullRequestStatus convertPullRequestStatus(PullRequestState state) {
switch (state) {
case OPENED:
return PullRequestStatus.OPEN;
case MERGED:
return PullRequestStatus.MERGED;
case DECLINED:
return PullRequestStatus.DECLINED;
default:
throw new ConvertException("Неподдерживаемый тип ПР");
}
}
private static ReviewerStatus convertStatusReviewer(UserPullRequestStatus status) {
switch (status) {
case APPROVED:
return ReviewerStatus.APPROVED;
case NEEDS_WORK:
return ReviewerStatus.UNAPPROVED;
case UNAPPROVED:
return ReviewerStatus.NEEDS_WORK;
default:
throw new ConvertException("Неподдерживаемый статус ревьювера");
}
}
@Override
public PullRequest convert(PullRequestJson json) {
final PullRequest pullRequest = new PullRequest();
pullRequest.setBitbucketId(json.getId());
pullRequest.setCreateDate(json.getCreatedDate());
pullRequest.setUpdateDate(json.getUpdatedDate());
pullRequest.setConflict(convertConflict(json.getProperties()));
pullRequest.setDescription(StringUtils.cutOff(json.getDescription(), 180));
pullRequest.setAuthorLogin(json.getAuthor().getUser().getName());
pullRequest.setTitle(StringUtils.cutOff(json.getTitle(), 90));
pullRequest.setUrl(json.getLinks().getSelf().get(0).getHref());
pullRequest.setStatus(convertPullRequestStatus(json.getState()));
pullRequest.setProjectKey(json.getFromRef().getRepository().getProject().getKey());
pullRequest.setRepositorySlug(json.getFromRef().getRepository().getSlug());
pullRequest.setReviewers(convertReviewers(json.getReviewers()));
pullRequest.setBitbucketVersion(json.getVersion());
pullRequest.setRepositoryId(json.getFromRef().getRepository().getId());
pullRequest.setResolvedTaskCount(json.getProperties().getResolvedTaskCount());
pullRequest.setCommentCount(json.getProperties().getCommentCount());
pullRequest.setOpenTaskCount(json.getProperties().getOpenTaskCount());
return pullRequest;
}
private boolean convertConflict(Properties properties) {
return properties != null
&& properties.getMergeResult() != null
&& properties.getMergeResult().getOutcome() != null
&& Outcome.CONFLICTED.equals(properties.getMergeResult().getOutcome());
}
private List<Reviewer> convertReviewers(List<AuthorJson> jsonReviewers) {
return jsonReviewers.stream()
.map(
jsonReviewer -> {
final Reviewer reviewer = new Reviewer();
reviewer.setPersonLogin(jsonReviewer.getUser().getName());
reviewer.setStatus(convertStatusReviewer(jsonReviewer.getStatus()));
return reviewer;
}
)
.collect(Collectors.toList());
}
}

View File

@ -1,18 +0,0 @@
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import org.sadtech.bot.gitlab.sdk.domain.UserJson;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
public class UserJsonConverter implements Converter<UserJson, Person> {
@Override
public Person convert(UserJson source) {
final Person person = new Person();
person.setFullName(source.getDisplayName());
person.setLogin(source.getName());
return person;
}
}

View File

@ -22,6 +22,12 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.12.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.gitlab.sdk.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Data
public class GroupJson {
private Long id;
@JsonProperty("web_url")
private String webUrl;
private String name;
}

View File

@ -13,7 +13,7 @@ import java.time.LocalDateTime;
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Data @Data
public class PullRequestJson { public class MergeRequestJson {
private Long id; private Long id;

View File

@ -1,10 +1,32 @@
package org.sadtech.bot.gitlab.sdk.domain; package org.sadtech.bot.gitlab.sdk.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Data @Data
public class ProjectJson { public class ProjectJson {
private String key; private Long id;
private String name;
private String description;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonProperty("created_at")
private LocalDateTime createdDate;
@JsonProperty("creator_id")
private Integer creatorId;
} }

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain.sheet;
import org.sadtech.bot.gitlab.sdk.domain.Sheet;
import org.sadtech.bot.gitlab.sdk.domain.UserJson;
/**
* TODO: Добавить описание класса.
*
* @author upagge [02.02.2020]
*/
public class UserSheetJson extends Sheet<UserJson> {
}

View File

@ -89,8 +89,8 @@
<gitlab.telegram.version>3.0.1-RELEASE</gitlab.telegram.version> <gitlab.telegram.version>3.0.1-RELEASE</gitlab.telegram.version>
<gitlab.core.version>3.0.1-RELEASE</gitlab.core.version> <gitlab.core.version>3.0.1-RELEASE</gitlab.core.version>
<haiti.context.version>0.0.1-RELEASE</haiti.context.version> <haiti.context.version>0.0.2-SNAPSHOT</haiti.context.version>
<haiti.database.version>0.0.2-RELEASE</haiti.database.version> <haiti.database.version>0.0.3-SNAPSHOT</haiti.database.version>
<haiti.filter.criteria.version>0.0.2-RELEASE</haiti.filter.criteria.version> <haiti.filter.criteria.version>0.0.2-RELEASE</haiti.filter.criteria.version>
<sadtech.bot.telegram.core.version>0.0.1-RELEASE</sadtech.bot.telegram.core.version> <sadtech.bot.telegram.core.version>0.0.1-RELEASE</sadtech.bot.telegram.core.version>
<sadtech.bot.vsc.context.version>0.0.1-RELEASE</sadtech.bot.vsc.context.version> <sadtech.bot.vsc.context.version>0.0.1-RELEASE</sadtech.bot.vsc.context.version>

View File

@ -33,6 +33,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.sadtech.haiti</groupId>
<artifactId>haiti-utils</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -5,6 +5,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.bot.gitlab.teamcity.sdk.BuildState; import org.sadtech.bot.gitlab.teamcity.sdk.BuildState;
import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus; import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -23,12 +24,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "teamcity_build") @Table(name = "teamcity_build")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class BuildShort { public class BuildShort extends BasicEntity<Long> {
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
private Long id;
@Column(name = "project_id") @Column(name = "project_id")
private String projectId; private String projectId;
@ -56,4 +52,16 @@ public class BuildShort {
@Column(name = "url") @Column(name = "url")
private String url; private String url;
@Override
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
} }

View File

@ -3,6 +3,7 @@ package org.sadtech.bot.gitlab.teamcity.core.domain.entity;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -19,12 +20,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "teamcity_project") @Table(name = "teamcity_project")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class TeamcityProject { public class TeamcityProject extends BasicEntity<String> {
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
private String id;
@Column(name = "name") @Column(name = "name")
private String name; private String name;
@ -35,4 +31,16 @@ public class TeamcityProject {
@Column(name = "url") @Column(name = "url")
private String url; private String url;
@Override
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
public String getId() {
return super.getId();
}
@Override
public void setId(String id) {
super.setId(id);
}
} }

View File

@ -4,6 +4,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.EntityType;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -24,13 +25,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(name = "teamcity_setting") @Table(name = "teamcity_setting")
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class TeamcitySetting { public class TeamcitySetting extends BasicEntity<Long> {
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "recipient_id") @Column(name = "recipient_id")
private String recipientId; private String recipientId;
@ -51,4 +46,17 @@ public class TeamcitySetting {
@Column(name = "failure") @Column(name = "failure")
private boolean failure; private boolean failure;
@Override
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return super.getId();
}
@Override
public void setId(Long id) {
super.setId(id);
}
} }

View File

@ -3,29 +3,27 @@ package org.sadtech.bot.gitlab.teamcity.core.scheduler;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.teamcity.core.service.parser.BuildShortParser; import org.sadtech.bot.gitlab.teamcity.core.service.parser.BuildShortParser;
import org.sadtech.bot.gitlab.teamcity.core.service.parser.TeamcityProjectParser; import org.sadtech.bot.gitlab.teamcity.core.service.parser.TeamcityProjectParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/** /**
* // TODO: 21.09.2020 Добавить описание. * // TODO: 21.09.2020 Добавить описание.
* *
* @author upagge 21.09.2020 * @author upagge 21.09.2020
*/ */
@Component //@Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class TeamcityProjectScheduler { public class TeamcityProjectScheduler {
private final TeamcityProjectParser projectParser; private final TeamcityProjectParser projectParser;
private final BuildShortParser buildShortParser; private final BuildShortParser buildShortParser;
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void parseNewProject() { // public void parseNewProject() {
projectParser.parseNewProject(); // projectParser.parseNewProject();
} // }
//
@Scheduled(cron = "0 */1 * * * *") // @Scheduled(cron = "0 */1 * * * *")
public void parseNewBuilds() { // public void parseNewBuilds() {
buildShortParser.parseNewBuilds(); // buildShortParser.parseNewBuilds();
} // }
} }

View File

@ -9,9 +9,10 @@ import org.sadtech.bot.gitlab.teamcity.core.repository.BuildShortRepository;
import org.sadtech.bot.gitlab.teamcity.core.service.BuildShortService; import org.sadtech.bot.gitlab.teamcity.core.service.BuildShortService;
import org.sadtech.bot.gitlab.teamcity.core.service.TeamcitySettingService; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcitySettingService;
import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus; import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -20,7 +21,7 @@ import java.util.Set;
* *
* @author upagge 21.09.2020 * @author upagge 21.09.2020
*/ */
@Service //@Service
public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildShort, Long> implements BuildShortService { public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildShort, Long> implements BuildShortService {
private final TeamcitySettingService teamcitySettingService; private final TeamcitySettingService teamcitySettingService;
@ -76,4 +77,9 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildSho
return buildShortRepository.save(buildShort); return buildShortRepository.save(buildShort);
} }
@Override
public ExistsContainer<BuildShort, Long> existsById(@NonNull Collection<Long> collection) {
return null;
}
} }

View File

@ -4,9 +4,10 @@ import lombok.NonNull;
import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject;
import org.sadtech.bot.gitlab.teamcity.core.repository.TeamcityProjectRepository; import org.sadtech.bot.gitlab.teamcity.core.repository.TeamcityProjectRepository;
import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -15,7 +16,7 @@ import java.util.Set;
* *
* @author upagge 21.09.2020 * @author upagge 21.09.2020
*/ */
@Service //@Service
public class TeamcityProjectServiceImpl extends AbstractSimpleManagerService<TeamcityProject, String> implements TeamcityProjectService { public class TeamcityProjectServiceImpl extends AbstractSimpleManagerService<TeamcityProject, String> implements TeamcityProjectService {
private final TeamcityProjectRepository teamcityProjectRepository; private final TeamcityProjectRepository teamcityProjectRepository;
@ -40,4 +41,9 @@ public class TeamcityProjectServiceImpl extends AbstractSimpleManagerService<Tea
return teamcityProjectRepository.save(teamcityProject); return teamcityProjectRepository.save(teamcityProject);
} }
@Override
public ExistsContainer<TeamcityProject, String> existsById(@NonNull Collection<String> collection) {
return null;
}
} }

View File

@ -4,9 +4,10 @@ import lombok.NonNull;
import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcitySetting; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcitySetting;
import org.sadtech.bot.gitlab.teamcity.core.repository.TeamcitySettingRepository; import org.sadtech.bot.gitlab.teamcity.core.repository.TeamcitySettingRepository;
import org.sadtech.bot.gitlab.teamcity.core.service.TeamcitySettingService; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcitySettingService;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -14,7 +15,7 @@ import java.util.List;
* *
* @author upagge 21.09.2020 * @author upagge 21.09.2020
*/ */
@Service //@Service
public class TeamcitySettingServiceImpl extends AbstractSimpleManagerService<TeamcitySetting, Long> implements TeamcitySettingService { public class TeamcitySettingServiceImpl extends AbstractSimpleManagerService<TeamcitySetting, Long> implements TeamcitySettingService {
private final TeamcitySettingRepository teamcitySettingRepository; private final TeamcitySettingRepository teamcitySettingRepository;
@ -39,4 +40,9 @@ public class TeamcitySettingServiceImpl extends AbstractSimpleManagerService<Tea
return null; return null;
} }
@Override
public ExistsContainer<TeamcitySetting, Long> existsById(@NonNull Collection<Long> collection) {
return null;
}
} }

View File

@ -13,19 +13,22 @@ import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject;
import org.sadtech.bot.gitlab.teamcity.core.service.BuildShortService; import org.sadtech.bot.gitlab.teamcity.core.service.BuildShortService;
import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService;
import org.sadtech.bot.gitlab.teamcity.sdk.BuildShortJson; import org.sadtech.bot.gitlab.teamcity.sdk.BuildShortJson;
import org.sadtech.bot.gitlab.teamcity.sdk.sheet.BuildShortJsonSheet;
import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.core.page.PaginationImpl;
import org.sadtech.haiti.utils.network.HttpHeader;
import org.sadtech.haiti.utils.network.HttpParse;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service 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;
//@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class BuildShortParser { public class BuildShortParser {
@ -42,16 +45,11 @@ public class BuildShortParser {
} }
private void parse(TeamcityProject project) { private void parse(TeamcityProject project) {
final Optional<BuildShortJsonSheet> buildShortJsonSheet = Utils.urlToJson( final List<BuildShortJson> buildShortJsons = HttpParse.request(MessageFormat.format(teamcityProperty.getBuildUrl(), project.getId()))
MessageFormat.format( .header(ACCEPT)
teamcityProperty.getBuildUrl(), .header(HttpHeader.of(AUTHORIZATION, BEARER + teamcityProperty.getToken()))
project.getId() .executeList(BuildShortJson.class);
), if (!buildShortJsons.isEmpty()) {
teamcityProperty.getToken(),
BuildShortJsonSheet.class
);
if (buildShortJsonSheet.isPresent()) {
final List<BuildShortJson> buildShortJsons = buildShortJsonSheet.get().getContent();
final Set<Long> buildIds = buildShortJsons.stream() final Set<Long> buildIds = buildShortJsons.stream()
.map(BuildShortJson::getId) .map(BuildShortJson::getId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());

View File

@ -5,21 +5,24 @@ import org.sadtech.bot.gitlab.teamcity.core.config.property.TeamcityProperty;
import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject;
import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService;
import org.sadtech.bot.gitlab.teamcity.sdk.TeamcityProjectJson; import org.sadtech.bot.gitlab.teamcity.sdk.TeamcityProjectJson;
import org.sadtech.bot.gitlab.teamcity.sdk.sheet.TeamcityProjectJsonSheet; import org.sadtech.haiti.utils.network.HttpHeader;
import org.sadtech.haiti.utils.network.HttpParse;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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;
/** /**
* // TODO: 21.09.2020 Добавить описание. * // TODO: 21.09.2020 Добавить описание.
* *
* @author upagge 21.09.2020 * @author upagge 21.09.2020
*/ */
@Component //@Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class TeamcityProjectParser { public class TeamcityProjectParser {
@ -30,13 +33,13 @@ public class TeamcityProjectParser {
private final ConversionService conversionService; private final ConversionService conversionService;
public void parseNewProject() { public void parseNewProject() {
final Optional<TeamcityProjectJsonSheet> optTeamcityProjectJsonSheet = Utils.urlToJson(
teamcityProperty.getProjectUrl(), final List<TeamcityProjectJson> teamcityProjectJsons = HttpParse.request(teamcityProperty.getProjectUrl())
teamcityProperty.getToken(), .header(ACCEPT)
TeamcityProjectJsonSheet.class .header(HttpHeader.of(AUTHORIZATION, BEARER + teamcityProperty.getToken()))
); .executeList(TeamcityProjectJson.class);
if (optTeamcityProjectJsonSheet.isPresent()) {
final List<TeamcityProjectJson> teamcityProjectJsons = optTeamcityProjectJsonSheet.get().getContent(); if (!teamcityProjectJsons.isEmpty()) {
final Set<String> projectIds = teamcityProjectJsons.stream() final Set<String> projectIds = teamcityProjectJsons.stream()
.map(TeamcityProjectJson::getId) .map(TeamcityProjectJson::getId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());

View File

@ -9,7 +9,7 @@ import org.sadtech.bot.godfather.telegram.listen.EventDistributor;
import org.sadtech.bot.godfather.telegram.listen.EventDistributorImpl; import org.sadtech.bot.godfather.telegram.listen.EventDistributorImpl;
import org.sadtech.bot.godfather.telegram.listen.TelegramConnect; import org.sadtech.bot.godfather.telegram.listen.TelegramConnect;
import org.sadtech.bot.godfather.telegram.listen.TelegramSender; import org.sadtech.bot.godfather.telegram.listen.TelegramSender;
import org.sadtech.social.bot.domain.unit.AnswerCheck; import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.impl.local.MailRepositoryList; import org.sadtech.social.core.repository.impl.local.MailRepositoryList;
import org.sadtech.social.core.service.MailService; import org.sadtech.social.core.service.MailService;
@ -18,7 +18,6 @@ import org.sadtech.social.core.service.impl.MailServiceImpl;
import org.sadtech.social.core.service.sender.Sending; import org.sadtech.social.core.service.sender.Sending;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.Collections; import java.util.Collections;
@ -28,7 +27,7 @@ import java.util.Collections;
* *
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Configuration //@Configuration
@EnableScheduling @EnableScheduling
public class TelegramBotConfig { public class TelegramBotConfig {
@ -44,13 +43,12 @@ public class TelegramBotConfig {
@Bean @Bean
public MessageAutoresponderTelegram messageAutoresponderTelegram( public MessageAutoresponderTelegram messageAutoresponderTelegram(
AnswerCheck regCheck,
Sending sending, Sending sending,
MessageService<Mail> messageService, MessageService<Mail> messageService,
UnitPointerRepository unitPointerRepository UnitPointerRepository unitPointerRepository
) { ) {
return new MessageAutoresponderTelegram( return new MessageAutoresponderTelegram(
Collections.singleton(regCheck), Collections.singleton(AnswerText.of("TEST")),
sending, sending,
messageService, messageService,
unitPointerRepository unitPointerRepository

View File

@ -3,9 +3,8 @@ package org.sadtech.bot.gitlab.telegram.scheduler;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.godfather.telegram.autoresponder.MessageAutoresponderTelegram; import org.sadtech.bot.godfather.telegram.autoresponder.MessageAutoresponderTelegram;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service //@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class CheckNewMessage { public class CheckNewMessage {

View File

@ -3,13 +3,12 @@ package org.sadtech.bot.gitlab.telegram.service;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.notify.Notify; import org.sadtech.bot.gitlab.context.domain.notify.Notify;
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
import org.sadtech.bot.gitlab.context.service.ChatService; import org.sadtech.bot.gitlab.context.service.ChatService;
import org.sadtech.bot.gitlab.context.service.MessageSendService; import org.sadtech.bot.gitlab.context.service.MessageSendService;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.service.sender.Sending; import org.sadtech.social.core.service.sender.Sending;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Set; import java.util.Set;
/** /**
@ -17,13 +16,12 @@ import java.util.Set;
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Service //@Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class MessageSendTelegramService implements MessageSendService { public class MessageSendTelegramService implements MessageSendService {
private final Sending sending; private final Sending sending;
private final PersonService personService;
private final ChatService chatService; private final ChatService chatService;
@Override @Override
@ -35,14 +33,15 @@ public class MessageSendTelegramService implements MessageSendService {
} }
private Set<Long> getTelegramIds(Notify notify) { private Set<Long> getTelegramIds(Notify notify) {
switch (notify.getEntityType()) { // switch (notify.getEntityType()) {
case PERSON: // case PERSON:
return personService.getAllTelegramIdByLogin(notify.getRecipients()); // return personService.getAllTelegramIdByLogin(notify.getRecipients());
case CHAT: // case CHAT:
return chatService.getAllTelegramIdByKey(notify.getRecipients()); // return chatService.getAllTelegramIdByKey(notify.getRecipients());
default: // default:
throw new NotFoundException("Отправка сообщения этому типу не возможна"); // throw new NotFoundException("Отправка сообщения этому типу не возможна");
} // }
return Collections.emptySet();
} }
} }

View File

@ -1,14 +1,13 @@
package org.sadtech.bot.gitlab.telegram.service; package org.sadtech.bot.gitlab.telegram.service;
import org.sadtech.bot.godfather.telegram.service.SendPreProcessing; import org.sadtech.bot.godfather.telegram.service.SendPreProcessing;
import org.springframework.stereotype.Component;
/** /**
* // TODO: 18.09.2020 Добавить описание. * // TODO: 18.09.2020 Добавить описание.
* *
* @author upagge 18.09.2020 * @author upagge 18.09.2020
*/ */
@Component //@Component
public class ReplaceUrlLocalhost implements SendPreProcessing { public class ReplaceUrlLocalhost implements SendPreProcessing {
@Override @Override

View File

@ -1,49 +1,44 @@
package org.sadtech.bot.gitlab.telegram.service.unit; package org.sadtech.bot.gitlab.telegram.service.unit;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.TaskStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.domain.entity.Task;
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
import org.sadtech.bot.gitlab.context.service.TaskService; import org.sadtech.bot.gitlab.context.service.TaskService;
import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.bot.service.usercode.ProcessingData;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* // TODO: 17.09.2020 Добавить описание. * // TODO: 17.09.2020 Добавить описание.
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Component //@Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class TaskProcessing implements ProcessingData<Message> { public class TaskProcessing implements ProcessingData<Message> {
private final PersonService personService;
private final TaskService taskService; private final TaskService taskService;
@Override @Override
public BoxAnswer processing(Message message) { public BoxAnswer processing(Message message) {
final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Ошибочка")); // .orElseThrow(() -> new NotFoundException("Ошибочка"));
final List<Task> tasks = taskService.getAllByResponsibleAndStatus(person.getLogin(), TaskStatus.OPEN); // final List<Task> tasks = taskService.getAllByResponsibleAndStatus(person.getLogin(), TaskStatus.OPEN);
String messageText; // String messageText;
if (tasks.isEmpty()) { // if (tasks.isEmpty()) {
messageText = "Задач нет"; // messageText = "Задач нет";
} else { // } else {
final String tasksString = tasks.stream() // final String tasksString = tasks.stream()
.map(this::createTaskString) // .map(this::createTaskString)
.collect(Collectors.joining("\n")); // .collect(Collectors.joining("\n"));
messageText = MessageFormat.format( // messageText = MessageFormat.format(
"Список ваших задач:\n\n{0}", // "Список ваших задач:\n\n{0}",
tasksString // tasksString
); // );
} // }
return BoxAnswer.of(messageText); // return BoxAnswer.of(messageText);
return null;
} }
private String createTaskString(Task task) { private String createTaskString(Task task) {

View File

@ -1,39 +1,32 @@
package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.gitlab.context.utils.MessageUtils;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.bot.service.usercode.ProcessingData;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.springframework.stereotype.Component;
import java.util.List;
/** /**
* // TODO: 17.09.2020 Добавить описание. * // TODO: 17.09.2020 Добавить описание.
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Component //@Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class PullRequestNeedWorkProcessing implements ProcessingData<Message> { public class PullRequestNeedWorkProcessing implements ProcessingData<Message> {
private final PersonService personService;
private final PullRequestsService pullRequestsService; private final PullRequestsService pullRequestsService;
@Override @Override
public BoxAnswer processing(Message message) { public BoxAnswer processing(Message message) {
final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Пользователь не найден")); // .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
final List<PullRequest> pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED); // final List<PullRequest> pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED);
return BoxAnswer.of( // return BoxAnswer.of(
MessageUtils.pullRequestForNeedWork(pullRequests) // MessageUtils.pullRequestForNeedWork(pullRequests)
.orElse("Не найдено ПРов, которые нуждаются в доработке :)") // .orElse("Не найдено ПРов, которые нуждаются в доработке :)")
); // );
return null;
} }
} }

View File

@ -1,45 +1,36 @@
package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.entity.PullRequest;
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.PullRequestsService;
import org.sadtech.bot.gitlab.context.utils.MessageUtils;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.bot.service.usercode.ProcessingData;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
/** /**
* // TODO: 17.09.2020 Добавить описание. * // TODO: 17.09.2020 Добавить описание.
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Component //@Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class PullRequestReviewProcessing implements ProcessingData<Message> { public class PullRequestReviewProcessing implements ProcessingData<Message> {
private final PersonService personService;
private final PullRequestsService pullRequestsService; private final PullRequestsService pullRequestsService;
@Override @Override
public BoxAnswer processing(Message message) { public BoxAnswer processing(Message message) {
final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Пользователь не найден")); // .orElseThrow(() -> new NotFoundException("Пользователь не найден"));
final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses( // final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses(
person.getLogin(), // person.getLogin(),
ReviewerStatus.NEEDS_WORK, // ReviewerStatus.NEEDS_WORK,
Collections.singleton(PullRequestStatus.OPEN) // Collections.singleton(PullRequestStatus.OPEN)
); // );
return BoxAnswer.of( // return BoxAnswer.of(
MessageUtils.pullRequestForReview(pullRequests) // MessageUtils.pullRequestForReview(pullRequests)
.orElse("Все ПР проверены :)") // .orElse("Все ПР проверены :)")
); // );
return null;
} }
} }

View File

@ -3,7 +3,6 @@ package org.sadtech.bot.gitlab.telegram.unit;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting;
import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.exception.NotFoundException;
import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.social.bot.domain.unit.AnswerProcessing; import org.sadtech.social.bot.domain.unit.AnswerProcessing;
@ -12,9 +11,7 @@ import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.sadtech.social.core.utils.KeyBoards; import org.sadtech.social.core.utils.KeyBoards;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -23,11 +20,10 @@ import java.util.stream.Collectors;
* *
* @author upagge 20.09.2020 * @author upagge 20.09.2020
*/ */
@Configuration //@Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class NotifySettingUnit { public class NotifySettingUnit {
private final PersonService personService;
private final NotifyService notifyService; private final NotifyService notifyService;
@Bean @Bean
@ -57,15 +53,16 @@ public class NotifySettingUnit {
return AnswerProcessing.builder() return AnswerProcessing.builder()
.processingData( .processingData(
message -> { message -> {
final Person person = personService.getByTelegramId(message.getPersonId()) // final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Не найдено")); // .orElseThrow(() -> new NotFoundException("Не найдено"));
final NotifySetting notifySetting = notifyService.getSetting(person.getLogin()) // final NotifySetting notifySetting = notifyService.getSetting(person.getLogin())
.orElseThrow(() -> new NotFoundException("Не найдено")); // .orElseThrow(() -> new NotFoundException("Не найдено"));
notifySetting.setStartReceiving( // notifySetting.setStartReceiving(
LocalDateTime.now().plusMinutes(DisableMenu.from(message.getText()).getMinutes()) // LocalDateTime.now().plusMinutes(DisableMenu.from(message.getText()).getMinutes())
); // );
notifyService.saveSettings(notifySetting); // notifyService.saveSettings(notifySetting);
return BoxAnswer.of("Настройки сохранены"); // return BoxAnswer.of("Настройки сохранены");
return null;
} }
) )
.build(); .build();

View File

@ -8,14 +8,13 @@ import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.sadtech.social.core.utils.KeyBoards; import org.sadtech.social.core.utils.KeyBoards;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** /**
* // TODO: 02.10.2020 Добавить описание. * // TODO: 02.10.2020 Добавить описание.
* *
* @author upagge 02.10.2020 * @author upagge 02.10.2020
*/ */
@Configuration //@Configuration
public class PullRequestUnitConfig { public class PullRequestUnitConfig {
@Bean @Bean

View File

@ -3,7 +3,6 @@ package org.sadtech.bot.gitlab.telegram.unit;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.telegram.service.unit.TaskProcessing; import org.sadtech.bot.gitlab.telegram.service.unit.TaskProcessing;
import org.sadtech.bot.gitlab.telegram.utils.GeneratorKeyBoards; import org.sadtech.bot.gitlab.telegram.utils.GeneratorKeyBoards;
import org.sadtech.social.bot.domain.unit.AnswerCheck;
import org.sadtech.social.bot.domain.unit.AnswerProcessing; import org.sadtech.social.bot.domain.unit.AnswerProcessing;
import org.sadtech.social.bot.domain.unit.AnswerText; import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
@ -11,39 +10,22 @@ import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.domain.content.Message; import org.sadtech.social.core.domain.content.Message;
import org.sadtech.social.core.utils.KeyBoards; import org.sadtech.social.core.utils.KeyBoards;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** /**
* TODO: Добавить описание класса. * TODO: Добавить описание класса.
* *
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Configuration //@Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class UnitConfig { public class UnitConfig {
private final PersonService personService;
@Bean
public AnswerCheck regCheck(
AnswerProcessing<Mail> noRegister,
AnswerText menu
) {
return AnswerCheck.builder()
.check(
message -> personService.existsByTelegram(message.getPersonId())
)
.unitFalse(noRegister)
.unitTrue(menu)
.build();
}
@Bean @Bean
public AnswerText menu( public AnswerText menu(
AnswerProcessing<Message> getTasks, AnswerProcessing<Message> getTasks,
AnswerText menuPullRequest, AnswerText menuPullRequest,
AnswerText settings, AnswerText settings
AnswerProcessing<Message> getTopRating
) { ) {
return AnswerText.builder() return AnswerText.builder()
.boxAnswer( .boxAnswer(
@ -55,7 +37,6 @@ public class UnitConfig {
.nextUnit(getTasks) .nextUnit(getTasks)
.nextUnit(menuPullRequest) .nextUnit(menuPullRequest)
.nextUnit(settings) .nextUnit(settings)
.nextUnit(getTopRating)
.build(); .build();
} }
@ -87,17 +68,6 @@ public class UnitConfig {
.build(); .build();
} }
@Bean
AnswerProcessing<Message> getTopRating(
RatingTopProcessing ratingTopProcessing
) {
return AnswerProcessing.builder()
.processingData(ratingTopProcessing)
.keyWord("таблица")
.keyWord("рейтинга")
.build();
}
@Bean @Bean
public AnswerProcessing<Mail> noRegister() { public AnswerProcessing<Mail> noRegister() {
return AnswerProcessing.<Mail>builder() return AnswerProcessing.<Mail>builder()