Доработка уведомлений в тимсити
This commit is contained in:
parent
54492e551b
commit
464e34c1fd
@ -7,6 +7,7 @@ package org.sadtech.bot.vcs.bitbucket.app.scheduler;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.entity.Person;
|
import org.sadtech.bot.vcs.core.domain.entity.Person;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.SimpleTextNotify;
|
import org.sadtech.bot.vcs.core.domain.notify.SimpleTextNotify;
|
||||||
import org.sadtech.bot.vcs.core.service.NotifyService;
|
import org.sadtech.bot.vcs.core.service.NotifyService;
|
||||||
@ -38,8 +39,9 @@ public class RatingScheduler {
|
|||||||
final String message = ratingService.getRatingTop(person.getLogin());
|
final String message = ratingService.getRatingTop(person.getLogin());
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
SimpleTextNotify.builder()
|
SimpleTextNotify.builder()
|
||||||
|
.entityType(EntityType.PERSON)
|
||||||
.message(message)
|
.message(message)
|
||||||
.logins(Collections.singleton(person.getLogin()))
|
.recipients(Collections.singleton(person.getLogin()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,6 @@
|
|||||||
<include file="liquibase/v.2.0.0/2020-10-01-rating.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-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-07-add-colum-reviewer-date.xml"/>
|
||||||
|
<include file="liquibase/v.2.0.0/2020-10-11-teamcity-refactoring.xml"/>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
@ -0,0 +1,40 @@
|
|||||||
|
<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>
|
@ -1,13 +1,13 @@
|
|||||||
package org.sadtech.bot.vcs.core.domain.notify;
|
package org.sadtech.bot.vcs.core.domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 21.09.2020 Добавить описание.
|
* // TODO: 21.09.2020 Добавить описание.
|
||||||
*
|
*
|
||||||
* @author upagge 21.09.2020
|
* @author upagge 21.09.2020
|
||||||
*/
|
*/
|
||||||
public enum TypeNotify {
|
public enum EntityType {
|
||||||
|
|
||||||
SERVICE,
|
CHAT,
|
||||||
PERSON
|
PERSON
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
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.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "chat")
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
public class Chat {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "key")
|
||||||
|
@EqualsAndHashCode.Include
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@Column(name = "telegram_id")
|
||||||
|
private Long telegramId;
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.domain.notify;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
|
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
|
||||||
import org.sadtech.bot.vcs.core.utils.MessageUtils;
|
import org.sadtech.bot.vcs.core.utils.MessageUtils;
|
||||||
import org.sadtech.bot.vcs.core.utils.Smile;
|
import org.sadtech.bot.vcs.core.utils.Smile;
|
||||||
@ -27,11 +28,11 @@ public class GoodMorningNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected GoodMorningNotify(
|
protected GoodMorningNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
List<PullRequest> pullRequestsReviews,
|
List<PullRequest> pullRequestsReviews,
|
||||||
List<PullRequest> pullRequestsNeedWork
|
List<PullRequest> pullRequestsNeedWork
|
||||||
) {
|
) {
|
||||||
super(logins);
|
super(EntityType.PERSON, recipients);
|
||||||
this.pullRequestsReviews = pullRequestsReviews;
|
this.pullRequestsReviews = pullRequestsReviews;
|
||||||
this.pullRequestsNeedWork = pullRequestsNeedWork;
|
this.pullRequestsNeedWork = pullRequestsNeedWork;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.domain.notify;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -9,12 +10,12 @@ import java.util.Set;
|
|||||||
@Setter
|
@Setter
|
||||||
public abstract class Notify {
|
public abstract class Notify {
|
||||||
|
|
||||||
protected TypeNotify typeNotify;
|
protected EntityType entityType;
|
||||||
protected Set<String> logins;
|
protected Set<String> recipients;
|
||||||
|
|
||||||
protected Notify(Set<String> logins) {
|
protected Notify(EntityType entityType, Set<String> recipients) {
|
||||||
this.typeNotify = TypeNotify.PERSON;
|
this.entityType = entityType;
|
||||||
this.logins = logins;
|
this.recipients = recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String generateMessage();
|
public abstract String generateMessage();
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.domain.notify;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -16,8 +17,8 @@ public class SimpleTextNotify extends Notify {
|
|||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private SimpleTextNotify(Set<String> logins, String message) {
|
private SimpleTextNotify(EntityType entityType, Set<String> recipients, String message) {
|
||||||
super(logins);
|
super(entityType, recipients);
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,4 +26,5 @@ public class SimpleTextNotify extends Notify {
|
|||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import lombok.Builder;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.sadtech.bot.vcs.core.domain.Answer;
|
import org.sadtech.bot.vcs.core.domain.Answer;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
import org.sadtech.bot.vcs.core.utils.Smile;
|
import org.sadtech.bot.vcs.core.utils.Smile;
|
||||||
|
|
||||||
@ -22,12 +23,12 @@ public class AnswerCommentNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected AnswerCommentNotify(
|
protected AnswerCommentNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String youMessage,
|
String youMessage,
|
||||||
String url,
|
String url,
|
||||||
List<Answer> answers
|
List<Answer> answers
|
||||||
) {
|
) {
|
||||||
super(logins);
|
super(EntityType.PERSON, recipients);
|
||||||
this.youMessage = youMessage;
|
this.youMessage = youMessage;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.answers = answers;
|
this.answers = answers;
|
||||||
|
@ -3,6 +3,7 @@ package org.sadtech.bot.vcs.core.domain.notify.comment;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
import org.sadtech.bot.vcs.core.utils.Smile;
|
import org.sadtech.bot.vcs.core.utils.Smile;
|
||||||
|
|
||||||
@ -19,12 +20,12 @@ public class CommentNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private CommentNotify(
|
private CommentNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String url,
|
String url,
|
||||||
String authorName,
|
String authorName,
|
||||||
String message
|
String message
|
||||||
) {
|
) {
|
||||||
super(logins);
|
super(EntityType.PERSON, recipients);
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -12,11 +12,11 @@ public class ConflictPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private ConflictPrNotify(
|
private ConflictPrNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String name,
|
String name,
|
||||||
String url
|
String url
|
||||||
) {
|
) {
|
||||||
super(logins, name, url);
|
super(recipients, name, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,12 +17,12 @@ public class NewPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewPrNotify(
|
private NewPrNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String description,
|
String description,
|
||||||
String author) {
|
String author) {
|
||||||
super(logins, title, url);
|
super(recipients, title, url);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
|
|||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -13,8 +14,8 @@ public abstract class PrNotify extends Notify {
|
|||||||
protected final String title;
|
protected final String title;
|
||||||
protected final String url;
|
protected final String url;
|
||||||
|
|
||||||
protected PrNotify(Set<String> logins, String title, String url) {
|
protected PrNotify(Set<String> recipients, String title, String url) {
|
||||||
super(logins);
|
super(EntityType.PERSON, recipients);
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ public class ReviewersPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private ReviewersPrNotify(
|
private ReviewersPrNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
List<ReviewerChange> reviewerChanges) {
|
List<ReviewerChange> reviewerChanges) {
|
||||||
super(logins, title, url);
|
super(recipients, title, url);
|
||||||
this.reviewerChanges = reviewerChanges;
|
this.reviewerChanges = reviewerChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ public class StatusPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private StatusPrNotify(
|
private StatusPrNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
PullRequestStatus oldStatus,
|
PullRequestStatus oldStatus,
|
||||||
PullRequestStatus newStatus) {
|
PullRequestStatus newStatus) {
|
||||||
super(logins, name, url);
|
super(recipients, name, url);
|
||||||
this.oldStatus = oldStatus;
|
this.oldStatus = oldStatus;
|
||||||
this.newStatus = newStatus;
|
this.newStatus = newStatus;
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ public class UpdatePrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private UpdatePrNotify(
|
private UpdatePrNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String name,
|
String name,
|
||||||
String url, String author) {
|
String url, String author) {
|
||||||
super(logins, name, url);
|
super(recipients, name, url);
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ public class TaskCloseNotify extends TaskNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected TaskCloseNotify(
|
protected TaskCloseNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(logins, authorName, url, messageTask);
|
super(recipients, authorName, url, messageTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,12 +17,12 @@ public class TaskNewNotify extends TaskNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected TaskNewNotify(
|
protected TaskNewNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(logins, authorName, url, messageTask);
|
super(recipients, authorName, url, messageTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.domain.notify.task;
|
|||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -15,12 +16,12 @@ public abstract class TaskNotify extends Notify {
|
|||||||
protected final String messageTask;
|
protected final String messageTask;
|
||||||
|
|
||||||
protected TaskNotify(
|
protected TaskNotify(
|
||||||
Set<String> logins,
|
Set<String> recipients,
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(logins);
|
super(EntityType.PERSON, recipients);
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.messageTask = messageTask;
|
this.messageTask = messageTask;
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package org.sadtech.bot.vcs.core.repository;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.sadtech.basic.context.repository.SimpleManagerRepository;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.entity.Chat;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
public interface ChatRepository extends SimpleManagerRepository<Chat, String> {
|
||||||
|
|
||||||
|
Set<Long> findAllTelegramIdByKey(@NonNull Set<String> keys);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.sadtech.bot.vcs.core.repository.impl;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.entity.Chat;
|
||||||
|
import org.sadtech.bot.vcs.core.repository.ChatRepository;
|
||||||
|
import org.sadtech.bot.vcs.core.repository.jpa.ChatJpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class ChatRepositoryImpl extends AbstractSimpleManagerRepository<Chat, String> implements ChatRepository {
|
||||||
|
|
||||||
|
private final ChatJpaRepository jpaRepository;
|
||||||
|
|
||||||
|
public ChatRepositoryImpl(ChatJpaRepository jpaRepository) {
|
||||||
|
super(jpaRepository);
|
||||||
|
this.jpaRepository = jpaRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Long> findAllTelegramIdByKey(@NonNull Set<String> keys) {
|
||||||
|
return jpaRepository.findAllTelegramIdByKey(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.sadtech.bot.vcs.core.repository.jpa;
|
||||||
|
|
||||||
|
import org.sadtech.bot.vcs.core.domain.entity.Chat;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
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")
|
||||||
|
Set<Long> findAllTelegramIdByKey(@Param("keys") Set<String> keys);
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package org.sadtech.bot.vcs.core.scheduler;
|
package org.sadtech.bot.vcs.core.scheduler;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
|
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
|
||||||
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
|
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
|
||||||
import org.sadtech.bot.vcs.core.domain.entity.Person;
|
import org.sadtech.bot.vcs.core.domain.entity.Person;
|
||||||
@ -49,7 +50,7 @@ public class NotificationScheduler {
|
|||||||
GoodMorningNotify.builder()
|
GoodMorningNotify.builder()
|
||||||
.pullRequestsNeedWork(pullRequestsNeedWork)
|
.pullRequestsNeedWork(pullRequestsNeedWork)
|
||||||
.pullRequestsReviews(pullRequestsReviews)
|
.pullRequestsReviews(pullRequestsReviews)
|
||||||
.logins(Collections.singleton(user.getLogin()))
|
.recipients(Collections.singleton(user.getLogin()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ public class NotificationScheduler {
|
|||||||
notifyService.send(
|
notifyService.send(
|
||||||
SimpleTextNotify
|
SimpleTextNotify
|
||||||
.builder()
|
.builder()
|
||||||
.logins(
|
.recipients(
|
||||||
usersTks.stream()
|
usersTks.stream()
|
||||||
.map(Person::getLogin)
|
.map(Person::getLogin)
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
@ -79,9 +80,10 @@ public class NotificationScheduler {
|
|||||||
List<Person> allRegister = personService.getAllRegister();
|
List<Person> allRegister = personService.getAllRegister();
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
SimpleTextNotify.builder()
|
SimpleTextNotify.builder()
|
||||||
|
.entityType(EntityType.PERSON)
|
||||||
.message("Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR +
|
.message("Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BR +
|
||||||
"До понедельника" + Smile.BUY + Smile.TWO_BR)
|
"До понедельника" + Smile.BUY + Smile.TWO_BR)
|
||||||
.logins(
|
.recipients(
|
||||||
allRegister.stream()
|
allRegister.stream()
|
||||||
.map(Person::getLogin)
|
.map(Person::getLogin)
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.sadtech.bot.vcs.core.service;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
public interface ChatService {
|
||||||
|
|
||||||
|
Set<Long> getAllTelegramIdByKey(@NonNull Set<String> keys);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package org.sadtech.bot.vcs.core.service.impl;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.sadtech.bot.vcs.core.repository.ChatRepository;
|
||||||
|
import org.sadtech.bot.vcs.core.service.ChatService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
|
*
|
||||||
|
* @author upagge 11.10.2020
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ChatServiceImpl implements ChatService {
|
||||||
|
|
||||||
|
private final ChatRepository chatRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Long> getAllTelegramIdByKey(@NonNull Set<String> keys) {
|
||||||
|
return chatRepository.findAllTelegramIdByKey(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -90,7 +90,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
|||||||
CommentNotify.builder()
|
CommentNotify.builder()
|
||||||
.authorName(comment.getAuthor())
|
.authorName(comment.getAuthor())
|
||||||
.url(comment.getUrl())
|
.url(comment.getUrl())
|
||||||
.logins(recipientsLogins)
|
.recipients(recipientsLogins)
|
||||||
.message(comment.getMessage())
|
.message(comment.getMessage())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
@ -142,7 +142,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
|||||||
oldComment.setAnswers(existsNewAnswersIds);
|
oldComment.setAnswers(existsNewAnswersIds);
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
AnswerCommentNotify.builder()
|
AnswerCommentNotify.builder()
|
||||||
.logins(Collections.singleton(newComment.getAuthor()))
|
.recipients(Collections.singleton(newComment.getAuthor()))
|
||||||
.url(oldComment.getUrl())
|
.url(oldComment.getUrl())
|
||||||
.youMessage(newComment.getMessage())
|
.youMessage(newComment.getMessage())
|
||||||
.answers(
|
.answers(
|
||||||
|
@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.service.impl;
|
|||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
|
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
import org.sadtech.bot.vcs.core.repository.NotifySettingRepository;
|
import org.sadtech.bot.vcs.core.repository.NotifySettingRepository;
|
||||||
@ -22,8 +23,10 @@ public class NotifyServiceImpl implements NotifyService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Notify> void send(T notify) {
|
public <T extends Notify> void send(T notify) {
|
||||||
final Set<String> recipientLogins = settingRepository.isNotification(notify.getLogins());
|
if (EntityType.PERSON.equals(notify.getEntityType())) {
|
||||||
notify.setLogins(recipientLogins);
|
final Set<String> recipientLogins = settingRepository.isNotification(notify.getRecipients());
|
||||||
|
notify.setRecipients(recipientLogins);
|
||||||
|
}
|
||||||
messageSendService.send(notify);
|
messageSendService.send(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
|||||||
.description(newPullRequest.getDescription())
|
.description(newPullRequest.getDescription())
|
||||||
.title(newPullRequest.getTitle())
|
.title(newPullRequest.getTitle())
|
||||||
.url(newPullRequest.getUrl())
|
.url(newPullRequest.getUrl())
|
||||||
.logins(
|
.recipients(
|
||||||
newPullRequest.getReviewers().stream()
|
newPullRequest.getReviewers().stream()
|
||||||
.map(Reviewer::getPersonLogin)
|
.map(Reviewer::getPersonLogin)
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
@ -106,7 +106,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
|||||||
UpdatePrNotify.builder()
|
UpdatePrNotify.builder()
|
||||||
.author(oldPullRequest.getAuthorLogin())
|
.author(oldPullRequest.getAuthorLogin())
|
||||||
.name(newPullRequest.getTitle())
|
.name(newPullRequest.getTitle())
|
||||||
.logins(
|
.recipients(
|
||||||
newPullRequest.getReviewers().stream()
|
newPullRequest.getReviewers().stream()
|
||||||
.map(Reviewer::getPersonLogin)
|
.map(Reviewer::getPersonLogin)
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
@ -125,7 +125,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
|||||||
ConflictPrNotify.builder()
|
ConflictPrNotify.builder()
|
||||||
.name(pullRequest.getTitle())
|
.name(pullRequest.getTitle())
|
||||||
.url(pullRequest.getUrl())
|
.url(pullRequest.getUrl())
|
||||||
.logins(Collections.singleton(pullRequest.getAuthorLogin()))
|
.recipients(Collections.singleton(pullRequest.getAuthorLogin()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
|||||||
.url(oldPullRequest.getUrl())
|
.url(oldPullRequest.getUrl())
|
||||||
.newStatus(newStatus)
|
.newStatus(newStatus)
|
||||||
.oldStatus(oldStatus)
|
.oldStatus(oldStatus)
|
||||||
.logins(Collections.singleton(oldPullRequest.getAuthorLogin()))
|
.recipients(Collections.singleton(oldPullRequest.getAuthorLogin()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
oldPullRequest.setStatus(newStatus);
|
oldPullRequest.setStatus(newStatus);
|
||||||
@ -202,7 +202,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
|||||||
ReviewersPrNotify.builder()
|
ReviewersPrNotify.builder()
|
||||||
.title(newPullRequest.getTitle())
|
.title(newPullRequest.getTitle())
|
||||||
.url(newPullRequest.getUrl())
|
.url(newPullRequest.getUrl())
|
||||||
.logins(Collections.singleton(newPullRequest.getAuthorLogin()))
|
.recipients(Collections.singleton(newPullRequest.getAuthorLogin()))
|
||||||
.reviewerChanges(reviewerChanges)
|
.reviewerChanges(reviewerChanges)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
@ -100,7 +100,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
.messageTask(task.getDescription())
|
.messageTask(task.getDescription())
|
||||||
.authorName(oldTask.getAuthor())
|
.authorName(oldTask.getAuthor())
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.logins(Collections.singleton(oldTask.getResponsible()))
|
.recipients(Collections.singleton(oldTask.getResponsible()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -110,7 +110,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
.messageTask(oldTask.getDescription())
|
.messageTask(oldTask.getDescription())
|
||||||
.authorName(oldTask.getAuthor())
|
.authorName(oldTask.getAuthor())
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.logins(Collections.singleton(oldTask.getAuthor()))
|
.recipients(Collections.singleton(oldTask.getAuthor()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -134,7 +134,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
oldTask.setAnswers(existsNewAnswersIds);
|
oldTask.setAnswers(existsNewAnswersIds);
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
AnswerCommentNotify.builder()
|
AnswerCommentNotify.builder()
|
||||||
.logins(Collections.singleton(oldTask.getAuthor()))
|
.recipients(Collections.singleton(oldTask.getAuthor()))
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.youMessage(oldTask.getDescription())
|
.youMessage(oldTask.getDescription())
|
||||||
.answers(
|
.answers(
|
||||||
@ -181,7 +181,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
.authorName(task.getAuthor())
|
.authorName(task.getAuthor())
|
||||||
.messageTask(task.getDescription())
|
.messageTask(task.getDescription())
|
||||||
.url(task.getUrl())
|
.url(task.getUrl())
|
||||||
.logins(Collections.singleton(pullRequest.getAuthorLogin()))
|
.recipients(Collections.singleton(pullRequest.getAuthorLogin()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
CommentNotify.builder()
|
CommentNotify.builder()
|
||||||
.authorName(task.getAuthor())
|
.authorName(task.getAuthor())
|
||||||
.url(task.getUrl())
|
.url(task.getUrl())
|
||||||
.logins(recipientsLogins)
|
.recipients(recipientsLogins)
|
||||||
.message(task.getDescription())
|
.message(task.getDescription())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
@ -2,14 +2,14 @@ package org.sadtech.bot.vcs.teamcity.core.domain;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.sadtech.bot.vcs.core.domain.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.TypeNotify;
|
|
||||||
import org.sadtech.bot.vcs.core.utils.Smile;
|
import org.sadtech.bot.vcs.core.utils.Smile;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort;
|
import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort;
|
||||||
import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus;
|
import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Collections;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 21.09.2020 Добавить описание.
|
* // TODO: 21.09.2020 Добавить описание.
|
||||||
@ -17,17 +17,14 @@ import java.util.Collections;
|
|||||||
* @author upagge 21.09.2020
|
* @author upagge 21.09.2020
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public class ServiceNotify extends Notify {
|
public class TeamcityBuildNotify extends Notify {
|
||||||
|
|
||||||
private final Long chatId;
|
|
||||||
private final BuildShort buildShort;
|
private final BuildShort buildShort;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private ServiceNotify(Long chatId, BuildShort buildShort) {
|
private TeamcityBuildNotify(EntityType entityType, Set<String> recipients, BuildShort buildShort) {
|
||||||
super(Collections.emptySet());
|
super(entityType, recipients);
|
||||||
this.chatId = chatId;
|
|
||||||
this.buildShort = buildShort;
|
this.buildShort = buildShort;
|
||||||
this.typeNotify = TypeNotify.SERVICE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -3,9 +3,12 @@ package org.sadtech.bot.vcs.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.bot.vcs.core.domain.EntityType;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
@ -29,12 +32,19 @@ public class TeamcitySetting {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "chat_id")
|
@Column(name = "recipient_id")
|
||||||
private Long chatId;
|
private String recipientId;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "recipient_type")
|
||||||
|
private EntityType recipientType;
|
||||||
|
|
||||||
@Column(name = "project_id")
|
@Column(name = "project_id")
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
|
@Column(name = "build_type_id")
|
||||||
|
private String buildTypeId;
|
||||||
|
|
||||||
@Column(name = "success")
|
@Column(name = "success")
|
||||||
private boolean success;
|
private boolean success;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package org.sadtech.bot.vcs.teamcity.core.service.impl;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.sadtech.basic.core.service.AbstractSimpleManagerService;
|
import org.sadtech.basic.core.service.AbstractSimpleManagerService;
|
||||||
import org.sadtech.bot.vcs.core.service.NotifyService;
|
import org.sadtech.bot.vcs.core.service.NotifyService;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.domain.ServiceNotify;
|
import org.sadtech.bot.vcs.teamcity.core.domain.TeamcityBuildNotify;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort;
|
import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.domain.entity.TeamcitySetting;
|
import org.sadtech.bot.vcs.teamcity.core.domain.entity.TeamcitySetting;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.repository.BuildShortRepository;
|
import org.sadtech.bot.vcs.teamcity.core.repository.BuildShortRepository;
|
||||||
@ -12,6 +12,7 @@ import org.sadtech.bot.vcs.teamcity.core.service.TeamcitySettingService;
|
|||||||
import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus;
|
import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,19 +50,27 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildSho
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(TeamcitySetting teamcitySetting, BuildShort buildShort) {
|
private void sendNotification(TeamcitySetting teamcitySetting, BuildShort buildShort) {
|
||||||
if (
|
if (isStatusBuild(teamcitySetting, buildShort.getStatus()) && isTypeBuild(teamcitySetting, buildShort.getBuildTypeId())) {
|
||||||
(teamcitySetting.isFailure() && BuildStatus.FAILURE.equals(buildShort.getStatus()))
|
|
||||||
|| (teamcitySetting.isSuccess() && BuildStatus.SUCCESS.equals(buildShort.getStatus()))
|
|
||||||
) {
|
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
ServiceNotify.builder()
|
TeamcityBuildNotify.builder()
|
||||||
|
.entityType(teamcitySetting.getRecipientType())
|
||||||
|
.recipients(Collections.singleton(teamcitySetting.getRecipientId()))
|
||||||
.buildShort(buildShort)
|
.buildShort(buildShort)
|
||||||
.chatId(teamcitySetting.getChatId())
|
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTypeBuild(TeamcitySetting teamcitySetting, String buildTypeId) {
|
||||||
|
return teamcitySetting.getBuildTypeId() == null
|
||||||
|
|| (teamcitySetting.getBuildTypeId().equals(buildTypeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStatusBuild(TeamcitySetting teamcitySetting, BuildStatus buildStatus) {
|
||||||
|
return (teamcitySetting.isFailure() && BuildStatus.FAILURE.equals(buildStatus))
|
||||||
|
|| (teamcitySetting.isSuccess() && BuildStatus.SUCCESS.equals(buildStatus));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuildShort update(@NonNull BuildShort buildShort) {
|
public BuildShort update(@NonNull BuildShort buildShort) {
|
||||||
return buildShortRepository.save(buildShort);
|
return buildShortRepository.save(buildShort);
|
||||||
|
@ -3,9 +3,10 @@ package org.sadtech.bot.vcs.telegram.service;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
import org.sadtech.bot.vcs.core.domain.notify.Notify;
|
||||||
|
import org.sadtech.bot.vcs.core.exception.NotFoundException;
|
||||||
|
import org.sadtech.bot.vcs.core.service.ChatService;
|
||||||
import org.sadtech.bot.vcs.core.service.MessageSendService;
|
import org.sadtech.bot.vcs.core.service.MessageSendService;
|
||||||
import org.sadtech.bot.vcs.core.service.PersonService;
|
import org.sadtech.bot.vcs.core.service.PersonService;
|
||||||
import org.sadtech.bot.vcs.teamcity.core.domain.ServiceNotify;
|
|
||||||
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 org.springframework.stereotype.Service;
|
||||||
@ -24,22 +25,25 @@ public class MessageSendTelegramService implements MessageSendService {
|
|||||||
private final Sending sending;
|
private final Sending sending;
|
||||||
|
|
||||||
private final PersonService personService;
|
private final PersonService personService;
|
||||||
|
private final ChatService chatService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(@NonNull Notify notify) {
|
public void send(@NonNull Notify notify) {
|
||||||
switch (notify.getTypeNotify()) {
|
final Set<Long> telegramIds = getTelegramIds(notify);
|
||||||
case PERSON:
|
|
||||||
final Set<Long> telegramIds = personService.getAllTelegramIdByLogin(notify.getLogins());
|
|
||||||
telegramIds.forEach(
|
telegramIds.forEach(
|
||||||
telegramId -> sending.send(telegramId, BoxAnswer.of(notify.generateMessage()))
|
telegramId -> sending.send(telegramId, BoxAnswer.of(notify.generateMessage()))
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
case SERVICE:
|
|
||||||
ServiceNotify serviceNotify = (ServiceNotify) notify;
|
|
||||||
sending.send(serviceNotify.getChatId(), BoxAnswer.of(notify.generateMessage()));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<Long> getTelegramIds(Notify notify) {
|
||||||
|
switch (notify.getEntityType()) {
|
||||||
|
case PERSON:
|
||||||
|
return personService.getAllTelegramIdByLogin(notify.getRecipients());
|
||||||
|
case CHAT:
|
||||||
|
return chatService.getAllTelegramIdByKey(notify.getRecipients());
|
||||||
|
default:
|
||||||
|
throw new NotFoundException("Отправка сообщения этому типу не возможна");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user