Search in sources :

Example 16 with RecordType

use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.

the class RecordServiceTest method getRecordsBySnapshotId.

private void getRecordsBySnapshotId(TestContext context, String uuid, RecordType parsedRecordType, Record.RecordType recordType) {
    Async async = context.async();
    List<Record> records = TestMocks.getRecords();
    RecordCollection recordCollection = new RecordCollection().withRecords(records).withTotalRecords(records.size());
    saveRecords(recordCollection.getRecords()).onComplete(batch -> {
        if (batch.failed()) {
            context.fail(batch.cause());
        }
        String snapshotId = uuid;
        Condition condition = RECORDS_LB.SNAPSHOT_ID.eq(UUID.fromString(snapshotId));
        List<OrderField<?>> orderFields = new ArrayList<>();
        orderFields.add(RECORDS_LB.ORDER.sort(SortOrder.ASC));
        recordService.getRecords(condition, parsedRecordType, orderFields, 0, 1, TENANT_ID).onComplete(get -> {
            if (get.failed()) {
                context.fail(get.cause());
            }
            List<Record> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).filter(r -> r.getSnapshotId().equals(snapshotId)).sorted(comparing(Record::getOrder)).collect(Collectors.toList());
            context.assertEquals(expected.size(), get.result().getTotalRecords());
            compareRecords(context, expected.get(0), get.result().getRecords().get(0));
            async.complete();
        });
    });
}
Also used : Condition(org.jooq.Condition) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) DSL(org.jooq.impl.DSL) RecordDaoImpl(org.folio.dao.RecordDaoImpl) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) RecordType(org.folio.dao.util.RecordType) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordState(org.folio.rest.jooq.enums.RecordState) RECORDS_LB(org.folio.rest.jooq.Tables.RECORDS_LB) Flowable(io.reactivex.Flowable) IdType(org.folio.dao.util.IdType) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) After(org.junit.After) AsyncResult(io.vertx.core.AsyncResult) Comparator.comparing(java.util.Comparator.comparing) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SortOrder(org.jooq.SortOrder) TestMocks(org.folio.TestMocks) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) RecordDao(org.folio.dao.RecordDao) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Future(io.vertx.core.Future) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) State(org.folio.rest.jaxrs.model.Record.State) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) OrderField(org.jooq.OrderField) Assertions(org.junit.jupiter.api.Assertions) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) OrderField(org.jooq.OrderField)

Example 17 with RecordType

use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.

the class RecordServiceTest method streamRecordsBySnapshotId.

private void streamRecordsBySnapshotId(TestContext context, String s, RecordType parsedRecordType, Record.RecordType recordType) {
    Async async = context.async();
    List<Record> records = TestMocks.getRecords();
    RecordCollection recordCollection = new RecordCollection().withRecords(records).withTotalRecords(records.size());
    saveRecords(recordCollection.getRecords()).onComplete(batch -> {
        if (batch.failed()) {
            context.fail(batch.cause());
        }
        String snapshotId = s;
        Condition condition = RECORDS_LB.SNAPSHOT_ID.eq(UUID.fromString(snapshotId));
        List<OrderField<?>> orderFields = new ArrayList<>();
        orderFields.add(RECORDS_LB.ORDER.sort(SortOrder.ASC));
        Flowable<Record> flowable = recordService.streamRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID);
        List<Record> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).filter(r -> r.getSnapshotId().equals(snapshotId)).sorted(comparing(Record::getOrder)).collect(Collectors.toList());
        List<Record> actual = new ArrayList<>();
        flowable.doFinally(() -> {
            context.assertEquals(expected.size(), actual.size());
            compareRecords(context, expected.get(0), actual.get(0));
            async.complete();
        }).collect(() -> actual, List::add).subscribe();
    });
}
Also used : Condition(org.jooq.Condition) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) DSL(org.jooq.impl.DSL) RecordDaoImpl(org.folio.dao.RecordDaoImpl) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) RecordType(org.folio.dao.util.RecordType) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordState(org.folio.rest.jooq.enums.RecordState) RECORDS_LB(org.folio.rest.jooq.Tables.RECORDS_LB) Flowable(io.reactivex.Flowable) IdType(org.folio.dao.util.IdType) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) After(org.junit.After) AsyncResult(io.vertx.core.AsyncResult) Comparator.comparing(java.util.Comparator.comparing) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SortOrder(org.jooq.SortOrder) TestMocks(org.folio.TestMocks) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) RecordDao(org.folio.dao.RecordDao) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Future(io.vertx.core.Future) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) State(org.folio.rest.jaxrs.model.Record.State) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) OrderField(org.jooq.OrderField) Assertions(org.junit.jupiter.api.Assertions) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) ArrayList(java.util.ArrayList) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) OrderField(org.jooq.OrderField)

Example 18 with RecordType

use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.

the class RecordServiceTest method saveMarcRecordsWithExpectedErrors.

private void saveMarcRecordsWithExpectedErrors(TestContext context, Record.RecordType recordType) {
    Async async = context.async();
    List<Record> expected = TestMocks.getRecords().stream().filter(record -> record.getRecordType().equals(recordType)).map(record -> record.withSnapshotId(TestMocks.getSnapshot(0).getJobExecutionId())).map(record -> record.withErrorRecord(TestMocks.getErrorRecord(0))).collect(Collectors.toList());
    RecordCollection recordCollection = new RecordCollection().withRecords(expected).withTotalRecords(expected.size());
    recordService.saveRecords(recordCollection, TENANT_ID).onComplete(batch -> {
        if (batch.failed()) {
            context.fail(batch.cause());
        }
        context.assertEquals(0, batch.result().getErrorMessages().size());
        context.assertEquals(expected.size(), batch.result().getTotalRecords());
        expected.sort(comparing(Record::getId));
        batch.result().getRecords().sort(comparing(Record::getId));
        compareRecords(context, expected, batch.result().getRecords());
        checkRecordErrorRecords(context, batch.result().getRecords(), TestMocks.getErrorRecord(0).getContent().toString(), TestMocks.getErrorRecord(0).getDescription());
        RecordDaoUtil.countByCondition(postgresClientFactory.getQueryExecutor(TENANT_ID), DSL.trueCondition()).onComplete(count -> {
            if (count.failed()) {
                context.fail(count.cause());
            }
            context.assertEquals(expected.size(), count.result());
            async.complete();
        });
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) DSL(org.jooq.impl.DSL) RecordDaoImpl(org.folio.dao.RecordDaoImpl) RawRecord(org.folio.rest.jaxrs.model.RawRecord) RunWith(org.junit.runner.RunWith) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) RecordType(org.folio.dao.util.RecordType) RecordsBatchResponse(org.folio.rest.jaxrs.model.RecordsBatchResponse) RecordState(org.folio.rest.jooq.enums.RecordState) RECORDS_LB(org.folio.rest.jooq.Tables.RECORDS_LB) Flowable(io.reactivex.Flowable) IdType(org.folio.dao.util.IdType) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) After(org.junit.After) AsyncResult(io.vertx.core.AsyncResult) Comparator.comparing(java.util.Comparator.comparing) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SortOrder(org.jooq.SortOrder) TestMocks(org.folio.TestMocks) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) RecordDao(org.folio.dao.RecordDao) DuplicateEventException(org.folio.kafka.exception.DuplicateEventException) Record(org.folio.rest.jaxrs.model.Record) RecordDaoUtil(org.folio.dao.util.RecordDaoUtil) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) UUID(java.util.UUID) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) Future(io.vertx.core.Future) ParsedRecordDto(org.folio.rest.jaxrs.model.ParsedRecordDto) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ChronoUnit(java.time.temporal.ChronoUnit) State(org.folio.rest.jaxrs.model.Record.State) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) OrderField(org.jooq.OrderField) Assertions(org.junit.jupiter.api.Assertions) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) RecordCollection(org.folio.rest.jaxrs.model.RecordCollection) SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) RawRecord(org.folio.rest.jaxrs.model.RawRecord) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Record(org.folio.rest.jaxrs.model.Record) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord)

Aggregations

RecordType (org.folio.dao.util.RecordType)18 DuplicateEventException (org.folio.kafka.exception.DuplicateEventException)17 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)17 Flowable (io.reactivex.Flowable)16 Future (io.vertx.core.Future)16 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Objects (java.util.Objects)16 UUID (java.util.UUID)16 Collectors (java.util.stream.Collectors)16 IdType (org.folio.dao.util.IdType)16 ParsedRecordDaoUtil (org.folio.dao.util.ParsedRecordDaoUtil)16 RecordDaoUtil (org.folio.dao.util.RecordDaoUtil)16 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)16 GenericCompositeFuture (org.folio.okapi.common.GenericCompositeFuture)16 AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)16 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)16 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)16 RawRecord (org.folio.rest.jaxrs.model.RawRecord)16 Record (org.folio.rest.jaxrs.model.Record)16