Search in sources :

Example 6 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class RecordServiceTest method streamMarcSourceRecords.

private void streamMarcSourceRecords(TestContext context, 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());
        }
        Condition condition = DSL.trueCondition();
        List<OrderField<?>> orderFields = new ArrayList<>();
        Flowable<SourceRecord> flowable = recordService.streamSourceRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID);
        List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).sorted(comparing(SourceRecord::getOrder)).collect(Collectors.toList());
        List<SourceRecord> actual = new ArrayList<>();
        flowable.doFinally(() -> {
            actual.sort(comparing(SourceRecord::getRecordId));
            context.assertEquals(expected.size(), actual.size());
            compareSourceRecords(context, expected, actual);
            async.complete();
        }).collect(() -> actual, List::add).subscribe();
    });
}
Also used : Condition(org.jooq.Condition) 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) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) OrderField(org.jooq.OrderField)

Example 7 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceRecordApiTest method shouldReturnSortedMarcBibSourceRecordsOnGetWhenSortByOrderIsSpecified.

@Test
public void shouldReturnSortedMarcBibSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_2, snapshot_3);
    postRecords(testContext, record_2, record_3, record_5, record_6, record_7);
    Async async = testContext.async();
    // NOTE: get source records will not return if there is no associated parsed record
    List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?snapshotId=" + snapshot_2.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(2)).body("totalRecords", is(2)).body("sourceRecords*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
    testContext.assertEquals(11, sourceRecordList.get(0).getOrder());
    testContext.assertEquals(101, sourceRecordList.get(1).getOrder());
    async.complete();
}
Also used : SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 8 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceRecordApiTest method shouldReturnSourceRecordsForPeriod.

@Test
public void shouldReturnSourceRecordsForPeriod(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    postRecords(testContext, record_1);
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    Date fromDate = new Date();
    String from = dateTimeFormatter.format(ZonedDateTime.ofInstant(fromDate.toInstant(), ZoneId.systemDefault()));
    // NOTE: record_5 saves but fails parsed record content validation and does not save parsed record
    postRecords(testContext, record_2, record_3, record_4, record_5);
    Date toDate = new Date();
    String to = dateTimeFormatter.format(ZonedDateTime.ofInstant(toDate.toInstant(), ZoneId.systemDefault()));
    postRecords(testContext, record_6);
    Async async = testContext.async();
    // NOTE: we do not expect record_3 or record_5 as they do not have a parsed record
    List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from + "&updatedBefore=" + to).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(2)).body("totalRecords", is(2)).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
    testContext.assertTrue(sourceRecordList.get(0).getMetadata().getUpdatedDate().after(fromDate));
    testContext.assertTrue(sourceRecordList.get(1).getMetadata().getUpdatedDate().after(fromDate));
    testContext.assertTrue(sourceRecordList.get(0).getMetadata().getUpdatedDate().before(toDate));
    testContext.assertTrue(sourceRecordList.get(1).getMetadata().getUpdatedDate().before(toDate));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + from).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(3)).body("totalRecords", is(3)).body("sourceRecords*.deleted", everyItem(is(false)));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedAfter=" + to).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(1)).body("totalRecords", is(1)).body("sourceRecords*.deleted", everyItem(is(false)));
    async.complete();
    // NOTE: we do not expect record_1 id does not have a parsed record
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + to).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(2)).body("totalRecords", is(2)).body("sourceRecords*.deleted", everyItem(is(false)));
    async.complete();
    async = testContext.async();
    RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?updatedBefore=" + from).then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(0)).body("totalRecords", is(0));
    async.complete();
}
Also used : SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) DateTimeFormatter(java.time.format.DateTimeFormatter) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Date(java.util.Date) Test(org.junit.Test)

Example 9 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceRecordApiTest method shouldReturnSortedMarcSourceRecordsOnGetWhenSortByOrderIsSpecified.

private void shouldReturnSortedMarcSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext, RecordType recordType, Record record, Snapshot snapshot) {
    postSnapshots(testContext, snapshot_2, snapshot_3, snapshot);
    postRecords(testContext, record_2, record_3, record_5, record_6, record_7, record);
    Async async = testContext.async();
    // NOTE: get source records will not return if there is no associated parsed record
    List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?recordType=" + recordType + "&snapshotId=" + snapshot.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(1)).body("totalRecords", is(1)).body("sourceRecords*.recordType", everyItem(is(recordType.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
    testContext.assertEquals(0, sourceRecordList.get(0).getOrder());
    async.complete();
}
Also used : SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord)

Example 10 with SourceRecord

use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.

the class SourceRecordApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified.

@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2, snapshot_3);
    String firstMatchedId = UUID.randomUUID().toString();
    Record record_4_tmp = new Record().withId(firstMatchedId).withSnapshotId(snapshot_1.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(firstMatchedId).withOrder(1).withState(Record.State.ACTUAL);
    String secondMathcedId = UUID.randomUUID().toString();
    Record record_2_tmp = new Record().withId(secondMathcedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(secondMathcedId).withOrder(11).withState(Record.State.ACTUAL);
    postRecords(testContext, record_2, record_2_tmp, record_4, record_4_tmp, record_7);
    Async async = testContext.async();
    List<SourceRecord> sourceRecordList = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?recordType=MARC_BIB&orderBy=createdDate,DESC").then().statusCode(HttpStatus.SC_OK).body("sourceRecords.size()", is(4)).body("totalRecords", is(4)).body("sourceRecords*.recordType", everyItem(is(RecordType.MARC_BIB.name()))).body("sourceRecords*.deleted", everyItem(is(false))).extract().response().body().as(SourceRecordCollection.class).getSourceRecords();
    testContext.assertTrue(sourceRecordList.get(0).getMetadata().getCreatedDate().after(sourceRecordList.get(1).getMetadata().getCreatedDate()));
    testContext.assertTrue(sourceRecordList.get(1).getMetadata().getCreatedDate().after(sourceRecordList.get(2).getMetadata().getCreatedDate()));
    testContext.assertTrue(sourceRecordList.get(2).getMetadata().getCreatedDate().after(sourceRecordList.get(3).getMetadata().getCreatedDate()));
    async.complete();
}
Also used : SourceRecordCollection(org.folio.rest.jaxrs.model.SourceRecordCollection) Async(io.vertx.ext.unit.Async) 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) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Aggregations

SourceRecord (org.folio.rest.jaxrs.model.SourceRecord)30 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)22 Async (io.vertx.ext.unit.Async)21 RawRecord (org.folio.rest.jaxrs.model.RawRecord)20 Record (org.folio.rest.jaxrs.model.Record)20 Test (org.junit.Test)20 ErrorRecord (org.folio.rest.jaxrs.model.ErrorRecord)19 ArrayList (java.util.ArrayList)17 AdditionalInfo (org.folio.rest.jaxrs.model.AdditionalInfo)17 ExternalIdsHolder (org.folio.rest.jaxrs.model.ExternalIdsHolder)17 List (java.util.List)16 Objects (java.util.Objects)16 Flowable (io.reactivex.Flowable)14 UUID (java.util.UUID)14 ParsedRecordDaoUtil (org.folio.dao.util.ParsedRecordDaoUtil)14 SnapshotDaoUtil (org.folio.dao.util.SnapshotDaoUtil)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 TestContext (io.vertx.ext.unit.TestContext)12 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)12 SourceRecordCollection (org.folio.rest.jaxrs.model.SourceRecordCollection)10