TbMsgAttributesNode updateAttributesOnValueChange renamed with updateAttributesOnlyOnValueChange
This commit is contained in:
parent
125385b582
commit
cc9a47a763
@ -53,7 +53,7 @@
|
||||
"scope": "CLIENT_SCOPE",
|
||||
"notifyDevice": "false",
|
||||
"sendAttributesUpdatedNotification": "false",
|
||||
"updateAttributesOnValueChange": "true"
|
||||
"updateAttributesOnlyOnValueChange": "true"
|
||||
},
|
||||
"externalId": null
|
||||
},
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
"scope": "CLIENT_SCOPE",
|
||||
"notifyDevice": "false",
|
||||
"sendAttributesUpdatedNotification": "false",
|
||||
"updateAttributesOnValueChange": "true"
|
||||
"updateAttributesOnlyOnValueChange": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
"scope": "CLIENT_SCOPE",
|
||||
"notifyDevice": "false",
|
||||
"sendAttributesUpdatedNotification": "false",
|
||||
"updateAttributesOnValueChange": "true"
|
||||
"updateAttributesOnlyOnValueChange": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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 <b>Success</b> chain, otherwise, <b>Failure</b> chain is used. " +
|
||||
"Additionally if checkbox <b>Send attributes updated notification</b> is set to true, rule node will put the \"Attributes Updated\" " +
|
||||
"event for <b>SHARED_SCOPE</b> and <b>SERVER_SCOPE</b> 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:
|
||||
|
||||
@ -26,7 +26,7 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration<TbMsg
|
||||
|
||||
private Boolean notifyDevice;
|
||||
private boolean sendAttributesUpdatedNotification;
|
||||
private boolean updateAttributesOnValueChange;
|
||||
private boolean updateAttributesOnlyOnValueChange;
|
||||
|
||||
@Override
|
||||
public TbMsgAttributesNodeConfiguration defaultConfiguration() {
|
||||
@ -35,7 +35,7 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration<TbMsg
|
||||
configuration.setNotifyDevice(false);
|
||||
configuration.setSendAttributesUpdatedNotification(false);
|
||||
//Since version 1. For an existing rule nodes for version 0. See the TbVersionedNode implementation
|
||||
configuration.setUpdateAttributesOnValueChange(true);
|
||||
configuration.setUpdateAttributesOnlyOnValueChange(true);
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,8 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class TbMsgAttributesNodeConfigurationTest {
|
||||
|
||||
@Test
|
||||
void testDefaultConfig_givenUpdateAttributesOnValueChange_thenTrue_sinceVersion1() {
|
||||
assertThat(new TbMsgAttributesNodeConfiguration().defaultConfiguration().isUpdateAttributesOnValueChange()).isTrue();
|
||||
void testDefaultConfig_givenupdateAttributesOnlyOnValueChange_thenTrue_sinceVersion1() {
|
||||
assertThat(new TbMsgAttributesNodeConfiguration().defaultConfiguration().isUpdateAttributesOnlyOnValueChange()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,42 +32,43 @@ import static org.mockito.Mockito.mock;
|
||||
@Slf4j
|
||||
class TbMsgAttributesNodeTest {
|
||||
|
||||
final String updateAttributesOnlyOnValueChangeKey = "updateAttributesOnlyOnValueChange";
|
||||
|
||||
@Test
|
||||
void testUpgrade_fromVersion0() throws TbNodeException {
|
||||
final String updateAttributesOnValueChangeKey = "updateAttributesOnValueChange";
|
||||
|
||||
TbMsgAttributesNode node = mock(TbMsgAttributesNode.class);
|
||||
willCallRealMethod().given(node).upgrade(anyInt(), any());
|
||||
|
||||
ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration());
|
||||
jsonNode.remove(updateAttributesOnValueChangeKey);
|
||||
assertThat(jsonNode.has(updateAttributesOnValueChangeKey)).as("pre condition has no " + updateAttributesOnValueChangeKey).isFalse();
|
||||
jsonNode.remove(updateAttributesOnlyOnValueChangeKey);
|
||||
assertThat(jsonNode.has(updateAttributesOnlyOnValueChangeKey)).as("pre condition has no " + updateAttributesOnlyOnValueChangeKey).isFalse();
|
||||
|
||||
TbPair<Boolean, JsonNode> 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<Boolean, JsonNode> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user