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

This commit is contained in:
2026-05-13 13:39:02 +07:00
parent 0546f6acd5
commit 48c14d475d
10 changed files with 154 additions and 21 deletions
@@ -1,5 +1,7 @@
package ru.soune.nocopy.service.monitoring;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.mail.MessagingException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -11,7 +13,6 @@ import ru.soune.nocopy.dto.file.YandexSearchResponse;
import ru.soune.nocopy.dto.tarriff.TariffDTO;
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
import ru.soune.nocopy.entity.monitoring.MonitoringType;
import ru.soune.nocopy.entity.notification.NotificationMessage;
import ru.soune.nocopy.entity.notification.NotificationType;
import ru.soune.nocopy.entity.tarif.TariffInfo;
import ru.soune.nocopy.entity.tarif.TariffType;
@@ -29,8 +30,10 @@ import ru.soune.nocopy.service.violation.ViolationService;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeoutException;
@Slf4j
@@ -97,7 +100,12 @@ public class MonitoringSearchService {
monitoringRepository.save(monitoring);
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId());
ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("status", NotificationType.SEARCH_OPERATION_FAILED.name());
context.put("error_message", e.getMessage());
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context);
}
} else {
log.info("Yandex search is disabled by settings");
@@ -121,7 +129,14 @@ public class MonitoringSearchService {
monitoringRepository.save(monitoring);
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId());
ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("message", "Error processing monitoring search");
context.put("reason", e.getMessage());
context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context);
}
} else {
log.info("Google search is disabled by settings");
@@ -159,8 +174,15 @@ public class MonitoringSearchService {
monitoringRepository.save(monitoring);
notificationService.addNotification(NotificationType.TOKEN_NOT_FOUND, user.getId(),
NotificationMessage.FILE_SEARCH.getMessageKey());
ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("current_tokens", currentTokens);
context.put("need_tokens", tariffMonitoring.getTokens());
context.put("message", "Not have tokens for search");
context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.TOKEN_NOT_FOUND, user.getId(), context);
} catch (Exception e) {
log.error("Error processing monitoring search", e);
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
@@ -168,7 +190,14 @@ public class MonitoringSearchService {
monitoringRepository.save(monitoring);
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId());
ObjectMapper mapper = new ObjectMapper();
ObjectNode context = mapper.createObjectNode();
context.put("message", "Error processing monitoring search");
context.put("reason", e.getMessage());
context.put("next_run", Objects.requireNonNull(calculateNextRun(
monitoring.getMonitoringType())).format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
notificationService.addNotification(NotificationType.SEARCH_OPERATION_FAILED, user.getId(), context);
}
}