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);
}
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));
}
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();
}
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();
}
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();
}
Aggregations