rollback sorting in sql

This commit is contained in:
ShvaykaD 2023-12-08 14:32:26 +02:00
parent f7af8e298c
commit cfe47f88b6
5 changed files with 17 additions and 6 deletions

View File

@ -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<EntitySubtype> convertTenantEntityInfosToDto(UUID tenantUUID, EntityType entityType, List<EntityInfo> 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());
}

View File

@ -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<AssetPr
public List<EntityInfo> 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<TenantId, AssetProfile> tenantAssetProfilesRemover =

View File

@ -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<Device
public List<EntityInfo> 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<TenantId, DeviceProfile> tenantDeviceProfilesRemover =

View File

@ -74,11 +74,11 @@ public interface AssetProfileRepository extends JpaRepository<AssetProfileEntity
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(ap.id, 'ASSET_PROFILE', ap.name) " +
"FROM AssetProfileEntity ap WHERE ap.tenantId = :tenantId AND EXISTS " +
"(SELECT 1 FROM AssetEntity a WHERE a.tenantId = :tenantId AND a.assetProfileId = ap.id) ORDER BY ap.name ASC")
"(SELECT 1 FROM AssetEntity a WHERE a.tenantId = :tenantId AND a.assetProfileId = ap.id)")
List<EntityInfo> 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<EntityInfo> findAllTenantAssetProfileNames(@Param("tenantId") UUID tenantId);
}

View File

@ -85,11 +85,11 @@ public interface DeviceProfileRepository extends JpaRepository<DeviceProfileEnti
@Query("SELECT new org.thingsboard.server.common.data.EntityInfo(dp.id, 'DEVICE_PROFILE', dp.name) " +
"FROM DeviceProfileEntity dp WHERE dp.tenantId = :tenantId AND EXISTS " +
"(SELECT 1 FROM DeviceEntity dv WHERE dv.tenantId = :tenantId AND dv.deviceProfileId = dp.id) ORDER BY dp.name ASC")
"(SELECT 1 FROM DeviceEntity dv WHERE dv.tenantId = :tenantId AND dv.deviceProfileId = dp.id)")
List<EntityInfo> 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<EntityInfo> findAllTenantDeviceProfileNames(@Param("tenantId") UUID tenantId);
}