use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method toSourceRecord.
private SourceRecord toSourceRecord(Row row) {
SourceRecord sourceRecord = RecordDaoUtil.toSourceRecord(row);
ParsedRecord parsedRecord = ParsedRecordDaoUtil.toParsedRecord(row);
if (Objects.nonNull(parsedRecord.getContent())) {
sourceRecord.setParsedRecord(parsedRecord);
}
return sourceRecord;
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method streamSourceRecords.
@Override
public Flowable<SourceRecord> streamSourceRecords(Condition condition, RecordType recordType, Collection<OrderField<?>> orderFields, int offset, int limit, String tenantId) {
Name prt = name(recordType.getTableName());
String sql = DSL.select(getRecordFields(prt)).from(RECORDS_LB).innerJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).where(condition.and(recordType.getSourceRecordImplicitCondition())).orderBy(orderFields).offset(offset).limit(limit).getSQL(ParamType.INLINED);
return getCachedPool(tenantId).rxGetConnection().flatMapPublisher(conn -> conn.rxBegin().flatMapPublisher(tx -> conn.rxPrepare(sql).flatMapPublisher(pq -> pq.createStream(1).toFlowable().map(this::toRow).map(this::toSourceRecord)).doAfterTerminate(tx::commit)));
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-manager by folio-org.
the class ChangeManagerParsedRecordsAPITest method shouldReturnParsedRecordDtoIfSourceRecordExists.
@Test
public void shouldReturnParsedRecordDtoIfSourceRecordExists(TestContext testContext) {
Async async = testContext.async();
String externalId = UUID.randomUUID().toString();
SourceRecord sourceRecord = new SourceRecord().withRecordId(UUID.randomUUID().toString()).withParsedRecord(new ParsedRecord().withId(UUID.randomUUID().toString()).withContent("{\"leader\":\"01240cas a2200397 4500\",\"fields\":[]}")).withRecordType(SourceRecord.RecordType.MARC_BIB).withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(externalId));
WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(SOURCE_RECORDS_URL + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(sourceRecord).encode())));
RestAssured.given().spec(spec).queryParam(EXTERNAL_ID_QUERY_PARAM, externalId).when().get(PARSED_RECORDS_URL).then().statusCode(HttpStatus.SC_OK).body("id", is(sourceRecord.getRecordId())).body("parsedRecord.id", is(sourceRecord.getParsedRecord().getId())).body("recordType", is(sourceRecord.getRecordType().value())).body("externalIdsHolder.instanceId", is(externalId));
async.complete();
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method toSourceRecordCollection.
private SourceRecordCollection toSourceRecordCollection(QueryResult result) {
SourceRecordCollection sourceRecordCollection = new SourceRecordCollection().withTotalRecords(0);
List<SourceRecord> sourceRecords = result.stream().map(res -> asRow(res.unwrap())).map(row -> {
sourceRecordCollection.setTotalRecords(row.getInteger(COUNT));
return RecordDaoUtil.toSourceRecord(RecordDaoUtil.toRecord(row)).withParsedRecord(ParsedRecordDaoUtil.toParsedRecord(row));
}).collect(Collectors.toList());
if (!sourceRecords.isEmpty() && Objects.nonNull(sourceRecords.get(0).getRecordId())) {
sourceRecordCollection.withSourceRecords(sourceRecords);
}
return sourceRecordCollection;
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class TestMocks method readRecord.
private static Optional<Record> readRecord(SourceRecord sourceRecord) {
File file = new File(format(RECORD_PATH_TEMPLATE, sourceRecord.getRecordId()));
if (file.exists()) {
try {
Record record = new ObjectMapper().readValue(file, Record.class).withRawRecord(sourceRecord.getRawRecord()).withParsedRecord(sourceRecord.getParsedRecord()).withExternalIdsHolder(sourceRecord.getExternalIdsHolder()).withAdditionalInfo(sourceRecord.getAdditionalInfo());
if (Objects.nonNull(sourceRecord.getMetadata())) {
record.withMetadata(sourceRecord.getMetadata());
}
Optional<ErrorRecord> errorRecord = errorRecords.stream().filter(er -> er.getId().equals(record.getId())).findAny();
if (errorRecord.isPresent()) {
record.withErrorRecord(errorRecord.get());
}
return Optional.of(record);
} catch (IOException e) {
e.printStackTrace();
}
}
return Optional.empty();
}
Aggregations