From cfe47f88b682127f0cf2bc97376e6a1537770ec0 Mon Sep 17 00:00:00 2001 From: ShvaykaD Date: Fri, 8 Dec 2023 14:32:26 +0200 Subject: [PATCH] rollback sorting in sql --- dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java | 3 +++ .../server/dao/asset/AssetProfileServiceImpl.java | 6 +++++- .../server/dao/device/DeviceProfileServiceImpl.java | 6 +++++- .../server/dao/sql/asset/AssetProfileRepository.java | 4 ++-- .../server/dao/sql/device/DeviceProfileRepository.java | 4 ++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java index 1d9b276f65..1c4aed5393 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java +++ b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java @@ -32,6 +32,7 @@ import org.thingsboard.server.dao.model.ToData; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -163,6 +164,7 @@ public abstract class DaoUtil { .collect(Collectors.toList()); } + @Deprecated // used only in deprecated DAO api public static List convertTenantEntityInfosToDto(UUID tenantUUID, EntityType entityType, List entityInfos) { if (CollectionUtils.isEmpty(entityInfos)) { return Collections.emptyList(); @@ -170,6 +172,7 @@ public abstract class DaoUtil { var tenantId = TenantId.fromUUID(tenantUUID); return entityInfos.stream() .map(info -> new EntitySubtype(tenantId, entityType, info.getName())) + .sorted(Comparator.comparing(EntitySubtype::getType)) .collect(Collectors.toList()); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java index a46978bec1..0b9e949c7c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java @@ -43,9 +43,11 @@ import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.Validator; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import static org.thingsboard.server.dao.service.Validator.validateId; @@ -323,7 +325,9 @@ public class AssetProfileServiceImpl extends AbstractCachedEntityService findAssetProfileNamesByTenantId(TenantId tenantId, boolean activeOnly) { log.trace("Executing findAssetProfileNamesByTenantId, tenantId [{}]", tenantId); validateId(tenantId, INCORRECT_TENANT_ID + tenantId); - return assetProfileDao.findTenantAssetProfileNames(tenantId.getId(), activeOnly); + return assetProfileDao.findTenantAssetProfileNames(tenantId.getId(), activeOnly) + .stream().sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); } private final PaginatedRemover tenantAssetProfilesRemover = diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java index c67babdab0..7e3567c888 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java @@ -58,11 +58,13 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.thingsboard.server.dao.service.Validator.validateId; import static org.thingsboard.server.dao.service.Validator.validateString; @@ -378,7 +380,9 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService findDeviceProfileNamesByTenantId(TenantId tenantId, boolean activeOnly) { log.trace("Executing findDeviceProfileNamesByTenantId, tenantId [{}]", tenantId); validateId(tenantId, INCORRECT_TENANT_ID + tenantId); - return deviceProfileDao.findTenantDeviceProfileNames(tenantId.getId(), activeOnly); + return deviceProfileDao.findTenantDeviceProfileNames(tenantId.getId(), activeOnly) + .stream().sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); } private final PaginatedRemover tenantDeviceProfilesRemover = diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java index faf4510879..27dde2fc51 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java @@ -74,11 +74,11 @@ public interface AssetProfileRepository extends JpaRepository findActiveTenantAssetProfileNames(@Param("tenantId") UUID tenantId); @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(a.id, 'ASSET_PROFILE', a.name) " + - "FROM AssetProfileEntity a WHERE a.tenantId = :tenantId ORDER BY a.name ASC") + "FROM AssetProfileEntity a WHERE a.tenantId = :tenantId") List findAllTenantAssetProfileNames(@Param("tenantId") UUID tenantId); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java index cc50b06e6e..3b74de9e98 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java @@ -85,11 +85,11 @@ public interface DeviceProfileRepository extends JpaRepository findActiveTenantDeviceProfileNames(@Param("tenantId") UUID tenantId); @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(d.id, 'DEVICE_PROFILE', d.name) " + - "FROM DeviceProfileEntity d WHERE d.tenantId = :tenantId ORDER BY d.name ASC") + "FROM DeviceProfileEntity d WHERE d.tenantId = :tenantId") List findAllTenantDeviceProfileNames(@Param("tenantId") UUID tenantId); }