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 b810774832..f0ff5c061e 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
@@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.telemetry;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
+import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.rule.engine.api.RuleNode;
import org.thingsboard.rule.engine.api.TbContext;
@@ -40,8 +41,10 @@ import java.util.List;
configClazz = TbMsgAttributesNodeConfiguration.class,
nodeDescription = "Saves attributes data",
nodeDetails = "Saves entity attributes based on configurable scope parameter. Expects messages with 'POST_ATTRIBUTES_REQUEST' message type. " +
- "If upsert(update/insert) operation is completed successfully, rule node will send the \"Attributes Updated\" " +
- "event to the root chain of the message originator and send the incoming message via Success chain, otherwise, Failure chain is used.",
+ "Rule node allows user to enable/disable sending attributes updated notifications for SHARED_SCOPE and SERVER_SCOPE attributes updates. " +
+ "If upsert(update/insert) operation is completed successfully rule node will send the incoming message via Success chain, otherwise, Failure chain is used. " +
+ "Additionally if checkbox Send attributes updated notification is set to true, rule node will send the \"Attributes Updated\" " +
+ "event to the root chain of the message originator.",
uiResources = {"static/rulenode/rulenode-core-config.js"},
configDirective = "tbActionNodeAttributesConfig",
icon = "file_upload"
@@ -49,6 +52,8 @@ import java.util.List;
public class TbMsgAttributesNode implements TbNode {
private TbMsgAttributesNodeConfiguration config;
+ private String scope;
+ private boolean sendAttributesUpdateNotification;
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
@@ -56,6 +61,10 @@ 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
@@ -65,7 +74,7 @@ public class TbMsgAttributesNode implements TbNode {
return;
}
String src = msg.getData();
- List attributes = new ArrayList<>(JsonConverter.convertToAttributes(new JsonParser().parse(src)));
+ List attributes = new ArrayList<>(JsonConverter.convertToAttributes(JsonParser.parseString(src)));
if (attributes.isEmpty()) {
ctx.tellSuccess(msg);
return;
@@ -74,10 +83,12 @@ public class TbMsgAttributesNode implements TbNode {
ctx.getTelemetryService().saveAndNotify(
ctx.getTenantId(),
msg.getOriginator(),
- config.getScope(),
+ scope,
attributes,
config.getNotifyDevice() || StringUtils.isEmpty(notifyDeviceStr) || Boolean.parseBoolean(notifyDeviceStr),
- new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes)
+ sendAttributesUpdateNotification ?
+ new AttributesUpdateNodeCallback(ctx, msg, config.getScope(), attributes) :
+ new TelemetryNodeCallback(ctx, msg)
);
}
diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNodeConfiguration.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNodeConfiguration.java
index 1586048b81..93b8d63b47 100644
--- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNodeConfiguration.java
+++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/telemetry/TbMsgAttributesNodeConfiguration.java
@@ -25,12 +25,14 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration keys;
+ private boolean sendAttributesDeletedNotification;
@Override
public TbMsgDeleteAttributesConfiguration defaultConfiguration() {
TbMsgDeleteAttributesConfiguration configuration = new TbMsgDeleteAttributesConfiguration();
configuration.setScope(DataConstants.SERVER_SCOPE);
configuration.setKeys(Collections.emptyList());
+ configuration.setSendAttributesDeletedNotification(false);
return configuration;
}
}
diff --git a/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributesTest.java b/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributesTest.java
index 8972a3aa1f..a329f890af 100644
--- a/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributesTest.java
+++ b/rule-engine/rule-engine-components/src/test/java/org/thingsboard/rule/engine/telemetry/TbMsgDeleteAttributesTest.java
@@ -99,7 +99,19 @@ public class TbMsgDeleteAttributesTest {
}
@Test
- void givenMsg_whenOnMsg_thenVerifyOutput() throws Exception {
+ void givenMsg_whenOnMsg_thenVerifyOutput_NoSendAttributesDeletedNotification() throws Exception {
+ onMsg_thenVerifyOutput(false);
+ }
+
+ @Test
+ void givenMsg_whenOnMsg_thenVerifyOutput_SendAttributesDeletedNotification() throws Exception {
+ config.setSendAttributesDeletedNotification(true);
+ nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
+ node.init(ctx, nodeConfiguration);
+ onMsg_thenVerifyOutput(true);
+ }
+
+ void onMsg_thenVerifyOutput(boolean sendAttributesDeletedNotification) throws Exception {
final Map mdMap = Map.of(
"TestAttribute_1", "temperature",
"city", "NY"
@@ -114,11 +126,12 @@ public class TbMsgDeleteAttributesTest {
ArgumentCaptor> failureCaptor = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor newMsgCaptor = ArgumentCaptor.forClass(TbMsg.class);
- verify(ctx, times(1)).enqueue(any(), successCaptor.capture(), failureCaptor.capture());
- successCaptor.getValue().run();
+ if (sendAttributesDeletedNotification) {
+ verify(ctx, times(1)).enqueue(any(), successCaptor.capture(), failureCaptor.capture());
+ successCaptor.getValue().run();
+ verify(ctx, times(1)).attributesDeletedActionMsg(any(), any(), anyString(), anyList());
+ }
verify(ctx, times(1)).tellSuccess(newMsgCaptor.capture());
-
- verify(ctx, times(1)).attributesDeletedActionMsg(any(), any(), anyString(), anyList());
verify(ctx, never()).tellFailure(any(), any());
verify(telemetryService, times(1)).deleteAndNotify(any(), any(), anyString(), anyList(), any());
}