From cc9a47a7636779c72a6c9a8f07128bd2381844cd Mon Sep 17 00:00:00 2001 From: Sergey Matvienko Date: Tue, 5 Sep 2023 17:06:09 +0200 Subject: [PATCH] TbMsgAttributesNode updateAttributesOnValueChange renamed with updateAttributesOnlyOnValueChange --- .../rule_chains/edge_root_rule_chain.json | 2 +- .../device_profile/rule_chain_template.json | 2 +- .../tenant/rule_chains/root_rule_chain.json | 2 +- .../engine/telemetry/TbMsgAttributesNode.java | 10 +++---- .../TbMsgAttributesNodeConfiguration.java | 4 +-- .../TbMsgAttributesNodeConfigurationTest.java | 4 +-- .../telemetry/TbMsgAttributesNodeTest.java | 27 ++++++++++--------- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/application/src/main/data/json/edge/rule_chains/edge_root_rule_chain.json b/application/src/main/data/json/edge/rule_chains/edge_root_rule_chain.json index 47a811d402..de71ced3a5 100644 --- a/application/src/main/data/json/edge/rule_chains/edge_root_rule_chain.json +++ b/application/src/main/data/json/edge/rule_chains/edge_root_rule_chain.json @@ -53,7 +53,7 @@ "scope": "CLIENT_SCOPE", "notifyDevice": "false", "sendAttributesUpdatedNotification": "false", - "updateAttributesOnValueChange": "true" + "updateAttributesOnlyOnValueChange": "true" }, "externalId": null }, diff --git a/application/src/main/data/json/tenant/device_profile/rule_chain_template.json b/application/src/main/data/json/tenant/device_profile/rule_chain_template.json index 7e1325d412..7d1deb7e41 100644 --- a/application/src/main/data/json/tenant/device_profile/rule_chain_template.json +++ b/application/src/main/data/json/tenant/device_profile/rule_chain_template.json @@ -37,7 +37,7 @@ "scope": "CLIENT_SCOPE", "notifyDevice": "false", "sendAttributesUpdatedNotification": "false", - "updateAttributesOnValueChange": "true" + "updateAttributesOnlyOnValueChange": "true" } }, { diff --git a/application/src/main/data/json/tenant/rule_chains/root_rule_chain.json b/application/src/main/data/json/tenant/rule_chains/root_rule_chain.json index b850de3e70..57c3a86dfb 100644 --- a/application/src/main/data/json/tenant/rule_chains/root_rule_chain.json +++ b/application/src/main/data/json/tenant/rule_chains/root_rule_chain.json @@ -36,7 +36,7 @@ "scope": "CLIENT_SCOPE", "notifyDevice": "false", "sendAttributesUpdatedNotification": "false", - "updateAttributesOnValueChange": "true" + "updateAttributesOnlyOnValueChange": "true" } }, { 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 79cbf87274..923abe444c 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 @@ -61,14 +61,14 @@ import static org.thingsboard.server.common.data.msg.TbMsgType.POST_ATTRIBUTES_R "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 put the \"Attributes Updated\" " + "event for SHARED_SCOPE and SERVER_SCOPE attributes updates to the corresponding rule engine queue." + - "Performance checkbox 'Update Attributes On Value Change' will skip attributes overwrites for values with no changes (avoid concurrent writes because this check is not transactional; will not update 'Last updated time' for skipped attributes).", + "Performance checkbox 'Save attributes only if the value changes' will skip attributes overwrites for values with no changes (avoid concurrent writes because this check is not transactional; will not update 'Last updated time' for skipped attributes).", uiResources = {"static/rulenode/rulenode-core-config.js"}, configDirective = "tbActionNodeAttributesConfig", icon = "file_upload" ) public class TbMsgAttributesNode implements TbNode, TbVersionedNode { - static final String UPDATE_ATTRIBUTES_ON_VALUE_CHANGE_KEY = "updateAttributesOnValueChange"; + static final String UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY = "updateAttributesOnlyOnValueChange"; private TbMsgAttributesNodeConfiguration config; @Override @@ -94,7 +94,7 @@ public class TbMsgAttributesNode implements TbNode, TbVersionedNode { String scope = getScope(msg.getMetaData().getValue(SCOPE)); boolean sendAttributesUpdateNotification = checkSendNotification(scope); - if (!config.isUpdateAttributesOnValueChange()) { + if (!config.isUpdateAttributesOnlyOnValueChange()) { saveAttr(newAttributes, ctx, msg, scope, sendAttributesUpdateNotification); return; } @@ -171,9 +171,9 @@ public class TbMsgAttributesNode implements TbNode, TbVersionedNode { boolean hasChanges = false; switch (fromVersion) { case 0: - if (!oldConfiguration.has(UPDATE_ATTRIBUTES_ON_VALUE_CHANGE_KEY)) { + if (!oldConfiguration.has(UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY)) { hasChanges = true; - ((ObjectNode) oldConfiguration).put(UPDATE_ATTRIBUTES_ON_VALUE_CHANGE_KEY, false); + ((ObjectNode) oldConfiguration).put(UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY, false); } break; default: 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 1c3112c4de..1dd98feb16 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 @@ -26,7 +26,7 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration upgradeResult = node.upgrade(0, jsonNode); ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond(); assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isTrue(); - assertThat(resultNode.has(updateAttributesOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnValueChangeKey).isTrue(); - assertThat(resultNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("upgrade result value [false] for key " + updateAttributesOnValueChangeKey).isFalse(); + assertThat(resultNode.has(updateAttributesOnlyOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnlyOnValueChangeKey).isTrue(); + assertThat(resultNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("upgrade result value [false] for key " + updateAttributesOnlyOnValueChangeKey).isFalse(); } @Test - void testUpgrade_fromVersion0_alreadyHasUpdateAttributesOnValueChange() throws TbNodeException { - final String updateAttributesOnValueChangeKey = "updateAttributesOnValueChange"; + void testUpgrade_fromVersion0_alreadyHasupdateAttributesOnlyOnValueChange() throws TbNodeException { TbMsgAttributesNode node = mock(TbMsgAttributesNode.class); willCallRealMethod().given(node).upgrade(anyInt(), any()); ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration()); - jsonNode.remove(updateAttributesOnValueChangeKey); - jsonNode.put(updateAttributesOnValueChangeKey, true); - assertThat(jsonNode.has(updateAttributesOnValueChangeKey)).as("pre condition has no " + updateAttributesOnValueChangeKey).isTrue(); - assertThat(jsonNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("pre condition has [true] for key " + updateAttributesOnValueChangeKey).isTrue(); + jsonNode.remove(updateAttributesOnlyOnValueChangeKey); + jsonNode.put(updateAttributesOnlyOnValueChangeKey, true); + assertThat(jsonNode.has(updateAttributesOnlyOnValueChangeKey)).as("pre condition has no " + updateAttributesOnlyOnValueChangeKey).isTrue(); + assertThat(jsonNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("pre condition has [true] for key " + updateAttributesOnlyOnValueChangeKey).isTrue(); TbPair upgradeResult = node.upgrade(0, jsonNode); ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond(); assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isFalse(); - assertThat(resultNode.has(updateAttributesOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnValueChangeKey).isTrue(); - assertThat(resultNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("upgrade result value [true] for key " + updateAttributesOnValueChangeKey).isTrue(); + assertThat(resultNode.has(updateAttributesOnlyOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnlyOnValueChangeKey).isTrue(); + assertThat(resultNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("upgrade result value [true] for key " + updateAttributesOnlyOnValueChangeKey).isTrue(); } }