Showing
1 changed file
with
9 additions
and
2 deletions
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.telemetry; |
17 | 17 | |
18 | 18 | import com.google.gson.JsonParser; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | +import org.springframework.util.StringUtils; | |
20 | 21 | import org.thingsboard.rule.engine.api.RuleNode; |
21 | 22 | import org.thingsboard.rule.engine.api.TbContext; |
22 | 23 | import org.thingsboard.rule.engine.api.TbNode; |
... | ... | @@ -51,6 +52,8 @@ public class TbMsgAttributesNode implements TbNode { |
51 | 52 | |
52 | 53 | private TbMsgAttributesNodeConfiguration config; |
53 | 54 | |
55 | + private static final String SCOPE = "scope"; | |
56 | + | |
54 | 57 | @Override |
55 | 58 | public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
56 | 59 | this.config = TbNodeUtils.convert(configuration, TbMsgAttributesNodeConfiguration.class); |
... | ... | @@ -64,8 +67,12 @@ public class TbMsgAttributesNode implements TbNode { |
64 | 67 | } |
65 | 68 | String src = msg.getData(); |
66 | 69 | Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src)); |
67 | - msg.getMetaData().putValue("scope", config.getScope()); | |
68 | - ctx.getTelemetryService().saveAndNotify(ctx.getTenantId(), msg.getOriginator(), config.getScope(), new ArrayList<>(attributes), new TelemetryNodeCallback(ctx, msg)); | |
70 | + String scope = msg.getMetaData().getValue(SCOPE); | |
71 | + if (StringUtils.isEmpty(scope)) { | |
72 | + scope = config.getScope(); | |
73 | + msg.getMetaData().putValue("scope", scope); | |
74 | + } | |
75 | + ctx.getTelemetryService().saveAndNotify(ctx.getTenantId(), msg.getOriginator(), scope, new ArrayList<>(attributes), new TelemetryNodeCallback(ctx, msg)); | |
69 | 76 | } |
70 | 77 | |
71 | 78 | @Override | ... | ... |