Search in sources :

Example 16 with ResumptionTokenType

use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method getOaiListVerbResumptionFlowStartedWithFromParamHasDateAndTimeGranularity.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiListVerbResumptionFlowStartedWithFromParamHasDateAndTimeGranularity(MetadataPrefix prefix, VerbType verb) {
    String timeGranularity = System.getProperty(REPOSITORY_TIME_GRANULARITY);
    System.setProperty(REPOSITORY_TIME_GRANULARITY, GranularityType.YYYY_MM_DD_THH_MM_SS_Z.value());
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE_TIME).param(METADATA_PREFIX_PARAM, prefix.getName()).param(SET_PARAM, "all");
    OAIPMH oaipmh = verify200WithXml(request, verb);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
    // rollback changes of system properties as they were before test
    System.setProperty(REPOSITORY_TIME_GRANULARITY, timeGranularity);
    assertThat(resumptionToken, is(notNullValue()));
    String resumptionTokenValue = new String(Base64.getUrlDecoder().decode(resumptionToken.getValue()), StandardCharsets.UTF_8);
    List<NameValuePair> params = URLEncodedUtils.parse(resumptionTokenValue, StandardCharsets.UTF_8);
    assertThat(params, is(hasSize(8)));
    assertTrue(getParamValue(params, UNTIL_PARAM).matches(DATE_TIME_GRANULARITY_PATTERN));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) NameValuePair(org.apache.http.NameValuePair) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with ResumptionTokenType

use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.

the class MarcWithHoldingsRequestHelper method buildRecordsResponse.

private Future<Response> buildRecordsResponse(Request request, String requestId, List<JsonObject> batch, Map<String, JsonObject> srsResponse, boolean firstBatch, String nextInstanceId, boolean deletedRecordSupport) {
    Promise<Response> promise = Promise.promise();
    try {
        List<RecordType> records = buildRecordsList(request, batch, srsResponse, deletedRecordSupport);
        logger.debug("Build records response, instances = {}, instances with srs records = {}.", batch.size(), records.size());
        ResponseHelper responseHelper = getResponseHelper();
        OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request);
        if (records.isEmpty() && nextInstanceId == null && firstBatch) {
            oaipmh.withErrors(createNoRecordsFoundError());
        } else {
            oaipmh.withListRecords(new ListRecordsType().withRecords(records));
        }
        Response response;
        if (oaipmh.getErrors().isEmpty()) {
            if (!firstBatch || nextInstanceId != null) {
                ResumptionTokenType resumptionToken = buildResumptionTokenFromRequest(request, requestId, records.size(), nextInstanceId);
                oaipmh.getListRecords().withResumptionToken(resumptionToken);
            }
            response = responseHelper.buildSuccessResponse(oaipmh);
        } else {
            response = responseHelper.buildFailureResponse(oaipmh, request);
        }
        promise.complete(response);
    } catch (Exception e) {
        handleException(promise, e);
    }
    return promise.future();
}
Also used : Response(javax.ws.rs.core.Response) HttpResponse(io.vertx.ext.web.client.HttpResponse) OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RecordType(org.openarchives.oai._2.RecordType) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper) DecodeException(io.vertx.core.json.DecodeException) ListRecordsType(org.openarchives.oai._2.ListRecordsType)

Example 18 with ResumptionTokenType

use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method shouldReturnBadResumptionTokenError_whenRequestListRecordsWithInvalidResumptionToken.

@Test
void shouldReturnBadResumptionTokenError_whenRequestListRecordsWithInvalidResumptionToken(Vertx vertx, VertxTestContext testContext) {
    final String currentValue = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "8");
    RequestSpecification listRecordRequest = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(FROM_PARAM, DATE_INVENTORY_10_INSTANCE_IDS).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
    OAIPMH oaipmh = verify200WithXml(listRecordRequest, LIST_RECORDS);
    verifyListResponse(oaipmh, LIST_RECORDS, 8);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, LIST_RECORDS);
    assertThat(resumptionToken, is(notNullValue()));
    assertThat(resumptionToken.getValue(), is(notNullValue()));
    String requestId = getRequestId(resumptionToken);
    instancesService.deleteInstancesById(getExpectedInstanceIds(), requestId, OAI_TEST_TENANT);
    RequestSpecification resumptionTokenRequest = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken.getValue());
    verifyResponseWithErrors(resumptionTokenRequest, LIST_RECORDS, 400, 1);
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
    testContext.completeNow();
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) 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 19 with ResumptionTokenType

use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method getOaiListVerbResumptionFlowStartedWithFromParamHasDateOnlyGranularity.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiListVerbResumptionFlowStartedWithFromParamHasDateOnlyGranularity(MetadataPrefix prefix, VerbType verb) {
    String timeGranularity = System.getProperty(REPOSITORY_TIME_GRANULARITY);
    System.setProperty(REPOSITORY_TIME_GRANULARITY, GranularityType.YYYY_MM_DD_THH_MM_SS_Z.value());
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE).param(METADATA_PREFIX_PARAM, prefix.getName()).param(SET_PARAM, "all");
    OAIPMH oaipmh = verify200WithXml(request, verb);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
    // rollback changes of system properties as they were before test
    System.setProperty(REPOSITORY_TIME_GRANULARITY, timeGranularity);
    assertThat(resumptionToken, is(notNullValue()));
    String resumptionTokenValue = new String(Base64.getUrlDecoder().decode(resumptionToken.getValue()), StandardCharsets.UTF_8);
    List<NameValuePair> params = URLEncodedUtils.parse(resumptionTokenValue, StandardCharsets.UTF_8);
    assertThat(params, is(hasSize(8)));
    assertTrue(getParamValue(params, UNTIL_PARAM).matches(DATE_ONLY_GRANULARITY_PATTERN));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) NameValuePair(org.apache.http.NameValuePair) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

OAIPMH (org.openarchives.oai._2.OAIPMH)18 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)18 RequestSpecification (io.restassured.specification.RequestSpecification)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)11 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 NameValuePair (org.apache.http.NameValuePair)5 HeaderType (org.openarchives.oai._2.HeaderType)3 JsonArray (io.vertx.core.json.JsonArray)2 Response (javax.ws.rs.core.Response)2 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)2 Test (org.junit.jupiter.api.Test)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)2 RecordType (org.openarchives.oai._2.RecordType)2 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 DecodeException (io.vertx.core.json.DecodeException)1