Set SERVER_SCOPE by default if not provided
This commit is contained in:
parent
905273ea3d
commit
c5e33e48f0
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.rule.engine.api.EmptyNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.api.RuleNode;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
@ -68,6 +69,8 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
|
||||
private static final ObjectMapper json = new ObjectMapper();
|
||||
|
||||
private static final String SCOPE = "scope";
|
||||
|
||||
@Override
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
|
||||
@ -154,12 +157,12 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
case ATTRIBUTES_UPDATED:
|
||||
case POST_ATTRIBUTES:
|
||||
entityBody.put("kv", dataJson);
|
||||
entityBody.put("scope", metadata.get("scope"));
|
||||
entityBody.put(SCOPE, getScope(metadata));
|
||||
break;
|
||||
case ATTRIBUTES_DELETED:
|
||||
List<String> keys = json.treeToValue(dataJson.get("attributes"), List.class);
|
||||
entityBody.put("keys", keys);
|
||||
entityBody.put("scope", metadata.get("scope"));
|
||||
entityBody.put(SCOPE, getScope(metadata));
|
||||
break;
|
||||
case TIMESERIES_UPDATED:
|
||||
entityBody.put("data", dataJson);
|
||||
@ -170,6 +173,15 @@ public class TbMsgPushToEdgeNode implements TbNode {
|
||||
}
|
||||
}
|
||||
|
||||
private String getScope(Map<String, String> metadata) {
|
||||
String scope = metadata.get(SCOPE);
|
||||
if (StringUtils.isEmpty(scope)) {
|
||||
// TODO: voba - move this to configuration of the node or some other place
|
||||
scope = DataConstants.SERVER_SCOPE;
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
private EdgeEvent buildEdgeEvent(TenantId tenantId, EdgeEventActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) {
|
||||
EdgeEvent edgeEvent = new EdgeEvent();
|
||||
edgeEvent.setTenantId(tenantId);
|
||||
|
||||
@ -48,7 +48,7 @@ public class TbMsgAttributesNode implements TbNode {
|
||||
|
||||
private TbMsgAttributesNodeConfiguration config;
|
||||
|
||||
private static final String SCOPE = "scope";
|
||||
|
||||
|
||||
@Override
|
||||
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
|
||||
@ -66,7 +66,6 @@ public class TbMsgAttributesNode implements TbNode {
|
||||
}
|
||||
String src = msg.getData();
|
||||
Set<AttributeKvEntry> attributes = JsonConverter.convertToAttributes(new JsonParser().parse(src));
|
||||
msg.getMetaData().putValue(SCOPE, config.getScope());
|
||||
String notifyDeviceStr = msg.getMetaData().getValue("notifyDevice");
|
||||
ctx.getTelemetryService().saveAndNotify(
|
||||
ctx.getTenantId(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user