diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AuthorityUpdateDelegate.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AuthorityUpdateDelegate.java index 1358ae93a..6f6af5698 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AuthorityUpdateDelegate.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AuthorityUpdateDelegate.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger; import org.folio.ActionProfile.FolioRecord; import org.folio.Authority; +import org.folio.AuthorityExtended; import org.folio.inventory.common.Context; import org.folio.inventory.dataimport.exceptions.DataImportException; import org.folio.inventory.dataimport.exceptions.OptimisticLockingException; @@ -109,7 +110,9 @@ private Future mergeRecords(Authority existingRecord, Authority mappe mappedRecord.setId(existingRecord.getId()); mappedRecord.setVersion(existingRecord.getVersion()); JsonObject mapped = JsonObject.mapFrom(mappedRecord); - Authority mergedAuthorityRecord = mapped.mapTo(Authority.class); + Authority mergedAuthorityRecord = getIsAuthorityExtended() + ? mapped.mapTo(AuthorityExtended.class) + : mapped.mapTo(Authority.class); mergedAuthorityRecord.setSource(Authority.Source.MARC); return Future.succeededFuture(mergedAuthorityRecord); } catch (Exception e) { diff --git a/src/test/java/org/folio/inventory/dataimport/handlers/actions/UpdateAuthorityEventHandlerTest.java b/src/test/java/org/folio/inventory/dataimport/handlers/actions/UpdateAuthorityEventHandlerTest.java index b4961c753..82fe38bf9 100644 --- a/src/test/java/org/folio/inventory/dataimport/handlers/actions/UpdateAuthorityEventHandlerTest.java +++ b/src/test/java/org/folio/inventory/dataimport/handlers/actions/UpdateAuthorityEventHandlerTest.java @@ -11,6 +11,8 @@ import io.vertx.core.json.JsonObject; import java.util.Arrays; import java.util.Collection; +import java.util.List; +import java.util.Map; import org.folio.ActionProfile; import org.folio.Authority; import org.folio.DataImportEventPayload; @@ -80,6 +82,7 @@ public class UpdateAuthorityEventHandlerTest { private static final String MAPPING_RULES_PATH = "src/test/resources/handlers/marc-authority-rules.json"; private static final String PARSED_AUTHORITY_RECORD = "src/test/resources/marc/authority/parsed-authority-record.json"; + private static final String PARSED_AUTHORITY_EXTENDED_RECORD = "src/test/resources/marc/authority/parsed-authority-extended-record.json"; private static final String MAPPING_METADATA_URL = "/mapping-metadata"; private final boolean isAuthorityExtended; @@ -408,4 +411,39 @@ public void shouldNotProcessEventIfOLErrorExist() throws IOException, ExecutionE CompletableFuture future = eventHandler.handle(dataImportEventPayload); future.get(5, TimeUnit.SECONDS); } + + @Test + public void shouldProcessAuthorityExtendedEvent() throws IOException, InterruptedException, ExecutionException, TimeoutException { + AbstractAuthorityEventHandler.setAuthorityExtendedMode(true); + when(storage.getAuthorityRecordCollection(any())).thenReturn(authorityCollection); + when(authorityCollection.findById(anyString())).thenReturn(CompletableFuture.completedFuture(new Authority().withVersion(1))); + + var parsedAuthorityRecord = new JsonObject(TestUtil.readFileFromPath(PARSED_AUTHORITY_EXTENDED_RECORD)); + Record parsedRecord = new Record().withParsedRecord(new ParsedRecord().withContent(parsedAuthorityRecord.encode())); + HashMap context = new HashMap<>(); + context.put(MARC_AUTHORITY.value(), Json.encode(parsedRecord)); + + DataImportEventPayload dataImportEventPayload = new DataImportEventPayload() + .withEventType(DI_INVENTORY_AUTHORITY_MATCHED.value()) + .withJobExecutionId(UUID.randomUUID().toString()) + .withOkapiUrl(mockServer.baseUrl()) + .withContext(context) + .withCurrentNode(profileSnapshotWrapper.getChildSnapshotWrappers().get(0)); + + CompletableFuture future = eventHandler.handle(dataImportEventPayload); + DataImportEventPayload actualDataImportEventPayload = future.get(5, TimeUnit.SECONDS); + + verify(publisher, times(1)).publish(dataImportEventPayload); + + assertEquals(DI_INVENTORY_AUTHORITY_UPDATED.value(), actualDataImportEventPayload.getEventType()); + assertNotNull(actualDataImportEventPayload.getContext().get(AUTHORITY.value())); + JsonObject authority = new JsonObject(actualDataImportEventPayload.getContext().get(AUTHORITY.value())); + assertNotNull(authority.getString("id")); + assertEquals("1", authority.getString("_version")); + assertEquals(List.of("Editor: C. W. Dugmore."), authority.getJsonArray("saftPersonalNameTrunc").getList()); + assertEquals(List.of("e Church history--linkText"), authority.getJsonArray("saftCorporateNameTrunc").getList()); + assertEquals(List.of("Church history", "nga Broader-earlier - 511", "h Some narrower term - 511"), authority.getJsonArray("saftMeetingNameTrunc").getList()); + assertEquals(List.of(Map.of("headingRef", "nga Broader-earlier - 511", "headingType", "meetingNameTrunc")), authority.getJsonArray("saftBroaderTerm").getList()); + assertEquals(List.of(Map.of("headingRef", "h Some narrower term - 511", "headingType", "meetingNameTrunc")), authority.getJsonArray("saftNarrowerTerm").getList()); + } } diff --git a/src/test/resources/marc/authority/parsed-authority-extended-record.json b/src/test/resources/marc/authority/parsed-authority-extended-record.json new file mode 100644 index 000000000..4ecfb1fcf --- /dev/null +++ b/src/test/resources/marc/authority/parsed-authority-extended-record.json @@ -0,0 +1,643 @@ +{ + "leader": "01012cz a2200241n 4500", + "fields": [ + { + "001": "1000649" + }, + { + "005": "20171119085041.0" + }, + { + "008": "201001 n acanaaabn n aaa d" + }, + { + "010": { + "subfields": [ + { + "a": "n 58020553 " + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "024": { + "subfields": [ + { + "a": "0022-0469" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "035": { + "subfields": [ + { + "a": "(CStRLIN)NYCX1604275S" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "100": { + "subfields": [ + { + "a": "Eimermacher, Karl" + }, + { + "d": "CtY" + }, + { + "d": "MBTI" + }, + { + "d": "CtY" + }, + { + "d": "MBTI" + }, + { + "d": "NIC" + }, + { + "d": "CStRLIN" + }, + { + "t": "NIC" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "110": { + "subfields": [ + { + "a": "BR140" + }, + { + "t": ".J6" + } + ], + "ind1": "0", + "ind2": " " + } + }, + { + "111": { + "subfields": [ + { + "t": "270.05" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "130": { + "subfields": [ + { + "a": "The Journal of ecclesiastical history" + }, + { + "v": "linkText" + } + ], + "ind1": "0", + "ind2": "4" + } + }, + { + "150": { + "subfields": [ + { + "a": "The Journal of ecclesiastical history." + } + ], + "ind1": "0", + "ind2": "4" + } + }, + { + "151": { + "subfields": [ + { + "a": "London," + }, + { + "b": "Cambridge University Press [etc.]" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "155": { + "subfields": [ + { + "a": "32 East 57th St., New York, 10022" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "375": { + "subfields": [ + { + "a": "male" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "377": { + "subfields": [ + { + "a": "ger" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "400": { + "subfields": [ + { + "a": "v." + }, + { + "t": "25 cm." + } + ], + "ind1": "1", + "ind2": " " + } + }, + { + "410": { + "subfields": [ + { + "a": "Quarterly," + }, + { + "t": "1970-" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "411": { + "subfields": [ + { + "a": "Semiannual," + }, + { + "t": "1950-69" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "430": { + "subfields": [ + { + "a": "v. 1- Apr. 1950-" + } + ], + "ind1": "0", + "ind2": " " + } + }, + { + "430": { + "subfields": [ + { + "w": "g" + }, + { + "a": "History," + }, + { + "b": "1950-" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "450": { + "subfields": [ + { + "a": "note$a" + }, + { + "u": "note$u" + }, + { + "3": "note$3" + }, + { + "5": "note$5" + }, + { + "6": "note$6" + }, + { + "8": "note$8" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "450": { + "subfields": [ + { + "w": "a" + }, + { + "a": "note$aa" + }, + { + "b": "note$bb" + }, + { + "3": "note$2" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "451": { + "subfields": [ + { + "a": "note$a" + }, + { + "b": "note$b" + }, + { + "c": "note$c" + }, + { + "d": "note$d" + }, + { + "e": "note$e" + }, + { + "3": "note$3" + }, + { + "5": "note$5" + }, + { + "6": "note$6" + }, + { + "8": "note$8" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "455": { + "subfields": [ + { + "a": "note$a" + }, + { + "b": "note$b" + }, + { + "c": "note$c" + }, + { + "d": "note$d" + }, + { + "e": "note$e" + }, + { + "f": "note$f" + }, + { + "h": "note$h" + }, + { + "i": "note$i" + }, + { + "j": "note$j" + }, + { + "k": "note$k" + }, + { + "l": "note$l" + }, + { + "n": "note$n" + }, + { + "o": "note$o" + }, + { + "u": "note$u" + }, + { + "x": "note$x" + }, + { + "z": "note$z" + }, + { + "2": "note$2" + }, + { + "3": "note$3" + }, + { + "5": "note$5" + }, + { + "8": "note$8" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "455": { + "subfields": [ + { + "w": "bh" + }, + { + "v": "Later-narrower - 455" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "455": { + "subfields": [ + { + "w": "a" + }, + { + "i": "Earlier" + }, + { + "x": "- 455" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "500": { + "subfields": [ + { + "t": "Editor: C. W. Dugmore." + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "510": { + "subfields": [ + { + "w": "e" + }, + { + "t": "Church history" + }, + { + "x": "linkText" + } + ], + "ind1": " ", + "ind2": "0" + } + }, + { + "511": { + "subfields": [ + { + "t": "Church history" + }, + { + "2": "fast" + }, + { + "0": "(OCoLC)fst00860740" + } + ], + "ind1": " ", + "ind2": "7" + } + }, + { + "511": { + "subfields": [ + { + "w": "nga" + }, + { + "t": "Broader-earlier" + }, + { + "a": "- 511" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "530": { + "subfields": [ + { + "w": "b" + }, + { + "a": "Periodicals" + }, + { + "2": "fast" + }, + { + "0": "(OCoLC)fst01411641" + }, + { + "x": "linkText" + } + ], + "ind1": " ", + "ind2": "7" + } + }, + { + "511": { + "subfields": [ + { + "w": "h" + }, + { + "a": "Some" + }, + { + "q": "narrower" + }, + { + "c": "term" + }, + { + "d": "- 511" + } + ], + "ind1": " ", + "ind2": " " + } + }, + { + "550": { + "subfields": [ + { + "w": "a" + }, + { + "k": "Dugmore, C. W." + }, + { + "q": "(Clifford William)," + }, + { + "e": "ed." + }, + { + "z": "linkText" + } + ], + "ind1": "1", + "ind2": " " + } + }, + { + "551": { + "subfields": [ + { + "a": "callNumber" + }, + { + "k": "callNumberPrefix" + }, + { + "h": "callNumber1" + }, + { + "i": "callNumber2" + }, + { + "m": "callNumberSuffix" + }, + { + "t": "copyNumber" + } + ], + "ind1": "0", + "ind2": "3" + } + }, + { + "555": { + "subfields": [ + { + "i": "Narrator:" + }, + { + "u": "uri" + }, + { + "y": "linkText" + }, + { + "3": "materialsSpecification" + }, + { + "z": "publicNote" + }, + { + "0": "http://some/url" + } + ], + "ind1": "0", + "ind2": "3" + } + }, + { + "551": { + "subfields": [ + { + "w": "a" + }, + { + "a": "Earlier" + }, + { + "g": "- 551" + }, + { + "i": "Successor:" + }, + { + "4": "https://some/url" + } + ], + "ind1": "0", + "ind2": " " + } + }, + { + "999": { + "ind1": "f", + "ind2": "f", + "subfields": [ + { + "i": "b90cb1bc-601f-45d7-b99e-b11efd281dcd" + } + ] + } + } + ] +}