From b1179d50adb8c2f81950a4031c98c819fdf9968f Mon Sep 17 00:00:00 2001 From: Dmytro Krutii Date: Wed, 17 Jul 2024 14:42:07 +0300 Subject: [PATCH] MODSOURMAN-1200 Find record by match id instead record id --- NEWS.md | 1 + .../org/folio/services/RecordServiceImpl.java | 2 +- .../org/folio/services/RecordServiceTest.java | 83 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 5885b4da9..44e8e189c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java index 1a91b8e99..b47400c15 100644 --- a/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java +++ b/mod-source-record-storage-server/src/main/java/org/folio/services/RecordServiceImpl.java @@ -182,7 +182,7 @@ public Future 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 -> { diff --git a/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java b/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java index a70b68f7c..6de404c4b 100644 --- a/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java +++ b/mod-source-record-storage-server/src/test/java/org/folio/services/RecordServiceTest.java @@ -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();