Minor refactoring for user notification settings

This commit is contained in:
ViacheslavKlimov 2023-08-15 17:34:10 +03:00
parent ce06ea10ca
commit d8896fe9dd
3 changed files with 12 additions and 5 deletions

View File

@ -298,7 +298,7 @@ public class NotificationController extends BaseController {
if (targetType == NotificationTargetType.PLATFORM_USERS) {
PageData<User> recipients = notificationTargetService.findRecipientsForNotificationTargetConfig(user.getTenantId(),
(PlatformUsersNotificationTargetConfig) target.getConfiguration(), new PageLink(recipientsPreviewSize, 0, null,
SortOrder.byCreatedTimeDesc));
SortOrder.BY_CREATED_TIME_DESC));
recipientsCount = (int) recipients.getTotalElements();
recipientsPart = recipients.getData().stream().map(r -> (NotificationRecipient) r).collect(Collectors.toList());
} else {

View File

@ -36,6 +36,6 @@ public class SortOrder {
ASC, DESC
}
public static final SortOrder byCreatedTimeDesc = new SortOrder("createdTime", Direction.DESC);
public static final SortOrder BY_CREATED_TIME_DESC = new SortOrder("createdTime", Direction.DESC);
}

View File

@ -16,6 +16,7 @@
package org.thingsboard.server.dao.notification;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@ -55,6 +56,7 @@ import java.util.Optional;
@Service
@RequiredArgsConstructor
@Slf4j
public class DefaultNotificationSettingsService implements NotificationSettingsService {
private final AdminSettingsService adminSettingsService;
@ -104,10 +106,15 @@ public class DefaultNotificationSettingsService implements NotificationSettingsS
@Override
public UserNotificationSettings getUserNotificationSettings(TenantId tenantId, UserId userId, boolean format) {
UserSettings userSettings = userSettingsService.findUserSettings(tenantId, userId, UserSettingsType.NOTIFICATIONS);
UserNotificationSettings settings;
UserNotificationSettings settings = null;
if (userSettings != null) {
settings = JacksonUtil.treeToValue(userSettings.getSettings(), UserNotificationSettings.class);
} else {
try {
settings = JacksonUtil.treeToValue(userSettings.getSettings(), UserNotificationSettings.class);
} catch (Exception e) {
log.warn("Failed to parse notification settings for user {}", userId, e);
}
}
if (settings == null) {
settings = UserNotificationSettings.DEFAULT;
}
if (format) {