use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorImpl method validateRows.
private void validateRows(Map<String, List<String>> queryMap) {
List<String> rowsList = queryMap.get("rows");
if (rowsList != null && !rowsList.isEmpty()) {
try {
String rowsString = rowsList.get(0);
int rows = Integer.valueOf(rowsString);
if (rows < 0 || rows > OrcidSearchManager.MAX_SEARCH_ROWS) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception", OrcidSearchManager.MAX_SEARCH_ROWS));
}
} catch (NumberFormatException e) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_invalid_search_rows.exception", OrcidSearchManager.MAX_SEARCH_ROWS));
}
} else {
// Set the default number of results
queryMap.put("rows", Arrays.asList(String.valueOf(OrcidSearchManager.DEFAULT_SEARCH_ROWS)));
}
}
use of org.orcid.core.exception.OrcidBadRequestException in project ORCID-Source by ORCID.
the class ApiVersionCheckFilter method filter.
@Override
public ContainerRequest filter(ContainerRequest request) {
String path = request.getPath();
String method = request.getMethod() == null ? null : request.getMethod().toUpperCase();
Matcher matcher = VERSION_PATTERN.matcher(path);
String version = null;
if (matcher.lookingAt()) {
version = matcher.group(1);
}
if (PojoUtil.isEmpty(version) && !PojoUtil.isEmpty(method) && !"oauth/token".equals(path) && !path.matches(WEBHOOKS_PATH_PATTERN)) {
if (!RequestMethod.GET.name().equals(method)) {
Object[] params = { method };
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_missing_version.exception", params));
}
} else if (version != null && version.startsWith("1.1") && v1xDisabled) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_version_disabled.exception"));
} else if (version != null && version.startsWith("2.0")) {
if (!OrcidUrlManager.isSecure(httpRequest)) {
throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_secure_only.exception"));
}
}
return request;
}
Aggregations