use of org.folio.oaipmh.Constants.REPOSITORY_MAX_RECORDS_PER_RESPONSE in project mod-oai-pmh by folio-org.
the class MarcWithHoldingsRequestHelper method processBatch.
private void processBatch(Request request, Context context, Promise<Response> oaiPmhResponsePromise, String requestId, boolean firstBatch) {
try {
boolean deletedRecordSupport = RepositoryConfigurationUtil.isDeletedRecordsEnabled(request.getRequestId());
int batchSize = Integer.parseInt(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_MAX_RECORDS_PER_RESPONSE));
getNextInstances(request, batchSize, requestId, firstBatch).future().onComplete(fut -> {
if (fut.failed()) {
logger.error("Get instances failed: {}.", fut.cause().getMessage(), fut.cause());
oaiPmhResponsePromise.fail(fut.cause());
return;
}
List<JsonObject> instances = fut.result();
logger.debug("Processing instances: {}.", instances.size());
if (CollectionUtils.isEmpty(instances) && !firstBatch) {
handleException(oaiPmhResponsePromise, new IllegalArgumentException("Specified resumption token doesn't exists."));
return;
}
if (!firstBatch && (CollectionUtils.isNotEmpty(instances) && !instances.get(0).getString(INSTANCE_ID_FIELD_NAME).equals(request.getNextRecordId()))) {
handleException(oaiPmhResponsePromise, new IllegalArgumentException("Stale resumption token."));
return;
}
if (CollectionUtils.isEmpty(instances)) {
logger.debug("Got empty instances.");
buildRecordsResponse(request, requestId, instances, new HashMap<>(), firstBatch, null, deletedRecordSupport).onSuccess(oaiPmhResponsePromise::complete).onFailure(e -> handleException(oaiPmhResponsePromise, e));
return;
}
String nextInstanceId = instances.size() <= batchSize ? null : instances.get(batchSize).getString(INSTANCE_ID_FIELD_NAME);
List<JsonObject> instancesWithoutLast = nextInstanceId != null ? instances.subList(0, batchSize) : instances;
final SourceStorageSourceRecordsClientWrapper srsClient = createAndSetupSrsClient(request);
int retryAttempts = Integer.parseInt(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_SRS_HTTP_REQUEST_RETRY_ATTEMPTS));
requestSRSByIdentifiers(srsClient, context.owner(), instancesWithoutLast, deletedRecordSupport, retryAttempts).onSuccess(res -> buildRecordsResponse(request, requestId, instancesWithoutLast, res, firstBatch, nextInstanceId, deletedRecordSupport).onSuccess(oaiPmhResponsePromise::complete).onFailure(e -> handleException(oaiPmhResponsePromise, e))).onFailure(e -> handleException(oaiPmhResponsePromise, e));
});
} catch (Exception e) {
handleException(oaiPmhResponsePromise, e);
}
}
Aggregations