Added EntityIdProto
This commit is contained in:
parent
8b09b660b0
commit
46a9d81a85
@ -23,14 +23,11 @@ import org.thingsboard.common.util.geo.PerimeterDefinition;
|
||||
import org.thingsboard.server.common.data.cf.configuration.GeofencingPresenceStatus;
|
||||
import org.thingsboard.server.common.data.cf.configuration.GeofencingTransitionEvent;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.data.kv.KvEntry;
|
||||
import org.thingsboard.server.common.util.ProtoUtils;
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.GeofencingZoneProto;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.thingsboard.server.common.data.cf.configuration.GeofencingPresenceStatus.INSIDE;
|
||||
import static org.thingsboard.server.common.data.cf.configuration.GeofencingPresenceStatus.OUTSIDE;
|
||||
|
||||
@ -57,7 +54,7 @@ public class GeofencingZoneState {
|
||||
}
|
||||
|
||||
public GeofencingZoneState(GeofencingZoneProto proto) {
|
||||
this.zoneId = toZoneId(proto);
|
||||
this.zoneId = ProtoUtils.fromProto(proto.getZoneId());
|
||||
this.ts = proto.getTs();
|
||||
this.version = proto.getVersion();
|
||||
this.perimeterDefinition = JacksonUtil.fromString(proto.getPerimeterDefinition(), PerimeterDefinition.class);
|
||||
@ -106,8 +103,4 @@ public class GeofencingZoneState {
|
||||
return new GeofencingEvalResult(null, status);
|
||||
}
|
||||
|
||||
private EntityId toZoneId(GeofencingZoneProto proto) {
|
||||
return EntityIdFactory.getByTypeAndUuid(ProtoUtils.fromProto(proto.getZoneType()), new UUID(proto.getZoneIdMSB(), proto.getZoneIdLSB()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -133,9 +133,7 @@ public class CalculatedFieldUtils {
|
||||
|
||||
private static GeofencingZoneProto toGeofencingZoneProto(EntityId entityId, GeofencingZoneState zoneState) {
|
||||
GeofencingZoneProto.Builder builder = GeofencingZoneProto.newBuilder()
|
||||
.setZoneType(ProtoUtils.toProto(entityId.getEntityType()))
|
||||
.setZoneIdMSB(entityId.getId().getMostSignificantBits())
|
||||
.setZoneIdLSB(entityId.getId().getLeastSignificantBits())
|
||||
.setZoneId(ProtoUtils.toProto(entityId))
|
||||
.setTs(zoneState.getTs())
|
||||
.setVersion(zoneState.getVersion())
|
||||
.setPerimeterDefinition(JacksonUtil.toString(zoneState.getPerimeterDefinition()));
|
||||
|
||||
@ -1377,6 +1377,18 @@ public class ProtoUtils {
|
||||
return TbMsg.fromProto(queueName, getTbMsgProto(ruleEngineMsg), callback);
|
||||
}
|
||||
|
||||
public static TransportProtos.EntityIdProto toProto(EntityId entityId) {
|
||||
return TransportProtos.EntityIdProto.newBuilder()
|
||||
.setEntityType(toProto(entityId.getEntityType()))
|
||||
.setEntityIdMSB(getMsb(entityId))
|
||||
.setEntityIdLSB(getLsb(entityId))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static EntityId fromProto(TransportProtos.EntityIdProto entityIdProto) {
|
||||
return EntityIdFactory.getByTypeAndUuid(fromProto(entityIdProto.getEntityType()), new UUID(entityIdProto.getEntityIdMSB(), entityIdProto.getEntityIdLSB()));
|
||||
}
|
||||
|
||||
private static boolean isNotNull(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@ -82,6 +82,12 @@ enum ApiUsageRecordKeyProto {
|
||||
INACTIVE_DEVICES = 10;
|
||||
}
|
||||
|
||||
message EntityIdProto {
|
||||
EntityTypeProto entityType = 1;
|
||||
int64 entityIdMSB = 2;
|
||||
int64 entityIdLSB = 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service Discovery Data Structures;
|
||||
*/
|
||||
@ -897,13 +903,11 @@ message TsRollingArgumentProto {
|
||||
}
|
||||
|
||||
message GeofencingZoneProto {
|
||||
EntityTypeProto zoneType = 1;
|
||||
int64 zoneIdMSB = 2;
|
||||
int64 zoneIdLSB = 3;
|
||||
int64 ts = 4;
|
||||
string perimeterDefinition = 5;
|
||||
int64 version = 6;
|
||||
optional bool inside = 7;
|
||||
EntityIdProto zoneId = 1;
|
||||
int64 ts = 2;
|
||||
string perimeterDefinition = 3;
|
||||
int64 version = 4;
|
||||
optional bool inside = 5;
|
||||
}
|
||||
|
||||
message GeofencingArgumentProto {
|
||||
|
||||
@ -22,6 +22,7 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
@ -43,6 +44,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventType;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKey;
|
||||
@ -344,4 +346,24 @@ class ProtoUtilsTest {
|
||||
assertThat(toDeviceRpcRequestActorMsg.getMsg()).isEqualTo(request);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(EntityType.class)
|
||||
void testEntityIdProto_toProto_fromProto(EntityType entityType) {
|
||||
UUID uuid = UUID.fromString("51a514d7-ea8f-496d-b567-f6e76f0f9b83");
|
||||
|
||||
EntityId original = EntityIdFactory.getByTypeAndUuid(entityType, uuid);
|
||||
assertThat(original).isNotNull();
|
||||
|
||||
// toProto
|
||||
TransportProtos.EntityIdProto proto = ProtoUtils.toProto(original);
|
||||
assertThat(proto).isNotNull();
|
||||
assertThat(proto.getEntityType().getNumber()).isEqualTo(entityType.getProtoNumber());
|
||||
assertThat(proto.getEntityIdMSB()).isEqualTo(uuid.getMostSignificantBits());
|
||||
assertThat(proto.getEntityIdLSB()).isEqualTo(uuid.getLeastSignificantBits());
|
||||
|
||||
// fromProto
|
||||
EntityId restored = ProtoUtils.fromProto(proto);
|
||||
assertThat(restored).isNotNull().isEqualTo(original);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user