use of org.folio.dao.util.RecordType 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.dao.util.RecordType in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method streamRecords.
@Override
public Flowable<Record> streamRecords(Condition condition, RecordType recordType, Collection<OrderField<?>> orderFields, int offset, int limit, String tenantId) {
Name prt = name(recordType.getTableName());
String sql = DSL.select(getAllRecordFields(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).leftJoin(RAW_RECORDS_LB).on(RECORDS_LB.ID.eq(RAW_RECORDS_LB.ID)).leftJoin(ERROR_RECORDS_LB).on(RECORDS_LB.ID.eq(ERROR_RECORDS_LB.ID)).where(condition.and(recordType.getRecordImplicitCondition())).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::toRecord)).doAfterTerminate(tx::commit)));
}
use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method insertOrUpdateParsedRecord.
private Future<ParsedRecord> insertOrUpdateParsedRecord(ReactiveClassicGenericQueryExecutor txQE, Record record) {
try {
// attempt to format record to validate
RecordType recordType = toRecordType(record.getRecordType().name());
recordType.formatRecord(record);
return ParsedRecordDaoUtil.save(txQE, record.getParsedRecord(), ParsedRecordDaoUtil.toRecordType(record)).map(parsedRecord -> {
record.withLeaderRecordStatus(ParsedRecordDaoUtil.getLeaderStatus(record.getParsedRecord()));
return parsedRecord;
});
} catch (Exception e) {
LOG.error("Couldn't format {} record", record.getRecordType(), e);
record.withErrorRecord(new ErrorRecord().withId(record.getId()).withDescription(e.getMessage()).withContent(record.getParsedRecord().getContent()));
record.withParsedRecord(null).withLeaderRecordStatus(null);
return Future.succeededFuture(null);
}
}
use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.
the class RecordServiceImpl method formatMarcRecord.
private Record formatMarcRecord(Record record) {
try {
RecordType recordType = toRecordType(record.getRecordType().name());
recordType.formatRecord(record);
} catch (Exception e) {
LOG.error("Couldn't format {} record", record.getRecordType(), e);
}
return record;
}
use of org.folio.dao.util.RecordType in project mod-source-record-storage by folio-org.
the class RecordServiceTest method deleteMarcRecordsBySnapshotId.
private void deleteMarcRecordsBySnapshotId(TestContext context, String snapshotId, RecordType parsedRecordType, Record.RecordType recordType) {
Async async = context.async();
List<Record> original = TestMocks.getRecords();
RecordCollection recordCollection = new RecordCollection().withRecords(original).withTotalRecords(original.size());
saveRecords(recordCollection.getRecords()).onComplete(batch -> {
if (batch.failed()) {
context.fail(batch.cause());
}
Condition condition = RECORDS_LB.SNAPSHOT_ID.eq(UUID.fromString(snapshotId));
List<OrderField<?>> orderFields = new ArrayList<>();
recordDao.getRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID).onComplete(getBefore -> {
if (getBefore.failed()) {
context.fail(getBefore.cause());
}
int expected = (int) original.stream().filter(r -> r.getRecordType().equals(recordType)).filter(record -> record.getSnapshotId().equals(snapshotId)).count();
context.assertTrue(expected > 0);
context.assertEquals(expected, getBefore.result().getTotalRecords());
recordService.deleteRecordsBySnapshotId(snapshotId, TENANT_ID).onComplete(delete -> {
if (delete.failed()) {
context.fail(delete.cause());
}
context.assertTrue(delete.result());
recordDao.getRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID).onComplete(getAfter -> {
if (getAfter.failed()) {
context.fail(getAfter.cause());
}
context.assertEquals(0, getAfter.result().getTotalRecords());
SnapshotDaoUtil.findById(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshotId).onComplete(getSnapshot -> {
if (getSnapshot.failed()) {
context.fail(getSnapshot.cause());
}
context.assertFalse(getSnapshot.result().isPresent());
async.complete();
});
});
});
});
});
}
Aggregations