src.dackar.RCA.cap_integration.cap_export_serializer¶
cap_export_serializer — CAPExportSerializer.
Maps a completed (and analyst-accepted) rca_card + kg_context into a CAPExportPackage conforming to schemas/cap_export_package.json.
Export is gated on an AnalystOverride record (see schemas/analyst_override.json)
whose writeback_decision == "accept" — the recommendation flag on the card
alone is not treated as proof of acceptance. The resulting export_id is
derived from run_id + the override’s override_id so regenerating the
package for the same accepted decision is idempotent.
FLOC resolution uses Option B (KG-augmented): component CMMS IDs are stored as optional properties on KG element_usage nodes (maximo_floc / sap_equipment_id) and are returned in kg_context.components[]. No additional KG query is required at export time.
The serializer self-validates its output against schemas/cap_export_package.json and raises on any schema violation (fail-closed); deep validation of the input rca_card / kg_context remains the orchestrator’s responsibility.
Attributes¶
Classes¶
Serializes an analyst-accepted RCA card into a CAPExportPackage. |
Functions¶
Return a cached jsonschema validator for the CAPExportPackage schema. |
Module Contents¶
- src.dackar.RCA.cap_integration.cap_export_serializer._output_validator()[source]¶
Return a cached jsonschema validator for the CAPExportPackage schema.
- class src.dackar.RCA.cap_integration.cap_export_serializer.CAPExportSerializer(config=None)[source]¶
Serializes an analyst-accepted RCA card into a CAPExportPackage.
- Parameters:
config (Optional[src.dackar.RCA.cap_integration.cap_config.CAPExportConfig]) –
CAPExportConfigcontrolling target system, field maps, and formatting options. Defaults to Maximo with standard mappings.Usage:: –
serializer = CAPExportSerializer(CAPExportConfig(target_system=”maximo”)) modified_card, override_record = orchestrator.apply_override(…) package = serializer.serialize(
rca_card=modified_card, kg_context=kg_context, run_id=”run-001”, override_record=override_record,
)
- serialize(rca_card, kg_context, run_id, override_record)[source]¶
Build and return a CAPExportPackage dict.
- Parameters:
rca_card (JsonDict) – The analyst-accepted RCA card (post
apply_override()).kg_context (JsonDict) – The kg_context artifact from the same RCA run. Its
asset_idis required, andcomponents[]are used for FLOC/equipment_id resolution viamaximo_floc/sap_equipment_id.run_id (str) – RCA run identifier.
override_record (JsonDict) – The
AnalystOverriderecord returned byapply_override(). Must carrywriteback_decision == "accept"and anoverride_id; both gate the export and seed the stableexport_id.
- Returns:
Conforms to
schemas/cap_export_package.json.- Return type:
dict
- Raises:
ValueError – If the override record does not represent an accepted writeback, if required identifiers (asset_id / event_id / override_id) are missing or inconsistent across artifacts, if an
action_typehas no configured mapping, or if the built package fails schema validation.
- _assert_override_accepted(override_record)[source]¶
Verify the override record represents an accepted writeback and return its
override_id. This is the authoritative acceptance gate.- Parameters:
override_record (JsonDict)
- Return type:
str
- _assert_card_approved(rca_card)[source]¶
Secondary guard: the pipeline must have flagged the card ready.
- Parameters:
rca_card (JsonDict)
- Return type:
None
- _build_floc_index(kg_context)[source]¶
Build component_id → FLOC/equipment_id lookup from kg_context.components[].
Returns a dict where a value of None means the KG property was absent.
- Parameters:
kg_context (JsonDict)
- Return type:
Dict[str, Optional[str]]
- _serialize_action(action, export_id, rca_card, run_id, floc_index)[source]¶
Returns
(cr_record_dict, unresolved_location_token_or_None).
- _build_short_description(description, run_id, action_id)[source]¶
Build a short description guaranteed to be
<= short_description_limit.When enabled, a stable
"[RCA:{run_id}] "trace token is prepended; if the token alone would exceed the limit it is truncated so the return value never overflows the CMMS field.- Parameters:
description (str)
run_id (str)
action_id (str)
- Return type:
str