Commit e832759eef0152450d8c8f50a6daa28624ca460a

Authored by Bohdan Smetaniuk
1 parent 12513019

bug by DeviceCredentials creation

... ... @@ -28,9 +28,8 @@ import com.google.gson.JsonObject;
28 28 import io.grpc.stub.StreamObserver;
29 29 import lombok.Data;
30 30 import lombok.extern.slf4j.Slf4j;
31   -import org.apache.commons.lang3.RandomStringUtils;
  31 +import org.apache.commons.lang.RandomStringUtils;
32 32 import org.checkerframework.checker.nullness.qual.Nullable;
33   -import org.springframework.util.StringUtils;
34 33 import org.thingsboard.server.common.data.Dashboard;
35 34 import org.thingsboard.server.common.data.DataConstants;
36 35 import org.thingsboard.server.common.data.Device;
... ... @@ -871,6 +870,7 @@ public final class EdgeGrpcSession implements Closeable {
871 870 device.setType(deviceUpdateMsg.getType());
872 871 device.setLabel(deviceUpdateMsg.getLabel());
873 872 device = ctx.getDeviceService().saveDevice(device);
  873 + createDeviceCredentials(device);
874 874 device = ctx.getDeviceService().assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId());
875 875 createRelationFromEdge(device.getId());
876 876 ctx.getRelationService().saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(edge.getId(), device.getId(), "Created"));
... ... @@ -883,6 +883,14 @@ public final class EdgeGrpcSession implements Closeable {
883 883 return device;
884 884 }
885 885
  886 + private void createDeviceCredentials(Device device) {
  887 + DeviceCredentials deviceCredentials = new DeviceCredentials();
  888 + deviceCredentials.setDeviceId(device.getId());
  889 + deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN);
  890 + deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20));
  891 + ctx.getDeviceCredentialsService().createDeviceCredentials(device.getTenantId(), deviceCredentials);
  892 + }
  893 +
886 894 private EntityId getAlarmOriginator(String entityName, org.thingsboard.server.common.data.EntityType entityType) {
887 895 switch (entityType) {
888 896 case DEVICE:
... ...