Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -26,15 +26,15 @@ public class AdminRegistrationApplicationListRequest extends AysPagingRequest {
private AdminRegistrationApplicationFilter filter;

/**
* Overrides the {@link AysPagingRequest#isSortPropertyAccepted()} method to validate sorting options
* Overrides the {@link AysPagingRequest#isOrderPropertyAccepted()} method to validate sorting options
* and ensures that no unsupported sorting property is used in the request.
*
* @return true if the sorting property is accepted, false otherwise.
*/
@JsonIgnore
@AssertTrue
@Override
public boolean isSortPropertyAccepted() {
public boolean isOrderPropertyAccepted() {
final Set<String> acceptedFilterFields = Set.of("createdAt");
return this.isPropertyAccepted(acceptedFilterFields);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/ays/common/model/AysSort.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ays.common.model;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class AysSort {
@NoArgsConstructor
public static class AysOrder {

@NotNull
@NotBlank
private String property;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.ays.common.model.AysPageable;
import org.ays.common.model.AysSort;

Expand All @@ -16,7 +17,7 @@
* Represents a base class for paging requests, providing common functionality for handling pageable data.
* <p>
* This class contains a pageable attribute and provides methods to validate if the sort properties used in the pageable are accepted.
* Subclasses should implement {@link #isSortPropertyAccepted()} to provide specific validation logic.
* Subclasses should implement {@link #isOrderPropertyAccepted()} to provide specific validation logic.
* </p>
*
* <h3>Example Usage</h3>
Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class AysPagingRequest {
*
* @return {@code true} if the sort properties are accepted; otherwise {@code false}
*/
public abstract boolean isSortPropertyAccepted();
public abstract boolean isOrderPropertyAccepted();

/**
* Validates if all properties used for sorting in the pageable object are within the accepted set of properties.
Expand All @@ -72,10 +73,16 @@ public abstract class AysPagingRequest {
@SuppressWarnings("all")
public boolean isPropertyAccepted(final Set<String> acceptedProperties) {

if (this.pageable == null) {
if (this.pageable == null || CollectionUtils.isEmpty(this.pageable.getOrders())) {
return true;
}

for (AysSort.AysOrder order : this.pageable.getOrders()) {
if (StringUtils.isBlank(order.getProperty()) || order.getDirection() == null) {
return true;
}
}

List<AysSort.AysOrder> orders = this.pageable.getOrders();
if (CollectionUtils.isEmpty(orders)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public class EmergencyEvacuationApplicationListRequest extends AysPagingRequest
private EmergencyEvacuationApplicationFilter filter;

/**
* Overrides the {@link AysPagingRequest#isSortPropertyAccepted()} method to validate sorting options
* Overrides the {@link AysPagingRequest#isOrderPropertyAccepted()} method to validate sorting options
* and ensures that no unsupported sorting property is used in the request.
*
* @return true if the sorting property is accepted, false otherwise.
*/
@JsonIgnore
@AssertTrue
@Override
public boolean isSortPropertyAccepted() {
public boolean isOrderPropertyAccepted() {
final Set<String> acceptedFilterFields = Set.of("createdAt");
return this.isPropertyAccepted(acceptedFilterFields);
}
Expand Down