TbMsgAttributesNode updateAttributesOnValueChange renamed with updateAttributesOnlyOnValueChange
This commit is contained in:
parent
125385b582
commit
cc9a47a763
@ -53,7 +53,7 @@
|
|||||||
"scope": "CLIENT_SCOPE",
|
"scope": "CLIENT_SCOPE",
|
||||||
"notifyDevice": "false",
|
"notifyDevice": "false",
|
||||||
"sendAttributesUpdatedNotification": "false",
|
"sendAttributesUpdatedNotification": "false",
|
||||||
"updateAttributesOnValueChange": "true"
|
"updateAttributesOnlyOnValueChange": "true"
|
||||||
},
|
},
|
||||||
"externalId": null
|
"externalId": null
|
||||||
},
|
},
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
"scope": "CLIENT_SCOPE",
|
"scope": "CLIENT_SCOPE",
|
||||||
"notifyDevice": "false",
|
"notifyDevice": "false",
|
||||||
"sendAttributesUpdatedNotification": "false",
|
"sendAttributesUpdatedNotification": "false",
|
||||||
"updateAttributesOnValueChange": "true"
|
"updateAttributesOnlyOnValueChange": "true"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
"scope": "CLIENT_SCOPE",
|
"scope": "CLIENT_SCOPE",
|
||||||
"notifyDevice": "false",
|
"notifyDevice": "false",
|
||||||
"sendAttributesUpdatedNotification": "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. " +
|
"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\" " +
|
"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." +
|
"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"},
|
uiResources = {"static/rulenode/rulenode-core-config.js"},
|
||||||
configDirective = "tbActionNodeAttributesConfig",
|
configDirective = "tbActionNodeAttributesConfig",
|
||||||
icon = "file_upload"
|
icon = "file_upload"
|
||||||
)
|
)
|
||||||
public class TbMsgAttributesNode implements TbNode, TbVersionedNode {
|
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;
|
private TbMsgAttributesNodeConfiguration config;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,7 +94,7 @@ public class TbMsgAttributesNode implements TbNode, TbVersionedNode {
|
|||||||
String scope = getScope(msg.getMetaData().getValue(SCOPE));
|
String scope = getScope(msg.getMetaData().getValue(SCOPE));
|
||||||
boolean sendAttributesUpdateNotification = checkSendNotification(scope);
|
boolean sendAttributesUpdateNotification = checkSendNotification(scope);
|
||||||
|
|
||||||
if (!config.isUpdateAttributesOnValueChange()) {
|
if (!config.isUpdateAttributesOnlyOnValueChange()) {
|
||||||
saveAttr(newAttributes, ctx, msg, scope, sendAttributesUpdateNotification);
|
saveAttr(newAttributes, ctx, msg, scope, sendAttributesUpdateNotification);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -171,9 +171,9 @@ public class TbMsgAttributesNode implements TbNode, TbVersionedNode {
|
|||||||
boolean hasChanges = false;
|
boolean hasChanges = false;
|
||||||
switch (fromVersion) {
|
switch (fromVersion) {
|
||||||
case 0:
|
case 0:
|
||||||
if (!oldConfiguration.has(UPDATE_ATTRIBUTES_ON_VALUE_CHANGE_KEY)) {
|
if (!oldConfiguration.has(UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY)) {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
((ObjectNode) oldConfiguration).put(UPDATE_ATTRIBUTES_ON_VALUE_CHANGE_KEY, false);
|
((ObjectNode) oldConfiguration).put(UPDATE_ATTRIBUTES_ONLY_ON_VALUE_CHANGE_KEY, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration<TbMsg
|
|||||||
|
|
||||||
private Boolean notifyDevice;
|
private Boolean notifyDevice;
|
||||||
private boolean sendAttributesUpdatedNotification;
|
private boolean sendAttributesUpdatedNotification;
|
||||||
private boolean updateAttributesOnValueChange;
|
private boolean updateAttributesOnlyOnValueChange;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TbMsgAttributesNodeConfiguration defaultConfiguration() {
|
public TbMsgAttributesNodeConfiguration defaultConfiguration() {
|
||||||
@ -35,7 +35,7 @@ public class TbMsgAttributesNodeConfiguration implements NodeConfiguration<TbMsg
|
|||||||
configuration.setNotifyDevice(false);
|
configuration.setNotifyDevice(false);
|
||||||
configuration.setSendAttributesUpdatedNotification(false);
|
configuration.setSendAttributesUpdatedNotification(false);
|
||||||
//Since version 1. For an existing rule nodes for version 0. See the TbVersionedNode implementation
|
//Since version 1. For an existing rule nodes for version 0. See the TbVersionedNode implementation
|
||||||
configuration.setUpdateAttributesOnValueChange(true);
|
configuration.setUpdateAttributesOnlyOnValueChange(true);
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
class TbMsgAttributesNodeConfigurationTest {
|
class TbMsgAttributesNodeConfigurationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDefaultConfig_givenUpdateAttributesOnValueChange_thenTrue_sinceVersion1() {
|
void testDefaultConfig_givenupdateAttributesOnlyOnValueChange_thenTrue_sinceVersion1() {
|
||||||
assertThat(new TbMsgAttributesNodeConfiguration().defaultConfiguration().isUpdateAttributesOnValueChange()).isTrue();
|
assertThat(new TbMsgAttributesNodeConfiguration().defaultConfiguration().isUpdateAttributesOnlyOnValueChange()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,42 +32,43 @@ import static org.mockito.Mockito.mock;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
class TbMsgAttributesNodeTest {
|
class TbMsgAttributesNodeTest {
|
||||||
|
|
||||||
|
final String updateAttributesOnlyOnValueChangeKey = "updateAttributesOnlyOnValueChange";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpgrade_fromVersion0() throws TbNodeException {
|
void testUpgrade_fromVersion0() throws TbNodeException {
|
||||||
final String updateAttributesOnValueChangeKey = "updateAttributesOnValueChange";
|
|
||||||
TbMsgAttributesNode node = mock(TbMsgAttributesNode.class);
|
TbMsgAttributesNode node = mock(TbMsgAttributesNode.class);
|
||||||
willCallRealMethod().given(node).upgrade(anyInt(), any());
|
willCallRealMethod().given(node).upgrade(anyInt(), any());
|
||||||
|
|
||||||
ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration());
|
ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration());
|
||||||
jsonNode.remove(updateAttributesOnValueChangeKey);
|
jsonNode.remove(updateAttributesOnlyOnValueChangeKey);
|
||||||
assertThat(jsonNode.has(updateAttributesOnValueChangeKey)).as("pre condition has no " + updateAttributesOnValueChangeKey).isFalse();
|
assertThat(jsonNode.has(updateAttributesOnlyOnValueChangeKey)).as("pre condition has no " + updateAttributesOnlyOnValueChangeKey).isFalse();
|
||||||
|
|
||||||
TbPair<Boolean, JsonNode> upgradeResult = node.upgrade(0, jsonNode);
|
TbPair<Boolean, JsonNode> upgradeResult = node.upgrade(0, jsonNode);
|
||||||
|
|
||||||
ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond();
|
ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond();
|
||||||
assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isTrue();
|
assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isTrue();
|
||||||
assertThat(resultNode.has(updateAttributesOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnValueChangeKey).isTrue();
|
assertThat(resultNode.has(updateAttributesOnlyOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnlyOnValueChangeKey).isTrue();
|
||||||
assertThat(resultNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("upgrade result value [false] for key " + updateAttributesOnValueChangeKey).isFalse();
|
assertThat(resultNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("upgrade result value [false] for key " + updateAttributesOnlyOnValueChangeKey).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpgrade_fromVersion0_alreadyHasUpdateAttributesOnValueChange() throws TbNodeException {
|
void testUpgrade_fromVersion0_alreadyHasupdateAttributesOnlyOnValueChange() throws TbNodeException {
|
||||||
final String updateAttributesOnValueChangeKey = "updateAttributesOnValueChange";
|
|
||||||
TbMsgAttributesNode node = mock(TbMsgAttributesNode.class);
|
TbMsgAttributesNode node = mock(TbMsgAttributesNode.class);
|
||||||
willCallRealMethod().given(node).upgrade(anyInt(), any());
|
willCallRealMethod().given(node).upgrade(anyInt(), any());
|
||||||
|
|
||||||
ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration());
|
ObjectNode jsonNode = (ObjectNode) JacksonUtil.valueToTree(new TbMsgAttributesNodeConfiguration().defaultConfiguration());
|
||||||
jsonNode.remove(updateAttributesOnValueChangeKey);
|
jsonNode.remove(updateAttributesOnlyOnValueChangeKey);
|
||||||
jsonNode.put(updateAttributesOnValueChangeKey, true);
|
jsonNode.put(updateAttributesOnlyOnValueChangeKey, true);
|
||||||
assertThat(jsonNode.has(updateAttributesOnValueChangeKey)).as("pre condition has no " + updateAttributesOnValueChangeKey).isTrue();
|
assertThat(jsonNode.has(updateAttributesOnlyOnValueChangeKey)).as("pre condition has no " + updateAttributesOnlyOnValueChangeKey).isTrue();
|
||||||
assertThat(jsonNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("pre condition has [true] for key " + updateAttributesOnValueChangeKey).isTrue();
|
assertThat(jsonNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("pre condition has [true] for key " + updateAttributesOnlyOnValueChangeKey).isTrue();
|
||||||
|
|
||||||
TbPair<Boolean, JsonNode> upgradeResult = node.upgrade(0, jsonNode);
|
TbPair<Boolean, JsonNode> upgradeResult = node.upgrade(0, jsonNode);
|
||||||
|
|
||||||
ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond();
|
ObjectNode resultNode = (ObjectNode) upgradeResult.getSecond();
|
||||||
assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isFalse();
|
assertThat(upgradeResult.getFirst()).as("upgrade result has changes").isFalse();
|
||||||
assertThat(resultNode.has(updateAttributesOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnValueChangeKey).isTrue();
|
assertThat(resultNode.has(updateAttributesOnlyOnValueChangeKey)).as("upgrade result has key " + updateAttributesOnlyOnValueChangeKey).isTrue();
|
||||||
assertThat(resultNode.get(updateAttributesOnValueChangeKey).asBoolean()).as("upgrade result value [true] for key " + updateAttributesOnValueChangeKey).isTrue();
|
assertThat(resultNode.get(updateAttributesOnlyOnValueChangeKey).asBoolean()).as("upgrade result value [true] for key " + updateAttributesOnlyOnValueChangeKey).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user