Browse Source

Add sequenceNumber to notification subscription updates

pull/9717/head
ViacheslavKlimov 3 years ago
parent
commit
e52782ee0e
  1. 3
      application/src/main/java/org/thingsboard/server/service/subscription/TbSubscription.java
  2. 5
      application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/UnreadNotificationsCountUpdate.java
  3. 5
      application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/UnreadNotificationsUpdate.java
  4. 1
      application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsCountSubscription.java
  5. 3
      application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsSubscription.java

3
application/src/main/java/org/thingsboard/server/service/subscription/TbSubscription.java

@ -21,6 +21,7 @@ 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
@ -35,6 +36,8 @@ 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;

5
application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/UnreadNotificationsCountUpdate.java

@ -28,14 +28,17 @@ import org.thingsboard.server.service.ws.telemetry.cmd.v2.CmdUpdateType;
public class UnreadNotificationsCountUpdate extends CmdUpdate { public class UnreadNotificationsCountUpdate extends CmdUpdate {
private final int totalUnreadCount; private final int totalUnreadCount;
private final int sequenceNumber;
@Builder @Builder
@JsonCreator @JsonCreator
public UnreadNotificationsCountUpdate(@JsonProperty("cmdId") int cmdId, @JsonProperty("errorCode") int errorCode, public UnreadNotificationsCountUpdate(@JsonProperty("cmdId") int cmdId, @JsonProperty("errorCode") int errorCode,
@JsonProperty("errorMsg") String errorMsg, @JsonProperty("errorMsg") String errorMsg,
@JsonProperty("totalUnreadCount") int totalUnreadCount) { @JsonProperty("totalUnreadCount") int totalUnreadCount,
@JsonProperty("sequenceNumber") int sequenceNumber) {
super(cmdId, errorCode, errorMsg); super(cmdId, errorCode, errorMsg);
this.totalUnreadCount = totalUnreadCount; this.totalUnreadCount = totalUnreadCount;
this.sequenceNumber = sequenceNumber;
} }
@Override @Override

5
application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/UnreadNotificationsUpdate.java

@ -33,6 +33,7 @@ public class UnreadNotificationsUpdate extends CmdUpdate {
private final Collection<Notification> notifications; private final Collection<Notification> notifications;
private final Notification update; private final Notification update;
private final int totalUnreadCount; private final int totalUnreadCount;
private final int sequenceNumber;
@Builder @Builder
@JsonCreator @JsonCreator
@ -40,11 +41,13 @@ public class UnreadNotificationsUpdate extends CmdUpdate {
@JsonProperty("errorMsg") String errorMsg, @JsonProperty("errorMsg") String errorMsg,
@JsonProperty("notifications") Collection<Notification> notifications, @JsonProperty("notifications") Collection<Notification> notifications,
@JsonProperty("update") Notification update, @JsonProperty("update") Notification update,
@JsonProperty("totalUnreadCount") int totalUnreadCount) { @JsonProperty("totalUnreadCount") int totalUnreadCount,
@JsonProperty("sequenceNumber") int sequenceNumber) {
super(cmdId, errorCode, errorMsg); super(cmdId, errorCode, errorMsg);
this.notifications = notifications; this.notifications = notifications;
this.update = update; this.update = update;
this.totalUnreadCount = totalUnreadCount; this.totalUnreadCount = totalUnreadCount;
this.sequenceNumber = sequenceNumber;
} }
@Override @Override

1
application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsCountSubscription.java

@ -41,6 +41,7 @@ public class NotificationsCountSubscription extends TbSubscription<Notifications
return UnreadNotificationsCountUpdate.builder() return UnreadNotificationsCountUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.totalUnreadCount(unreadCounter.get()) .totalUnreadCount(unreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }

3
application/src/main/java/org/thingsboard/server/service/ws/notification/sub/NotificationsSubscription.java

@ -54,6 +54,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.notifications(getSortedNotifications()) .notifications(getSortedNotifications())
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }
@ -68,6 +69,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.update(notification) .update(notification)
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }
@ -75,6 +77,7 @@ public class NotificationsSubscription extends TbSubscription<NotificationsSubsc
return UnreadNotificationsUpdate.builder() return UnreadNotificationsUpdate.builder()
.cmdId(getSubscriptionId()) .cmdId(getSubscriptionId())
.totalUnreadCount(totalUnreadCounter.get()) .totalUnreadCount(totalUnreadCounter.get())
.sequenceNumber(sequence.incrementAndGet())
.build(); .build();
} }

Loading…
Cancel
Save