From 6ee7b0a36e7d504f01fdd7de5b071248d52683b1 Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Wed, 2 Oct 2024 16:43:42 +0200 Subject: [PATCH] return 400 for invalid page param --- .../annotation/tests/web/AnnotationSearchIT.java | 2 +- .../request/ParamValidationI18NException.java | 1 - .../controller/jsonld/WebAnnotationSearchRest.java | 13 +++++++++---- .../api/common/config/I18nConstantsAnnotation.java | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationSearchIT.java b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationSearchIT.java index b9f7ecfab..362697579 100644 --- a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationSearchIT.java +++ b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationSearchIT.java @@ -482,7 +482,7 @@ protected Annotation searchLastCreated(String query) throws Exception { protected AnnotationPage search(String bodyValue, String profile, String limit) throws Exception { AnnotationPage annPg = searchAnnotations(bodyValue, null, null, WebAnnotationFields.CREATED, "desc", - "0", limit, profile, null); + "1", limit, profile, null); assertNotNull(annPg, "AnnotationPage must not be null"); return annPg; diff --git a/annotation-web/src/main/java/eu/europeana/annotation/web/exception/request/ParamValidationI18NException.java b/annotation-web/src/main/java/eu/europeana/annotation/web/exception/request/ParamValidationI18NException.java index fe4644130..bf2da0b44 100644 --- a/annotation-web/src/main/java/eu/europeana/annotation/web/exception/request/ParamValidationI18NException.java +++ b/annotation-web/src/main/java/eu/europeana/annotation/web/exception/request/ParamValidationI18NException.java @@ -20,7 +20,6 @@ public class ParamValidationI18NException extends HttpException{ public static final String MESSAGE_IDENTIFIER_NOT_NULL = "Identifier must not be set when creating a new Annotation for the given provider!"; public static final String MESSAGE_ANNOTATION_ID_EXISTS = "An annotation with the given identifier already exists in database! Overwrite not allowed in this method!"; public static final String MESSAGE_ANNOTATION_IDENTIFIER_PROVIDED_UPON_CREATION = "The annotation identifier cannot be provided in the input upon the anntation creation!"; - public static final String MESSAGE_INVALID_PARAMETER_VALUE = "Invalid request. Parameter value not supported or not allowed!{0}"; public static final String MESSAGE_BLANK_PARAMETER_VALUE = "Invalid request. Parameter value must not be null or empty!"; public static final String MESSAGE_URL_NOT_VALID = "Given URL is not valid!"; public static final String MESSAGE_INVALID_TAG_SIZE = "Invalid tag size. Must be shorter then 64 characters!"; diff --git a/annotation-web/src/main/java/eu/europeana/annotation/web/service/controller/jsonld/WebAnnotationSearchRest.java b/annotation-web/src/main/java/eu/europeana/annotation/web/service/controller/jsonld/WebAnnotationSearchRest.java index 669522529..593e268bc 100644 --- a/annotation-web/src/main/java/eu/europeana/annotation/web/service/controller/jsonld/WebAnnotationSearchRest.java +++ b/annotation-web/src/main/java/eu/europeana/annotation/web/service/controller/jsonld/WebAnnotationSearchRest.java @@ -88,10 +88,15 @@ private ResponseEntity searchAnnotation(String wskey, String queryString // ** Process input params queryString = queryString.trim(); - if (StringUtils.isBlank(queryString)) - throw new ParamValidationI18NException(ParamValidationI18NException.MESSAGE_BLANK_PARAMETER_VALUE, - I18nConstantsAnnotation.ANNOTATION_VALIDATION, - new String[] { WebAnnotationFields.PARAM_QUERY, queryString }); + if (StringUtils.isBlank(queryString)) { + throw new ParamValidationI18NException(ParamValidationI18NException.MESSAGE_BLANK_PARAMETER_VALUE, + I18nConstantsAnnotation.ANNOTATION_VALIDATION, + new String[] { WebAnnotationFields.PARAM_QUERY, queryString }); + } + if (page < Query.DEFAULT_PAGE) { + throw new ParamValidationI18NException(null, I18nConstantsAnnotation.INVALID_PARAM_VALUE, + new String[] { WebAnnotationFields.PAGE, String.valueOf(page) }); + } SearchProfiles searchProfile = getProfile(profile, request); // here we need a query search profile - dereference is not a query search diff --git a/annotation-web/src/main/java/eu/europeana/api/common/config/I18nConstantsAnnotation.java b/annotation-web/src/main/java/eu/europeana/api/common/config/I18nConstantsAnnotation.java index b550fc664..7911ad0d8 100644 --- a/annotation-web/src/main/java/eu/europeana/api/common/config/I18nConstantsAnnotation.java +++ b/annotation-web/src/main/java/eu/europeana/api/common/config/I18nConstantsAnnotation.java @@ -41,6 +41,7 @@ public interface I18nConstantsAnnotation extends eu.europeana.api.commons.defini String MESSAGE_INVALID_TAG_ID_FORMAT = "error.message_invalid_tag_id_format"; String MESSAGE_MISSING_MANDATORY_FIELD = "error.message_missing_mandatory_field"; String INVALID_PROVIDER = "error.invalid_provider"; + String INVALID_PARAM_VALUE = "error.invalid_param_value"; String SOLR_EXCEPTION = "error.solr_exception"; String SOLR_MALFORMED_QUERY_EXCEPTION = "error.solr_malformed_query_exception";