Spike: MODQM-75 - Investigate | MARC Authority record | Implement sequence number generation mechanism for HRIDs


Intro

This page a result of the investigation of organizing Hrid generation for MARC authority records in data-import. A generator needs to follow the requirements listed below:

  • supports a consistent sequence
  • honors what the user enters in Starts with field via Settings > quickMARC > Authorities > HRID handling
  • honors what the user enters in prefix field via Settings > quickMARC > Authorities > HRID handling
  • honors the HRID character limit of 21 [10 character limit for prefix, followed by up to 11 digits]


Approach

There is a similar approach that works already in the mod-inventory-storage. It generates Hrid numbers for Instances, Holdings, and Item records, and can be configured from UI (Settings → Inventory → Hrid handling);

We will place the generator and settings in the mod-source-record-manager.

This is how the configuration will look on UI:

Step 1: Create a table hrid_settings to store settings for the authority record. The table will look like below. 


Step 2: Create a sequencer marc_authority_hrid_sequencer to generate new numbers

CREATE SEQUENCE IF NOT EXISTS ${tenant}_${mymodule}.marc_authority_hrid_sequencer MINVALUE 1 NO MAXVALUE CACHE 1 NO CYCLE;
ALTER SEQUENCE ${tenant}_${mymodule}.marc_authority_hrid_sequencer OWNER TO ${tenant}_${mymodule};
   

Step 3: Create a utility class to work with the sequencer

   The org.folio.services.afterprocessing.HrIdFieldService can be used to work with a sequencer and settings. It should provide a method to get settings, update settings, get the next Hrid number.

   To generate the next Hrid the HrIdFieldService/Dao will make such query "select nextval('marc_authority_hrid_sequencer')";

   To update the existing settings the HrIdFieldService has to validate the incoming settings just to do not receive the number in the wrong format or number that lesser the existing value. After that, the HrIdFieldService has to update the sequencer to switch it to the new number: select setval('marc_authority_hrid_sequencer', <new number>);

The existing class can be taken from Inventory as an example  https://github.com/folio-org/mod-inventory-storage/blob/dde2915c304e8bc489b8d307a1f2a529168bfd06/src/main/java/org/folio/rest/support/HridManager.java


Step 4: Provide a REST API

  The API will be provided by the mod-source-record-manager to retrieve and update existing settings under the interface hrid-settings-storage:

  "GET" : "/hrid-settings-storage/hrid-settings"
"PUT" : "/hrid-settings-storage/hrid-settings"


Step 5: Assign Hrid to the record

   The mod-source-record-manager receives Marc records only in the raw state. Then, the SRM parses records so here the records become in Json format. So, once the records get parsed, we can work with a record like a usual Json, and put HRID to the 001 field. The ChunkProcessingService and ChangeEngineService might be used to work with a parsed record.


NOTE: The new Hrid number will be generated and assigned to each incoming Marc Authority record no matter what the content of a record is.