add this feature for target attribute:
use ${metadataKey} for value from metadata, $[messageKey] for value from the message body
This commit is contained in:
parent
436e19d652
commit
551f67ec02
@ -68,8 +68,11 @@ public abstract class TbEntityGetAttrNode<T extends EntityId> implements TbNode
|
|||||||
|
|
||||||
Map<String, String> mappingsMap = new HashMap<>();
|
Map<String, String> mappingsMap = new HashMap<>();
|
||||||
config.getAttrMapping().forEach((key, value) -> {
|
config.getAttrMapping().forEach((key, value) -> {
|
||||||
String processPattern = TbNodeUtils.processPattern(key, msg);
|
log.info("key = {}, value = {}", key, value);
|
||||||
mappingsMap.put(processPattern, 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());
|
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) {
|
private void putAttributesAndTell(TbContext ctx, TbMsg msg, List<? extends KvEntry> attributes, Map<String, String> map) {
|
||||||
attributes.forEach(r -> {
|
attributes.forEach(r -> {
|
||||||
String attrName = map.get(r.getKey());
|
String attrName = map.get(r.getKey());
|
||||||
|
log.info("attrName = {}, value = {}", attrName, r.getValueAsString());
|
||||||
msg.getMetaData().putValue(attrName, r.getValueAsString());
|
msg.getMetaData().putValue(attrName, r.getValueAsString());
|
||||||
});
|
});
|
||||||
ctx.tellSuccess(msg);
|
ctx.tellSuccess(msg);
|
||||||
|
|||||||
@ -72,7 +72,7 @@ public abstract class AbstractAttributeNodeTest {
|
|||||||
final RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
|
final RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
|
||||||
final RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
|
final RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
|
||||||
final String keyAttrConf = "${word}";
|
final String keyAttrConf = "${word}";
|
||||||
final String valueAttrConf = "result";
|
final String valueAttrConf = "${result}";
|
||||||
@Mock
|
@Mock
|
||||||
TbContext ctx;
|
TbContext ctx;
|
||||||
@Mock
|
@Mock
|
||||||
@ -95,6 +95,7 @@ public abstract class AbstractAttributeNodeTest {
|
|||||||
|
|
||||||
metaData = new HashMap<>();
|
metaData = new HashMap<>();
|
||||||
metaData.putIfAbsent("word", "temperature");
|
metaData.putIfAbsent("word", "temperature");
|
||||||
|
metaData.putIfAbsent("result", "answer");
|
||||||
|
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.node.init(null, nodeConfiguration);
|
this.node.init(null, nodeConfiguration);
|
||||||
@ -181,7 +182,7 @@ public abstract class AbstractAttributeNodeTest {
|
|||||||
|
|
||||||
node.onMsg(ctx, msg);
|
node.onMsg(ctx, msg);
|
||||||
verify(ctx).tellSuccess(msg);
|
verify(ctx).tellSuccess(msg);
|
||||||
assertEquals(msg.getMetaData().getValue("result"), "highest");
|
assertEquals(msg.getMetaData().getValue("answer"), "highest");
|
||||||
}
|
}
|
||||||
|
|
||||||
void entityAttributeFetched(EntityId entityId) {
|
void entityAttributeFetched(EntityId entityId) {
|
||||||
@ -193,7 +194,7 @@ public abstract class AbstractAttributeNodeTest {
|
|||||||
|
|
||||||
node.onMsg(ctx, msg);
|
node.onMsg(ctx, msg);
|
||||||
verify(ctx).tellSuccess(msg);
|
verify(ctx).tellSuccess(msg);
|
||||||
assertEquals(msg.getMetaData().getValue("result"), "high");
|
assertEquals(msg.getMetaData().getValue("answer"), "high");
|
||||||
}
|
}
|
||||||
|
|
||||||
TbGetEntityAttrNodeConfiguration getTbNodeConfig() {
|
TbGetEntityAttrNodeConfiguration getTbNodeConfig() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user