Skip to content

MODEXPW-638 - Resolve PO and PO line custom fields in the order email export - #749

Open
markusweigelt wants to merge 8 commits into
masterfrom
MODEXPW-638
Open

MODEXPW-638 - Resolve PO and PO line custom fields in the order email export#749
markusweigelt wants to merge 8 commits into
masterfrom
MODEXPW-638

Conversation

@markusweigelt

Copy link
Copy Markdown
Contributor

MODEXPW-638 - Resolve PO and PO line custom fields in the order email export

Purpose

Order email templates could not reference PO / PO-line custom fields. The records carry them only as a raw refId → value map, where selects store bare option-ids (opt_3) — unusable in a template, since neither the field's display name nor the option's label is present. This makes custom fields available as resolved tokens (order.customFields.<refId> / orderLine.customFields.<refId>) with names and option labels filled in.

Approach

  • Context mappingOrderEmailContextMapper feeds the raw maps from the purchase order and each PO line through the new CustomFieldsService, which pairs values with their definitions: select option-ids become { id, label }, checkboxes stay boolean, textbox/date/number become strings, multi-value fields land in values[]. Hidden fields (visible: false), unknown refIds and null values are dropped, so templates never see unresolved tokens.
  • DefinitionsCustomFieldDefinitionService fetches and caches definitions per entityType (purchase_order, po_line), so a job makes at most two calls. Values themselves ride the existing /purchase-orders + /po-lines fetch: no extra HTTP per order.
  • RoutingOrdersStorageModuleIdResolver derives the versioned mod-orders-storage module id per tenant from the entitlements API (scoping cross-tenant responses via the tenant name) and CustomFieldsClient sends it as X-Okapi-Module-Id. The definitions cache is tenant-aware.
  • Graceful degradation — when the interface is absent or the lookup fails, the definitions lookup returns empty and the email is still sent, just without custom-field tokens.
  • Permissioncustom-fields.collection.get added to the module's modulePermissions.
  • Docs — README's OrderEmailContext tree, the null/empty policy note and the example payload document the customFields shape for template authors.

Depends on

folio-org/folio-export-common#112

Turn the raw refId-to-value maps on purchase orders and PO lines into
template-ready custom-field tokens, resolving select option-ids to labels
via a cached definitions lookup targeted at mod-orders-storage. Degrade
gracefully to an unresolved-token-free email when the interface is absent.
Point the submodule at the commit that exposes customFields on the
purchase order and PO line schemas, and track branch MODEXPW-638.
The custom-fields interface is interfaceType:multiple, so the gateway
routes it on the exact versioned module id. Resolve that id per tenant
from entitlements (scoping cross-tenant responses via the tenant name)
instead of a hardcoded value, and make the definitions cache tenant-aware.
# Conflicts:
#	folio-export-common
The custom fields services, clients, DTOs and their tests ended without a
trailing newline, producing "No newline at end of file" markers in every
diff. Whitespace only, no behaviour change.
The merge from master had reset the submodule pointer to a commit without
customFields, so OrderEmailContextMapper no longer compiled. Point it back
at the branch commit that exposes the map on purchase order, composite
purchase order and PO line.
@markusweigelt
markusweigelt requested a review from a team August 6, 2026 16:56
The entry named a permission mod-orders-storage does not define
(orders-storage.custom-fields.collection.get) and sat on the _tenant
handler, which does not cover Kafka-triggered jobs. The permission belongs
to the token minted by mod-data-export-spring.
The lambda held three invocations that could throw, so a failure would not
prove result.put was the source of the UnsupportedOperationException.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant