
fr.ght1pc9kc.juery.basic.ParserConfiguration Maven / Gradle / Ivy
package fr.ght1pc9kc.juery.basic;
import lombok.Builder;
import lombok.Value;
import java.util.Optional;
import java.util.Set;
/**
* Build a QueryStringParser configuration.
*
* This allows to specify or customize the querystring parameters names for pagination and sorting
*
*
* - page: The current page number to return.
* - size: The size of the page to return, the number of elements.
* - from: The first element number to return (the offset).
* - to: The last element number to return (the limit).
* - sort: The parameter used for sorting clause.
* - max per page: The maximum elements returned in a page./
*
* @see QueryStringParser for more information
*/
@Value
public class ParserConfiguration {
/**
* The default configuration:
*
* - page = {@code "_p"}
* - size = {@code "_pp"}
* - from = {@code "_from"}
* - to = {@code "_to"}
* - sort = {@code "_s"}
* - maxPerPage = {@code 100}
*
*/
public static final ParserConfiguration DEFAULT = ParserConfiguration.builder().build();
private static final String DEFAULT_PAGE_PARAMETER = "_p";
private static final String DEFAULT_SIZE_PARAMETER = "_pp";
private static final String DEFAULT_FROM_PARAMETER = "_from";
private static final String DEFAULT_TO_PARAMETER = "_to";
private static final String DEFAULT_SORT_PARAMETER = "_s";
private static final int DEFAULT_MAX_PER_PAGE = 100;
String pageParameter;
String sizeParameter;
String fromParameter;
String toParameter;
String sortParameter;
int maxPageSize;
Set excludeFilterParameters;
@Builder
private ParserConfiguration(String page, String size, String from, String to, String sort, int maxPageSize) {
this.pageParameter = Optional.ofNullable(page).orElse(DEFAULT_PAGE_PARAMETER);
this.sizeParameter = Optional.ofNullable(size).orElse(DEFAULT_SIZE_PARAMETER);
this.fromParameter = Optional.ofNullable(from).orElse(DEFAULT_FROM_PARAMETER);
this.toParameter = Optional.ofNullable(to).orElse(DEFAULT_TO_PARAMETER);
this.sortParameter = Optional.ofNullable(sort).orElse(DEFAULT_SORT_PARAMETER);
this.maxPageSize = (maxPageSize <= 0) ? DEFAULT_MAX_PER_PAGE : maxPageSize;
this.excludeFilterParameters = Set.of(
pageParameter, sizeParameter, fromParameter, toParameter, sortParameter
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy