Browse Source

Add tenantId to device and asset profile info objects

pull/8247/head
Igor Kulikov 4 years ago
parent
commit
eac7ce25a8
  1. 1
      application/src/test/java/org/thingsboard/server/controller/BaseAssetProfileControllerTest.java
  2. 1
      application/src/test/java/org/thingsboard/server/controller/BaseDeviceProfileControllerTest.java
  3. 11
      common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfileInfo.java
  4. 17
      common/data/src/main/java/org/thingsboard/server/common/data/asset/AssetProfileInfo.java
  5. 2
      dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java
  6. 2
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java
  7. 6
      dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java
  8. 8
      dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java
  9. 2
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetProfileServiceTest.java
  10. 2
      dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceProfileServiceTest.java

1
application/src/test/java/org/thingsboard/server/controller/BaseAssetProfileControllerTest.java

@ -425,6 +425,7 @@ public abstract class BaseAssetProfileControllerTest extends AbstractControllerT
Collections.sort(loadedAssetProfileInfos, assetProfileInfoIdComparator);
List<AssetProfileInfo> assetProfileInfos = assetProfiles.stream().map(assetProfile -> new AssetProfileInfo(assetProfile.getId(),
assetProfile.getTenantId(),
assetProfile.getName(), assetProfile.getImage(), assetProfile.getDefaultDashboardId())).collect(Collectors.toList());
Assert.assertEquals(assetProfileInfos, loadedAssetProfileInfos);

1
application/src/test/java/org/thingsboard/server/controller/BaseDeviceProfileControllerTest.java

@ -546,6 +546,7 @@ public abstract class BaseDeviceProfileControllerTest extends AbstractController
Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator);
List<DeviceProfileInfo> deviceProfileInfos = deviceProfiles.stream().map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(),
deviceProfile.getTenantId(),
deviceProfile.getName(), deviceProfile.getImage(), deviceProfile.getDefaultDashboardId(),
deviceProfile.getType(), deviceProfile.getTransportType())).collect(Collectors.toList());

11
common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfileInfo.java

@ -24,6 +24,7 @@ import lombok.Value;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.TenantId;
import java.util.UUID;
@ -41,22 +42,28 @@ public class DeviceProfileInfo extends EntityInfo {
@ApiModelProperty(position = 6, value = "Type of the transport used to connect the device. Default transport supports HTTP, CoAP and MQTT.")
private final DeviceTransportType transportType;
@ApiModelProperty(position = 7, value = "Tenant id.")
private final TenantId tenantId;
@JsonCreator
public DeviceProfileInfo(@JsonProperty("id") EntityId id,
@JsonProperty("tenantId") TenantId tenantId,
@JsonProperty("name") String name,
@JsonProperty("image") String image,
@JsonProperty("defaultDashboardId") DashboardId defaultDashboardId,
@JsonProperty("type") DeviceProfileType type,
@JsonProperty("transportType") DeviceTransportType transportType) {
super(id, name);
this.tenantId = tenantId;
this.image = image;
this.defaultDashboardId = defaultDashboardId;
this.type = type;
this.transportType = transportType;
}
public DeviceProfileInfo(UUID uuid, String name, String image, UUID defaultDashboardId, DeviceProfileType type, DeviceTransportType transportType) {
public DeviceProfileInfo(UUID uuid, UUID tenantId, String name, String image, UUID defaultDashboardId, DeviceProfileType type, DeviceTransportType transportType) {
super(EntityIdFactory.getByTypeAndUuid(EntityType.DEVICE_PROFILE, uuid), name);
this.tenantId = new TenantId(tenantId);
this.image = image;
this.defaultDashboardId = defaultDashboardId != null ? new DashboardId(defaultDashboardId) : null;
this.type = type;
@ -64,7 +71,7 @@ public class DeviceProfileInfo extends EntityInfo {
}
public DeviceProfileInfo(DeviceProfile profile) {
this(profile.getId(), profile.getName(), profile.getImage(), profile.getDefaultDashboardId(),
this(profile.getId(), profile.getTenantId(), profile.getName(), profile.getImage(), profile.getDefaultDashboardId(),
profile.getType(), profile.getTransportType());
}

17
common/data/src/main/java/org/thingsboard/server/common/data/asset/AssetProfileInfo.java

@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.TenantId;
import java.util.UUID;
@ -39,24 +40,30 @@ public class AssetProfileInfo extends EntityInfo {
@ApiModelProperty(position = 4, value = "Reference to the dashboard. Used in the mobile application to open the default dashboard when user navigates to asset details.")
private final DashboardId defaultDashboardId;
@ApiModelProperty(position = 5, value = "Tenant id.")
private final TenantId tenantId;
@JsonCreator
public AssetProfileInfo(@JsonProperty("id") EntityId id,
@JsonProperty("name") String name,
@JsonProperty("image") String image,
@JsonProperty("defaultDashboardId") DashboardId defaultDashboardId) {
@JsonProperty("tenantId") TenantId tenantId,
@JsonProperty("name") String name,
@JsonProperty("image") String image,
@JsonProperty("defaultDashboardId") DashboardId defaultDashboardId) {
super(id, name);
this.tenantId = tenantId;
this.image = image;
this.defaultDashboardId = defaultDashboardId;
}
public AssetProfileInfo(UUID uuid, String name, String image, UUID defaultDashboardId) {
public AssetProfileInfo(UUID uuid, UUID tenantId, String name, String image, UUID defaultDashboardId) {
super(EntityIdFactory.getByTypeAndUuid(EntityType.ASSET_PROFILE, uuid), name);
this.tenantId = new TenantId(tenantId);
this.image = image;
this.defaultDashboardId = defaultDashboardId != null ? new DashboardId(defaultDashboardId) : null;
}
public AssetProfileInfo(AssetProfile profile) {
this(profile.getId(), profile.getName(), profile.getImage(), profile.getDefaultDashboardId());
this(profile.getId(), profile.getTenantId(), profile.getName(), profile.getImage(), profile.getDefaultDashboardId());
}
}

2
dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java

@ -293,7 +293,7 @@ public class AssetProfileServiceImpl extends AbstractCachedEntityService<AssetPr
};
private AssetProfileInfo toAssetProfileInfo(AssetProfile profile) {
return profile == null ? null : new AssetProfileInfo(profile.getId(), profile.getName(), profile.getImage(),
return profile == null ? null : new AssetProfileInfo(profile.getId(), profile.getTenantId(), profile.getName(), profile.getImage(),
profile.getDefaultDashboardId());
}

2
dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java

@ -315,7 +315,7 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService<Device
};
private DeviceProfileInfo toDeviceProfileInfo(DeviceProfile profile) {
return profile == null ? null : new DeviceProfileInfo(profile.getId(), profile.getName(), profile.getImage(),
return profile == null ? null : new DeviceProfileInfo(profile.getId(), profile.getTenantId(), profile.getName(), profile.getImage(),
profile.getDefaultDashboardId(), profile.getType(), profile.getTransportType());
}

6
dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java

@ -28,7 +28,7 @@ import java.util.UUID;
public interface AssetProfileRepository extends JpaRepository<AssetProfileEntity, UUID>, ExportableEntityRepository<AssetProfileEntity> {
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.name, a.image, a.defaultDashboardId) " +
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.tenantId, a.name, a.image, a.defaultDashboardId) " +
"FROM AssetProfileEntity a " +
"WHERE a.id = :assetProfileId")
AssetProfileInfo findAssetProfileInfoById(@Param("assetProfileId") UUID assetProfileId);
@ -39,7 +39,7 @@ public interface AssetProfileRepository extends JpaRepository<AssetProfileEntity
@Param("textSearch") String textSearch,
Pageable pageable);
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.name, a.image, a.defaultDashboardId) " +
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.tenantId, a.name, a.image, a.defaultDashboardId) " +
"FROM AssetProfileEntity a WHERE " +
"a.tenantId = :tenantId AND LOWER(a.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))")
Page<AssetProfileInfo> findAssetProfileInfos(@Param("tenantId") UUID tenantId,
@ -50,7 +50,7 @@ public interface AssetProfileRepository extends JpaRepository<AssetProfileEntity
"WHERE a.tenantId = :tenantId AND a.isDefault = true")
AssetProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId);
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.name, a.image, a.defaultDashboardId) " +
@Query("SELECT new org.thingsboard.server.common.data.asset.AssetProfileInfo(a.id, a.tenantId, a.name, a.image, a.defaultDashboardId) " +
"FROM AssetProfileEntity a " +
"WHERE a.tenantId = :tenantId AND a.isDefault = true")
AssetProfileInfo findDefaultAssetProfileInfo(@Param("tenantId") UUID tenantId);

8
dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java

@ -29,7 +29,7 @@ import java.util.UUID;
public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEntity, UUID>, ExportableEntityRepository<DeviceProfileEntity> {
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.tenantId, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
"FROM DeviceProfileEntity d " +
"WHERE d.id = :deviceProfileId")
DeviceProfileInfo findDeviceProfileInfoById(@Param("deviceProfileId") UUID deviceProfileId);
@ -40,14 +40,14 @@ public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEnti
@Param("textSearch") String textSearch,
Pageable pageable);
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.tenantId, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
"FROM DeviceProfileEntity d WHERE " +
"d.tenantId = :tenantId AND LOWER(d.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))")
Page<DeviceProfileInfo> findDeviceProfileInfos(@Param("tenantId") UUID tenantId,
@Param("textSearch") String textSearch,
Pageable pageable);
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.tenantId, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
"FROM DeviceProfileEntity d WHERE " +
"d.tenantId = :tenantId AND d.transportType = :transportType AND LOWER(d.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))")
Page<DeviceProfileInfo> findDeviceProfileInfos(@Param("tenantId") UUID tenantId,
@ -59,7 +59,7 @@ public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEnti
"WHERE d.tenantId = :tenantId AND d.isDefault = true")
DeviceProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId);
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
@Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.tenantId, d.name, d.image, d.defaultDashboardId, d.type, d.transportType) " +
"FROM DeviceProfileEntity d " +
"WHERE d.tenantId = :tenantId AND d.isDefault = true")
DeviceProfileInfo findDefaultDeviceProfileInfo(@Param("tenantId") UUID tenantId);

2
dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetProfileServiceTest.java

@ -259,7 +259,7 @@ public abstract class BaseAssetProfileServiceTest extends AbstractServiceTest {
Collections.sort(loadedAssetProfileInfos, assetProfileInfoIdComparator);
List<AssetProfileInfo> assetProfileInfos = assetProfiles.stream()
.map(assetProfile -> new AssetProfileInfo(assetProfile.getId(),
.map(assetProfile -> new AssetProfileInfo(assetProfile.getId(), assetProfile.getTenantId(),
assetProfile.getName(), assetProfile.getImage(), assetProfile.getDefaultDashboardId())).collect(Collectors.toList());
Assert.assertEquals(assetProfileInfos, loadedAssetProfileInfos);

2
dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceProfileServiceTest.java

@ -352,7 +352,7 @@ public abstract class BaseDeviceProfileServiceTest extends AbstractServiceTest {
Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator);
List<DeviceProfileInfo> deviceProfileInfos = deviceProfiles.stream()
.map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(),
.map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(), deviceProfile.getTenantId(),
deviceProfile.getName(), deviceProfile.getImage(), deviceProfile.getDefaultDashboardId(),
deviceProfile.getType(), deviceProfile.getTransportType())).collect(Collectors.toList());

Loading…
Cancel
Save