Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort search after exceptions #477

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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 @@ -34,7 +34,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 @@ -154,7 +154,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 @@ -163,8 +163,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
Loading