Search in sources :

Example 1 with TsKvProto

use of org.thingsboard.server.gen.transport.TransportProtos.TsKvProto in project thingsboard by thingsboard.

the class DeviceActorMessageProcessor method processAttributesUpdate.

void processAttributesUpdate(TbActorCtx context, DeviceAttributesEventNotificationMsg msg) {
    if (attributeSubscriptions.size() > 0) {
        boolean hasNotificationData = false;
        AttributeUpdateNotificationMsg.Builder notification = AttributeUpdateNotificationMsg.newBuilder();
        if (msg.isDeleted()) {
            List<String> sharedKeys = msg.getDeletedKeys().stream().filter(key -> DataConstants.SHARED_SCOPE.equals(key.getScope())).map(AttributeKey::getAttributeKey).collect(Collectors.toList());
            if (!sharedKeys.isEmpty()) {
                notification.addAllSharedDeleted(sharedKeys);
                hasNotificationData = true;
            }
        } else {
            if (DataConstants.SHARED_SCOPE.equals(msg.getScope())) {
                List<AttributeKvEntry> attributes = new ArrayList<>(msg.getValues());
                if (attributes.size() > 0) {
                    List<TsKvProto> sharedUpdated = msg.getValues().stream().map(this::toTsKvProto).collect(Collectors.toList());
                    if (!sharedUpdated.isEmpty()) {
                        notification.addAllSharedUpdated(sharedUpdated);
                        hasNotificationData = true;
                    }
                } else {
                    log.debug("[{}] No public shared side attributes changed!", deviceId);
                }
            }
        }
        if (hasNotificationData) {
            AttributeUpdateNotificationMsg finalNotification = notification.build();
            attributeSubscriptions.forEach((key, value) -> sendToTransport(finalNotification, key, value.getNodeId()));
        }
    } else {
        log.debug("[{}] No registered attributes subscriptions to process!", deviceId);
    }
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) AttributeUpdateNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg) ArrayList(java.util.ArrayList) TsKvProto(org.thingsboard.server.gen.transport.TransportProtos.TsKvProto)

Aggregations

ArrayList (java.util.ArrayList)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 AttributeUpdateNotificationMsg (org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg)1 TsKvProto (org.thingsboard.server.gen.transport.TransportProtos.TsKvProto)1