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