diff --git a/common/proto/pom.xml b/common/proto/pom.xml
index 745b4f105f..84460e8cd0 100644
--- a/common/proto/pom.xml
+++ b/common/proto/pom.xml
@@ -76,6 +76,12 @@
awaitility
test
+
+ org.jeasy
+ easy-random-core
+ test
+
+
diff --git a/common/proto/src/main/java/org/thingsboard/server/common/util/ProtoUtils.java b/common/proto/src/main/java/org/thingsboard/server/common/util/ProtoUtils.java
index 3ee6751370..71ee64c36a 100644
--- a/common/proto/src/main/java/org/thingsboard/server/common/util/ProtoUtils.java
+++ b/common/proto/src/main/java/org/thingsboard/server/common/util/ProtoUtils.java
@@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.device.data.PowerSavingConfiguration;
import org.thingsboard.server.common.data.id.ApiUsageStateId;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DashboardId;
+import org.thingsboard.server.common.data.id.DeviceCredentialsId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.EdgeId;
@@ -624,7 +625,7 @@ public class ProtoUtils {
}
if (isNotNull(deviceProfile.getDefaultRuleChainId())) {
builder.setDefaultRuleChainIdMSB(getMsb(deviceProfile.getDefaultRuleChainId()))
- .setDefaultRuleChainIdLSB(getMsb(deviceProfile.getDefaultRuleChainId()));
+ .setDefaultRuleChainIdLSB(getLsb(deviceProfile.getDefaultRuleChainId()));
}
if (isNotNull(deviceProfile.getDefaultDashboardId())) {
builder.setDefaultDashboardIdMSB(getMsb(deviceProfile.getDefaultDashboardId()))
@@ -744,7 +745,7 @@ public class ProtoUtils {
Tenant tenant = new Tenant(getEntityId(proto.getTenantIdMSB(), proto.getTenantIdLSB(), TenantId::new));
tenant.setCreatedTime(proto.getCreatedTime());
tenant.setTenantProfileId(getEntityId(proto.getTenantProfileIdMSB(), proto.getTenantProfileIdLSB(), TenantProfileId::new));
- tenant.setTitle(tenant.getTitle());
+ tenant.setTitle(proto.getTitle());
if (proto.hasRegion()) {
tenant.setRegion(proto.getRegion());
@@ -822,8 +823,12 @@ public class ProtoUtils {
.setTitle(resource.getTitle())
.setResourceType(resource.getResourceType().name())
.setResourceKey(resource.getResourceKey())
+ .setIsPublic(resource.isPublic())
.setSearchText(resource.getSearchText())
.setFileName(resource.getFileName());
+ if (isNotNull(resource.getPublicResourceKey())) {
+ builder.setPublicResourceKey(resource.getPublicResourceKey());
+ }
if (isNotNull(resource.getEtag())) {
builder.setEtag(resource.getEtag());
}
@@ -850,8 +855,12 @@ public class ProtoUtils {
resource.setTitle(proto.getTitle());
resource.setResourceType(ResourceType.valueOf(proto.getResourceType()));
resource.setResourceKey(proto.getResourceKey());
+ resource.setPublic(proto.getIsPublic());
resource.setSearchText(proto.getSearchText());
resource.setFileName(proto.getFileName());
+ if (proto.hasPublicResourceKey()) {
+ resource.setPublicResourceKey(proto.getPublicResourceKey());
+ }
if (proto.hasEtag()) {
resource.setEtag(proto.getEtag());
}
@@ -963,6 +972,9 @@ public class ProtoUtils {
public static TransportProtos.DeviceCredentialsProto toProto(DeviceCredentials deviceCredentials) {
TransportProtos.DeviceCredentialsProto.Builder builder = TransportProtos.DeviceCredentialsProto.newBuilder()
+ .setCredentialsIdMSB(deviceCredentials.getId().getId().getMostSignificantBits())
+ .setCredentialsIdLSB(deviceCredentials.getId().getId().getLeastSignificantBits())
+ .setCreatedTime(deviceCredentials.getCreatedTime())
.setDeviceIdMSB(getMsb(deviceCredentials.getDeviceId()))
.setDeviceIdLSB(getLsb(deviceCredentials.getDeviceId()))
.setCredentialsId(deviceCredentials.getCredentialsId())
@@ -975,7 +987,9 @@ public class ProtoUtils {
}
public static DeviceCredentials fromProto(TransportProtos.DeviceCredentialsProto proto) {
- DeviceCredentials deviceCredentials = new DeviceCredentials();
+ DeviceCredentials deviceCredentials =
+ new DeviceCredentials(new DeviceCredentialsId(new UUID(proto.getCredentialsIdMSB(), proto.getCredentialsIdLSB())));
+ deviceCredentials.setCreatedTime(proto.getCreatedTime());
deviceCredentials.setDeviceId(getEntityId(proto.getDeviceIdMSB(), proto.getDeviceIdLSB(), DeviceId::new));
deviceCredentials.setCredentialsId(proto.getCredentialsId());
deviceCredentials.setCredentialsType(DeviceCredentialsType.valueOf(proto.getCredentialsType().name()));
diff --git a/common/proto/src/main/proto/queue.proto b/common/proto/src/main/proto/queue.proto
index c2eb1ab56f..dd21c1730c 100644
--- a/common/proto/src/main/proto/queue.proto
+++ b/common/proto/src/main/proto/queue.proto
@@ -275,14 +275,16 @@ message TbResourceProto {
string title = 6;
string resourceType = 7;
string resourceKey = 8;
- string searchText = 9;
- optional string etag = 10;
- string fileName = 11;
- optional string resourceDescriptor = 12;
- optional int64 externalIdMSB = 13;
- optional int64 externalIdLSB = 14;
- optional bytes data = 15;
- optional bytes preview = 16;
+ bool isPublic = 9;
+ optional string publicResourceKey = 10;
+ string searchText = 11;
+ optional string etag = 12;
+ string fileName = 13;
+ optional string resourceDescriptor = 14;
+ optional int64 externalIdMSB = 15;
+ optional int64 externalIdLSB = 16;
+ optional bytes data = 17;
+ optional bytes preview = 18;
}
message ApiUsageStateProto {
@@ -637,11 +639,14 @@ message ClaimDeviceMsg {
}
message DeviceCredentialsProto {
- int64 deviceIdMSB = 1;
- int64 deviceIdLSB = 2;
- CredentialsType credentialsType = 3;
- string credentialsId = 4;
- optional string credentialsValue = 5;
+ int64 credentialsIdMSB = 1;
+ int64 credentialsIdLSB = 2;
+ int64 createdTime = 3;
+ int64 deviceIdMSB = 4;
+ int64 deviceIdLSB = 5;
+ CredentialsType credentialsType = 6;
+ string credentialsId = 7;
+ optional string credentialsValue = 8;
}
message CredentialsDataProto {
diff --git a/common/proto/src/test/java/org/thingsboard/server/common/util/ProtoUtilsTest.java b/common/proto/src/test/java/org/thingsboard/server/common/util/ProtoUtilsTest.java
index a41b2be208..3d3eee8e77 100644
--- a/common/proto/src/test/java/org/thingsboard/server/common/util/ProtoUtilsTest.java
+++ b/common/proto/src/test/java/org/thingsboard/server/common/util/ProtoUtilsTest.java
@@ -15,9 +15,25 @@
*/
package org.thingsboard.server.common.util;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.jeasy.random.EasyRandom;
+import org.jeasy.random.EasyRandomParameters;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.thingsboard.common.util.JacksonUtil;
+import org.thingsboard.server.common.data.ApiUsageState;
+import org.thingsboard.server.common.data.Device;
+import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.EntityType;
+import org.thingsboard.server.common.data.TbResource;
+import org.thingsboard.server.common.data.Tenant;
+import org.thingsboard.server.common.data.TenantProfile;
+import org.thingsboard.server.common.data.device.data.DefaultDeviceConfiguration;
+import org.thingsboard.server.common.data.device.data.DefaultDeviceTransportConfiguration;
+import org.thingsboard.server.common.data.device.data.DeviceConfiguration;
+import org.thingsboard.server.common.data.device.data.DeviceTransportConfiguration;
+import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId;
@@ -34,6 +50,9 @@ import org.thingsboard.server.common.data.rpc.RpcError;
import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody;
import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType;
+import org.thingsboard.server.common.data.sync.vc.RepositorySettings;
+import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
+import org.thingsboard.server.common.data.tenant.profile.TenantProfileConfiguration;
import org.thingsboard.server.common.msg.edge.EdgeEventUpdateMsg;
import org.thingsboard.server.common.msg.edge.FromEdgeSyncResponse;
import org.thingsboard.server.common.msg.edge.ToEdgeSyncRequest;
@@ -62,6 +81,19 @@ class ProtoUtilsTest {
DeviceId deviceId = new DeviceId(UUID.fromString("ceebb9e5-4239-437c-a507-dc5f71f1232d"));
EdgeId edgeId = new EdgeId(UUID.fromString("364be452-2183-459b-af93-1ddb325feac1"));
UUID id = UUID.fromString("31a07d85-6ed5-46f8-83c0-6715cb0a8782");
+ static EasyRandom easyRandom;
+
+ @BeforeAll
+ static void init() {
+ EasyRandomParameters parameters = new EasyRandomParameters()
+ .randomize(DeviceConfiguration.class, DefaultDeviceConfiguration::new)
+ .randomize(DeviceTransportConfiguration.class, DefaultDeviceTransportConfiguration::new)
+ .randomize(JsonNode.class, JacksonUtil::newObjectNode)
+ .randomize(DeviceProfileData.class, DeviceProfileData::new)
+ .randomize(TenantProfileConfiguration.class, DefaultTenantProfileConfiguration::new)
+ .randomize(EntityId.class, () -> new DeviceId(UUID.randomUUID()));
+ easyRandom = new EasyRandom(parameters);
+ }
@Test
void protoComponentLifecycleSerialization() {
@@ -179,4 +211,54 @@ class ProtoUtilsTest {
Assertions.assertNotNull(serializedMsg);
assertThat(ProtoUtils.fromProto(serializedMsg)).as("deserialized").isEqualTo(msg);
}
+
+ private static final String description = "Failed to deserialize %s, because found some new fields which absent in %sProto!!!";
+
+ @Test
+ void protoSerializationDeserializationEntities() {
+ Device expectedDevice = easyRandom.nextObject(Device.class);
+ TransportProtos.DeviceProto deviceProto = ProtoUtils.toProto(expectedDevice);
+ Device actualDevice = ProtoUtils.fromProto(deviceProto);
+ assertEqualDeserializedEntity(expectedDevice, actualDevice, "Device");
+
+ DeviceCredentials expectedCredentials = easyRandom.nextObject(DeviceCredentials.class);
+ TransportProtos.DeviceCredentialsProto credentialsProto = ProtoUtils.toProto(expectedCredentials);
+ DeviceCredentials actualCredentials = ProtoUtils.fromProto(credentialsProto);
+ assertEqualDeserializedEntity(expectedCredentials, actualCredentials, "DeviceCredentials");
+
+ DeviceProfile expectedDeviceProfile = easyRandom.nextObject(DeviceProfile.class);
+ TransportProtos.DeviceProfileProto deviceProfileProto = ProtoUtils.toProto(expectedDeviceProfile);
+ DeviceProfile actualDeviceProfile = ProtoUtils.fromProto(deviceProfileProto);
+ assertEqualDeserializedEntity(expectedDeviceProfile, actualDeviceProfile, "DeviceProfile");
+
+ Tenant expectedTenant = easyRandom.nextObject(Tenant.class);
+ TransportProtos.TenantProto tenantProto = ProtoUtils.toProto(expectedTenant);
+ Tenant actualTenant = ProtoUtils.fromProto(tenantProto);
+ assertEqualDeserializedEntity(expectedTenant, actualTenant, "Tenant");
+
+ TenantProfile expectedTenantProfile = easyRandom.nextObject(TenantProfile.class);
+ TransportProtos.TenantProfileProto tenantProfileProto = ProtoUtils.toProto(expectedTenantProfile);
+ TenantProfile actualTenantProfile = ProtoUtils.fromProto(tenantProfileProto);
+ assertEqualDeserializedEntity(expectedTenantProfile, actualTenantProfile, "TenantProfile");
+
+ TbResource expectedResource = easyRandom.nextObject(TbResource.class);
+ TransportProtos.TbResourceProto resourceProto = ProtoUtils.toProto(expectedResource);
+ TbResource actualResource = ProtoUtils.fromProto(resourceProto);
+ assertEqualDeserializedEntity(expectedResource, actualResource, "TbResource");
+
+ ApiUsageState expectedState = easyRandom.nextObject(ApiUsageState.class);
+ TransportProtos.ApiUsageStateProto stateProto = ProtoUtils.toProto(expectedState);
+ ApiUsageState actualState = ProtoUtils.fromProto(stateProto);
+ assertEqualDeserializedEntity(expectedState, actualState, "ApiUsageState");
+
+ RepositorySettings expectedSettings = easyRandom.nextObject(RepositorySettings.class);
+ TransportProtos.RepositorySettingsProto settingsProto = ProtoUtils.toProto(expectedSettings);
+ RepositorySettings actualSettings = ProtoUtils.fromProto(settingsProto);
+ assertEqualDeserializedEntity(expectedSettings, actualSettings, "RepositorySettings");
+ }
+
+ private void assertEqualDeserializedEntity(Object expected, Object actual, String entityName) {
+ assertThat(actual).as(String.format(description, entityName, entityName)).isEqualTo(expected);
+ }
+
}
diff --git a/pom.xml b/pom.xml
index 1204d02abf..9ebe900497 100755
--- a/pom.xml
+++ b/pom.xml
@@ -139,6 +139,7 @@
5.15.0
1.3.0
1.2.7
+ 5.0.0
7.6.1
3.23.1
@@ -2036,6 +2037,12 @@
${mock-server.version}
test
+
+ org.jeasy
+ easy-random-core
+ ${jeasy.version}
+ test
+
org.opensmpp
opensmpp-core