Search in sources :

Example 1 with BAD_RESUMPTION_TOKEN

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);
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RecordType(org.openarchives.oai._2.RecordType)

Example 2 with BAD_RESUMPTION_TOKEN

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);
        }
    }
}
Also used : INVALID_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.INVALID_RESUMPTION_TOKEN) EXPIRED_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.EXPIRED_RESUMPTION_TOKEN) Set(java.util.Set) VERB_PARAM(org.folio.oaipmh.Constants.VERB_PARAM) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) BAD_ARGUMENT(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) Component(org.springframework.stereotype.Component) List(java.util.List) Request(org.folio.oaipmh.Request) Verb(org.folio.oaipmh.domain.Verb) Map(java.util.Map) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) BAD_VERB(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_VERB) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType)

Example 3 with BAD_RESUMPTION_TOKEN

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();
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with BAD_RESUMPTION_TOKEN

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));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with BAD_RESUMPTION_TOKEN

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();
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH)

Aggregations

OAIPMH (org.openarchives.oai._2.OAIPMH)10 RequestSpecification (io.restassured.specification.RequestSpecification)4 Response (javax.ws.rs.core.Response)4 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)3 JsonArray (io.vertx.core.json.JsonArray)2 List (java.util.List)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Request (org.folio.oaipmh.Request)2 Test (org.junit.jupiter.api.Test)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 BAD_RESUMPTION_TOKEN (org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN)2 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)2 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 JsonObject (io.vertx.core.json.JsonObject)1