Browse Source

Minor refactoring for user notification settings

pull/8793/head
ViacheslavKlimov 3 years ago
parent
commit
d8896fe9dd
  1. 2
      application/src/main/java/org/thingsboard/server/controller/NotificationController.java
  2. 2
      common/data/src/main/java/org/thingsboard/server/common/data/page/SortOrder.java
  3. 13
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java

2
application/src/main/java/org/thingsboard/server/controller/NotificationController.java

@ -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 {

2
common/data/src/main/java/org/thingsboard/server/common/data/page/SortOrder.java

@ -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);
}

13
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationSettingsService.java

@ -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…
Cancel
Save