Compare commits
4 Commits
develop
...
feature/de
Author | SHA1 | Date | |
---|---|---|---|
1a46edadec | |||
8d8acb6496 | |||
2d90c751a2 | |||
f9b5b86bb1 |
@ -0,0 +1,28 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.context.domain.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "deferred_messages")
|
||||||
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
public class DeferredMessage {
|
||||||
|
@Id
|
||||||
|
@Column(name = "deferred_messages_id")
|
||||||
|
private int id;
|
||||||
|
@Column(name = "message")
|
||||||
|
private String message;
|
||||||
|
@Column (name = "time")
|
||||||
|
private LocalDateTime time;
|
||||||
|
@Column (name = "type")
|
||||||
|
private String type;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@ -90,6 +90,15 @@
|
|||||||
<artifactId>jakarta.el</artifactId>
|
<artifactId>jakarta.el</artifactId>
|
||||||
<version>4.0.2</version>
|
<version>4.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.struchkov.bot.gitlab</groupId>
|
||||||
|
<artifactId>bot-data</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,67 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.core.service.impl;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.entity.DeferredMessage;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.*;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
|
||||||
|
import dev.struchkov.bot.gitlab.data.jpa.DelayedNotifyJpaRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DelayedNotifyServiceImpl {
|
||||||
|
|
||||||
|
private final DelayedNotifyJpaRepository delayedNotifyJpaRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public <T extends Notify> void save(T notify) {
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
DeferredMessage deferredMessage = new DeferredMessage();
|
||||||
|
String notifyForSave = gson.toJson(notify);
|
||||||
|
deferredMessage.setMessage(notifyForSave);
|
||||||
|
deferredMessage.setTime(LocalDateTime.now().withNano(0));
|
||||||
|
deferredMessage.setType(notify.getType());
|
||||||
|
delayedNotifyJpaRepository.save(deferredMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> getAllNotify(){
|
||||||
|
|
||||||
|
List<DeferredMessage> allDeferredMessageFromDb = delayedNotifyJpaRepository.findAll();
|
||||||
|
|
||||||
|
return allDeferredMessageFromDb.stream()
|
||||||
|
.map(DelayedNotifyServiceImpl::convertToNotifyClass).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Notify> T convertToNotifyClass(DeferredMessage deferredMessage) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Class<? extends Notify> newNotifyClass = switch (deferredMessage.getType()) {
|
||||||
|
case ConflictMrNotify.TYPE -> ConflictMrNotify.class;
|
||||||
|
case DiscussionNewNotify.TYPE -> DiscussionNewNotify.class;
|
||||||
|
case NewCommentNotify.TYPE -> NewCommentNotify.class;
|
||||||
|
case NewMrForAssignee.TYPE -> NewMrForAssignee.class;
|
||||||
|
case NewMrForReview.TYPE -> NewMrForReview.class;
|
||||||
|
case NewProjectNotify.TYPE -> NewProjectNotify.class;
|
||||||
|
case PipelineNotify.TYPE -> PipelineNotify.class;
|
||||||
|
case StatusMrNotify.TYPE -> StatusMrNotify.class;
|
||||||
|
case TaskCloseNotify.TYPE -> TaskCloseNotify.class;
|
||||||
|
case UpdateMrNotify.TYPE -> UpdateMrNotify.class;
|
||||||
|
default -> throw new RuntimeException("the " + deferredMessage.getType() + " type class is not found");
|
||||||
|
};
|
||||||
|
|
||||||
|
Object notify = gson.fromJson(deferredMessage.getMessage(), newNotifyClass);
|
||||||
|
return (T) notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -12,18 +12,21 @@ public class NotifyServiceImpl implements NotifyService {
|
|||||||
|
|
||||||
private final MessageSendService messageSendService;
|
private final MessageSendService messageSendService;
|
||||||
private final AppSettingService settingService;
|
private final AppSettingService settingService;
|
||||||
|
private final DelayedNotifyServiceImpl delayedNotifyService;
|
||||||
|
|
||||||
public NotifyServiceImpl(
|
public NotifyServiceImpl(
|
||||||
@Lazy MessageSendService messageSendService,
|
@Lazy MessageSendService messageSendService,
|
||||||
AppSettingService settingService
|
AppSettingService settingService,
|
||||||
) {
|
DelayedNotifyServiceImpl delayedNotifyService) {
|
||||||
this.messageSendService = messageSendService;
|
this.messageSendService = messageSendService;
|
||||||
this.settingService = settingService;
|
this.settingService = settingService;
|
||||||
|
this.delayedNotifyService = delayedNotifyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Notify> void send(T notify) {
|
public <T extends Notify> void send(T notify) {
|
||||||
if (settingService.isEnableAllNotify()) {
|
if (settingService.isEnableAllNotify()) {
|
||||||
|
delayedNotifyService.save(notify);
|
||||||
messageSendService.send(notify);
|
messageSendService.send(notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.data.jpa;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.entity.DeferredMessage;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface DelayedNotifyJpaRepository extends JpaRepository<DeferredMessage, Long> {
|
||||||
|
}
|
@ -274,4 +274,15 @@
|
|||||||
<addPrimaryKey tableName="merge_request_reviewer" columnNames="merge_request_id, person_id"/>
|
<addPrimaryKey tableName="merge_request_reviewer" columnNames="merge_request_id, person_id"/>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="2023-02-08-create-table-messages" author="uPagge">
|
||||||
|
<createTable tableName="deferred_messages">
|
||||||
|
<column name="deferred_messages_id" type="int">
|
||||||
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="message" type="varchar"/>
|
||||||
|
<column name="time" type="timestamp"/>
|
||||||
|
<column name="type" type="varchar"/>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
Loading…
x
Reference in New Issue
Block a user