dev add context for notifcations
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-05-13 14:03:15 +07:00
parent 48c14d475d
commit cda829829c
8 changed files with 31 additions and 22 deletions
@@ -1,5 +1,7 @@
package ru.soune.nocopy.scheduler; package ru.soune.nocopy.scheduler;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@@ -55,7 +57,11 @@ public class MonitoringScheduler {
Set<Long> usersForNotifications = groupingFilesMonitoring.keySet(); Set<Long> usersForNotifications = groupingFilesMonitoring.keySet();
for (Long userId : usersForNotifications) { for (Long userId : usersForNotifications) {
notificationService.addNotification(NotificationType.MONITORING_RESULT, userId); ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("message", "Monitoring files on monitoring");
notificationService.addNotification(NotificationType.MONITORING_RESULT, userId, context.toString());
} }
} }
} }
@@ -458,7 +458,7 @@ public class FileUploadServiceImpl implements FileUploadService {
context.put("support_id", fileEntity.getSupportId()); context.put("support_id", fileEntity.getSupportId());
notificationService.addNotification(NotificationType.FILE_ADDED_TO_SYSTEM, session.getUserId(), notificationService.addNotification(NotificationType.FILE_ADDED_TO_SYSTEM, session.getUserId(),
context); context.toString());
} }
if (status != FileStatus.TEMP) { if (status != FileStatus.TEMP) {
@@ -98,7 +98,7 @@ public class ModerationService {
context.put("new_status", request.getNewStatus().name()); context.put("new_status", request.getNewStatus().name());
context.put("comment", request.getComment()); context.put("comment", request.getComment());
notificationService.addNotification(NotificationType.FILE_MODERATION_EVENT, file.getUserId(), context); notificationService.addNotification(NotificationType.FILE_MODERATION_EVENT, file.getUserId(), context.toString());
} }
/** /**
@@ -105,7 +105,8 @@ public class MonitoringSearchService {
context.put("status", NotificationType.SEARCH_OPERATION_FAILED.name()); context.put("status", NotificationType.SEARCH_OPERATION_FAILED.name());
context.put("error_message", e.getMessage()); context.put("error_message", e.getMessage());
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context); notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(),
context.toString());
} }
} else { } else {
log.info("Yandex search is disabled by settings"); log.info("Yandex search is disabled by settings");
@@ -136,7 +137,8 @@ public class MonitoringSearchService {
context.put("next_run", Objects.requireNonNull(calculateNextRun( context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"))); monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context); notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(),
context.toString());
} }
} else { } else {
log.info("Google search is disabled by settings"); log.info("Google search is disabled by settings");
@@ -182,7 +184,7 @@ public class MonitoringSearchService {
context.put("next_run", Objects.requireNonNull(calculateNextRun( context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"))); monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.TOKEN_NOT_FOUND, user.getId(), context); notificationService.addNotification(NotificationType.TOKEN_NOT_FOUND, user.getId(), context.toString());
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing monitoring search", e); log.error("Error processing monitoring search", e);
monitoring.setLastRunStatus("ERROR: " + e.getMessage()); monitoring.setLastRunStatus("ERROR: " + e.getMessage());
@@ -197,7 +199,8 @@ public class MonitoringSearchService {
context.put("next_run", Objects.requireNonNull(calculateNextRun( context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"))); monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context); notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(),
context.toString());
} }
} }
@@ -32,18 +32,18 @@ public class NotificationService {
private final MessageSource messageSource; private final MessageSource messageSource;
@Transactional // @Transactional
public void addNotification(NotificationType notificationType, long userId, Object... args) { // public void addNotification(NotificationType notificationType, long userId, Object... args) {
Notification notification = Notification.builder() // Notification notification = Notification.builder()
.notificationType(notificationType) // .notificationType(notificationType)
.createdAt(LocalDateTime.now()) // .createdAt(LocalDateTime.now())
.user(userRepository.findById(userId).orElseThrow()) // .user(userRepository.findById(userId).orElseThrow())
.status(NotificationStatus.NEW) // .status(NotificationStatus.NEW)
.message(notificationType.getMessageKey()) // .message(notificationType.getMessageKey())
.build(); // .build();
//
notificationRepository.save(notification); // notificationRepository.save(notification);
} // }
@Transactional @Transactional
public void addNotification(NotificationType notificationType, long userId, String context) { public void addNotification(NotificationType notificationType, long userId, String context) {
@@ -206,7 +206,7 @@ public class PaymentService {
context.put("reason", reason); context.put("reason", reason);
context.put("amount", payment.getAmount()); context.put("amount", payment.getAmount());
notificationService.addNotification(NotificationType.PAYMENT_RESULT, userId, context); notificationService.addNotification(NotificationType.PAYMENT_RESULT, userId, context.toString());
} }
public List<Payment> userPayments(String email) { public List<Payment> userPayments(String email) {
@@ -177,7 +177,7 @@ public class ReferralRepoImpl implements ReferralRepo {
ObjectNode context = mapper.createObjectNode(); ObjectNode context = mapper.createObjectNode();
context.put("referral_user", user != null ? user.getFullName(): null); context.put("referral_user", user != null ? user.getFullName(): null);
notificationService.addNotification(NotificationType.REFERRAL_REGISTERED, inviter); notificationService.addNotification(NotificationType.REFERRAL_REGISTERED, inviter, context.toString());
} }
} }
@@ -98,7 +98,7 @@ public class GlobalSearchAsyncProcessor {
context.put("files_id", files.toString()); context.put("files_id", files.toString());
context.put("count", files.toString()); context.put("count", files.toString());
notificationService.addNotification(NotificationType.SEARCH_RESULT, userId, context); notificationService.addNotification(NotificationType.SEARCH_RESULT, userId, context.toString());
} }
private GlobalSearchResult processFile(FileEntity file, String taskId, Long userId) { private GlobalSearchResult processFile(FileEntity file, String taskId, Long userId) {