From dd41c781d562c8174e67a97bfb1731917bd053ac Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 10 Jul 2024 17:06:59 +0200 Subject: [PATCH 1/4] [Fix partially kbss-cvut/fta-fmea-ui#507] Add fault tree summary fulltext filtering based on fault tree label and sns system label. --- .../controller/FaultTreeController.java | 8 ++- .../util/FaultTreeFilterMapper.java | 61 ++++++++++++++++ .../dao/util/FaultTreeFilterParams.java | 70 +++++++++++++++++++ .../service/FaultTreeRepositoryService.java | 6 ++ 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 src/main/java/cz/cvut/kbss/analysis/controller/util/FaultTreeFilterMapper.java create mode 100644 src/main/java/cz/cvut/kbss/analysis/dao/util/FaultTreeFilterParams.java diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java index 598c9ea7..79a102fd 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java @@ -1,5 +1,7 @@ package cz.cvut.kbss.analysis.controller; +import cz.cvut.kbss.analysis.controller.util.FaultTreeFilterMapper; +import cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams; import cz.cvut.kbss.analysis.model.*; import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter; import cz.cvut.kbss.analysis.security.SecurityConstants; @@ -15,6 +17,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import java.net.URI; @@ -39,8 +42,9 @@ public List findAll() { } @GetMapping("/summaries") - public List summaries() { - return repositoryService.findAllSummaries(); + public List summaries(@RequestParam(required = false) MultiValueMap params) { + FaultTreeFilterParams filterParams = FaultTreeFilterMapper.constructFaultTreeFilter(params); + return repositoryService.findAllSummaries(filterParams); } @GetMapping(value = "/{faultTreeFragment}", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}) diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/FaultTreeFilterMapper.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/FaultTreeFilterMapper.java new file mode 100644 index 00000000..2b8cc8bb --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/FaultTreeFilterMapper.java @@ -0,0 +1,61 @@ +package cz.cvut.kbss.analysis.controller.util; + +import cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import java.util.*; + +/** + * Maps query parameters to {@link FaultTreeFilterParams} instances. + */ +@Slf4j +public class FaultTreeFilterMapper { + + private static final String SNS_LABEL_PARAM = "snsLabel"; + + private static final String LABEL_PARAM = "label"; + + + /** + * Maps the specified single parameter and value to a new {@link FaultTreeFilterParams} instance. + * + * @param param Parameter name + * @param value Parameter value + * @return New {@code FaultTreeFilterParams} instance + */ + public static FaultTreeFilterParams constructFaultTreeFilter(String param, String value) { + return constructFaultTreeFilter(new LinkedMultiValueMap<>(Map.of(param, List.of(value)))); + } + + public static FaultTreeFilterParams constructFaultTreeFilter(MultiValueMap params) { + final FaultTreeFilterParams result = new FaultTreeFilterParams(); + return constructFaultTreeFilter(result, new LinkedMultiValueMap<>(params)); + } + + /** + * Maps the specified parameters to a new {@link FaultTreeFilterParams} instance. + * + * @param params Request parameters to map + * @return New {@code FaultTreeFilterParams} instance + */ + public static FaultTreeFilterParams constructFaultTreeFilter(final FaultTreeFilterParams result, MultiValueMap params) { + Objects.requireNonNull(params); + getSingleValue(SNS_LABEL_PARAM, params).ifPresent(s -> result.setSnsLabel(s)); + getSingleValue(LABEL_PARAM, params).ifPresent(s -> result.setLabel(s)); + + return result; + } + + private static Optional getSingleValue(String param, MultiValueMap source) { + final List values = source.getOrDefault(param, Collections.emptyList()); + if (values.isEmpty()) { + return Optional.empty(); + } + if (values.size() > 1) { + log.warn("Found multiple values of parameter '{}'. Using the first one - '{}'.", param, values.get(0)); + } + return Optional.of(values.get(0)); + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/dao/util/FaultTreeFilterParams.java b/src/main/java/cz/cvut/kbss/analysis/dao/util/FaultTreeFilterParams.java new file mode 100644 index 00000000..a753419e --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/dao/util/FaultTreeFilterParams.java @@ -0,0 +1,70 @@ +package cz.cvut.kbss.analysis.dao.util; + +import cz.cvut.kbss.analysis.model.FaultTree; + +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Stream; + +/** + * Encapsulates {@link cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams} filtering criteria. + */ +public class FaultTreeFilterParams { + + /** + * Value to filter fault tree according to sns system + */ + private String snsLabel; + + private String label; + + public FaultTreeFilterParams() { + } + + public String getSnsLabel() { + return snsLabel; + } + + public void setSnsLabel(String snsLabel) { + this.snsLabel = snsLabel; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public boolean matches(FaultTree ft) { + return Stream.of( + Optional.ofNullable(ft.getName()).filter(n -> matches(n, label)), + Optional.ofNullable(ft.getSubsystem()).map(i -> i.getName()).filter(n -> matches(n, snsLabel)) + ).allMatch(Optional::isPresent); + } + + protected boolean matches(String val, String pattern){ + return pattern == null || pattern.isBlank() || val.contains(pattern.trim()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FaultTreeFilterParams that)) return false; + return Objects.equals(snsLabel, that.snsLabel) && Objects.equals(label, that.label); + } + + @Override + public int hashCode() { + return Objects.hash(snsLabel, label); + } + + @Override + public String toString() { + return "FaultTreeFilterParams{" + + "snsFilter='" + snsLabel + '\'' + + ", nameFilter='" + label + '\'' + + '}'; + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java index b4b172fc..87d2651c 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -1,6 +1,7 @@ package cz.cvut.kbss.analysis.service; import cz.cvut.kbss.analysis.dao.*; +import cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams; import cz.cvut.kbss.analysis.exception.EntityNotFoundException; import cz.cvut.kbss.analysis.model.*; import cz.cvut.kbss.analysis.model.System; @@ -130,6 +131,11 @@ public FaultTree findSummary(URI faultTreeUri){ return faultTreeSummary; } + public List findAllSummaries(FaultTreeFilterParams filterParams){ + List summaries = findAllSummaries(); + return summaries.stream().filter(filterParams::matches).toList(); + } + @Override public List findAllSummaries(){ List summaries = super.findAllSummaries(); From 7beed157fe5a0639dc940dd17e8c335b522f4ae5 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 10 Jul 2024 18:51:32 +0200 Subject: [PATCH 2/4] [Fix partially kbss-cvut/fta-fmea-ui#507] Add paging support for fault tree summary api --- .../controller/FaultTreeController.java | 15 ++- .../event/PaginatedResultRetrievedEvent.java | 37 +++++++ .../handler/HateoasPagingListener.java | 85 ++++++++++++++ .../controller/util/HttpPaginationLink.java | 18 +++ .../analysis/controller/util/PagingUtils.java | 104 ++++++++++++++++++ .../service/FaultTreeRepositoryService.java | 24 +++- .../cz/cvut/kbss/analysis/util/Constants.java | 49 +++++++++ 7 files changed, 327 insertions(+), 5 deletions(-) create mode 100644 src/main/java/cz/cvut/kbss/analysis/controller/event/PaginatedResultRetrievedEvent.java create mode 100644 src/main/java/cz/cvut/kbss/analysis/controller/handler/HateoasPagingListener.java create mode 100644 src/main/java/cz/cvut/kbss/analysis/controller/util/HttpPaginationLink.java create mode 100644 src/main/java/cz/cvut/kbss/analysis/controller/util/PagingUtils.java create mode 100644 src/main/java/cz/cvut/kbss/analysis/util/Constants.java diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java index 79a102fd..c86a8547 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java @@ -1,6 +1,8 @@ package cz.cvut.kbss.analysis.controller; +import cz.cvut.kbss.analysis.controller.event.PaginatedResultRetrievedEvent; import cz.cvut.kbss.analysis.controller.util.FaultTreeFilterMapper; +import cz.cvut.kbss.analysis.controller.util.PagingUtils; import cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams; import cz.cvut.kbss.analysis.model.*; import cz.cvut.kbss.analysis.model.opdata.OperationalDataFilter; @@ -11,14 +13,18 @@ import cz.cvut.kbss.analysis.service.IdentifierService; import cz.cvut.kbss.analysis.util.Vocabulary; import cz.cvut.kbss.jsonld.JsonLd; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.Page; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; +import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; import java.net.URISyntaxException; @@ -35,16 +41,21 @@ public class FaultTreeController { private final FaultTreeEvaluationService faultTreeEvaluationService; private final IdentifierService identifierService; private final FaultTreeService faultTreeService; + private final ApplicationEventPublisher eventPublisher; @GetMapping public List findAll() { return repositoryService.findAll(); } + @PreAuthorize("permitAll()") @GetMapping("/summaries") - public List summaries(@RequestParam(required = false) MultiValueMap params) { + public List summaries(@RequestParam(required = false) MultiValueMap params, + UriComponentsBuilder uriBuilder, HttpServletResponse response) { FaultTreeFilterParams filterParams = FaultTreeFilterMapper.constructFaultTreeFilter(params); - return repositoryService.findAllSummaries(filterParams); + Page result = repositoryService.findAllSummaries(filterParams, PagingUtils.resolvePaging(params)); + eventPublisher.publishEvent(new PaginatedResultRetrievedEvent(this, uriBuilder, response, result)); + return result.getContent(); } @GetMapping(value = "/{faultTreeFragment}", produces = {JsonLd.MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE}) diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/event/PaginatedResultRetrievedEvent.java b/src/main/java/cz/cvut/kbss/analysis/controller/event/PaginatedResultRetrievedEvent.java new file mode 100644 index 00000000..33b9fcbb --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/controller/event/PaginatedResultRetrievedEvent.java @@ -0,0 +1,37 @@ +package cz.cvut.kbss.analysis.controller.event; + +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.context.ApplicationEvent; +import org.springframework.data.domain.Page; +import org.springframework.web.util.UriComponentsBuilder; + +/** + * Fired when a paginated result is retrieved by a REST controller, so that HATEOAS headers can be added to the + * response. + */ +public class PaginatedResultRetrievedEvent extends ApplicationEvent { + + private final UriComponentsBuilder uriBuilder; + private final HttpServletResponse response; + private final Page page; + + public PaginatedResultRetrievedEvent(Object source, UriComponentsBuilder uriBuilder, HttpServletResponse response, + Page page) { + super(source); + this.uriBuilder = uriBuilder; + this.response = response; + this.page = page; + } + + public UriComponentsBuilder getUriBuilder() { + return uriBuilder; + } + + public HttpServletResponse getResponse() { + return response; + } + + public Page getPage() { + return page; + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/handler/HateoasPagingListener.java b/src/main/java/cz/cvut/kbss/analysis/controller/handler/HateoasPagingListener.java new file mode 100644 index 00000000..ec588e50 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/controller/handler/HateoasPagingListener.java @@ -0,0 +1,85 @@ +package cz.cvut.kbss.analysis.controller.handler; + +import cz.cvut.kbss.analysis.controller.event.PaginatedResultRetrievedEvent; +import cz.cvut.kbss.analysis.controller.util.HttpPaginationLink; +import cz.cvut.kbss.analysis.util.Constants; +import org.springframework.context.ApplicationListener; +import org.springframework.data.domain.Page; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; +import org.springframework.web.util.UriComponentsBuilder; + +/** + * Generates HATEOAS paging headers based on the paginated result retrieved by a REST controller. + */ +@Component +public class HateoasPagingListener implements ApplicationListener { + + @Override + public void onApplicationEvent(PaginatedResultRetrievedEvent event) { + final Page page = event.getPage(); + final LinkHeader header = new LinkHeader(); + if (!page.isEmpty() || page.getTotalPages() > 0) { + // Always add first and last links, even when there is just one page. This allows clients to know where the limits + // are + header.addLink(generateFirstPageLink(page, event.getUriBuilder()), HttpPaginationLink.FIRST); + header.addLink(generateLastPageLink(page, event.getUriBuilder()), HttpPaginationLink.LAST); + } + if (page.hasNext()) { + header.addLink(generateNextPageLink(page, event.getUriBuilder()), HttpPaginationLink.NEXT); + } + if (page.hasPrevious()) { + header.addLink(generatePreviousPageLink(page, event.getUriBuilder()), HttpPaginationLink.PREVIOUS); + } + if (header.hasLinks()) { + event.getResponse().addHeader(HttpHeaders.LINK, header.toString()); + } + event.getResponse().addHeader(Constants.X_TOTAL_COUNT_HEADER, Long.toString(page.getTotalElements())); + } + + private String generateNextPageLink(Page page, UriComponentsBuilder uriBuilder) { + return uriBuilder.replaceQueryParam(Constants.PAGE_PARAM, page.getNumber() + 1) + .replaceQueryParam(Constants.PAGE_SIZE_PARAM, page.getSize()) + .build().encode().toUriString(); + } + + private String generatePreviousPageLink(Page page, UriComponentsBuilder uriBuilder) { + return uriBuilder.replaceQueryParam(Constants.PAGE_PARAM, page.getNumber() - 1) + .replaceQueryParam(Constants.PAGE_SIZE_PARAM, page.getSize()) + .build().encode().toUriString(); + } + + private String generateFirstPageLink(Page page, UriComponentsBuilder uriBuilder) { + return uriBuilder.replaceQueryParam(Constants.PAGE_PARAM, 0) + .replaceQueryParam(Constants.PAGE_SIZE_PARAM, page.getSize()) + .build().encode().toUriString(); + } + + private String generateLastPageLink(Page page, UriComponentsBuilder uriBuilder) { + return uriBuilder.replaceQueryParam(Constants.PAGE_PARAM, page.getTotalPages() - 1) + .replaceQueryParam(Constants.PAGE_SIZE_PARAM, page.getSize()) + .build().encode().toUriString(); + } + + private static class LinkHeader { + + private final StringBuilder linkBuilder = new StringBuilder(); + + private void addLink(String url, HttpPaginationLink type) { + if (!linkBuilder.isEmpty()) { + linkBuilder.append(", "); + } + linkBuilder.append('<').append(url).append('>').append("; ").append("rel=\"").append(type.getName()) + .append('"'); + } + + private boolean hasLinks() { + return !linkBuilder.isEmpty(); + } + + @Override + public String toString() { + return linkBuilder.toString(); + } + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/HttpPaginationLink.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/HttpPaginationLink.java new file mode 100644 index 00000000..a6970f91 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/HttpPaginationLink.java @@ -0,0 +1,18 @@ +package cz.cvut.kbss.analysis.controller.util; + +/** + * Types of HTTP pagination links. + */ +public enum HttpPaginationLink { + NEXT("next"), PREVIOUS("prev"), FIRST("first"), LAST("last"); + + private final String name; + + HttpPaginationLink(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/PagingUtils.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/PagingUtils.java new file mode 100644 index 00000000..55f2182e --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/PagingUtils.java @@ -0,0 +1,104 @@ +package cz.cvut.kbss.analysis.controller.util; + +import cz.cvut.kbss.analysis.model.FaultTree; +import cz.cvut.kbss.analysis.util.Constants; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.util.MultiValueMap; + +import java.util.Comparator; +import java.util.Date; +import java.util.Iterator; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class PagingUtils { + + /** + * Prefix indicating ascending sort order. + */ + public static final char SORT_ASC = '+'; + + /** + * Prefix indicating descending sort order. + */ + public static final char SORT_DESC = '-'; + + + + private PagingUtils() { + throw new AssertionError(); + } + + /** + * Resolves paging and sorting configuration from the specified request parameters. + *

+ * If no paging and filtering info is specified, an {@link Pageable#unpaged()} object is returned. + *

+ * Note that for sorting, {@literal +} should be used before sorting property name to specify ascending order, + * {@literal -} for descending order, for example, {@literal -date} indicates sorting by date in descending order. + * + * @param params Request parameters + * @return {@code Pageable} containing values resolved from the params or defaults + */ + public static Pageable resolvePaging(MultiValueMap params) { + Sort sort; + if (params.containsKey(Constants.SORT_PARAM)) { + sort = Sort.by(params.get(Constants.SORT_PARAM).stream().map(sp -> { + if (sp.charAt(0) == SORT_ASC || sp.charAt(0) == SORT_DESC) { + final String property = sp.substring(1); + return sp.charAt(0) == SORT_DESC ? Sort.Order.desc(property) : Sort.Order.asc(property); + } + return Sort.Order.asc(sp); + }).collect(Collectors.toList())); + }else{ + sort = Sort.by( + Sort.Order.desc(Constants.SORT_BY_DATE_PARAM), + Sort.Order.asc(Constants.SORT_BY_SNS_LABEL_PARAM), + Sort.Order.asc(Constants.SORT_BY_LABEL_PARAM) + ); + } + + if (params.getFirst(Constants.PAGE_PARAM) == null) + return Pageable.unpaged(sort); + + final int page = Integer.parseInt(params.getFirst(Constants.PAGE_PARAM)); + final int size = Optional.ofNullable(params.getFirst(Constants.PAGE_SIZE_PARAM)).map(Integer::parseInt) + .orElse(Constants.DEFAULT_PAGE_SIZE); + + return PageRequest.of(page, size, sort); + } + + public static Comparator comparator(Sort sort){ + Iterator orders = sort.iterator(); + Comparator c = null; + while(orders.hasNext()){ + Sort.Order order = orders.next(); + if(c == null) + c = getFunction(order); + else + c.thenComparing(getFunction(order)); + } + return c; + } + + private static Comparator getFunction(Sort.Order order){ + Comparator comp = switch (order.getProperty()){ + case Constants.SORT_BY_DATE_PARAM -> Comparator.comparing((FaultTree t) -> + Stream.of(t.getModified(), t.getCreated()) + .filter(d -> d != null).findFirst().orElse(new Date(0))); + case Constants.SORT_BY_LABEL_PARAM -> Comparator.comparing((FaultTree t) -> + Optional.ofNullable(t.getSubsystem()).map(i -> i.getName()).orElse("")); + case Constants.SORT_BY_SNS_LABEL_PARAM -> Comparator.comparing((FaultTree t) -> + Optional.ofNullable(t.getName()).orElse("")); + default -> null; + }; + + return order.getDirection() == Sort.Direction.DESC + ? comp.reversed() + : comp; + } + +} diff --git a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java index 87d2651c..b67119e0 100755 --- a/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java +++ b/src/main/java/cz/cvut/kbss/analysis/service/FaultTreeRepositoryService.java @@ -1,5 +1,6 @@ package cz.cvut.kbss.analysis.service; +import cz.cvut.kbss.analysis.controller.util.PagingUtils; import cz.cvut.kbss.analysis.dao.*; import cz.cvut.kbss.analysis.dao.util.FaultTreeFilterParams; import cz.cvut.kbss.analysis.exception.EntityNotFoundException; @@ -23,6 +24,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.Validator; @@ -131,9 +135,23 @@ public FaultTree findSummary(URI faultTreeUri){ return faultTreeSummary; } - public List findAllSummaries(FaultTreeFilterParams filterParams){ - List summaries = findAllSummaries(); - return summaries.stream().filter(filterParams::matches).toList(); + public Page findAllSummaries(FaultTreeFilterParams filterParams, Pageable pageSpec){ + List allSummaries = findAllSummaries(); + Comparator comparator = PagingUtils.comparator(pageSpec.getSort()); + List matchingSummaries = allSummaries.stream() + .filter(filterParams::matches) + .sorted(comparator) + .toList(); + + List result = matchingSummaries; + long totalCount = result.size(); + if(pageSpec.isPaged()) { + result = matchingSummaries.stream() + .skip(pageSpec.getOffset()) + .limit(pageSpec.getPageSize()) + .toList(); + } + return new PageImpl(result, pageSpec, totalCount); } @Override diff --git a/src/main/java/cz/cvut/kbss/analysis/util/Constants.java b/src/main/java/cz/cvut/kbss/analysis/util/Constants.java new file mode 100644 index 00000000..01b76990 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/analysis/util/Constants.java @@ -0,0 +1,49 @@ +package cz.cvut.kbss.analysis.util; + +public final class Constants { + + private Constants() { + throw new AssertionError(); + } + + /** + * Number of history actions fetched from database. Needs to be changes also in front-end. + */ + public static final int DEFAULT_PAGE_SIZE = 25; + + /** + * Name of the request parameter specifying page number. + */ + public static final String PAGE_PARAM = "page"; + + /** + * Name of the request parameter specifying page size. + */ + public static final String PAGE_SIZE_PARAM = "size"; + + /** + * Name of the request parameter specifying sorting. + */ + public static final String SORT_PARAM = "sort"; + + /** + * Name of the request parameter specifying ordering by last date. + */ + public static final String SORT_BY_DATE_PARAM = "date"; + + /** + * Name of the request parameter specifying ordering by label. + */ + public static final String SORT_BY_LABEL_PARAM = "label"; + + /** + * Name of the request parameter specifying ordering by SNS label. + */ + public static final String SORT_BY_SNS_LABEL_PARAM = "snsLabel"; + + /** + * Represents the X-Total-Count HTTP header used to convey the total number of items in paged or otherwise + * restricted response. + */ + public static final String X_TOTAL_COUNT_HEADER = "X-Total-Count"; +} From 1662b20933153b68bb15427d8293370261a9bced Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 10 Jul 2024 18:58:02 +0200 Subject: [PATCH 3/4] [Fix kbss-cvut/fta-fmea-ui#507] Remove wrong preAuthorize on FaultTreeController.summaries --- .../cz/cvut/kbss/analysis/controller/FaultTreeController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java index c86a8547..052f086a 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/FaultTreeController.java @@ -48,7 +48,6 @@ public List findAll() { return repositoryService.findAll(); } - @PreAuthorize("permitAll()") @GetMapping("/summaries") public List summaries(@RequestParam(required = false) MultiValueMap params, UriComponentsBuilder uriBuilder, HttpServletResponse response) { From bff20697c76238f365ad1b713a32a7567a734312 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 10 Jul 2024 19:56:56 +0200 Subject: [PATCH 4/4] [Fix kbss-cvut/fta-fmea-ui#507] Add missing spring-data-commons dependency --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 886fd8ff..a90dce9d 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.security:spring-security-oauth2-core' + implementation 'org.springframework.data:spring-data-commons' implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' implementation 'org.springframework.boot:spring-boot-starter-validation'