|
|
|
@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.telemetry; |
|
|
|
|
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.thingsboard.rule.engine.api.RuleNode; |
|
|
|
import org.thingsboard.rule.engine.api.TbContext; |
|
|
|
import org.thingsboard.rule.engine.api.TbNode; |
|
|
|
@ -51,6 +52,8 @@ public class TbMsgAttributesNode implements TbNode { |
|
|
|
|
|
|
|
private TbMsgAttributesNodeConfiguration config; |
|
|
|
|
|
|
|
private static final String SCOPE = "scope"; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { |
|
|
|
this.config = TbNodeUtils.convert(configuration, TbMsgAttributesNodeConfiguration.class); |
|
|
|
@ -64,8 +67,12 @@ public class TbMsgAttributesNode implements TbNode { |
|
|
|
} |
|
|
|
String src = msg.getData(); |
|
|
|
Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src)); |
|
|
|
msg.getMetaData().putValue("scope", config.getScope()); |
|
|
|
ctx.getTelemetryService().saveAndNotify(ctx.getTenantId(), msg.getOriginator(), config.getScope(), new ArrayList<>(attributes), new TelemetryNodeCallback(ctx, msg)); |
|
|
|
String scope = msg.getMetaData().getValue(SCOPE); |
|
|
|
if (StringUtils.isEmpty(scope)) { |
|
|
|
scope = config.getScope(); |
|
|
|
msg.getMetaData().putValue("scope", scope); |
|
|
|
} |
|
|
|
ctx.getTelemetryService().saveAndNotify(ctx.getTenantId(), msg.getOriginator(), scope, new ArrayList<>(attributes), new TelemetryNodeCallback(ctx, msg)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|