diff --git a/bitbucket-app/src/main/resources/application-dev.yaml b/bitbucket-app/src/main/resources/application-dev.yaml index c327b23..2f6f089 100644 --- a/bitbucket-app/src/main/resources/application-dev.yaml +++ b/bitbucket-app/src/main/resources/application-dev.yaml @@ -24,7 +24,7 @@ bitbucketbot: no-comment-count: 20 comment-count: 100 init: - start-comment-id: 7914 + start-comment-id: 8157 use: false bitbucket: token: ${BITBUCKET_ADMIN_TOKEN} diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml index 5224d2e..79212a1 100644 --- a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-01-rating.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-01-rating.xml new file mode 100644 index 0000000..95711a7 --- /dev/null +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-01-rating.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/logback.xml b/bitbucket-app/src/main/resources/logback.xml index 0335154..e106cf3 100644 --- a/bitbucket-app/src/main/resources/logback.xml +++ b/bitbucket-app/src/main/resources/logback.xml @@ -18,7 +18,7 @@ - + \ No newline at end of file diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/PointType.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/PointType.java new file mode 100644 index 0000000..2474ab8 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/PointType.java @@ -0,0 +1,26 @@ +package org.sadtech.bot.vcs.core.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +@Getter +@RequiredArgsConstructor +public enum PointType { + + CREATE_PULL_REQUEST(10), + DECLINE_PULL_REQUEST(-CREATE_PULL_REQUEST.getPoints()), + COMMENT_ADD(1), + COMMENT_DELETE(-COMMENT_ADD.getPoints()), + TASK_CREATE(2), + TASK_DELETE(-TASK_CREATE.getPoints()), + TASK_RECIPIENT(-1), + TASK_DELETE_RECIPIENT(1); + + private final Integer points; + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingHistory.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingHistory.java new file mode 100644 index 0000000..b7b0023 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingHistory.java @@ -0,0 +1,49 @@ +package org.sadtech.bot.vcs.core.domain.entity; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import org.sadtech.bot.vcs.core.domain.PointType; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.LocalDateTime; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +@Getter +@Setter +@Entity +@Table(name = "rating_history") +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class RatingHistory { + + @Id + @Column(name = "id") + @EqualsAndHashCode.Include + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "login") + private String login; + + @Column(name = "points") + private Integer points; + + @Enumerated(EnumType.STRING) + @Column(name = "type") + private PointType type; + + @Column(name = "date_add") + private LocalDateTime dateAdd; + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingList.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingList.java new file mode 100644 index 0000000..c4c9d12 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/RatingList.java @@ -0,0 +1,31 @@ +//package org.sadtech.bot.vcs.core.domain.entity; +// +//import lombok.EqualsAndHashCode; +//import lombok.Getter; +//import lombok.Setter; +// +//import javax.persistence.Column; +//import javax.persistence.Entity; +//import javax.persistence.Table; +// +///** +// * // TODO: 01.10.2020 Добавить описание. +// * +// * @author upagge 01.10.2020 +// */ +// +//@Getter +//@Setter +//@Entity +//@Table(name = "rating_list") +//@EqualsAndHashCode(onlyExplicitlyIncluded = true) +//public class RatingList { +// +// @Column(name = "login") +// @EqualsAndHashCode.Include +// private String login; +// +// @Column(name = "points") +// private Integer points; +// +//} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/RatingHistoryRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/RatingHistoryRepository.java new file mode 100644 index 0000000..d962b53 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/RatingHistoryRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.vcs.core.repository; + +import org.sadtech.basic.context.repository.SimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.entity.RatingHistory; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +public interface RatingHistoryRepository extends SimpleManagerRepository { + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/RatingHistoryRepositoryImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/RatingHistoryRepositoryImpl.java new file mode 100644 index 0000000..4ea02b1 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/RatingHistoryRepositoryImpl.java @@ -0,0 +1,24 @@ +package org.sadtech.bot.vcs.core.repository.impl; + +import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.entity.RatingHistory; +import org.sadtech.bot.vcs.core.repository.RatingHistoryRepository; +import org.sadtech.bot.vcs.core.repository.jpa.RatingHistoryJpaRepository; +import org.springframework.stereotype.Repository; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +@Repository +public class RatingHistoryRepositoryImpl extends AbstractSimpleManagerRepository implements RatingHistoryRepository { + + private final RatingHistoryJpaRepository jpaRepository; + + public RatingHistoryRepositoryImpl(RatingHistoryJpaRepository jpaRepository) { + super(jpaRepository); + this.jpaRepository = jpaRepository; + } + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/RatingHistoryJpaRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/RatingHistoryJpaRepository.java new file mode 100644 index 0000000..9d1ee0b --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/RatingHistoryJpaRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.vcs.core.repository.jpa; + +import org.sadtech.bot.vcs.core.domain.entity.RatingHistory; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +public interface RatingHistoryJpaRepository extends JpaRepository { + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java index b63db3a..184cd61 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/scheduler/NotificationScheduler.java @@ -26,7 +26,7 @@ import java.util.stream.Collectors; public class NotificationScheduler { private static final Set tksLoginNotify = new HashSet<>(Arrays.asList( - "mstruchkov", "emukhin", "ktorgaeva", "imescheryakov", "kkeglev" + "mstruchkov", "emukhin", "imescheryakov", "kkeglev" )); private final PersonService personService; diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/RatingService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/RatingService.java new file mode 100644 index 0000000..53c1b81 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/RatingService.java @@ -0,0 +1,15 @@ +package org.sadtech.bot.vcs.core.service; + +import lombok.NonNull; +import org.sadtech.bot.vcs.core.domain.PointType; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +public interface RatingService { + + void addRating(@NonNull String login, @NonNull PointType type, @NonNull Integer points); + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/ReportService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/ReportService.java deleted file mode 100644 index 3b02e99..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/ReportService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.bot.vcs.core.service; - -import lombok.NonNull; - -public interface ReportService { - - String generateReport(@NonNull String login); - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java index f05e680..e2deede 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/CommentServiceImpl.java @@ -2,7 +2,9 @@ package org.sadtech.bot.vcs.core.service.impl; import lombok.NonNull; import org.sadtech.basic.core.service.AbstractSimpleManagerService; +import org.sadtech.basic.core.util.Assert; import org.sadtech.bot.vcs.core.domain.Answer; +import org.sadtech.bot.vcs.core.domain.PointType; import org.sadtech.bot.vcs.core.domain.entity.Comment; import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.domain.notify.comment.AnswerCommentNotify; @@ -11,6 +13,7 @@ import org.sadtech.bot.vcs.core.exception.NotFoundException; import org.sadtech.bot.vcs.core.repository.CommentRepository; import org.sadtech.bot.vcs.core.service.CommentService; import org.sadtech.bot.vcs.core.service.NotifyService; +import org.sadtech.bot.vcs.core.service.RatingService; import org.sadtech.bot.vcs.core.service.TaskService; import org.springframework.context.annotation.Lazy; import org.springframework.core.convert.ConversionService; @@ -33,6 +36,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService recipientsLogins = new HashSet<>(); @@ -108,7 +120,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService new NotFoundException("Комментарий не найден")); + ratingService.addRating(comment.getAuthor(), PointType.COMMENT_DELETE, PointType.COMMENT_DELETE.getPoints()); + super.deleteById(id); + } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java index fb929a9..6326139 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java @@ -9,6 +9,7 @@ import org.sadtech.basic.core.util.Assert; import org.sadtech.basic.filter.criteria.CriteriaFilter; import org.sadtech.basic.filter.criteria.CriteriaQuery; import org.sadtech.bot.vcs.core.domain.IdAndStatusPr; +import org.sadtech.bot.vcs.core.domain.PointType; import org.sadtech.bot.vcs.core.domain.PullRequestStatus; import org.sadtech.bot.vcs.core.domain.ReviewerStatus; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; @@ -26,6 +27,7 @@ import org.sadtech.bot.vcs.core.exception.UpdateException; import org.sadtech.bot.vcs.core.repository.PullRequestsRepository; import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.PullRequestsService; +import org.sadtech.bot.vcs.core.service.RatingService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @@ -42,16 +44,19 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService filterService; protected PullRequestsServiceImpl( PullRequestsRepository pullRequestsRepository, NotifyService notifyService, + RatingService ratingService, @Qualifier("pullRequestFilterService") FilterService pullRequestsFilterService ) { super(pullRequestsRepository); this.notifyService = notifyService; this.pullRequestsRepository = pullRequestsRepository; + this.ratingService = ratingService; this.filterService = pullRequestsFilterService; } @@ -61,6 +66,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService getReviewerTelegrams(@NonNull List reviewers) { -// return personService.getAllTelegramIdByLogin( -// reviewers.stream() -// .map(Reviewer::getPersonLogin) -// .collect(Collectors.toSet()) -// ); -// } @Override public PullRequest update(@NonNull PullRequest pullRequest) { @@ -133,6 +131,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService oldReviewers = oldPullRequest.getReviewers().stream() .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer)); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/RatingServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/RatingServiceImpl.java new file mode 100644 index 0000000..60ca6a7 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/RatingServiceImpl.java @@ -0,0 +1,34 @@ +package org.sadtech.bot.vcs.core.service.impl; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.domain.PointType; +import org.sadtech.bot.vcs.core.domain.entity.RatingHistory; +import org.sadtech.bot.vcs.core.repository.RatingHistoryRepository; +import org.sadtech.bot.vcs.core.service.RatingService; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; + +/** + * // TODO: 01.10.2020 Добавить описание. + * + * @author upagge 01.10.2020 + */ +@Service +@RequiredArgsConstructor +public class RatingServiceImpl implements RatingService { + + private final RatingHistoryRepository ratingHistoryRepository; + + @Override + public void addRating(@NonNull String login, @NonNull PointType type, @NonNull Integer points) { + final RatingHistory ratingHistory = new RatingHistory(); + ratingHistory.setLogin(login); + ratingHistory.setPoints(points); + ratingHistory.setType(type); + ratingHistory.setDateAdd(LocalDateTime.now()); + ratingHistoryRepository.save(ratingHistory); + } + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java index 4ccd900..6da8562 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java @@ -4,6 +4,7 @@ import lombok.NonNull; import org.sadtech.basic.core.service.AbstractSimpleManagerService; import org.sadtech.basic.core.util.Assert; import org.sadtech.bot.vcs.core.domain.Answer; +import org.sadtech.bot.vcs.core.domain.PointType; import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.entity.Comment; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; @@ -17,6 +18,7 @@ import org.sadtech.bot.vcs.core.repository.TaskRepository; import org.sadtech.bot.vcs.core.service.CommentService; import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.core.service.PullRequestsService; +import org.sadtech.bot.vcs.core.service.RatingService; import org.sadtech.bot.vcs.core.service.TaskService; import org.springframework.core.convert.ConversionService; import org.springframework.stereotype.Service; @@ -40,6 +42,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im private final PullRequestsService pullRequestsService; private final NotifyService notifyService; private final CommentService commentService; + private final RatingService ratingService; private final ConversionService conversionService; @@ -48,6 +51,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im PullRequestsService pullRequestsService, NotifyService notifyService, CommentService commentService, + RatingService ratingService, ConversionService conversionService ) { super(taskRepository); @@ -55,6 +59,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im this.pullRequestsService = pullRequestsService; this.notifyService = notifyService; this.commentService = commentService; + this.ratingService = ratingService; this.conversionService = conversionService; } @@ -65,6 +70,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im final Task newTask = taskRepository.save(task); notifyNewTask(task); notificationPersonal(task); + ratingCreateTask(task.getAuthor(), task.getResponsible()); return newTask; } @@ -197,4 +203,21 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im ); } + @Override + public void deleteById(@NonNull Long id) { + final Task task = taskRepository.findById(id).orElseThrow(() -> new NotFoundException("Задача не найдена")); + ratingDeleteTask(task.getAuthor(), task.getResponsible()); + super.deleteById(id); + } + + private void ratingCreateTask(String authorLogin, String responsibleLogin) { + ratingService.addRating(authorLogin, PointType.TASK_CREATE, PointType.TASK_CREATE.getPoints()); + ratingService.addRating(responsibleLogin, PointType.TASK_RECIPIENT, PointType.TASK_RECIPIENT.getPoints()); + } + + 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()); + } + }