|
|
|
@ -30,6 +30,8 @@ import org.thingsboard.server.common.data.kv.KvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.LongDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.StringDataEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.dao.util.mapping.JacksonUtil; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.KeyValueProto; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.KeyValueType; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.SubscriptionMgrMsgProto; |
|
|
|
@ -44,6 +46,9 @@ import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesSubscrip |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.TbTimeSeriesUpdateProto; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.TbAlarmUpdateProto; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos.TbAlarmDeleteProto; |
|
|
|
import org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate; |
|
|
|
import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; |
|
|
|
import org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate; |
|
|
|
|
|
|
|
@ -90,6 +95,13 @@ public class TbSubscriptionUtils { |
|
|
|
TbSubscriptionKetStateProto.newBuilder().setKey(key).setTs(value).build())); |
|
|
|
msgBuilder.setAttributeSub(aSubProto.build()); |
|
|
|
break; |
|
|
|
case ALARMS: |
|
|
|
TbAlarmsSubscription alarmSub = (TbAlarmsSubscription) subscription; |
|
|
|
TransportProtos.TbAlarmSubscriptionProto.Builder alarmSubProto = TransportProtos.TbAlarmSubscriptionProto.newBuilder() |
|
|
|
.setSub(subscriptionProto) |
|
|
|
.setTs(alarmSub.getTs()); |
|
|
|
msgBuilder.setAlarmSub(alarmSubProto.build()); |
|
|
|
break; |
|
|
|
} |
|
|
|
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build(); |
|
|
|
} |
|
|
|
@ -138,6 +150,18 @@ public class TbSubscriptionUtils { |
|
|
|
return builder.build(); |
|
|
|
} |
|
|
|
|
|
|
|
public static TbSubscription fromProto(TransportProtos.TbAlarmSubscriptionProto alarmSub) { |
|
|
|
TbSubscriptionProto subProto = alarmSub.getSub(); |
|
|
|
TbAlarmsSubscription.TbAlarmsSubscriptionBuilder builder = TbAlarmsSubscription.builder() |
|
|
|
.serviceId(subProto.getServiceId()) |
|
|
|
.sessionId(subProto.getSessionId()) |
|
|
|
.subscriptionId(subProto.getSubscriptionId()) |
|
|
|
.entityId(EntityIdFactory.getByTypeAndUuid(subProto.getEntityType(), new UUID(subProto.getEntityIdMSB(), subProto.getEntityIdLSB()))) |
|
|
|
.tenantId(new TenantId(new UUID(subProto.getTenantIdMSB(), subProto.getTenantIdLSB()))); |
|
|
|
builder.ts(alarmSub.getTs()); |
|
|
|
return builder.build(); |
|
|
|
} |
|
|
|
|
|
|
|
public static TelemetrySubscriptionUpdate fromProto(TbSubscriptionUpdateProto proto) { |
|
|
|
if (proto.getErrorCode() > 0) { |
|
|
|
return new TelemetrySubscriptionUpdate(proto.getSubscriptionId(), SubscriptionErrorCode.forCode(proto.getErrorCode()), proto.getErrorMsg()); |
|
|
|
@ -156,6 +180,16 @@ public class TbSubscriptionUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static AlarmSubscriptionUpdate fromProto(TransportProtos.TbAlarmSubscriptionUpdateProto proto) { |
|
|
|
if (proto.getErrorCode() > 0) { |
|
|
|
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), SubscriptionErrorCode.forCode(proto.getErrorCode()), proto.getErrorMsg()); |
|
|
|
} else { |
|
|
|
Alarm alarm = JacksonUtil.fromString(proto.getAlarm(), Alarm.class); |
|
|
|
return new AlarmSubscriptionUpdate(proto.getSubscriptionId(), alarm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static ToCoreMsg toTimeseriesUpdateProto(TenantId tenantId, EntityId entityId, List<TsKvEntry> ts) { |
|
|
|
TbTimeSeriesUpdateProto.Builder builder = TbTimeSeriesUpdateProto.newBuilder(); |
|
|
|
builder.setEntityType(entityId.getEntityType().name()); |
|
|
|
@ -264,12 +298,28 @@ public class TbSubscriptionUtils { |
|
|
|
} |
|
|
|
|
|
|
|
public static ToCoreMsg toAlarmUpdateProto(TenantId tenantId, EntityId entityId, Alarm alarm) { |
|
|
|
// TODO: 3.1
|
|
|
|
throw new RuntimeException("Not implemented!"); |
|
|
|
TbAlarmUpdateProto.Builder builder = TbAlarmUpdateProto.newBuilder(); |
|
|
|
builder.setEntityType(entityId.getEntityType().name()); |
|
|
|
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits()); |
|
|
|
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits()); |
|
|
|
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); |
|
|
|
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); |
|
|
|
builder.setAlarm(JacksonUtil.toString(alarm)); |
|
|
|
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder(); |
|
|
|
msgBuilder.setAlarmUpdate(builder); |
|
|
|
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build(); |
|
|
|
} |
|
|
|
|
|
|
|
public static ToCoreMsg toAlarmDeletedProto(TenantId tenantId, EntityId entityId, Alarm alarm) { |
|
|
|
// TODO: 3.1
|
|
|
|
throw new RuntimeException("Not implemented!"); |
|
|
|
TbAlarmDeleteProto.Builder builder = TbAlarmDeleteProto.newBuilder(); |
|
|
|
builder.setEntityType(entityId.getEntityType().name()); |
|
|
|
builder.setEntityIdMSB(entityId.getId().getMostSignificantBits()); |
|
|
|
builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits()); |
|
|
|
builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); |
|
|
|
builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); |
|
|
|
builder.setAlarm(JacksonUtil.toString(alarm)); |
|
|
|
SubscriptionMgrMsgProto.Builder msgBuilder = SubscriptionMgrMsgProto.newBuilder(); |
|
|
|
msgBuilder.setAlarmDelete(builder); |
|
|
|
return ToCoreMsg.newBuilder().setToSubscriptionMgrMsg(msgBuilder.build()).build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|