Refactoring for notification types filter
This commit is contained in:
parent
5009440bf5
commit
d9e90ea663
@ -21,7 +21,6 @@ import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@Data
|
||||
@ -36,8 +35,6 @@ public abstract class TbSubscription<T> {
|
||||
private final TbSubscriptionType type;
|
||||
private final BiConsumer<TbSubscription<T>, T> updateProcessor;
|
||||
|
||||
protected final AtomicInteger sequence = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -54,4 +51,5 @@ public abstract class TbSubscription<T> {
|
||||
public int hashCode() {
|
||||
return Objects.hash(sessionId, subscriptionId, tenantId, entityId, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ package org.thingsboard.server.service.ws.notification;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -80,7 +79,7 @@ public class DefaultNotificationCommandsHandler implements NotificationCommandsH
|
||||
.entityId(securityCtx.getId())
|
||||
.updateProcessor(this::handleNotificationsSubscriptionUpdate)
|
||||
.limit(cmd.getLimit())
|
||||
.notificationTypes(CollectionUtils.isNotEmpty(cmd.getTypes()) ? cmd.getTypes() : NotificationType.all)
|
||||
.notificationTypes(cmd.getTypes())
|
||||
.build();
|
||||
localSubscriptionService.addSubscription(subscription);
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ package org.thingsboard.server.service.ws.notification.sub;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.thingsboard.server.common.data.BaseData;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -52,7 +53,7 @@ public class NotificationsSubscription extends AbstractNotificationSubscription<
|
||||
}
|
||||
|
||||
public boolean checkNotificationType(NotificationType type) {
|
||||
return notificationTypes.contains(type);
|
||||
return CollectionUtils.isEmpty(notificationTypes) || notificationTypes.contains(type);
|
||||
}
|
||||
|
||||
public UnreadNotificationsUpdate createFullUpdate() {
|
||||
|
||||
@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.thingsboard.server.common.data.notification;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public enum NotificationType {
|
||||
|
||||
GENERAL,
|
||||
@ -34,8 +31,6 @@ public enum NotificationType {
|
||||
RATE_LIMITS,
|
||||
EDGE_CONNECTION,
|
||||
EDGE_COMMUNICATION_FAILURE,
|
||||
TASK_PROCESSING_FAILURE;
|
||||
|
||||
public static final Set<NotificationType> all = EnumSet.allOf(NotificationType.class);
|
||||
TASK_PROCESSING_FAILURE
|
||||
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class JpaNotificationDao extends JpaPartitionedAbstractDao<NotificationEn
|
||||
@Override
|
||||
public PageData<Notification> findUnreadByDeliveryMethodAndRecipientIdAndNotificationTypesAndPageLink(TenantId tenantId, NotificationDeliveryMethod deliveryMethod, UserId recipientId, Set<NotificationType> types, PageLink pageLink) {
|
||||
if (CollectionUtils.isEmpty(types)) {
|
||||
types = NotificationType.all;
|
||||
return findUnreadByDeliveryMethodAndRecipientIdAndPageLink(tenantId, deliveryMethod, recipientId, pageLink);
|
||||
}
|
||||
return DaoUtil.toPageData(notificationRepository.findByDeliveryMethodAndRecipientIdAndTypeInAndStatusNot(deliveryMethod,
|
||||
recipientId.getId(), types, NotificationStatus.READ, pageLink.getTextSearch(), DaoUtil.toPageable(pageLink)));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user