Skip to content

Commit

Permalink
Merge pull request #477 from NASA-PDS/sort-search-after-exceptions
Browse files Browse the repository at this point in the history
Sort search after exceptions
  • Loading branch information
alexdunnjpl authored Jul 11, 2024
2 parents 17759eb + df5bc52 commit d3edf80
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -216,7 +213,7 @@ public ResponseEntity<Object> selectByLidvidLatest(String identifier, List<Strin
@Override
public ResponseEntity<Object> selectByLidvidAll(String identifier, List<String> fields,
Integer limit, List<String> sort, List<String> searchAfter) throws UnhandledException,
NotFoundException, AcceptFormatNotSupportedException, MissSortWithSearchAfterException {
NotFoundException, AcceptFormatNotSupportedException, SortSearchAfterMismatchException {

RawMultipleProductResponse response;

Expand Down Expand Up @@ -321,7 +318,7 @@ private HashMap<String, Object> getLatestLidVid(PdsProductIdentifier identifier,

private RawMultipleProductResponse getAllLidVid(PdsProductIdentifier identifier,
List<String> fields, Integer limit, List<String> sort, List<String> searchAfter)
throws OpenSearchException, IOException, NotFoundException, MissSortWithSearchAfterException {
throws OpenSearchException, IOException, NotFoundException, SortSearchAfterMismatchException {

RegistrySearchRequestBuilder registrySearchRequestBuilder =
new RegistrySearchRequestBuilder(this.registrySearchRequestBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,9 +66,9 @@ protected ResponseEntity<Object> notAcceptable(AcceptFormatNotSupportedException

}

@ExceptionHandler(value = {MissSortWithSearchAfterException.class})
protected ResponseEntity<Object> missSort(MissSortWithSearchAfterException ex,
WebRequest request) {
@ExceptionHandler(value = {SortSearchAfterMismatchException.class})
protected ResponseEntity<Object> missSort(SortSearchAfterMismatchException ex,
WebRequest request) {
return genericExceptionHandler(ex, request, "", HttpStatus.BAD_REQUEST);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -155,7 +155,7 @@ public RegistrySearchRequestBuilder addLidMatch(PdsProductIdentifier identifier)
}

public RegistrySearchRequestBuilder paginates(Integer limit, List<String> sort,
List<String> searchAfter) throws MissSortWithSearchAfterException {
List<String> searchAfter) throws SortSearchAfterMismatchException {

if ((sort != null) && (!sort.isEmpty())) {
this.sort(sort);
Expand All @@ -164,8 +164,10 @@ public RegistrySearchRequestBuilder paginates(Integer limit, List<String> 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);
}
Expand Down

0 comments on commit d3edf80

Please sign in to comment.