use of org.folio.oaipmh.service.SourceStorageSourceRecordsClientWrapper 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);
}
}
use of org.folio.oaipmh.service.SourceStorageSourceRecordsClientWrapper in project mod-oai-pmh by folio-org.
the class AbstractGetRecordsHelper method requestAndProcessSrsRecords.
protected void requestAndProcessSrsRecords(Request request, Context ctx, Promise<Response> promise) {
final var srsClient = new SourceStorageSourceRecordsClientWrapper(request.getOkapiUrl(), request.getTenant(), request.getOkapiToken(), WebClientProvider.getWebClient());
final boolean deletedRecordsSupport = RepositoryConfigurationUtil.isDeletedRecordsEnabled(request.getRequestId());
final boolean suppressedRecordsSupport = getBooleanProperty(request.getRequestId(), REPOSITORY_SUPPRESSED_RECORDS_PROCESSING);
final Date updatedAfter = request.getFrom() == null ? null : convertStringToDate(request.getFrom(), false, true);
final Date updatedBefore = request.getUntil() == null ? null : convertStringToDate(request.getUntil(), true, true);
int batchSize = Integer.parseInt(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_MAX_RECORDS_PER_RESPONSE));
srsClient.getSourceStorageSourceRecords(null, null, null, null, request.getIdentifier() != null ? request.getStorageIdentifier() : null, null, null, null, "MARC_BIB", // 2. use suppressed from discovery filtering only when deleted record support is enabled
deletedRecordsSupport ? null : suppressedRecordsSupport, deletedRecordsSupport, null, updatedAfter, updatedBefore, null, request.getOffset(), batchSize + 1, getSrsRecordsBodyHandler(request, ctx, promise));
}
Aggregations