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