use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class QuickMarcKafkaHandlerTest method shouldUpdateParsedRecordAndSendRecordUpdatedEvent.
@Test
public void shouldUpdateParsedRecordAndSendRecordUpdatedEvent(TestContext context) throws InterruptedException {
Async async = context.async();
ParsedRecord parsedRecord = record.getParsedRecord();
Future<Record> future = recordService.saveRecord(record, TENANT_ID);
ParsedRecordDto parsedRecordDto = new ParsedRecordDto().withId(record.getMatchedId()).withParsedRecord(new ParsedRecord().withContent(UPDATED_PARSED_RECORD_CONTENT)).withRelatedRecordVersion("1").withRecordType(ParsedRecordDto.RecordType.MARC_BIB);
var payload = new HashMap<String, String>();
payload.put("PARSED_RECORD_DTO", Json.encode(parsedRecordDto));
cluster.send(createRequest(payload));
String observeTopic = formatTopicName(kafkaConfig.getEnvId(), getDefaultNameSpace(), TENANT_ID, QM_SRS_MARC_RECORD_UPDATED.name());
cluster.observeValues(ObserveKeyValues.on(observeTopic, 1).observeFor(30, TimeUnit.SECONDS).build());
future.onComplete(ar -> {
if (ar.failed()) {
context.fail(ar.cause());
}
recordService.getSourceRecordById(record.getMatchedId(), IdType.RECORD, TENANT_ID).onComplete(getNew -> {
if (getNew.failed()) {
context.fail(getNew.cause());
}
context.assertTrue(getNew.result().isPresent());
SourceRecord updatedRecord = getNew.result().get();
context.assertNotEquals(parsedRecord.getId(), updatedRecord.getParsedRecord().getId());
context.assertNotEquals(record.getSnapshotId(), updatedRecord.getSnapshotId());
recordDao.getRecordByCondition(Tables.RECORDS_LB.ID.eq(UUID.fromString(record.getId())), TENANT_ID).onComplete(getOld -> {
if (getOld.failed()) {
context.fail(getOld.cause());
}
context.assertTrue(getOld.result().isPresent());
Record existingRecord = getOld.result().get();
context.assertEquals(State.OLD, existingRecord.getState());
context.assertEquals(0, existingRecord.getGeneration());
context.assertEquals(parsedRecord.getId(), existingRecord.getParsedRecord().getId());
context.assertEquals(parsedRecord.getContent(), existingRecord.getParsedRecord().getContent());
context.assertEquals(record.getSnapshotId(), existingRecord.getSnapshotId());
async.complete();
});
});
});
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordServiceTest method getMarcSourceRecordsByListOfIdsThatAreDeleted.
private void getMarcSourceRecordsByListOfIdsThatAreDeleted(TestContext context, Record.RecordType recordType, RecordType parsedRecordType) {
Async async = context.async();
List<Record> records = TestMocks.getRecords().stream().map(record -> {
Record deletedRecord = new Record().withId(record.getId()).withSnapshotId(record.getSnapshotId()).withMatchedId(record.getMatchedId()).withRecordType(record.getRecordType()).withState(State.DELETED).withGeneration(record.getGeneration()).withOrder(record.getOrder()).withLeaderRecordStatus(record.getLeaderRecordStatus()).withRawRecord(record.getRawRecord()).withParsedRecord(record.getParsedRecord()).withAdditionalInfo(record.getAdditionalInfo()).withExternalIdsHolder(record.getExternalIdsHolder());
if (Objects.nonNull(record.getMetadata())) {
deletedRecord.withMetadata(record.getMetadata());
}
if (Objects.nonNull(record.getErrorRecord())) {
deletedRecord.withErrorRecord(record.getErrorRecord());
}
return deletedRecord;
}).collect(Collectors.toList());
RecordCollection recordCollection = new RecordCollection().withRecords(records).withTotalRecords(records.size());
saveRecords(recordCollection.getRecords()).onComplete(batch -> {
if (batch.failed()) {
context.fail(batch.cause());
}
List<String> ids = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(Record::getMatchedId).collect(Collectors.toList());
recordService.getSourceRecords(ids, IdType.RECORD, parsedRecordType, true, TENANT_ID).onComplete(get -> {
if (get.failed()) {
context.fail(get.cause());
}
List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).collect(Collectors.toList());
get.result().getSourceRecords().sort(comparing(SourceRecord::getRecordId));
context.assertEquals(expected.size(), get.result().getTotalRecords());
compareSourceRecords(context, expected, get.result().getSourceRecords());
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordServiceTest method getMarcSourceRecords.
private void getMarcSourceRecords(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<>();
recordService.getSourceRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID).onComplete(get -> {
if (get.failed()) {
context.fail(get.cause());
}
List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).collect(Collectors.toList());
get.result().getSourceRecords().sort(comparing(SourceRecord::getRecordId));
context.assertEquals(expected.size(), get.result().getTotalRecords());
compareSourceRecords(context, expected, get.result().getSourceRecords());
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordServiceTest method getMarcSourceRecordsBetweenDates.
private void getMarcSourceRecordsBetweenDates(TestContext context, Record.RecordType recordType, RecordType parsedRecordType, OffsetDateTime earliestDate, OffsetDateTime latestDate) {
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 = RECORDS_LB.CREATED_DATE.between(earliestDate, latestDate);
List<OrderField<?>> orderFields = new ArrayList<>();
recordService.getSourceRecords(condition, parsedRecordType, orderFields, 0, 10, TENANT_ID).onComplete(get -> {
if (get.failed()) {
context.fail(get.cause());
}
List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).collect(Collectors.toList());
get.result().getSourceRecords().sort(comparing(SourceRecord::getRecordId));
context.assertEquals(expected.size(), get.result().getTotalRecords());
compareSourceRecords(context, expected, get.result().getSourceRecords());
async.complete();
});
});
}
use of org.folio.rest.jaxrs.model.SourceRecord in project mod-source-record-storage by folio-org.
the class RecordServiceTest method getMarcSourceRecordsByListOfIds.
private void getMarcSourceRecordsByListOfIds(TestContext context, Record.RecordType recordType, RecordType parsedRecordType) {
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());
}
List<String> ids = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(Record::getMatchedId).collect(Collectors.toList());
recordService.getSourceRecords(ids, IdType.RECORD, parsedRecordType, false, TENANT_ID).onComplete(get -> {
if (get.failed()) {
context.fail(get.cause());
}
List<SourceRecord> expected = records.stream().filter(r -> r.getRecordType().equals(recordType)).map(RecordDaoUtil::toSourceRecord).sorted(comparing(SourceRecord::getRecordId)).collect(Collectors.toList());
sortByRecordId(get);
context.assertEquals(expected.size(), get.result().getTotalRecords());
compareSourceRecords(context, expected, get.result().getSourceRecords());
async.complete();
});
});
}
Aggregations