Search in sources :

Example 6 with EdgeEventType

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

the class EntityEdgeProcessor method processEntityNotificationForAllEdges.

public void processEntityNotificationForAllEdges(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
    EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
    EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
    EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
    switch(actionType) {
        case ADDED:
        case UPDATED:
        case DELETED:
            processActionForAllEdges(tenantId, type, actionType, entityId);
            break;
    }
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) EdgeEventType(org.thingsboard.server.common.data.edge.EdgeEventType) EdgeEventActionType(org.thingsboard.server.common.data.edge.EdgeEventActionType) UUID(java.util.UUID)

Example 7 with EdgeEventType

use of org.thingsboard.server.common.data.edge.EdgeEventType 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

EdgeEventType (org.thingsboard.server.common.data.edge.EdgeEventType)7 UUID (java.util.UUID)6 EdgeEventActionType (org.thingsboard.server.common.data.edge.EdgeEventActionType)5 EdgeId (org.thingsboard.server.common.data.id.EdgeId)3 EntityId (org.thingsboard.server.common.data.id.EntityId)3 PageLink (org.thingsboard.server.common.data.page.PageLink)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashMap (java.util.HashMap)2 Edge (org.thingsboard.server.common.data.edge.Edge)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)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 TenantId (org.thingsboard.server.common.data.id.TenantId)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1