use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN in project mod-oai-pmh by folio-org.
the class AbstractGetRecordsHelper method processRecords.
protected Response processRecords(Context ctx, Request request, JsonObject instancesResponseBody) {
JsonArray instances = storageHelper.getItems(instancesResponseBody);
Integer totalRecords = storageHelper.getTotalRecords(instancesResponseBody);
logger.debug("{} entries retrieved out of {}.", instances != null ? instances.size() : 0, totalRecords);
if (request.isRestored() && !canResumeRequestSequence(request, totalRecords, instances)) {
OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request).withErrors(new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(RESUMPTION_TOKEN_FLOW_ERROR));
return getResponseHelper().buildFailureResponse(oaipmh, request);
}
ResumptionTokenType resumptionToken = buildResumptionToken(request, instances, totalRecords);
/*
* According to OAI-PMH guidelines: it is recommended that the responseDate reflect the time of the repository's clock at the start
* of any database query or search function necessary to answer the list request, rather than when the output is written.
*/
final OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request);
final Map<String, RecordType> recordsMap = buildRecords(ctx, request, instances);
if (recordsMap.isEmpty()) {
return buildNoRecordsFoundOaiResponse(oaipmh, request);
} else {
addRecordsToOaiResponse(oaipmh, recordsMap.values());
addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
return buildResponse(oaipmh, request);
}
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN 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_RESUMPTION_TOKEN in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method testGetOaiSetsWithResumptionToken.
@Test
void testGetOaiSetsWithResumptionToken(VertxTestContext testContext) {
String resumptionToken = "ZnJvbT0xOTk5LTA5LTA5Jm9mZnNldD0w";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, LIST_SETS.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken);
OAIPMH oai = verifyResponseWithErrors(request, LIST_SETS, 400, 1);
assertThat(oai.getErrors().get(0).getCode(), is(equalTo(BAD_RESUMPTION_TOKEN)));
assertThat(oai.getRequest().getResumptionToken(), is(equalTo(resumptionToken)));
testContext.completeNow();
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithBadResumptionTokenExpiredDate.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithBadResumptionTokenExpiredDate(VerbType verb) {
// base64 encoded string:
// metadataPrefix=oai_dc&from=2003-01-01T00:00:00Z&until=2003-10-01T00:00:00Z
// &set=all&offset=0&totalRecords=101&nextRecordId=6506b79b-7702-48b2-9774-a1c538fdd34e&expirationDate=2003-10-01T00:00:00Z
String resumptionToken = "bWV0YWRhdGFQcmVmaXg9b2FpX2RjJmZyb209MjAwMy0wMS0wMVQwMDowMDowMFomdW50aWw9M" + "jAwMy0xMC0wMVQwMDowMDowMFomc2V0PWFsbCZvZmZzZXQ9MCZ0b3RhbFJlY29yZHM9MTAxJm5leHRSZWNvcmRJZD02NTA2Y" + "jc5Yi03NzAyLTQ4YjItOTc3NC1hMWM1MzhmZGQzNGUmZXhwaXJhdGlvbkRhdGU9MjAwMy0xMC0wMVQwMDowMDowMFo=";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken);
OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 400, 1);
assertThat(oaipmh.getErrors(), is(hasSize(1)));
assertThat(oaipmh.getErrors().get(0).getCode(), is(equalTo(BAD_RESUMPTION_TOKEN)));
assertThat(oaipmh.getRequest().getResumptionToken(), equalTo(resumptionToken));
}
use of org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN in project mod-oai-pmh by folio-org.
the class AbstractHelper method buildResponseWithErrors.
protected Future<Response> buildResponseWithErrors(Request request, Promise<Response> promise, List<OAIPMHerrorType> errors) {
OAIPMH oai;
if (request.isRestored()) {
oai = responseHelper.buildOaipmhResponseWithErrors(request, BAD_RESUMPTION_TOKEN, RESUMPTION_TOKEN_FORMAT_ERROR);
} else {
oai = responseHelper.buildOaipmhResponseWithErrors(request, errors);
}
promise.complete(responseHelper.buildFailureResponse(oai, request));
return promise.future();
}
Aggregations