Search in sources :

Example 21 with SourceRecord

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

the class EdifactUtilTest method shouldFormatEdifactWithIgnoredCodeValues.

@Test
public void shouldFormatEdifactWithIgnoredCodeValues() throws IOException, EDIStreamException {
    SourceRecord sourceRecord = new ObjectMapper().readValue(new File(SOURCE_RECORD_WITH_IGNORED_CODES_PATH), SourceRecord.class);
    String rawEdifact = sourceRecord.getParsedRecord().getFormattedContent();
    String formattedEdifact = EdifactUtil.formatEdifact(rawEdifact);
    assertNotNull(formattedEdifact);
    assertEquals(sourceRecord.getParsedRecord().getFormattedContent(), formattedEdifact);
}
Also used : SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 22 with SourceRecord

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

the class RecordDaoUtil method toSourceRecord.

/**
 * Convert database query result {@link Row} to {@link SourceRecord}
 *
 * @param row query result row
 * @return SourceRecord
 */
public static SourceRecord toSourceRecord(Row row) {
    RecordsLb pojo = RowMappers.getRecordsLbMapper().apply(row);
    SourceRecord sourceRecord = new SourceRecord();
    if (Objects.nonNull(pojo.getId())) {
        sourceRecord.withRecordId(pojo.getId().toString());
    }
    if (Objects.nonNull(pojo.getSnapshotId())) {
        sourceRecord.withSnapshotId(pojo.getSnapshotId().toString());
    }
    if (Objects.nonNull(pojo.getRecordType())) {
        sourceRecord.withRecordType(SourceRecord.RecordType.valueOf(pojo.getRecordType().toString()));
    }
    sourceRecord.withOrder(pojo.getOrder()).withDeleted((Objects.nonNull(pojo.getState()) && State.valueOf(pojo.getState().toString()).equals(State.DELETED)) || DELETED_LEADER_RECORD_STATUS.contains(pojo.getLeaderRecordStatus()));
    return sourceRecord.withAdditionalInfo(toAdditionalInfo(pojo)).withExternalIdsHolder(toExternalIdsHolder(pojo)).withMetadata(toMetadata(pojo));
}
Also used : RecordsLb(org.folio.rest.jooq.tables.pojos.RecordsLb) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord)

Example 23 with SourceRecord

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

the class SourceStorageStreamApiTest method shouldReturnSortedSourceRecordsOnGetWhenSortByOrderIsSpecified.

@Test
public void shouldReturnSortedSourceRecordsOnGetWhenSortByOrderIsSpecified(TestContext testContext) {
    postSnapshots(testContext, snapshot_2);
    // NOTE: record_5 saves but fails parsed record content validation and does not save parsed record
    postRecords(testContext, marc_bib_record_2, marc_bib_record_3, marc_bib_record_5, marc_bib_record_6);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?snapshotId=" + snapshot_2.getJobExecutionId() + "&orderBy=order").then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<SourceRecord> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
        testContext.assertEquals(2, actual.size());
        testContext.assertTrue(Objects.nonNull(actual.get(0).getParsedRecord()));
        testContext.assertTrue(Objects.nonNull(actual.get(1).getParsedRecord()));
        testContext.assertEquals(false, actual.get(0).getDeleted());
        testContext.assertEquals(false, actual.get(1).getDeleted());
        testContext.assertEquals(11, actual.get(0).getOrder().intValue());
        testContext.assertEquals(101, actual.get(1).getOrder().intValue());
        async.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Test(org.junit.Test)

Example 24 with SourceRecord

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

the class SourceStorageStreamApiTest method shouldReturnSpecificNumberOfSourceRecordsOnGetByInstanceExternalHrid.

@Test
public void shouldReturnSpecificNumberOfSourceRecordsOnGetByInstanceExternalHrid(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    Async async = testContext.async();
    String firstHrid = "123";
    String secondHrid = "1234";
    String thirdHrid = "1235";
    Record firstRecord = new Record().withId(FIRST_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(FIRST_UUID).withOrder(11).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(firstHrid));
    Record secondRecord = new Record().withId(SECOND_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(SECOND_UUID).withOrder(11).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(FIRST_UUID).withInstanceHrid(secondHrid));
    RestAssured.given().spec(spec).body(firstRecord).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    RestAssured.given().spec(spec).body(secondRecord).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    Record recordWithOldState = new Record().withId(FOURTH_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(FOURTH_UUID).withOrder(11).withState(Record.State.OLD).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(THIRD_UUID).withInstanceHrid(thirdHrid));
    Record record = new Record().withId(THIRD_UUID).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(THIRD_UUID).withOrder(11).withState(Record.State.ACTUAL).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(SECOND_UUID).withInstanceHrid(secondHrid));
    RestAssured.given().spec(spec).body(record).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    RestAssured.given().spec(spec).body(recordWithOldState).when().post(SOURCE_STORAGE_RECORDS_PATH).body().as(Record.class);
    async.complete();
    final Async finalAsync = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?instanceHrid=" + secondHrid).then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<SourceRecord> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
        testContext.assertEquals(2, actual.size());
        testContext.assertTrue(Objects.nonNull(actual.get(0).getParsedRecord()));
        testContext.assertTrue(Objects.nonNull(actual.get(1).getParsedRecord()));
        testContext.assertEquals(secondHrid, actual.get(0).getExternalIdsHolder().getInstanceHrid());
        testContext.assertEquals(secondHrid, actual.get(1).getExternalIdsHolder().getInstanceHrid());
        finalAsync.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) 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) Test(org.junit.Test)

Example 25 with SourceRecord

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

the class SourceStorageStreamApiTest method shouldReturnEmptyCollectionOnGetByRecordIdIfThereIsNoSuchRecord.

@Test
public void shouldReturnEmptyCollectionOnGetByRecordIdIfThereIsNoSuchRecord(TestContext testContext) {
    postSnapshots(testContext, snapshot_1, snapshot_2);
    postRecords(testContext, marc_bib_record_1, marc_bib_record_2, marc_bib_record_3);
    final Async async = testContext.async();
    InputStream response = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_STREAM_SOURCE_RECORDS_PATH + "?recordId=" + UUID.randomUUID().toString() + "&limit=1&offset=0").then().statusCode(HttpStatus.SC_OK).extract().response().asInputStream();
    List<SourceRecord> actual = new ArrayList<>();
    flowableInputStreamScanner(response).map(r -> Json.decodeValue(r, SourceRecord.class)).doFinally(() -> {
        testContext.assertEquals(0, actual.size());
        async.complete();
    }).collect(() -> actual, (a, r) -> a.add(r)).subscribe();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) RawRecord(org.folio.rest.jaxrs.model.RawRecord) Scanner(java.util.Scanner) HttpStatus(org.apache.http.HttpStatus) ArrayList(java.util.ArrayList) RecordType(org.folio.rest.jaxrs.model.Record.RecordType) Matchers.everyItem(org.hamcrest.Matchers.everyItem) Flowable(io.reactivex.Flowable) ExternalIdsHolder(org.folio.rest.jaxrs.model.ExternalIdsHolder) TestUtil(org.folio.TestUtil) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AdditionalInfo(org.folio.rest.jaxrs.model.AdditionalInfo) SourceRecord(org.folio.rest.jaxrs.model.SourceRecord) Before(org.junit.Before) BackpressureStrategy(io.reactivex.BackpressureStrategy) Record(org.folio.rest.jaxrs.model.Record) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) ParsedRecordDaoUtil(org.folio.dao.util.ParsedRecordDaoUtil) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SnapshotDaoUtil(org.folio.dao.util.SnapshotDaoUtil) ZoneId(java.time.ZoneId) Objects(java.util.Objects) ExtractableResponse(io.restassured.response.ExtractableResponse) List(java.util.List) Response(io.restassured.response.Response) ErrorRecord(org.folio.rest.jaxrs.model.ErrorRecord) DateTimeFormatter(java.time.format.DateTimeFormatter) PostgresClientFactory(org.folio.dao.PostgresClientFactory) MarcRecordSearchRequest(org.folio.rest.jaxrs.model.MarcRecordSearchRequest) Matchers.is(org.hamcrest.Matchers.is) RestAssured(io.restassured.RestAssured) ParsedRecord(org.folio.rest.jaxrs.model.ParsedRecord) Snapshot(org.folio.rest.jaxrs.model.Snapshot) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Async(io.vertx.ext.unit.Async) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) 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