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))));
}
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))));
}
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);
}
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());
}
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));
}
Aggregations