fixed edqs sorting

This commit is contained in:
dashevchenko 2025-03-19 15:35:48 +02:00
parent 8615dd4ce5
commit 1e0bdc9032
5 changed files with 22 additions and 23 deletions

View File

@ -35,12 +35,12 @@ public class ApiUsageStateData extends BaseEntityData<ApiUsageStateFields> {
@Override
public String getEntityName() {
return getEntityOwnerName();
return getOwnerName();
}
@Override
public String getEntityOwnerName() {
return repo.getOwnerName(fields.getEntityId());
public String getOwnerName() {
return repo.getOwnerEntityName(fields.getEntityId());
}
}

View File

@ -98,8 +98,13 @@ public abstract class BaseEntityData<T extends EntityFields> implements EntityDa
}
@Override
public EntityType getOwnerType() {
return customerId != null ? EntityType.CUSTOMER : EntityType.TENANT;
public String getOwnerName() {
return repo.getOwnerEntityName(isTenantEntity() ? repo.getTenantId() : new CustomerId(getCustomerId()));
}
@Override
public String getOwnerType() {
return isTenantEntity() ? EntityType.TENANT.name() : EntityType.CUSTOMER.name();
}
@Override
@ -132,22 +137,21 @@ public abstract class BaseEntityData<T extends EntityFields> implements EntityDa
}
return switch (name) {
case "name" -> getEntityName();
case "ownerName" -> getEntityOwnerName();
case "ownerType" -> customerId != null ? EntityType.CUSTOMER.name() : EntityType.TENANT.name();
case "ownerName" -> getOwnerName();
case "ownerType" -> getOwnerType();
case "entityType" -> Optional.ofNullable(getEntityType()).map(EntityType::name).orElse("");
default -> fields.getAsString(name);
};
}
public String getEntityOwnerName() {
return repo.getOwnerName(getCustomerId() == null || CustomerId.NULL_UUID.equals(getCustomerId()) ? null :
new CustomerId(getCustomerId()));
}
public String getEntityName() {
return getFields().getName();
}
private boolean isTenantEntity() {
return getCustomerId() == null || CustomerId.NULL_UUID.equals(getCustomerId());
}
private String getRelatedParentId(QueryContext ctx) {
return Optional.ofNullable(ctx.getRelatedParentIdMap().get(getId()))
.map(UUID::toString)

View File

@ -54,7 +54,9 @@ public interface EntityData<T extends EntityFields> {
boolean removeTs(Integer keyId);
EntityType getOwnerType();
String getOwnerName();
String getOwnerType();
DataPoint getDataPoint(DataKey key, QueryContext queryContext);

View File

@ -421,14 +421,7 @@ public class TenantRepo {
return relations.computeIfAbsent(relationTypeGroup, type -> new RelationsRepo());
}
public String getOwnerName(EntityId ownerId) {
if (ownerId == null || (ownerId.getEntityType() == EntityType.CUSTOMER && ownerId.isNullUid())) {
return getOwnerEntityName(tenantId);
}
return getOwnerEntityName(ownerId);
}
private String getOwnerEntityName(EntityId entityId) {
public String getOwnerEntityName(EntityId entityId) {
EntityType entityType = entityId.getEntityType();
return switch (entityType) {
case CUSTOMER, TENANT -> {

View File

@ -67,10 +67,10 @@ import static org.thingsboard.server.common.data.query.ComplexFilterPredicate.Co
@Slf4j
public class RepositoryUtils {
public static final Comparator<SortableEntityData> SORT_ASC = Comparator.comparing((SortableEntityData sed) -> Optional.ofNullable(sed.getSortValue()).orElse(""))
public static final Comparator<SortableEntityData> SORT_ASC = Comparator.comparing((SortableEntityData sed) -> Optional.ofNullable(sed.getSortValue()).orElse(""), String.CASE_INSENSITIVE_ORDER)
.thenComparing(sp -> sp.getId().toString());
public static final Comparator<SortableEntityData> SORT_DESC = Comparator.comparing((SortableEntityData sed) -> Optional.ofNullable(sed.getSortValue()).orElse(""))
public static final Comparator<SortableEntityData> SORT_DESC = Comparator.comparing((SortableEntityData sed) -> Optional.ofNullable(sed.getSortValue()).orElse(""), String.CASE_INSENSITIVE_ORDER)
.thenComparing(sp -> sp.getId().toString()).reversed();
public static EntityType resolveEntityType(EntityFilter entityFilter) {