Search in sources :

Example 1 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class AlarmMsgConstructor method constructAlarmUpdatedMsg.

public AlarmUpdateMsg constructAlarmUpdatedMsg(TenantId tenantId, UpdateMsgType msgType, Alarm alarm) {
    String entityName = null;
    switch(alarm.getOriginator().getEntityType()) {
        case DEVICE:
            entityName = deviceService.findDeviceById(tenantId, new DeviceId(alarm.getOriginator().getId())).getName();
            break;
        case ASSET:
            entityName = assetService.findAssetById(tenantId, new AssetId(alarm.getOriginator().getId())).getName();
            break;
        case ENTITY_VIEW:
            entityName = entityViewService.findEntityViewById(tenantId, new EntityViewId(alarm.getOriginator().getId())).getName();
            break;
    }
    AlarmUpdateMsg.Builder builder = AlarmUpdateMsg.newBuilder().setMsgType(msgType).setIdMSB(alarm.getId().getId().getMostSignificantBits()).setIdLSB(alarm.getId().getId().getLeastSignificantBits()).setName(alarm.getName()).setType(alarm.getType()).setOriginatorName(entityName).setOriginatorType(alarm.getOriginator().getEntityType().name()).setSeverity(alarm.getSeverity().name()).setStatus(alarm.getStatus().name()).setStartTs(alarm.getStartTs()).setEndTs(alarm.getEndTs()).setAckTs(alarm.getAckTs()).setClearTs(alarm.getClearTs()).setDetails(JacksonUtil.toString(alarm.getDetails())).setPropagate(alarm.isPropagate()).setPropagateToOwner(alarm.isPropagateToOwner()).setPropagateToTenant(alarm.isPropagateToTenant());
    return builder.build();
}
Also used : AlarmUpdateMsg(org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) AssetId(org.thingsboard.server.common.data.id.AssetId)

Example 2 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class RelationEdgeProcessor method processRelationToEdge.

public DownlinkMsg processRelationToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType) {
    EntityRelation entityRelation = mapper.convertValue(edgeEvent.getBody(), EntityRelation.class);
    RelationUpdateMsg relationUpdateMsg = relationMsgConstructor.constructRelationUpdatedMsg(msgType, entityRelation);
    return DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRelationUpdateMsg(relationUpdateMsg).build();
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) RelationUpdateMsg(org.thingsboard.server.gen.edge.v1.RelationUpdateMsg)

Example 3 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class WidgetBundleEdgeProcessor method processWidgetsBundleToEdge.

public DownlinkMsg processWidgetsBundleToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    WidgetsBundleId widgetsBundleId = new WidgetsBundleId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            WidgetsBundle widgetsBundle = widgetsBundleService.findWidgetsBundleById(edgeEvent.getTenantId(), widgetsBundleId);
            if (widgetsBundle != null) {
                WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = widgetsBundleMsgConstructor.constructWidgetsBundleUpdateMsg(msgType, widgetsBundle);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetsBundleUpdateMsg(widgetsBundleUpdateMsg).build();
            }
            break;
        case DELETED:
            WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = widgetsBundleMsgConstructor.constructWidgetsBundleDeleteMsg(widgetsBundleId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetsBundleUpdateMsg(widgetsBundleUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) WidgetsBundleId(org.thingsboard.server.common.data.id.WidgetsBundleId) WidgetsBundleUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 4 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class CustomerEdgeProcessor method processCustomerToEdge.

public DownlinkMsg processCustomerToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    CustomerId customerId = new CustomerId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
            Customer customer = customerService.findCustomerById(edgeEvent.getTenantId(), customerId);
            if (customer != null) {
                CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerUpdatedMsg(msgType, customer);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            }
            break;
        case DELETED:
            CustomerUpdateMsg customerUpdateMsg = customerMsgConstructor.constructCustomerDeleteMsg(customerId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addCustomerUpdateMsg(customerUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) Customer(org.thingsboard.server.common.data.Customer) CustomerId(org.thingsboard.server.common.data.id.CustomerId) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg)

Example 5 with UpdateMsgType

use of org.thingsboard.server.gen.edge.v1.UpdateMsgType in project thingsboard by thingsboard.

the class RuleChainEdgeProcessor method processRuleChainMetadataToEdge.

public DownlinkMsg processRuleChainMetadataToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeVersion edgeVersion) {
    RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
    RuleChain ruleChain = ruleChainService.findRuleChainById(edgeEvent.getTenantId(), ruleChainId);
    DownlinkMsg downlinkMsg = null;
    if (ruleChain != null) {
        RuleChainMetaData ruleChainMetaData = ruleChainService.loadRuleChainMetaData(edgeEvent.getTenantId(), ruleChainId);
        RuleChainMetadataUpdateMsg ruleChainMetadataUpdateMsg = ruleChainMsgConstructor.constructRuleChainMetadataUpdatedMsg(msgType, ruleChainMetaData, edgeVersion);
        if (ruleChainMetadataUpdateMsg != null) {
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addRuleChainMetadataUpdateMsg(ruleChainMetadataUpdateMsg).build();
        }
    }
    return downlinkMsg;
}
Also used : DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) RuleChainMetadataUpdateMsg(org.thingsboard.server.gen.edge.v1.RuleChainMetadataUpdateMsg) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainMetaData(org.thingsboard.server.common.data.rule.RuleChainMetaData) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId)

Aggregations

DownlinkMsg (org.thingsboard.server.gen.edge.v1.DownlinkMsg)12 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 AssetId (org.thingsboard.server.common.data.id.AssetId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 EntityViewId (org.thingsboard.server.common.data.id.EntityViewId)2 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)2 RuleChain (org.thingsboard.server.common.data.rule.RuleChain)2 AlarmUpdateMsg (org.thingsboard.server.gen.edge.v1.AlarmUpdateMsg)2 EntityViewUpdateMsg (org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Customer (org.thingsboard.server.common.data.Customer)1 Dashboard (org.thingsboard.server.common.data.Dashboard)1 Device (org.thingsboard.server.common.data.Device)1 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)1 EntityView (org.thingsboard.server.common.data.EntityView)1 User (org.thingsboard.server.common.data.User)1 Alarm (org.thingsboard.server.common.data.alarm.Alarm)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 AlarmId (org.thingsboard.server.common.data.id.AlarmId)1 DashboardId (org.thingsboard.server.common.data.id.DashboardId)1