Skip to content

Commit

Permalink
MODSOURMAN-1200 Find record by match id instead record id
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokrutii authored Jul 17, 2024
1 parent 2d06578 commit b1179d5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [MODSOURCE-753](https://folio-org.atlassian.net/browse/MODSOURCE-753) Change SQL query parameters for MARC Search
* [MODSOURCE-773](https://folio-org.atlassian.net/browse/MODSOURCE-773) MARC Search omits suppressed from discovery records in default search
* [MODINV-1044](https://folio-org.atlassian.net/browse/MODINV-1044) Additional Requirements - Update Data Import logic to normalize OCLC 035 values
* [MODSOURMAN-1200](https://folio-org.atlassian.net/browse/MODSOURMAN-1200) Find record by match id on update generation

## 2024-03-20 5.8.0
* [MODSOURCE-733](https://issues.folio.org/browse/MODSOURCE-733) Reduce Memory Allocation of Strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Future<Record> updateRecordGeneration(String matchedId, Record record, St
}
record.setId(UUID.randomUUID().toString());

return recordDao.getRecordById(matchedId, tenantId)
return recordDao.getRecordByMatchedId(matchedId, tenantId)
.map(r -> r.orElseThrow(() -> new NotFoundException(format(RECORD_WITH_GIVEN_MATCHED_ID_NOT_FOUND, matchedId))))
.compose(v -> saveRecord(record, tenantId))
.recover(throwable -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,89 @@ public void shouldUpdateRecordGeneration(TestContext context) {
});
}

@Test
public void shouldUpdateRecordGenerationByMatchId(TestContext context) {
var mock = TestMocks.getMarcBibRecord();
var recordToSave = new Record()
.withId(UUID.randomUUID().toString())
.withSnapshotId(mock.getSnapshotId())
.withRecordType(mock.getRecordType())
.withState(State.ACTUAL)
.withOrder(mock.getOrder())
.withRawRecord(rawRecord)
.withParsedRecord(marcRecord)
.withAdditionalInfo(mock.getAdditionalInfo())
.withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()))
.withMetadata(mock.getMetadata());

var async = context.async();

recordService.saveRecord(recordToSave, TENANT_ID).onComplete(savedRecord -> {
if (savedRecord.failed()) {
context.fail(savedRecord.cause());
}
context.assertNotNull(savedRecord.result().getRawRecord());
context.assertNotNull(savedRecord.result().getParsedRecord());
context.assertEquals(savedRecord.result().getState(), State.ACTUAL);
compareRecords(context, recordToSave, savedRecord.result());

var matchedId = savedRecord.result().getMatchedId();
var snapshot = new Snapshot().withJobExecutionId(UUID.randomUUID().toString())
.withProcessingStartedDate(new Date())
.withStatus(Snapshot.Status.PROCESSING_IN_PROGRESS);

var parsedRecord = new ParsedRecord().withId(UUID.randomUUID().toString())
.withContent(new JsonObject().put("leader", "01542ccm a2200361 4500")
.put("fields", new JsonArray().add(new JsonObject().put("999", new JsonObject()
.put("subfields",
new JsonArray().add(new JsonObject().put("s", matchedId)))
.put("ind1", "f")
.put("ind2", "f")))).encode());

var recordToUpdateGeneration = new Record()
.withId(UUID.randomUUID().toString())
.withSnapshotId(snapshot.getJobExecutionId())
.withRecordType(mock.getRecordType())
.withState(State.ACTUAL)
.withOrder(mock.getOrder())
.withRawRecord(mock.getRawRecord())
.withParsedRecord(parsedRecord)
.withAdditionalInfo(mock.getAdditionalInfo())
.withExternalIdsHolder(new ExternalIdsHolder().withInstanceId(UUID.randomUUID().toString()))
.withMetadata(mock.getMetadata());

SnapshotDaoUtil.save(postgresClientFactory.getQueryExecutor(TENANT_ID), snapshot).onComplete(snapshotSaved -> {
if (snapshotSaved.failed()) {
context.fail(snapshotSaved.cause());
}

recordService.updateRecordGeneration(matchedId, recordToUpdateGeneration, TENANT_ID).onComplete(recordToUpdateGenerationSaved -> {
context.assertTrue(recordToUpdateGenerationSaved.succeeded());
context.assertEquals(recordToUpdateGenerationSaved.result().getMatchedId(), matchedId);
context.assertEquals(recordToUpdateGenerationSaved.result().getGeneration(), 1);
recordDao.getRecordByMatchedId(matchedId, TENANT_ID).onComplete(get -> {
if (get.failed()) {
context.fail(get.cause());
}
context.assertTrue(get.result().isPresent());
context.assertEquals(get.result().get().getGeneration(), 1);
context.assertEquals(get.result().get().getMatchedId(), matchedId);
context.assertNotEquals(get.result().get().getId(), matchedId);
context.assertEquals(get.result().get().getState(), State.ACTUAL);
recordDao.getRecordById(matchedId, TENANT_ID).onComplete(getRecord1 -> {
if (getRecord1.failed()) {
context.fail(get.cause());
}
context.assertTrue(getRecord1.result().isPresent());
context.assertEquals(getRecord1.result().get().getState(), State.OLD);
async.complete();
});
});
});
});
});
}

@Test
public void shouldSaveMarcBibRecordWithMatchedIdFromRecordId(TestContext context) {
Record original = TestMocks.getMarcBibRecord();
Expand Down

0 comments on commit b1179d5

Please sign in to comment.