Skip to content

Commit

Permalink
MODDINV-1071: Extended Authority Mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ShmElena committed Aug 31, 2024
1 parent 8e019f9 commit 8fcd923
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/org/folio/inventory/config/PropertiesReader.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,7 +163,9 @@ private Future<Authority> 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<Authority> recordMapper = RecordMapperBuilder.buildMapper(sourceRecordType().value());
RecordMapper<Authority> 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);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
authorities-extended: false
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -112,6 +119,15 @@ public class UpdateAuthorityEventHandlerTest {

private UpdateAuthorityEventHandler eventHandler;

public UpdateAuthorityEventHandlerTest(String propertyValue) {
this.propertyValue = propertyValue;
}

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{{"true"}, {"false"}});
}

@Before
public void setUp() throws IOException {
MockitoAnnotations.openMocks(this);
Expand All @@ -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
Expand Down

0 comments on commit 8fcd923

Please sign in to comment.