Skip to content

Commit

Permalink
Merge pull request #389 from europeana/EA-3841-validate-page-param
Browse files Browse the repository at this point in the history
return 400 for invalid page param
  • Loading branch information
gsergiu authored Dec 16, 2024
2 parents c12c793 + 6ee7b0a commit 3fecfa1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ private ResponseEntity<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 3fecfa1

Please sign in to comment.