|
|
|
@ -139,17 +139,15 @@ public class TbMsgPushToEdgeNode implements TbNode { |
|
|
|
if (edgeEventTypeByEntityType == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
ActionType actionType = getActionTypeByMsgType(msg.getType()); |
|
|
|
JsonNode entityBody = null; |
|
|
|
JsonNode data = json.readTree(msg.getData()); |
|
|
|
if (SessionMsgType.POST_ATTRIBUTES_REQUEST.name().equals(msg.getType())) { |
|
|
|
Map<String, Object> entityData = new HashMap<>(); |
|
|
|
entityData.put("kv", data); |
|
|
|
entityData.put("scope", msg.getMetaData().getData().get("scope")); |
|
|
|
entityBody = json.valueToTree(entityData); |
|
|
|
if (actionType.equals(ActionType.ATTRIBUTES_UPDATED) || actionType.equals(ActionType.ATTRIBUTES_DELETED)) { |
|
|
|
entityBody = getAttributeEntityBody(actionType, data, msg.getMetaData().getData()); |
|
|
|
} else { |
|
|
|
entityBody = data; |
|
|
|
} |
|
|
|
return buildEdgeEvent(ctx.getTenantId(), getActionTypeByMsgType(msg.getType()), msg.getOriginator().getId(), edgeEventTypeByEntityType, entityBody); |
|
|
|
return buildEdgeEvent(ctx.getTenantId(), actionType, msg.getOriginator().getId(), edgeEventTypeByEntityType, entityBody); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -163,6 +161,21 @@ public class TbMsgPushToEdgeNode implements TbNode { |
|
|
|
return edgeEvent; |
|
|
|
} |
|
|
|
|
|
|
|
private JsonNode getAttributeEntityBody(ActionType actionType, JsonNode data, Map<String, String> metadata) throws JsonProcessingException { |
|
|
|
Map<String, Object> entityData = new HashMap<>(); |
|
|
|
switch (actionType) { |
|
|
|
case ATTRIBUTES_UPDATED: |
|
|
|
entityData.put("kv", data); |
|
|
|
break; |
|
|
|
case ATTRIBUTES_DELETED: |
|
|
|
List<String> keys = json.treeToValue(data.get("attributes"), List.class); |
|
|
|
entityData.put("keys", keys); |
|
|
|
break; |
|
|
|
} |
|
|
|
entityData.put("scope", metadata.get("scope")); |
|
|
|
return json.valueToTree(entityData); |
|
|
|
} |
|
|
|
|
|
|
|
private UUID getUUIDFromMsgData(TbMsg msg) throws JsonProcessingException { |
|
|
|
JsonNode data = json.readTree(msg.getData()).get("id"); |
|
|
|
String id = json.treeToValue(data.get("id"), String.class); |
|
|
|
|