Search in sources :

Example 6 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiRecordsWithFromAndUntilAndMetadataPrefixMarc21AndResumptionToken.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiRecordsWithFromAndUntilAndMetadataPrefixMarc21AndResumptionToken(MetadataPrefix prefix, VerbType verb) {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE_TIME).param(UNTIL_PARAM, LocalDateTime.now(ZoneOffset.UTC).format(ISO_UTC_DATE_TIME));
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 10);
    ResumptionTokenType actualResumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(actualResumptionToken, is(notNullValue()));
    assertThat(actualResumptionToken.getValue(), is(notNullValue()));
    RequestSpecification requestWithResumptionToken = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, actualResumptionToken.getValue());
    OAIPMH oai = verify200WithXml(requestWithResumptionToken, verb);
    ResumptionTokenType nextResumptionToken = getResumptionToken(oai, verb);
    assertThat(nextResumptionToken, is(notNullValue()));
    assertThat(nextResumptionToken.getValue(), is(notNullValue()));
    assertThat(nextResumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(100))));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RequestSpecification(io.restassured.specification.RequestSpecification) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiRecordsWithoutFromAndWithMetadataPrefixMarc21AndResumptionToken.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiRecordsWithoutFromAndWithMetadataPrefixMarc21AndResumptionToken(MetadataPrefix prefix, VerbType verb) {
    String set = "all";
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(SET_PARAM, set);
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 9);
    ResumptionTokenType actualResumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(actualResumptionToken, is(notNullValue()));
    assertThat(actualResumptionToken.getValue(), is(notNullValue()));
    RequestSpecification requestWithResumptionToken = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, actualResumptionToken.getValue());
    OAIPMH oai = verify200WithXml(requestWithResumptionToken, verb);
    ResumptionTokenType nextResumptionToken = getResumptionToken(oai, verb);
    assertThat(nextResumptionToken, is(notNullValue()));
    assertThat(nextResumptionToken.getValue(), is(""));
    assertThat(nextResumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(11))));
}
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) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with ResumptionTokenType

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

the class OaiPmhImplTest method verifyResumptionTokenFlowForMarc21AndOaiDcMetadataPrefixes.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void verifyResumptionTokenFlowForMarc21AndOaiDcMetadataPrefixes(MetadataPrefix prefix, VerbType verb) {
    String maxRecordsPerResponse = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "4");
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(FROM_PARAM, DATE_FOR_INSTANCES_10_PARTIALLY);
    OAIPMH oaipmh = verify200WithXml(request, verb);
    verifyListResponse(oaipmh, verb, 4);
    ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
    assertThat(resumptionToken, is(notNullValue()));
    assertThat(resumptionToken.getValue(), is(notNullValue()));
    assertEquals(BigInteger.TEN, resumptionToken.getCompleteListSize());
    assertEquals(BigInteger.ZERO, resumptionToken.getCursor());
    List<HeaderType> totalRecords = getHeadersListDependOnVerbType(verb, oaipmh);
    resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 4, 4);
    resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 2, 8);
    assertThat(resumptionToken.getValue(), isEmptyString());
    System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, maxRecordsPerResponse);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) HeaderType(org.openarchives.oai._2.HeaderType) 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 9 with ResumptionTokenType

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

the class GetOaiIdentifiersHelper method buildListIdentifiers.

/**
 * Builds {@link ListIdentifiersType} with headers if there is any item or {@code null}
 *
 * @param request           request
 * @param srsRecords the response from the storage which contains items
 * @return {@link ListIdentifiersType} with headers if there is any or {@code null}
 */
private OAIPMH buildListIdentifiers(Request request, JsonObject srsRecords) {
    ResponseHelper responseHelper = getResponseHelper();
    JsonArray instances = storageHelper.getItems(srsRecords);
    Integer totalRecords = storageHelper.getTotalRecords(srsRecords);
    if (request.isRestored() && !canResumeRequestSequence(request, totalRecords, instances)) {
        return responseHelper.buildOaipmhResponseWithErrors(request, BAD_RESUMPTION_TOKEN, RESUMPTION_TOKEN_FLOW_ERROR);
    }
    if (instances != null && !instances.isEmpty()) {
        logger.debug("{} entries retrieved out of {}.", instances.size(), totalRecords);
        ListIdentifiersType identifiers = new ListIdentifiersType().withResumptionToken(buildResumptionToken(request, instances, totalRecords));
        String identifierPrefix = request.getIdentifierPrefix();
        instances.stream().map(object -> (JsonObject) object).filter(instance -> StringUtils.isNotEmpty(storageHelper.getIdentifierId(instance))).filter(instance -> filterInstance(request, instance)).map(instance -> addHeader(identifierPrefix, request, instance)).forEach(identifiers::withHeaders);
        if (identifiers.getHeaders().isEmpty()) {
            OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request);
            return oaipmh.withErrors(createNoRecordsFoundError());
        }
        ResumptionTokenType resumptionToken = buildResumptionToken(request, instances, totalRecords);
        OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request).withListIdentifiers(identifiers);
        addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
        return oaipmh;
    }
    return responseHelper.buildOaipmhResponseWithErrors(request, createNoRecordsFoundError());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) RESUMPTION_TOKEN_FLOW_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FLOW_ERROR) Promise(io.vertx.core.Promise) ListIdentifiersType(org.openarchives.oai._2.ListIdentifiersType) Context(io.vertx.core.Context) Future(io.vertx.core.Future) StringUtils(org.apache.commons.lang3.StringUtils) JsonArray(io.vertx.core.json.JsonArray) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Request(org.folio.oaipmh.Request) Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) RESUMPTION_TOKEN_FORMAT_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FORMAT_ERROR) JsonObject(io.vertx.core.json.JsonObject) LogManager(org.apache.logging.log4j.LogManager) ListIdentifiersType(org.openarchives.oai._2.ListIdentifiersType) OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper)

Example 10 with ResumptionTokenType

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

the class OaiPmhImplTest method getOaiListVerbResumptionFlowStartedWithoutFromParamAndGranularitySettingIsFull.

@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiListVerbResumptionFlowStartedWithoutFromParamAndGranularitySettingIsFull(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(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(7)));
    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)

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