src.dackar.RCA.cap_integration.cap_adapter

cap_adapter — CAPAdapter Protocol, FileDropCAPAdapter, NoOpCAPAdapter.

Concrete live adapters (MaximoCAPAdapter, SAPPMCAPAdapter) live in separate files and implement the same Protocol. See CAP_INTEGRATION_GUIDE.md for the implementation skeleton.

Attributes

JsonDict

Classes

CAPSubmissionReceipt

Returned by every CAPAdapter.submit() call.

CAPAdapter

Protocol for CAP submission adapters.

FileDropCAPAdapter

Writes the CAPExportPackage as a JSON file to a watched directory.

NoOpCAPAdapter

Silently discards the package. Used in unit tests and CI.

Functions

_utcnow_iso()

_safe_export_filename(export_id)

Return a filesystem-safe stem for CAP export files.

Module Contents

src.dackar.RCA.cap_integration.cap_adapter.JsonDict[source]
src.dackar.RCA.cap_integration.cap_adapter._utcnow_iso()[source]
Return type:

str

src.dackar.RCA.cap_integration.cap_adapter._safe_export_filename(export_id)[source]

Return a filesystem-safe stem for CAP export files.

Parameters:

export_id (str)

Return type:

str

class src.dackar.RCA.cap_integration.cap_adapter.CAPSubmissionReceipt[source]

Returned by every CAPAdapter.submit() call.

receipt_id[source]

Unique ID for this submission attempt.

submitted_at[source]

ISO-8601 UTC timestamp.

adapter[source]

Class name of the adapter that produced this receipt.

export_id[source]

export_id from the CAPExportPackage that was submitted.

cr_numbers[source]

CMMS-assigned corrective action / work order numbers. Empty list for adapters that do not receive synchronous confirmation (e.g. FileDropCAPAdapter).

status[source]

"submitted" — accepted by CMMS synchronously. "pending" — written to drop zone; CMMS import job pending. "partial" — some records submitted, some failed. "failed" — no records submitted. "noop" — NoOpCAPAdapter; nothing was done.

errors[source]

List of per-record error dicts when status is partial or failed.

notes[source]

Free-text adapter notes (e.g. path of the written file).

receipt_id: str[source]
submitted_at: str[source]
adapter: str[source]
export_id: str[source]
cr_numbers: List[str] = [][source]
status: str = 'pending'[source]
errors: List[JsonDict] = [][source]
notes: str | None = None[source]
to_dict()[source]

Return the receipt as a plain JSON-serializable dict.

Returns:

Keys mirror the dataclass attributes; suitable for persisting alongside the CAPExportPackage as the cap_submission_receipt artifact.

Return type:

dict

class src.dackar.RCA.cap_integration.cap_adapter.CAPAdapter[source]

Bases: Protocol

Protocol for CAP submission adapters.

All implementations must be idempotent with respect to package["export_id"]: submitting the same package twice must not create duplicate CMMS records.

submit(package)[source]

Submit a CAPExportPackage to the target CMMS (or file drop zone).

Parameters:

package (JsonDict) – Dict conforming to schemas/cap_export_package.json.

Return type:

CAPSubmissionReceipt

class src.dackar.RCA.cap_integration.cap_adapter.FileDropCAPAdapter(drop_dir)[source]

Writes the CAPExportPackage as a JSON file to a watched directory.

This is the default adapter for dev and pre-live deployments. The plant’s CMMS import job polls the directory and ingests the file asynchronously. Returns a receipt with status="pending" and an empty cr_numbers list — CMMS record numbers are not available at submission time.

Parameters:

drop_dir (str | pathlib.Path) – Directory where export files are written. Created if absent.

drop_dir[source]
submit(package)[source]

Write the package to the drop zone as JSON and return a receipt.

The file is written atomically (to a hidden *.tmp sibling, then os.replace``d into place) so a CMMS import job polling the directory never observes a partially written ``cap_export_*.json file.

Parameters:

package (JsonDict) – Dict conforming to schemas/cap_export_package.json.

Returns:

status="pending" with an empty cr_numbers list; notes holds the written file path.

Return type:

CAPSubmissionReceipt

static _atomic_write_json(file_path, package)[source]

Write package as JSON to file_path via a temp file + os.replace.

Parameters:
  • file_path (pathlib.Path)

  • package (JsonDict)

Return type:

None

class src.dackar.RCA.cap_integration.cap_adapter.NoOpCAPAdapter[source]

Silently discards the package. Used in unit tests and CI.

Returns a receipt with status="noop" and an empty cr_numbers list. Makes no file I/O and has no external dependencies.

submit(package)[source]

Discard the package and return a status="noop" receipt.

Parameters:

package (JsonDict) – Dict conforming to schemas/cap_export_package.json. Only export_id is read; nothing is written.

Returns:

status="noop" with an empty cr_numbers list.

Return type:

CAPSubmissionReceipt