diff --git a/application/src/main/java/org/thingsboard/server/service/ws/DefaultWebSocketService.java b/application/src/main/java/org/thingsboard/server/service/ws/DefaultWebSocketService.java index 895699756a..85f8bd7207 100644 --- a/application/src/main/java/org/thingsboard/server/service/ws/DefaultWebSocketService.java +++ b/application/src/main/java/org/thingsboard/server/service/ws/DefaultWebSocketService.java @@ -66,7 +66,7 @@ import org.thingsboard.server.service.subscription.TbTimeSeriesSubscription; import org.thingsboard.server.service.ws.notification.NotificationCommandsHandler; import org.thingsboard.server.service.ws.notification.cmd.NotificationCmdsWrapper; import org.thingsboard.server.service.ws.notification.cmd.WsCmd; -import org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper; +import org.thingsboard.server.service.ws.telemetry.cmd.WsCommandsWrapper; import org.thingsboard.server.service.ws.telemetry.cmd.v1.AttributesSubscriptionCmd; import org.thingsboard.server.service.ws.telemetry.cmd.v1.GetHistoryCmd; import org.thingsboard.server.service.ws.telemetry.cmd.v1.SubscriptionCmd; @@ -160,22 +160,22 @@ public class DefaultWebSocketService implements WebSocketService { pingExecutor.scheduleWithFixedDelay(this::sendPing, pingTimeout / NUMBER_OF_PING_ATTEMPTS, pingTimeout / NUMBER_OF_PING_ATTEMPTS, TimeUnit.MILLISECONDS); cmdsHandlers = List.of( - newCmdsHandler(WsCmdsWrapper::getAttrSubCmds, this::handleWsAttributesSubscriptionCmd), - newCmdsHandler(WsCmdsWrapper::getTsSubCmds, this::handleWsTimeseriesSubscriptionCmd), - newCmdsHandler(WsCmdsWrapper::getHistoryCmds, this::handleWsHistoryCmd), - newCmdsHandler(WsCmdsWrapper::getEntityDataCmds, this::handleWsEntityDataCmd), - newCmdsHandler(WsCmdsWrapper::getAlarmDataCmds, this::handleWsAlarmDataCmd), - newCmdsHandler(WsCmdsWrapper::getEntityCountCmds, this::handleWsEntityCountCmd), - newCmdsHandler(WsCmdsWrapper::getAlarmCountCmds, this::handleWsAlarmCountCmd), - newCmdsHandler(WsCmdsWrapper::getEntityDataUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), - newCmdsHandler(WsCmdsWrapper::getAlarmDataUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), - newCmdsHandler(WsCmdsWrapper::getEntityCountUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), - newCmdsHandler(WsCmdsWrapper::getAlarmCountUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), - newCmdHandler(WsCmdsWrapper::getUnreadNotificationsSubCmd, notificationCmdsHandler::handleUnreadNotificationsSubCmd), - newCmdHandler(WsCmdsWrapper::getUnreadNotificationsCountSubCmd, notificationCmdsHandler::handleUnreadNotificationsCountSubCmd), - newCmdHandler(WsCmdsWrapper::getMarkNotificationAsReadCmd, notificationCmdsHandler::handleMarkAsReadCmd), - newCmdHandler(WsCmdsWrapper::getMarkAllNotificationsAsReadCmd, notificationCmdsHandler::handleMarkAllAsReadCmd), - newCmdHandler(WsCmdsWrapper::getNotificationsUnsubCmd, notificationCmdsHandler::handleUnsubCmd) + newCmdsHandler(WsCommandsWrapper::getAttrSubCmds, this::handleWsAttributesSubscriptionCmd), + newCmdsHandler(WsCommandsWrapper::getTsSubCmds, this::handleWsTimeseriesSubscriptionCmd), + newCmdsHandler(WsCommandsWrapper::getHistoryCmds, this::handleWsHistoryCmd), + newCmdsHandler(WsCommandsWrapper::getEntityDataCmds, this::handleWsEntityDataCmd), + newCmdsHandler(WsCommandsWrapper::getAlarmDataCmds, this::handleWsAlarmDataCmd), + newCmdsHandler(WsCommandsWrapper::getEntityCountCmds, this::handleWsEntityCountCmd), + newCmdsHandler(WsCommandsWrapper::getAlarmCountCmds, this::handleWsAlarmCountCmd), + newCmdsHandler(WsCommandsWrapper::getEntityDataUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), + newCmdsHandler(WsCommandsWrapper::getAlarmDataUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), + newCmdsHandler(WsCommandsWrapper::getEntityCountUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), + newCmdsHandler(WsCommandsWrapper::getAlarmCountUnsubscribeCmds, this::handleWsDataUnsubscribeCmd), + newCmdsHandler(WsCommandsWrapper::getUnreadNotificationsSubCmds, notificationCmdsHandler::handleUnreadNotificationsSubCmd), + newCmdsHandler(WsCommandsWrapper::getUnreadNotificationsCountSubCmds, notificationCmdsHandler::handleUnreadNotificationsCountSubCmd), + newCmdsHandler(WsCommandsWrapper::getMarkNotificationAsReadCmds, notificationCmdsHandler::handleMarkAsReadCmd), + newCmdsHandler(WsCommandsWrapper::getMarkAllNotificationsAsReadCmds, notificationCmdsHandler::handleMarkAllAsReadCmd), + newCmdsHandler(WsCommandsWrapper::getNotificationsUnsubCmds, notificationCmdsHandler::handleUnsubCmd) ); } @@ -232,7 +232,7 @@ public class DefaultWebSocketService implements WebSocketService { } private void processCmds(WebSocketSessionRef sessionRef, String msg) throws JsonProcessingException { - WsCmdsWrapper cmdsWrapper = JacksonUtil.fromString(msg, WsCmdsWrapper.class); + WsCommandsWrapper cmdsWrapper = JacksonUtil.fromString(msg, WsCommandsWrapper.class); processCmds(sessionRef, cmdsWrapper); } @@ -241,7 +241,7 @@ public class DefaultWebSocketService implements WebSocketService { processCmds(sessionRef, cmdsWrapper.toCommonCmdsWrapper()); } - private void processCmds(WebSocketSessionRef sessionRef, WsCmdsWrapper cmdsWrapper) { + private void processCmds(WebSocketSessionRef sessionRef, WsCommandsWrapper cmdsWrapper) { if (cmdsWrapper == null) { return; } @@ -1033,22 +1033,17 @@ public class DefaultWebSocketService implements WebSocketService { } - public static WsCmdHandler newCmdHandler(java.util.function.Function cmdExtractor, - BiConsumer handler) { - return new WsCmdHandler<>(cmdExtractor, handler); - } - - public static WsCmdsHandler newCmdsHandler(java.util.function.Function> cmdsExtractor, + public static WsCmdsHandler newCmdsHandler(java.util.function.Function> cmdsExtractor, BiConsumer handler) { return new WsCmdsHandler<>(cmdsExtractor, handler); } @RequiredArgsConstructor public static class WsCmdsHandler { - private final java.util.function.Function> cmdsExtractor; + private final java.util.function.Function> cmdsExtractor; protected final BiConsumer handler; - public List extract(WsCmdsWrapper cmdsWrapper) { + public List extract(WsCommandsWrapper cmdsWrapper) { return cmdsExtractor.apply(cmdsWrapper); } @@ -1059,7 +1054,7 @@ public class DefaultWebSocketService implements WebSocketService { } public static class WsCmdHandler extends WsCmdsHandler { - public WsCmdHandler(java.util.function.Function cmdExtractor, BiConsumer handler) { + public WsCmdHandler(java.util.function.Function cmdExtractor, BiConsumer handler) { super(cmdsWrapper -> { C cmd = cmdExtractor.apply(cmdsWrapper); return cmd != null ? List.of(cmd) : null; diff --git a/application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/NotificationCmdsWrapper.java b/application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/NotificationCmdsWrapper.java index de7a6adab7..664cfcef5b 100644 --- a/application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/NotificationCmdsWrapper.java +++ b/application/src/main/java/org/thingsboard/server/service/ws/notification/cmd/NotificationCmdsWrapper.java @@ -17,10 +17,12 @@ package org.thingsboard.server.service.ws.notification.cmd; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; -import org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper; +import org.thingsboard.server.service.ws.telemetry.cmd.WsCommandsWrapper; + +import java.util.List; /** - * @deprecated Use {@link org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper}. This class is left for backward compatibility + * @deprecated Use {@link WsCommandsWrapper}. This class is left for backward compatibility * */ @Data @Deprecated @@ -37,13 +39,13 @@ public class NotificationCmdsWrapper { private NotificationsUnsubCmd unsubCmd; @JsonIgnore - public WsCmdsWrapper toCommonCmdsWrapper() { - WsCmdsWrapper wrapper = new WsCmdsWrapper(); - wrapper.setUnreadNotificationsCountSubCmd(unreadCountSubCmd); - wrapper.setUnreadNotificationsSubCmd(unreadSubCmd); - wrapper.setMarkNotificationAsReadCmd(markAsReadCmd); - wrapper.setMarkAllNotificationsAsReadCmd(markAllAsReadCmd); - wrapper.setNotificationsUnsubCmd(unsubCmd); + public WsCommandsWrapper toCommonCmdsWrapper() { + WsCommandsWrapper wrapper = new WsCommandsWrapper(); + wrapper.setUnreadNotificationsCountSubCmds(List.of(unreadCountSubCmd)); + wrapper.setUnreadNotificationsSubCmds(List.of(unreadSubCmd)); + wrapper.setMarkNotificationAsReadCmds(List.of(markAsReadCmd)); + wrapper.setMarkAllNotificationsAsReadCmds(List.of(markAllAsReadCmd)); + wrapper.setNotificationsUnsubCmds(List.of(unsubCmd)); return wrapper; } diff --git a/application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCmdsWrapper.java b/application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCommandsWrapper.java similarity index 87% rename from application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCmdsWrapper.java rename to application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCommandsWrapper.java index 40eb672030..34d2acfbb9 100644 --- a/application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCmdsWrapper.java +++ b/application/src/main/java/org/thingsboard/server/service/ws/telemetry/cmd/WsCommandsWrapper.java @@ -39,7 +39,7 @@ import java.util.List; * @author Andrew Shvayka */ @Data -public class WsCmdsWrapper { +public class WsCommandsWrapper { private List attrSubCmds; @@ -63,14 +63,14 @@ public class WsCmdsWrapper { private List alarmCountUnsubscribeCmds; - private NotificationsCountSubCmd unreadNotificationsCountSubCmd; + private List unreadNotificationsCountSubCmds; - private NotificationsSubCmd unreadNotificationsSubCmd; + private List unreadNotificationsSubCmds; - private MarkNotificationsAsReadCmd markNotificationAsReadCmd; + private List markNotificationAsReadCmds; - private MarkAllNotificationsAsReadCmd markAllNotificationsAsReadCmd; + private List markAllNotificationsAsReadCmds; - private NotificationsUnsubCmd notificationsUnsubCmd; + private List notificationsUnsubCmds; } diff --git a/application/src/test/java/org/thingsboard/server/controller/TbTestWebSocketClient.java b/application/src/test/java/org/thingsboard/server/controller/TbTestWebSocketClient.java index 43afcfc845..a365a36cf4 100644 --- a/application/src/test/java/org/thingsboard/server/controller/TbTestWebSocketClient.java +++ b/application/src/test/java/org/thingsboard/server/controller/TbTestWebSocketClient.java @@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.query.EntityDataPageLink; import org.thingsboard.server.common.data.query.EntityDataQuery; import org.thingsboard.server.common.data.query.EntityFilter; import org.thingsboard.server.common.data.query.EntityKey; -import org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper; +import org.thingsboard.server.service.ws.telemetry.cmd.WsCommandsWrapper; import org.thingsboard.server.service.ws.telemetry.cmd.v1.AttributesSubscriptionCmd; import org.thingsboard.server.service.ws.telemetry.cmd.v2.AlarmCountCmd; import org.thingsboard.server.service.ws.telemetry.cmd.v2.AlarmCountUpdate; @@ -106,19 +106,19 @@ public class TbTestWebSocketClient extends WebSocketClient { } public void send(EntityDataCmd cmd) throws NotYetConnectedException { - WsCmdsWrapper wrapper = new WsCmdsWrapper(); + WsCommandsWrapper wrapper = new WsCommandsWrapper(); wrapper.setEntityDataCmds(Collections.singletonList(cmd)); this.send(JacksonUtil.toString(wrapper)); } public void send(EntityCountCmd cmd) throws NotYetConnectedException { - WsCmdsWrapper wrapper = new WsCmdsWrapper(); + WsCommandsWrapper wrapper = new WsCommandsWrapper(); wrapper.setEntityCountCmds(Collections.singletonList(cmd)); this.send(JacksonUtil.toString(wrapper)); } public void send(AlarmCountCmd cmd) throws NotYetConnectedException { - WsCmdsWrapper wrapper = new WsCmdsWrapper(); + WsCommandsWrapper wrapper = new WsCommandsWrapper(); wrapper.setAlarmCountCmds(Collections.singletonList(cmd)); this.send(JacksonUtil.toString(wrapper)); } @@ -240,7 +240,7 @@ public class TbTestWebSocketClient extends WebSocketClient { cmd.setEntityId(entityId.getId().toString()); cmd.setScope(scope); cmd.setKeys(String.join(",", keys)); - WsCmdsWrapper cmdsWrapper = new WsCmdsWrapper(); + WsCommandsWrapper cmdsWrapper = new WsCommandsWrapper(); cmdsWrapper.setAttrSubCmds(List.of(cmd)); JsonNode msg = JacksonUtil.valueToTree(cmdsWrapper); ((ObjectNode) msg.get("attrSubCmds").get(0)).remove("type"); diff --git a/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiWsClient.java b/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiWsClient.java index 31023fe258..1c4772ebf5 100644 --- a/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiWsClient.java +++ b/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiWsClient.java @@ -28,7 +28,7 @@ import org.thingsboard.server.service.ws.notification.cmd.NotificationsCountSubC import org.thingsboard.server.service.ws.notification.cmd.NotificationsSubCmd; import org.thingsboard.server.service.ws.notification.cmd.UnreadNotificationsCountUpdate; import org.thingsboard.server.service.ws.notification.cmd.UnreadNotificationsUpdate; -import org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper; +import org.thingsboard.server.service.ws.telemetry.cmd.WsCommandsWrapper; import org.thingsboard.server.service.ws.telemetry.cmd.v2.CmdUpdateType; import java.net.URI; @@ -54,33 +54,33 @@ public class NotificationApiWsClient extends TbTestWebSocketClient { } public NotificationApiWsClient subscribeForUnreadNotifications(int limit) { - WsCmdsWrapper cmdsWrapper = new WsCmdsWrapper(); - cmdsWrapper.setUnreadNotificationsSubCmd(new NotificationsSubCmd(1, limit)); + WsCommandsWrapper cmdsWrapper = new WsCommandsWrapper(); + cmdsWrapper.setUnreadNotificationsSubCmds(List.of(new NotificationsSubCmd(1, limit))); sendCmd(cmdsWrapper); this.limit = limit; return this; } public NotificationApiWsClient subscribeForUnreadNotificationsCount() { - WsCmdsWrapper cmdsWrapper = new WsCmdsWrapper(); - cmdsWrapper.setUnreadNotificationsCountSubCmd(new NotificationsCountSubCmd(2)); + WsCommandsWrapper cmdsWrapper = new WsCommandsWrapper(); + cmdsWrapper.setUnreadNotificationsCountSubCmds(List.of(new NotificationsCountSubCmd(2))); sendCmd(cmdsWrapper); return this; } public void markNotificationAsRead(UUID... notifications) { - WsCmdsWrapper cmdsWrapper = new WsCmdsWrapper(); - cmdsWrapper.setMarkNotificationAsReadCmd(new MarkNotificationsAsReadCmd(newCmdId(), Arrays.asList(notifications))); + WsCommandsWrapper cmdsWrapper = new WsCommandsWrapper(); + cmdsWrapper.setMarkNotificationAsReadCmds(List.of(new MarkNotificationsAsReadCmd(newCmdId(), Arrays.asList(notifications)))); sendCmd(cmdsWrapper); } public void markAllNotificationsAsRead() { - WsCmdsWrapper cmdsWrapper = new WsCmdsWrapper(); - cmdsWrapper.setMarkAllNotificationsAsReadCmd(new MarkAllNotificationsAsReadCmd(newCmdId())); + WsCommandsWrapper cmdsWrapper = new WsCommandsWrapper(); + cmdsWrapper.setMarkAllNotificationsAsReadCmds(List.of(new MarkAllNotificationsAsReadCmd(newCmdId()))); sendCmd(cmdsWrapper); } - public void sendCmd(WsCmdsWrapper cmdsWrapper) { + public void sendCmd(WsCommandsWrapper cmdsWrapper) { String cmd = JacksonUtil.toString(cmdsWrapper); send(cmd); } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java index 3dd011ac78..94c18f1b73 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java @@ -63,7 +63,7 @@ import org.thingsboard.server.common.data.query.SingleEntityFilter; import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.service.ws.telemetry.cmd.WsCmdsWrapper; +import org.thingsboard.server.service.ws.telemetry.cmd.WsCommandsWrapper; import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityDataCmd; import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityDataUpdate; import org.thingsboard.server.service.ws.telemetry.cmd.v2.LatestValueCmd; @@ -229,7 +229,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null); - WsCmdsWrapper wrapper = new WsCmdsWrapper(); + WsCommandsWrapper wrapper = new WsCommandsWrapper(); wrapper.setEntityDataCmds(Collections.singletonList(cmd)); getWsClient().send(JacksonUtil.toString(wrapper));