Inventory PATCH implementation [Draft]
Introduction
The inventory is expected to support patching of entities (instances, holdings, items).
Implementing PATCH is required on two levels: the business logic layer (inventory) and the storage layer (inventory-storage). These implementations are independent. The need to support PATCH at the business logic level is related to additional operations performed on related entities during the update of a primary entity (instance, item, or holding).
API
To update only part of an entity, reduce traffic, and avoid overwriting the entire object, a PATCH request should contain only the fields that need to be modified. Existing entity schemas can be reused for this purpose, but the requests must define only the fields that are subject to update, for example, instance:
{
"modeOfIssuanceId": "068b5344-e2a6-40df-9186-1829e13cd344",
"catalogedDate": "2023-12-27",
"previouslyHeld": false,
"natureOfContentTermIds": [
"44cd89f3-2e76-469f-a955-cc57cb9e0395"
]
}Approach
mod-inventory
PATCH endpoints implementation
mod-inventory-storage
RMB supports record patching in the sense that it allows updating a single field via a method https://github.com/folio-org/raml-module-builder/blob/d45ce1a8c36b5a5fa358094337637ab59a7cd9a4/domain-models-runtime/src/main/java/org/folio/rest/persist/Conn.java#L713 . Therefore, to support patching at the storage level, one needs to implement logic that populate UpdateSection https://github.com/folio-org/raml-module-builder/blob/d45ce1a8c36b5a5fa358094337637ab59a7cd9a4/domain-models-runtime/src/main/java/org/folio/rest/persist/Criteria/UpdateSection.java#L13 based on content of PATCH request and calls method:
public void update(String table, UpdateSection section, Criterion when, boolean returnUpdatedIds,
Handler<AsyncResult<RowSet<Row>>> replyHandler)Risks
Performance degradation of the PATCH request at the business module level (mod-inventory) is caused by the need to retrieve the original entity and perform entity merging.
Although the same permission will be used for both PUT and PATCH methods, this should not lead to any security issues, since the logical purpose of both methods is to update an entity — either fully or partially.