diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java index 439b8bbb..9ca4f74f 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controllers/ProductsController.java @@ -6,7 +6,6 @@ import java.util.Map; import java.util.HashMap; import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.Valid; import com.fasterxml.jackson.databind.ObjectMapper; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch._types.OpenSearchException; @@ -18,15 +17,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import gov.nasa.pds.api.base.ProductsApi; import gov.nasa.pds.api.registry.ConnectionContext; import gov.nasa.pds.api.registry.model.ErrorMessageFactory; import gov.nasa.pds.api.registry.model.exceptions.AcceptFormatNotSupportedException; -import gov.nasa.pds.api.registry.model.exceptions.MissSortWithSearchAfterException; +import gov.nasa.pds.api.registry.model.exceptions.SortSearchAfterMismatchException; import gov.nasa.pds.api.registry.model.exceptions.NotFoundException; import gov.nasa.pds.api.registry.model.exceptions.UnhandledException; import gov.nasa.pds.api.registry.model.api_responses.PdsProductBusinessObject; @@ -216,7 +213,7 @@ public ResponseEntity selectByLidvidLatest(String identifier, List selectByLidvidAll(String identifier, List fields, Integer limit, List sort, List searchAfter) throws UnhandledException, - NotFoundException, AcceptFormatNotSupportedException, MissSortWithSearchAfterException { + NotFoundException, AcceptFormatNotSupportedException, SortSearchAfterMismatchException { RawMultipleProductResponse response; @@ -321,7 +318,7 @@ private HashMap getLatestLidVid(PdsProductIdentifier identifier, private RawMultipleProductResponse getAllLidVid(PdsProductIdentifier identifier, List fields, Integer limit, List sort, List searchAfter) - throws OpenSearchException, IOException, NotFoundException, MissSortWithSearchAfterException { + throws OpenSearchException, IOException, NotFoundException, SortSearchAfterMismatchException { RegistrySearchRequestBuilder registrySearchRequestBuilder = new RegistrySearchRequestBuilder(this.registrySearchRequestBuilder); diff --git a/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java b/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java index 4e2bf989..4caf77f4 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/controllers/RegistryApiResponseEntityExceptionHandler.java @@ -10,7 +10,7 @@ import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import gov.nasa.pds.api.registry.model.exceptions.AcceptFormatNotSupportedException; -import gov.nasa.pds.api.registry.model.exceptions.MissSortWithSearchAfterException; +import gov.nasa.pds.api.registry.model.exceptions.SortSearchAfterMismatchException; import gov.nasa.pds.api.registry.model.exceptions.NotFoundException; import gov.nasa.pds.api.registry.model.exceptions.RegistryApiException; import gov.nasa.pds.api.registry.model.exceptions.UnhandledException; @@ -66,9 +66,9 @@ protected ResponseEntity notAcceptable(AcceptFormatNotSupportedException } - @ExceptionHandler(value = {MissSortWithSearchAfterException.class}) - protected ResponseEntity missSort(MissSortWithSearchAfterException ex, - WebRequest request) { + @ExceptionHandler(value = {SortSearchAfterMismatchException.class}) + protected ResponseEntity missSort(SortSearchAfterMismatchException ex, + WebRequest request) { return genericExceptionHandler(ex, request, "", HttpStatus.BAD_REQUEST); } diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MissSortWithSearchAfterException.java b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MissSortWithSearchAfterException.java deleted file mode 100644 index 3dfef3ac..00000000 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/MissSortWithSearchAfterException.java +++ /dev/null @@ -1,8 +0,0 @@ -package gov.nasa.pds.api.registry.model.exceptions; - -public class MissSortWithSearchAfterException extends RegistryApiException { - - public MissSortWithSearchAfterException() { - super("sort parameter missing, sort is mandatory with search-after"); - } -} diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/SortSearchAfterMismatchException.java b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/SortSearchAfterMismatchException.java new file mode 100644 index 00000000..3c5d6367 --- /dev/null +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/exceptions/SortSearchAfterMismatchException.java @@ -0,0 +1,8 @@ +package gov.nasa.pds.api.registry.model.exceptions; + +public class SortSearchAfterMismatchException extends RegistryApiException { + + public SortSearchAfterMismatchException(String detail) { + super("Invalid combination of sort and searchAfter values: " + detail); + } +} diff --git a/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java b/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java index d34a1540..862ca7a5 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/search/RegistrySearchRequestBuilder.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; + import org.antlr.v4.runtime.BailErrorStrategy; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CodePointCharStream; @@ -35,7 +35,7 @@ import gov.nasa.pds.api.registry.model.Antlr4SearchListener; import gov.nasa.pds.api.registry.model.EntityProduct; import gov.nasa.pds.api.registry.model.SearchUtil; -import gov.nasa.pds.api.registry.model.exceptions.MissSortWithSearchAfterException; +import gov.nasa.pds.api.registry.model.exceptions.SortSearchAfterMismatchException; import gov.nasa.pds.api.registry.model.exceptions.UnparsableQParamException; import gov.nasa.pds.api.registry.model.identifiers.PdsProductIdentifier; @@ -155,7 +155,7 @@ public RegistrySearchRequestBuilder addLidMatch(PdsProductIdentifier identifier) } public RegistrySearchRequestBuilder paginates(Integer limit, List sort, - List searchAfter) throws MissSortWithSearchAfterException { + List searchAfter) throws SortSearchAfterMismatchException { if ((sort != null) && (!sort.isEmpty())) { this.sort(sort); @@ -164,8 +164,10 @@ public RegistrySearchRequestBuilder paginates(Integer limit, List sort, this.size(limit); if ((searchAfter != null) && (!searchAfter.isEmpty())) { - if ((sort == null) || (sort.isEmpty())) { - throw new MissSortWithSearchAfterException(); + if (sort == null) { + throw new SortSearchAfterMismatchException("sort argument must be provided if searchAfter argument is provided"); + } else if (searchAfter.size() != sort.size()) { + throw new SortSearchAfterMismatchException("sort and searchAfter arguments must be of equal length if provided"); } this.searchAfter(searchAfter); }