Merge pull request #12975 from dashevchenko/edqsSortFix
Fixed EDQS sorting
This commit is contained in:
		
						commit
						941f19b347
					
				@ -35,12 +35,12 @@ public class ApiUsageStateData extends BaseEntityData<ApiUsageStateFields> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public String getEntityName() {
 | 
					    public String getEntityName() {
 | 
				
			||||||
        return getEntityOwnerName();
 | 
					        return getOwnerName();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public String getEntityOwnerName() {
 | 
					    public String getOwnerName() {
 | 
				
			||||||
        return repo.getOwnerName(fields.getEntityId());
 | 
					        return repo.getOwnerEntityName(fields.getEntityId());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -98,8 +98,13 @@ public abstract class BaseEntityData<T extends EntityFields> implements EntityDa
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public EntityType getOwnerType() {
 | 
					    public String getOwnerName() {
 | 
				
			||||||
        return customerId != null ? EntityType.CUSTOMER : EntityType.TENANT;
 | 
					        return repo.getOwnerEntityName(isTenantEntity() ? repo.getTenantId() : new CustomerId(getCustomerId()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String getOwnerType() {
 | 
				
			||||||
 | 
					        return isTenantEntity() ? EntityType.TENANT.name() :  EntityType.CUSTOMER.name();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@ -132,22 +137,21 @@ public abstract class BaseEntityData<T extends EntityFields> implements EntityDa
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return switch (name) {
 | 
					        return switch (name) {
 | 
				
			||||||
            case "name" -> getEntityName();
 | 
					            case "name" -> getEntityName();
 | 
				
			||||||
            case "ownerName" -> getEntityOwnerName();
 | 
					            case "ownerName" -> getOwnerName();
 | 
				
			||||||
            case "ownerType" -> customerId != null ? EntityType.CUSTOMER.name() : EntityType.TENANT.name();
 | 
					            case "ownerType" -> getOwnerType();
 | 
				
			||||||
            case "entityType" -> Optional.ofNullable(getEntityType()).map(EntityType::name).orElse("");
 | 
					            case "entityType" -> Optional.ofNullable(getEntityType()).map(EntityType::name).orElse("");
 | 
				
			||||||
            default -> fields.getAsString(name);
 | 
					            default -> fields.getAsString(name);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getEntityOwnerName() {
 | 
					 | 
				
			||||||
        return repo.getOwnerName(getCustomerId() == null || CustomerId.NULL_UUID.equals(getCustomerId()) ? null :
 | 
					 | 
				
			||||||
                new CustomerId(getCustomerId()));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public String getEntityName() {
 | 
					    public String getEntityName() {
 | 
				
			||||||
        return getFields().getName();
 | 
					        return getFields().getName();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean isTenantEntity() {
 | 
				
			||||||
 | 
					        return getCustomerId() == null || CustomerId.NULL_UUID.equals(getCustomerId());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private String getRelatedParentId(QueryContext ctx) {
 | 
					    private String getRelatedParentId(QueryContext ctx) {
 | 
				
			||||||
        return Optional.ofNullable(ctx.getRelatedParentIdMap().get(getId()))
 | 
					        return Optional.ofNullable(ctx.getRelatedParentIdMap().get(getId()))
 | 
				
			||||||
                .map(UUID::toString)
 | 
					                .map(UUID::toString)
 | 
				
			||||||
 | 
				
			|||||||
@ -54,7 +54,9 @@ public interface EntityData<T extends EntityFields> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    boolean removeTs(Integer keyId);
 | 
					    boolean removeTs(Integer keyId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EntityType getOwnerType();
 | 
					    String getOwnerName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    String getOwnerType();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DataPoint getDataPoint(DataKey key, QueryContext queryContext);
 | 
					    DataPoint getDataPoint(DataKey key, QueryContext queryContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -421,14 +421,7 @@ public class TenantRepo {
 | 
				
			|||||||
        return relations.computeIfAbsent(relationTypeGroup, type -> new RelationsRepo());
 | 
					        return relations.computeIfAbsent(relationTypeGroup, type -> new RelationsRepo());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getOwnerName(EntityId ownerId) {
 | 
					    public String getOwnerEntityName(EntityId entityId) {
 | 
				
			||||||
        if (ownerId == null || (ownerId.getEntityType() == EntityType.CUSTOMER && ownerId.isNullUid())) {
 | 
					 | 
				
			||||||
            return getOwnerEntityName(tenantId);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return getOwnerEntityName(ownerId);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private String getOwnerEntityName(EntityId entityId) {
 | 
					 | 
				
			||||||
        EntityType entityType = entityId.getEntityType();
 | 
					        EntityType entityType = entityId.getEntityType();
 | 
				
			||||||
        return switch (entityType) {
 | 
					        return switch (entityType) {
 | 
				
			||||||
            case CUSTOMER, TENANT -> {
 | 
					            case CUSTOMER, TENANT -> {
 | 
				
			||||||
 | 
				
			|||||||
@ -67,10 +67,10 @@ import static org.thingsboard.server.common.data.query.ComplexFilterPredicate.Co
 | 
				
			|||||||
@Slf4j
 | 
					@Slf4j
 | 
				
			||||||
public class RepositoryUtils {
 | 
					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());
 | 
					            .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();
 | 
					            .thenComparing(sp -> sp.getId().toString()).reversed();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static EntityType resolveEntityType(EntityFilter entityFilter) {
 | 
					    public static EntityType resolveEntityType(EntityFilter entityFilter) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user