use of org.openarchives.oai._2.ResumptionTokenType 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.ResumptionTokenType in project mod-oai-pmh by folio-org.
the class MarcWithHoldingsRequestHelper method buildResumptionTokenFromRequest.
private ResumptionTokenType buildResumptionTokenFromRequest(Request request, String requestId, long returnedCount, String nextInstanceId) {
long cursor = request.getOffset();
if (nextInstanceId == null) {
return new ResumptionTokenType().withValue("").withCursor(BigInteger.valueOf(cursor));
}
Map<String, String> extraParams = new HashMap<>();
extraParams.put(OFFSET_PARAM, String.valueOf(cursor + returnedCount));
extraParams.put(REQUEST_ID_PARAM, requestId);
extraParams.put(NEXT_RECORD_ID_PARAM, nextInstanceId);
extraParams.put(EXPIRATION_DATE_RESUMPTION_TOKEN_PARAM, String.valueOf(Instant.now().with(ChronoField.NANO_OF_SECOND, 0).plusSeconds(RESUMPTION_TOKEN_TIMEOUT)));
if (request.getUntil() == null) {
extraParams.put(UNTIL_PARAM, getUntilDate(request, request.getFrom()));
}
int pk = request.getNextInstancePkValue();
if (pk > 0) {
extraParams.put(NEXT_INSTANCE_PK_VALUE, String.valueOf(pk));
}
String resumptionToken = request.toResumptionToken(extraParams);
return new ResumptionTokenType().withValue(resumptionToken).withExpirationDate(Instant.now().with(ChronoField.NANO_OF_SECOND, 0).plusSeconds(RESUMPTION_TOKEN_TIMEOUT)).withCursor(BigInteger.valueOf(cursor));
}
use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method makeResumptionTokenRequestsAndVerifyCount.
private ResumptionTokenType makeResumptionTokenRequestsAndVerifyCount(List<HeaderType> totalRecords, ResumptionTokenType resumptionToken, VerbType verb, int desiredCount, int expectedCursor) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken.getValue());
OAIPMH oaipmh;
List<HeaderType> records;
oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, desiredCount);
resumptionToken = getResumptionToken(oaipmh, verb);
assertThat(resumptionToken, is(notNullValue()));
assertEquals(expectedCursor, resumptionToken.getCursor().intValue());
records = getHeadersListDependOnVerbType(verb, oaipmh);
totalRecords.addAll(records);
return resumptionToken;
}
use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbResumptionFlowStarted.
@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiListVerbResumptionFlowStarted(MetadataPrefix metadataPrefix, VerbType verb) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, PARTITIONABLE_RECORDS_DATE_TIME).param(METADATA_PREFIX_PARAM, metadataPrefix.getName()).param(SET_PARAM, "all");
OAIPMH oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, 10);
ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
assertThat(resumptionToken, is(notNullValue()));
assertThat(resumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(100))));
assertThat(resumptionToken.getCursor(), is(equalTo(BigInteger.ZERO)));
assertThat(resumptionToken.getExpirationDate(), 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)));
assertThat(getParamValue(params, METADATA_PREFIX_PARAM), is(equalTo(metadataPrefix.getName())));
assertThat(getParamValue(params, FROM_PARAM), is(equalTo(PARTITIONABLE_RECORDS_DATE_TIME)));
assertThat(getParamValue(params, UNTIL_PARAM), is((notNullValue())));
assertThat(getParamValue(params, SET_PARAM), is(equalTo("all")));
assertThat(getParamValue(params, OFFSET_PARAM), is(equalTo("10")));
assertThat(getParamValue(params, TOTAL_RECORDS_PARAM), is(equalTo("100")));
assertThat(getParamValue(params, NEXT_RECORD_ID_PARAM), is(equalTo("6506b79b-7702-48b2-9774-a1c538fdd34e")));
}
use of org.openarchives.oai._2.ResumptionTokenType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiRecordsWithUntilAndMetadataPrefixMarc21AndResumptionToken.
@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void getOaiRecordsWithUntilAndMetadataPrefixMarc21AndResumptionToken(MetadataPrefix prefix, VerbType verb) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(UNTIL_PARAM, LocalDateTime.now(ZoneOffset.UTC).format(ISO_UTC_DATE_TIME));
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(notNullValue()));
assertThat(nextResumptionToken.getCompleteListSize(), is(equalTo(BigInteger.valueOf(11))));
}
Aggregations