add this feature for target attribute:

use ${metadataKey} for value from metadata, $[messageKey] for value from the message body
This commit is contained in:
van-vanich 2021-12-22 11:14:04 +02:00
parent 436e19d652
commit 551f67ec02
2 changed files with 10 additions and 5 deletions

View File

@ -68,8 +68,11 @@ public abstract class TbEntityGetAttrNode<T extends EntityId> implements TbNode
Map<String, String> mappingsMap = new HashMap<>();
config.getAttrMapping().forEach((key, value) -> {
String processPattern = TbNodeUtils.processPattern(key, msg);
mappingsMap.put(processPattern, value);
log.info("key = {}, value = {}", key, value);
log.info(msg.toString());
String processPatternKey = TbNodeUtils.processPattern(key, msg);
String processPatternValue = TbNodeUtils.processPattern(value, msg);
mappingsMap.put(processPatternKey, processPatternValue);
});
List<String> keys = List.copyOf(mappingsMap.keySet());
@ -94,6 +97,7 @@ public abstract class TbEntityGetAttrNode<T extends EntityId> implements TbNode
private void putAttributesAndTell(TbContext ctx, TbMsg msg, List<? extends KvEntry> attributes, Map<String, String> map) {
attributes.forEach(r -> {
String attrName = map.get(r.getKey());
log.info("attrName = {}, value = {}", attrName, r.getValueAsString());
msg.getMetaData().putValue(attrName, r.getValueAsString());
});
ctx.tellSuccess(msg);

View File

@ -72,7 +72,7 @@ public abstract class AbstractAttributeNodeTest {
final RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
final RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
final String keyAttrConf = "${word}";
final String valueAttrConf = "result";
final String valueAttrConf = "${result}";
@Mock
TbContext ctx;
@Mock
@ -95,6 +95,7 @@ public abstract class AbstractAttributeNodeTest {
metaData = new HashMap<>();
metaData.putIfAbsent("word", "temperature");
metaData.putIfAbsent("result", "answer");
this.node = node;
this.node.init(null, nodeConfiguration);
@ -181,7 +182,7 @@ public abstract class AbstractAttributeNodeTest {
node.onMsg(ctx, msg);
verify(ctx).tellSuccess(msg);
assertEquals(msg.getMetaData().getValue("result"), "highest");
assertEquals(msg.getMetaData().getValue("answer"), "highest");
}
void entityAttributeFetched(EntityId entityId) {
@ -193,7 +194,7 @@ public abstract class AbstractAttributeNodeTest {
node.onMsg(ctx, msg);
verify(ctx).tellSuccess(msg);
assertEquals(msg.getMetaData().getValue("result"), "high");
assertEquals(msg.getMetaData().getValue("answer"), "high");
}
TbGetEntityAttrNodeConfiguration getTbNodeConfig() {