Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: metadata api to support sort case-insensitive [DHIS2-18857] #19865

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,22 @@ public long count(Query query) {
@Nonnull
private static <T extends IdentifiableObject> List<jakarta.persistence.criteria.Order> getOrders(
Query query, CriteriaBuilder builder, Root<T> root) {
return query.getOrders().stream()
.map(
o ->
o.isAscending()
? builder.asc(root.get(o.getProperty().getFieldName()))
: builder.desc(root.get(o.getProperty().getFieldName())))
.toList();
return query.getOrders().stream().map(o -> getOrderPredicate(builder, root, o)).toList();
}

private static <T extends IdentifiableObject>
jakarta.persistence.criteria.Order getOrderPredicate(
CriteriaBuilder builder, Root<T> root, @Nonnull Order order) {

if (order.isIgnoreCase()) {
return order.isAscending()
? builder.asc(builder.lower(root.get(order.getProperty().getFieldName())))
: builder.desc(builder.lower(root.get(order.getProperty().getFieldName())));
}

return order.isAscending()
? builder.asc(root.get(order.getProperty().getFieldName()))
: builder.desc(root.get(order.getProperty().getFieldName()));
}

private void initStoreMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,25 @@ void testPostObject_MandatoryAttributeNoAttribute() {
assertErrorMandatoryAttributeRequired(attrId, POST("/users", user));
}

@Test
void testSortIAscending() {
POST(
"/categories/",
"{'name':'Child Health', 'shortName':'CAT1','dataDimensionType':'DISAGGREGATION'}")
.content(HttpStatus.CREATED);
POST(
"/categories/",
"{'name':'births attended by', 'shortName':'CAT2','dataDimensionType':'DISAGGREGATION'}")
.content(HttpStatus.CREATED);

JsonList<JsonIdentifiableObject> response =
GET("/categories?order=name:iasc")
.content()
.getList("categories", JsonIdentifiableObject.class);
assertEquals("births attended by", response.get(0).getDisplayName());
assertEquals("Child Health", response.get(1).getDisplayName());
}

private void assertErrorMandatoryAttributeRequired(String attrId, HttpResponse response) {
JsonError msg = response.content(HttpStatus.CONFLICT).as(JsonError.class);
JsonList<JsonErrorReport> errorReports = msg.getTypeReport().getErrorReports();
Expand Down
Loading