From 8fcd92367de5ee779508e160e1ccd80bb00dbcee Mon Sep 17 00:00:00 2001 From: ElenaShm Date: Sat, 31 Aug 2024 15:21:11 +0300 Subject: [PATCH] MODDINV-1071: Extended Authority Mapping --- NEWS.md | 1 + README.MD | 12 +++++ .../inventory/config/PropertiesReader.java | 47 +++++++++++++++++++ .../AbstractAuthorityEventHandler.java | 6 ++- src/main/resources/application.yaml | 1 + .../UpdateAuthorityEventHandlerTest.java | 25 +++++++++- 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/folio/inventory/config/PropertiesReader.java create mode 100644 src/main/resources/application.yaml diff --git a/NEWS.md b/NEWS.md index bf365f805..ebb154b4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,7 @@ * Disallow updating ownership of boundwith item [MODINV-1052](https://folio-org.atlassian.net/browse/MODINV-1052) * InstanceIngress update events consumption [MODINV-1008](https://folio-org.atlassian.net/browse/MODINV-1008) * Apply new date type fields to instance schema [MODINV-1067](https://folio-org.atlassian.net/browse/MODINV-1067) +* Extend Authority with Additional fields [MODINV-1071](https://folio-org.atlassian.net/browse/MODINV-1071) ## 20.2.0 2023-03-20 * Inventory cannot process Holdings with virtual fields ([MODINV-941](https://issues.folio.org/browse/MODINV-941)) diff --git a/README.MD b/README.MD index 71fa0e31b..85ec6c9a4 100644 --- a/README.MD +++ b/README.MD @@ -129,6 +129,18 @@ After setup, it is good to check logs in all related modules for errors. * DI_SRS_MARC_BIB_RECORD_MODIFIED_PARTITIONS Default value for all partitions is 1 +## Properties + +`authorities-extended` property enables extended mapping for Authorities to support advanced references classification in 4xx-5xx fields: +* broader terms (`$wg` tag) +* narrower terms (`$wh` tag) +* earlier headings (`$wa` tag) +* later headings (`$wb` tag) + +Default value for `authorities-extended` is `false`. +The mapping itself is implemented in [data-import-processing-core](https://github.com/folio-org/data-import-processing-core). + + # Making Requests These modules provide HTTP based APIs rather than any UI themselves. diff --git a/src/main/java/org/folio/inventory/config/PropertiesReader.java b/src/main/java/org/folio/inventory/config/PropertiesReader.java new file mode 100644 index 000000000..f196a3427 --- /dev/null +++ b/src/main/java/org/folio/inventory/config/PropertiesReader.java @@ -0,0 +1,47 @@ +package org.folio.inventory.config; + + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class PropertiesReader { + + private static final String PROPERTIES_FILE = "/application.yaml"; + + protected static final Logger LOGGER = LogManager.getLogger( + PropertiesReader.class); + private static final Properties properties = new Properties(); + + static { + loadProperties(); + } + + private PropertiesReader() { + } + + private static void loadProperties() { + try (InputStream inputStream = PropertiesReader.class.getResourceAsStream( + PROPERTIES_FILE)) { + properties.load(inputStream); + } catch (IOException e) { + LOGGER.error("Couldn't load application configuration file", e); + } + } + + public static boolean getPropertyAsBoolean(String key) { + String value = properties.getProperty(key); + return Boolean.parseBoolean(value); + } + + public static void setProperty(String key, String value) { + properties.setProperty(key, value); + } + + public static void clearProperties() { + properties.clear(); + loadProperties(); + } +} diff --git a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java index 12be75fd7..92dc32a20 100644 --- a/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java +++ b/src/main/java/org/folio/inventory/dataimport/handlers/actions/AbstractAuthorityEventHandler.java @@ -21,11 +21,13 @@ import org.apache.logging.log4j.Logger; import org.folio.ActionProfile; +import org.folio.ActionProfile.FolioRecord; import org.folio.Authority; import org.folio.DataImportEventPayload; import org.folio.MappingMetadataDto; import org.folio.MappingProfile; import org.folio.inventory.common.Context; +import org.folio.inventory.config.PropertiesReader; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.domain.AuthorityRecordCollection; import org.folio.inventory.storage.Storage; @@ -161,7 +163,9 @@ private Future mapAuthority(DataImportEventPayload payload, MappingMe var mappingParameters = Json.decodeValue(mappingMetadata.getMappingParams(), MappingParameters.class); var parsedRecord = new JsonObject((String) new JsonObject(payload.getContext().get(sourceRecordType().value())) .mapTo(Record.class).getParsedRecord().getContent()); - RecordMapper recordMapper = RecordMapperBuilder.buildMapper(sourceRecordType().value()); + RecordMapper recordMapper = PropertiesReader.getPropertyAsBoolean("authorities-extended") + ? RecordMapperBuilder.buildMapper(FolioRecord.MARC_AUTHORITY_EXTENDED.value()) + : RecordMapperBuilder.buildMapper(sourceRecordType().value()); var authority = recordMapper.mapRecord(parsedRecord, mappingParameters, mappingRules); authority.setSource(Authority.Source.MARC); return Future.succeededFuture(authority); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 000000000..e07fa3083 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1 @@ +authorities-extended: false 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 5cea2d3c4..e2ea909b8 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 @@ -9,6 +9,8 @@ import io.vertx.core.Vertx; import io.vertx.core.json.Json; import io.vertx.core.json.JsonObject; +import java.util.Arrays; +import java.util.Collection; import org.folio.ActionProfile; import org.folio.Authority; import org.folio.DataImportEventPayload; @@ -17,6 +19,7 @@ import org.folio.inventory.TestUtil; import org.folio.inventory.common.domain.Failure; import org.folio.inventory.common.domain.Success; +import org.folio.inventory.config.PropertiesReader; import org.folio.inventory.dataimport.cache.MappingMetadataCache; import org.folio.inventory.domain.AuthorityRecordCollection; import org.folio.inventory.storage.Storage; @@ -28,9 +31,12 @@ import org.folio.rest.jaxrs.model.ParsedRecord; import org.folio.rest.jaxrs.model.ProfileSnapshotWrapper; import org.folio.rest.jaxrs.model.Record; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -70,12 +76,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@RunWith(Parameterized.class) 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 MAPPING_METADATA_URL = "/mapping-metadata"; - + private final String propertyValue; private final Vertx vertx = Vertx.vertx(); @Rule public WireMockRule mockServer = new WireMockRule( @@ -112,6 +119,15 @@ public class UpdateAuthorityEventHandlerTest { private UpdateAuthorityEventHandler eventHandler; + public UpdateAuthorityEventHandlerTest(String propertyValue) { + this.propertyValue = propertyValue; + } + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][]{{"true"}, {"false"}}); + } + @Before public void setUp() throws IOException { MockitoAnnotations.openMocks(this); @@ -130,6 +146,13 @@ public void setUp() throws IOException { .willReturn(WireMock.ok().withBody(Json.encode(new MappingMetadataDto() .withMappingParams(Json.encode(new MappingParameters())) .withMappingRules(mappingRules.encode()))))); + + PropertiesReader.setProperty("authorities-extended", propertyValue); + } + + @After + public void tearDown() { + PropertiesReader.clearProperties(); } @Test