Skip to content

Commit

Permalink
MODDINV-1071: Extended Authority Mapping (#762)
Browse files Browse the repository at this point in the history
* MODDINV-1071: Extended Authority Mapping

* MODDINV-1071: Extended Authority Mapping

* MODDINV-1071: Extended Authority Mapping

* MODDINV-1071: Extended Authority Mapping

* MODDINV-1071: Extended Authority Mapping

---------

Co-authored-by: ElenaShm <[email protected]>
  • Loading branch information
elena-shmygaliova and ShmElena authored Sep 12, 2024
1 parent 41a10ff commit 39ad7d1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
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

`AUTHORITY_EXTENDED` environment variable enables extended mapping for Authority to support advanced references classification in 5xx fields:
* broader terms (`$wg` tag)
* narrower terms (`$wh` tag)
* earlier headings (`$wa` tag)
* later headings (`$wb` tag)

Default value for `AUTHORITY_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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -54,10 +55,13 @@ public abstract class AbstractAuthorityEventHandler implements EventHandler {

private static final String RECORD_ID_HEADER = "recordId";
private static final String CHUNK_ID_HEADER = "chunkId";
public static final String AUTHORITY_EXTENDED = "AUTHORITY_EXTENDED";

private final Storage storage;
private final MappingMetadataCache mappingMetadataCache;

private static boolean isAuthorityExtended = isAuthorityExtendedMode();

protected AbstractAuthorityEventHandler(Storage storage, MappingMetadataCache mappingMetadataCache) {
this.storage = storage;
this.mappingMetadataCache = mappingMetadataCache;
Expand Down Expand Up @@ -161,7 +165,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 = isAuthorityExtended
? 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 Expand Up @@ -215,4 +221,18 @@ private String constructMetaInfoMsg(DataImportEventPayload payload) {
getChunkIdHeader(payload)
);
}

private static boolean isAuthorityExtendedMode() {
return Boolean.parseBoolean(
System.getenv().getOrDefault(AUTHORITY_EXTENDED, "false"));
}

/**
* For test usage only.
*
* @param newIsAuthoritiesExtended New value for the env to set.
*/
public static void setAuthorityExtendedMode(boolean newIsAuthoritiesExtended) {
isAuthorityExtended = newIsAuthoritiesExtended;
}
}
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 @@ -28,9 +30,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,11 +75,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 boolean isAuthorityExtended;

private final Vertx vertx = Vertx.vertx();
@Rule
Expand Down Expand Up @@ -112,6 +119,15 @@ public class UpdateAuthorityEventHandlerTest {

private UpdateAuthorityEventHandler eventHandler;

public UpdateAuthorityEventHandlerTest(boolean isAuthorityExtended) {
this.isAuthorityExtended = isAuthorityExtended;
}

@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())))));

AbstractAuthorityEventHandler.setAuthorityExtendedMode(isAuthorityExtended);
}

@After
public void tearDown() {
AbstractAuthorityEventHandler.setAuthorityExtendedMode(false);
}

@Test
Expand Down

0 comments on commit 39ad7d1

Please sign in to comment.