Search in sources :

Example 1 with REQUEST_METADATA_LB

use of org.folio.rest.jooq.tables.RequestMetadataLb.REQUEST_METADATA_LB 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));
    }));
}
Also used : RequestMetadataLb(org.folio.rest.jooq.tables.pojos.RequestMetadataLb) InstancesDao(org.folio.oaipmh.dao.InstancesDao) ZonedDateTime(java.time.ZonedDateTime) RequestMetadataLbRecord(org.folio.rest.jooq.tables.records.RequestMetadataLbRecord) StringUtils(org.apache.commons.lang3.StringUtils) RowMappers(org.folio.rest.jooq.tables.mappers.RowMappers) PostgresClientFactory(org.folio.oaipmh.dao.PostgresClientFactory) RowSet(io.vertx.sqlclient.RowSet) Repository(org.springframework.stereotype.Repository) Record(org.jooq.Record) INSTANCES(org.folio.rest.jooq.tables.Instances.INSTANCES) REQUEST_METADATA_LB(org.folio.rest.jooq.tables.RequestMetadataLb.REQUEST_METADATA_LB) Instances(org.folio.rest.jooq.tables.pojos.Instances) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) InsertValuesStep3(org.jooq.InsertValuesStep3) QueryResult(io.github.jklingsporn.vertx.jooq.shared.internal.QueryResult) Future(io.vertx.core.Future) ZoneId(java.time.ZoneId) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Logger(org.apache.logging.log4j.Logger) InstancesRecord(org.folio.rest.jooq.tables.records.InstancesRecord) Row(io.vertx.sqlclient.Row) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) NotFoundException(javax.ws.rs.NotFoundException) RequestMetadataLb(org.folio.rest.jooq.tables.pojos.RequestMetadataLb)

Example 2 with REQUEST_METADATA_LB

use of org.folio.rest.jooq.tables.RequestMetadataLb.REQUEST_METADATA_LB 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));
}
Also used : RequestMetadataLb(org.folio.rest.jooq.tables.pojos.RequestMetadataLb) InstancesDao(org.folio.oaipmh.dao.InstancesDao) ZonedDateTime(java.time.ZonedDateTime) RequestMetadataLbRecord(org.folio.rest.jooq.tables.records.RequestMetadataLbRecord) StringUtils(org.apache.commons.lang3.StringUtils) RowMappers(org.folio.rest.jooq.tables.mappers.RowMappers) PostgresClientFactory(org.folio.oaipmh.dao.PostgresClientFactory) RowSet(io.vertx.sqlclient.RowSet) Repository(org.springframework.stereotype.Repository) Record(org.jooq.Record) INSTANCES(org.folio.rest.jooq.tables.Instances.INSTANCES) REQUEST_METADATA_LB(org.folio.rest.jooq.tables.RequestMetadataLb.REQUEST_METADATA_LB) Instances(org.folio.rest.jooq.tables.pojos.Instances) ReactiveClassicGenericQueryExecutor(io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) InsertValuesStep3(org.jooq.InsertValuesStep3) QueryResult(io.github.jklingsporn.vertx.jooq.shared.internal.QueryResult) Future(io.vertx.core.Future) ZoneId(java.time.ZoneId) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Logger(org.apache.logging.log4j.Logger) InstancesRecord(org.folio.rest.jooq.tables.records.InstancesRecord) Row(io.vertx.sqlclient.Row) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) UUID(java.util.UUID)

Aggregations

ReactiveClassicGenericQueryExecutor (io.github.jklingsporn.vertx.jooq.classic.reactivepg.ReactiveClassicGenericQueryExecutor)2 QueryResult (io.github.jklingsporn.vertx.jooq.shared.internal.QueryResult)2 Future (io.vertx.core.Future)2 Row (io.vertx.sqlclient.Row)2 RowSet (io.vertx.sqlclient.RowSet)2 Instant (java.time.Instant)2 OffsetDateTime (java.time.OffsetDateTime)2 ZoneId (java.time.ZoneId)2 ZonedDateTime (java.time.ZonedDateTime)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 NotFoundException (javax.ws.rs.NotFoundException)2 StringUtils (org.apache.commons.lang3.StringUtils)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 InstancesDao (org.folio.oaipmh.dao.InstancesDao)2 PostgresClientFactory (org.folio.oaipmh.dao.PostgresClientFactory)2