|
|
|
@ -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); |
|
|
|
|