use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT in project mod-oai-pmh by folio-org.
the class AbstractHelper method validateDateRange.
private void validateDateRange(Request request, List<OAIPMHerrorType> errors) {
Pair<GranularityType, LocalDateTime> from = null;
Pair<GranularityType, LocalDateTime> until = null;
// Get repository supported granularity
boolean isDateOnly = isDateOnlyGranularity(request);
if (request.getFrom() != null) {
ImmutablePair<String, String> date = new ImmutablePair<>(FROM_PARAM, request.getFrom());
from = isDateOnly ? parseDate(date, errors) : parseDateTime(date, errors);
if (from == null) {
// In case the 'from' date is invalid, it cannot be sent in OAI-PMH/request@from because it contradicts schema definition
request.getOaiRequest().setFrom(null);
}
}
if (request.getUntil() != null) {
ImmutablePair<String, String> date = new ImmutablePair<>(UNTIL_PARAM, request.getUntil());
until = isDateOnly ? parseDate(date, errors) : parseDateTime(date, errors);
if (until == null) {
// In case the 'until' date is invalid, it cannot be sent in OAI-PMH/request@until because it contradicts schema definition
request.getOaiRequest().setUntil(null);
}
}
if (from != null && until != null) {
// Both arguments must have the same granularity.
if (from.getLeft() != until.getLeft()) {
errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue("Invalid date range: 'from' must have the same granularity as 'until'."));
} else if (from.getRight().isAfter(until.getRight())) {
// The from argument must be less than or equal to the until argument.
errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue("Invalid date range: 'from' must be less than or equal to 'until'."));
}
}
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT in project mod-oai-pmh by folio-org.
the class VerbValidator method validateExclusiveParam.
/**
* In case of resumption token param presence verifies if there any other parameters were specified too. If they were then error
* will be added to error list.
*
* @param verb - verb
* @param requestParams - request parameters
* @param request - oai-pmh request
* @param errors - list of errors
*/
private void validateExclusiveParam(Verb verb, Map<String, String> requestParams, Request request, List<OAIPMHerrorType> errors) {
String resumptionToken = requestParams.get(verb.getExclusiveParam());
if (verb.getExclusiveParam() != null && resumptionToken != null) {
requestParams.keySet().stream().filter(p -> !verb.getExcludedParams().contains(p)).filter(p -> !verb.getExclusiveParam().equals(p)).findAny().ifPresent(param -> {
if (!param.equals(VERB_PARAM)) {
errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue(format(EXCLUSIVE_PARAM_ERROR_MESSAGE, verb.name(), verb.getExclusiveParam())));
}
});
if (!request.isResumptionTokenParsableAndValid()) {
OAIPMHerrorType error = new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(format(INVALID_RESUMPTION_TOKEN, verb.name()));
errors.add(error);
return;
}
if (request.isResumptionTokenTimeExpired()) {
OAIPMHerrorType errorByExpiredTime = new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(EXPIRED_RESUMPTION_TOKEN);
errors.add(errorByExpiredTime);
}
}
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiGetRecordVerbWithoutMetadataPrefix.
@Test
void getOaiGetRecordVerbWithoutMetadataPrefix(VertxTestContext testContext) {
String identifier = IDENTIFIER_PREFIX + OkapiMockServer.EXISTING_IDENTIFIER;
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, GET_RECORD.value()).param(IDENTIFIER_PARAM, identifier);
OAIPMH oaipmh = verifyResponseWithErrors(request, GET_RECORD, 400, 1);
assertThat(oaipmh.getGetRecord(), is(nullValue()));
assertThat(oaipmh.getErrors().get(0).getCode(), equalTo(BAD_ARGUMENT));
testContext.completeNow();
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithoutParams.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithoutParams(VerbType verb) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value());
List<OAIPMHerrorType> errors = verifyResponseWithErrors(request, verb, 400, 1).getErrors();
OAIPMHerrorType error = errors.get(0);
assertThat(error.getCode(), equalTo(BAD_ARGUMENT));
assertThat(error.getValue(), equalTo(LIST_NO_REQUIRED_PARAM_ERROR));
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method shouldRespondWithBadArgument_whenGetOaiRecordsMarc21WithHoldingsWithInvalidDateRange.
@Test
void shouldRespondWithBadArgument_whenGetOaiRecordsMarc21WithHoldingsWithInvalidDateRange() {
final String currentValue = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "50");
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(FROM_PARAM, INVALID_FROM_PARAM).param(UNTIL_PARAM, INVALID_UNTIL_PARAM).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
OAIPMH oaipmh = verifyResponseWithErrors(request, LIST_RECORDS, 400, 1);
assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(MetadataPrefix.MARC21WITHHOLDINGS.getName()));
OAIPMHerrorType error = oaipmh.getErrors().get(0);
assertThat(error.getCode(), equalTo(BAD_ARGUMENT));
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
}
Aggregations