From 126eeb6a4bee79629f6c604faa0bb1883955f376 Mon Sep 17 00:00:00 2001 From: Andrii Shvaika Date: Thu, 24 Nov 2022 17:53:10 +0200 Subject: [PATCH] Backport ability to specify scope in the metadata --- .../engine/telemetry/TbMsgAttributesNode.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java index bdd99914d6..77a4492858 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNode.java @@ -51,8 +51,8 @@ import java.util.List; public class TbMsgAttributesNode implements TbNode { private TbMsgAttributesNodeConfiguration config; - private String scope; - private boolean sendAttributesUpdateNotification; + + private static final String SCOPE = "scope"; @Override public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { @@ -60,10 +60,6 @@ public class TbMsgAttributesNode implements TbNode { if (config.getNotifyDevice() == null) { config.setNotifyDevice(true); } - this.scope = config.getScope(); - this.sendAttributesUpdateNotification = config.isSendAttributesUpdatedNotification() - && !DataConstants.CLIENT_SCOPE.equals(scope); - } @Override @@ -78,7 +74,12 @@ public class TbMsgAttributesNode implements TbNode { ctx.tellSuccess(msg); return; } + String scope = msg.getMetaData().getValue(SCOPE); + if (StringUtils.isEmpty(scope)) { + scope = config.getScope(); + } String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice"); + boolean sendAttributesUpdateNotification = checkSendNotification(scope); ctx.getTelemetryService().saveAndNotify( ctx.getTenantId(), msg.getOriginator(), @@ -91,4 +92,8 @@ public class TbMsgAttributesNode implements TbNode { ); } + private boolean checkSendNotification(String scope){ + return config.isSendAttributesUpdatedNotification() && !DataConstants.CLIENT_SCOPE.equals(scope); + } + }