use of org.folio.rest.jooq.tables.pojos.RequestMetadataLb in project mod-oai-pmh by folio-org.
the class InstancesDaoImpl method updateRequestUpdatedDate.
@Override
public Future<RequestMetadataLb> updateRequestUpdatedDate(String requestId, OffsetDateTime lastUpdatedDate, String tenantId) {
RequestMetadataLb requestMetadataLb = new RequestMetadataLb();
requestMetadataLb.setRequestId(UUID.fromString(requestId)).setLastUpdatedDate(lastUpdatedDate);
return getQueryExecutor(tenantId).transaction(queryExecutor -> queryExecutor.executeAny(dslContext -> dslContext.update(REQUEST_METADATA_LB).set(REQUEST_METADATA_LB.LAST_UPDATED_DATE, lastUpdatedDate).where(REQUEST_METADATA_LB.REQUEST_ID.eq(UUID.fromString(requestId))).returning()).map(this::toOptionalRequestMetadata).map(optional -> {
if (optional.isPresent()) {
return optional.get();
}
throw new NotFoundException(String.format(REQUEST_METADATA_WITH_ID_DOES_NOT_EXIST, requestId));
}));
}
use of org.folio.rest.jooq.tables.pojos.RequestMetadataLb in project mod-oai-pmh by folio-org.
the class InstancesServiceImplTest method shouldReturnFailedFuture_whenSaveRequestMetadataWithEmptyRequestId.
@Test
void shouldReturnFailedFuture_whenSaveRequestMetadataWithEmptyRequestId(VertxTestContext testContext) {
testContext.verify(() -> {
RequestMetadataLb requestMetadataLb = new RequestMetadataLb().setLastUpdatedDate(OffsetDateTime.now());
instancesService.saveRequestMetadata(requestMetadataLb, OAI_TEST_TENANT).onComplete(testContext.failing(throwable -> {
assertTrue(throwable instanceof IllegalStateException);
testContext.completeNow();
}));
});
}
use of org.folio.rest.jooq.tables.pojos.RequestMetadataLb in project mod-oai-pmh by folio-org.
the class InstancesDaoImpl method saveRequestMetadata.
@Override
public Future<RequestMetadataLb> saveRequestMetadata(RequestMetadataLb requestMetadata, String tenantId) {
UUID uuid = requestMetadata.getRequestId();
requestMetadata.setStreamEnded(false);
if (Objects.isNull(uuid) || StringUtils.isEmpty(uuid.toString())) {
return Future.failedFuture(new IllegalStateException("Cannot save request metadata, request metadata entity must contain requestId"));
}
return getQueryExecutor(tenantId).transaction(queryExecutor -> queryExecutor.executeAny(dslContext -> dslContext.insertInto(REQUEST_METADATA_LB).set(toDatabaseRecord(requestMetadata))).map(raw -> requestMetadata));
}
use of org.folio.rest.jooq.tables.pojos.RequestMetadataLb in project mod-oai-pmh by folio-org.
the class InstancesDaoImpl method toOptionalRequestMetadata.
private Optional<RequestMetadataLb> toOptionalRequestMetadata(RowSet<Row> rows) {
if (rows.rowCount() == 1) {
Row row = rows.iterator().next();
RequestMetadataLb requestMetadataLb = RowMappers.getRequestMetadataLbMapper().apply(row);
return Optional.of(requestMetadataLb);
}
return Optional.empty();
}
use of org.folio.rest.jooq.tables.pojos.RequestMetadataLb in project mod-oai-pmh by folio-org.
the class MarcWithHoldingsRequestHelper method handle.
/**
* Handle MarcWithHoldings request
*/
@Override
public Future<Response> handle(Request request, Context vertxContext) {
Promise<Response> oaipmhResponsePromise = Promise.promise();
metricsCollectingService.startMetric(request.getRequestId(), SEND_REQUEST);
try {
String resumptionToken = request.getResumptionToken();
List<OAIPMHerrorType> errors = validateListRequest(request);
if (!errors.isEmpty()) {
return buildResponseWithErrors(request, oaipmhResponsePromise, errors);
}
String requestId;
OffsetDateTime lastUpdateDate = OffsetDateTime.now(ZoneId.systemDefault());
RequestMetadataLb requestMetadata = new RequestMetadataLb().setLastUpdatedDate(lastUpdateDate);
Future<RequestMetadataLb> updateRequestMetadataFuture;
if (resumptionToken == null) {
requestId = request.getRequestId();
requestMetadata.setRequestId(UUID.fromString(requestId));
updateRequestMetadataFuture = instancesService.saveRequestMetadata(requestMetadata, request.getTenant());
} else {
requestId = request.getRequestId();
updateRequestMetadataFuture = instancesService.updateRequestUpdatedDate(requestId, lastUpdateDate, request.getTenant());
}
updateRequestMetadataFuture.onSuccess(res -> {
boolean isFirstBatch = resumptionToken == null;
processBatch(request, vertxContext, oaipmhResponsePromise, requestId, isFirstBatch);
if (isFirstBatch) {
saveInstancesExecutor.executeBlocking(downloadInstancesPromise -> downloadInstances(request, oaipmhResponsePromise, downloadInstancesPromise, downloadContext), downloadInstancesResult -> {
instancesService.updateRequestStreamEnded(requestId, true, request.getTenant());
if (downloadInstancesResult.succeeded()) {
logger.info("Downloading instances complete.");
} else {
logger.error("Downloading instances was canceled due to the error. ", downloadInstancesResult.cause());
if (!oaipmhResponsePromise.future().isComplete()) {
oaipmhResponsePromise.fail(new IllegalStateException(downloadInstancesResult.cause()));
}
}
});
}
}).onFailure(th -> handleException(oaipmhResponsePromise, th));
} catch (Exception e) {
handleException(oaipmhResponsePromise, e);
}
return oaipmhResponsePromise.future().onComplete(responseAsyncResult -> metricsCollectingService.endMetric(request.getRequestId(), SEND_REQUEST));
}
Aggregations