diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java index 723be1956..80eb79efd 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReactiveDataEntityRepositoryImpl.java @@ -699,6 +699,17 @@ public Mono> findByState(final FacetStateDto state .leftJoin(GROUP_ENTITY_RELATIONS) .on(GROUP_ENTITY_RELATIONS.DATA_ENTITY_ODDRN.eq(jooqQueryHelper.getField(deCte, DATA_ENTITY.ODDRN))); + final List> orderFields = new ArrayList<>(); + + orderFields.add(DSL.case_(deCte.field(DATA_ENTITY.STATUS)) + .when(DataEntityStatusDto.STABLE.getId(), 1) + .when(DataEntityStatusDto.DEPRECATED.getId(), 2) + .when(DataEntityStatusDto.DRAFT.getId(), 3) + .when(DataEntityStatusDto.UNASSIGNED.getId(), 4) + .when(DataEntityStatusDto.DELETED.getId(), 5)); + + orderFields.addAll(getOrderFields(cteConfig, deCte)); + final var query = DSL.with(deCteName) .asMaterialized(dataEntitySelect) .select(groupByFields) @@ -706,7 +717,7 @@ public Mono> findByState(final FacetStateDto state .from(fromTable) .where(conditions) .groupBy(groupByFields) - .orderBy(getOrderFields(cteConfig, deCte)) + .orderBy(orderFields) .limit(DSL.val(size)) .offset(DSL.val((page - 1) * size));