Search in sources :

Example 6 with EdgeEventActionType

use of org.thingsboard.server.common.data.edge.EdgeEventActionType in project thingsboard by thingsboard.

the class TbMsgPushToEdgeNode method buildEdgeEvent.

private EdgeEvent buildEdgeEvent(TbMsg msg, TbContext ctx) {
    String msgType = msg.getType();
    if (DataConstants.ALARM.equals(msgType)) {
        return buildEdgeEvent(ctx.getTenantId(), EdgeEventActionType.ADDED, getUUIDFromMsgData(msg), EdgeEventType.ALARM, null);
    } else {
        EdgeEventType edgeEventTypeByEntityType = EdgeUtils.getEdgeEventTypeByEntityType(msg.getOriginator().getEntityType());
        if (edgeEventTypeByEntityType == null) {
            return null;
        }
        EdgeEventActionType actionType = getEdgeEventActionTypeByMsgType(msgType);
        Map<String, Object> entityBody = new HashMap<>();
        Map<String, String> metadata = msg.getMetaData().getData();
        JsonNode dataJson = JacksonUtil.toJsonNode(msg.getData());
        switch(actionType) {
            case ATTRIBUTES_UPDATED:
            case POST_ATTRIBUTES:
                entityBody.put("kv", dataJson);
                entityBody.put(SCOPE, getScope(metadata));
                break;
            case ATTRIBUTES_DELETED:
                List<String> keys = JacksonUtil.convertValue(dataJson.get("attributes"), new TypeReference<>() {
                });
                entityBody.put("keys", keys);
                entityBody.put(SCOPE, getScope(metadata));
                break;
            case TIMESERIES_UPDATED:
                entityBody.put("data", dataJson);
                entityBody.put("ts", metadata.get("ts"));
                break;
        }
        return buildEdgeEvent(ctx.getTenantId(), actionType, msg.getOriginator().getId(), edgeEventTypeByEntityType, JacksonUtil.valueToTree(entityBody));
    }
}
Also used : EdgeEventType(org.thingsboard.server.common.data.edge.EdgeEventType) HashMap(java.util.HashMap) EdgeEventActionType(org.thingsboard.server.common.data.edge.EdgeEventActionType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

EdgeEventActionType (org.thingsboard.server.common.data.edge.EdgeEventActionType)6 UUID (java.util.UUID)5 EdgeEventType (org.thingsboard.server.common.data.edge.EdgeEventType)5 EdgeId (org.thingsboard.server.common.data.id.EdgeId)4 PageLink (org.thingsboard.server.common.data.page.PageLink)4 Edge (org.thingsboard.server.common.data.edge.Edge)3 CustomerId (org.thingsboard.server.common.data.id.CustomerId)3 EntityId (org.thingsboard.server.common.data.id.EntityId)2 PageData (org.thingsboard.server.common.data.page.PageData)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HashMap (java.util.HashMap)1 User (org.thingsboard.server.common.data.User)1 Alarm (org.thingsboard.server.common.data.alarm.Alarm)1 AlarmId (org.thingsboard.server.common.data.id.AlarmId)1 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)1