Minor refactoring for user notification settings
This commit is contained in:
parent
ce06ea10ca
commit
d8896fe9dd
@ -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 {
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user