Skip to main content

Mapper

Struct Mapper 

Source
pub struct Mapper { /* private fields */ }
Expand description

High-level facade for EDIFACT-to-BO4E conversion.

Wraps DataBundle loading with lazy/eager initialization, and provides convenient accessors for ConversionService and MappingEngine instances.

§Example

use edifact_mapper::{DataDir, Mapper};

let mapper = Mapper::from_data_dir(
    DataDir::path("/opt/edifact/data").eager(&["FV2504"])
)?;

let cs = mapper.conversion_service("FV2504", "UTILMD_Strom")?;
let engine = mapper.engine("FV2504", "UTILMD_Strom", "55001")?;

Implementations§

Source§

impl Mapper

Source

pub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>

Create a new Mapper from a DataDir configuration.

Any format versions marked as eager are loaded immediately. All others are loaded lazily on first access.

Source

pub fn conversion_service( &self, fv: &str, variant: &str, ) -> Result<ConversionService, MapperError>

Get a ConversionService for the given format version and variant.

The service can tokenize EDIFACT input and assemble it into a MIG tree.

Source

pub fn engine( &self, fv: &str, variant: &str, pid: &str, ) -> Result<MappingEngine, MapperError>

Get a MappingEngine for a specific PID within a format version and variant.

The engine can convert between assembled MIG trees and BO4E JSON.

Source

pub fn validate_pid( &self, json: &Value, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>

Validate a BO4E JSON object against PID requirements.

Returns a list of validation errors. Empty list = valid. The json should be the transaction-level stammdaten (the entity map).

Source

pub fn validate_pid_struct( &self, value: &impl Serialize, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>

Validate a typed BO4E struct against PID requirements.

Convenience wrapper that serializes the struct to JSON first. Works with any Pid*Interchange or Pid*MessageStammdaten type.

§Example
let interchange = build_55001_interchange();
let errors = mapper.validate_pid_struct(&interchange, "FV2504", "UTILMD_Strom", "55001")?;
assert!(errors.is_empty(), "Errors:\n{}", ValidationReport(errors));
Source

pub fn validate_pid_with_conditions( &self, json: &Value, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>

Validate with AHB condition awareness.

Reverse-maps the JSON to EDIFACT segments, evaluates AHB conditions, and reports fields as required/optional based on the actual data present.

Falls back to basic validation (without conditions) if no condition evaluator is available for the given variant/format version combination.

Source

pub fn to_edifact( &self, msg_stammdaten: &Value, tx_stammdaten: &[Value], fv: &str, variant: &str, pid: &str, ) -> Result<String, MapperError>

Convert BO4E JSON back to an EDIFACT string.

Takes message-level stammdaten, a slice of per-transaction stammdaten, and produces an EDIFACT message body (UNH through UNT content segments, without UNB/UNZ interchange envelope).

§Arguments
  • msg_stammdaten — message-level entities (e.g., Marktteilnehmer from SG2)
  • tx_stammdaten — per-transaction entities (one per transaction/SG4 instance)
  • fv — format version (e.g., “FV2504”)
  • variant — message variant (e.g., “UTILMD_Strom”)
  • pid — Pruefidentifikator (e.g., “55001”)
§Example
let edifact = mapper.to_edifact(
    &msg_json,
    &[tx_json],
    "FV2504",
    "UTILMD_Strom",
    "55001",
)?;
Source

pub fn to_edifact_struct( &self, nachricht: &impl Serialize, fv: &str, variant: &str, pid: &str, ) -> Result<String, MapperError>

Convert a typed BO4E struct to an EDIFACT string.

Convenience wrapper that serializes the struct to JSON first. The struct should serialize to the Nachricht shape: { "stammdaten": {...}, "transaktionen": [{...}] }

Source

pub fn association_code( &self, fv: &str, variant: &str, ) -> Result<String, MapperError>

Get the UNH association code for a variant (e.g., "S2.1", "2.4c").

This is the version string from the MIG schema, used as the last component of the UNH S009 composite: UTILMD:D:11A:UN:S2.1.

§Example
let code = mapper.association_code("FV2604", "UTILMD_Strom")?;
assert_eq!(code, "S2.1");
Source

pub fn message_metadata( &self, fv: &str, variant: &str, ) -> Result<MessageMetadata, MapperError>

Get full message metadata for a variant, including the UNH S009 components.

Returns the message type, UN/EDIFACT release code, and association code needed to construct UNH segments.

Source

pub fn to_edifact_interchange( &self, envelope: &InterchangeEnvelope, messages: &[InterchangeMessage], ) -> Result<String, MapperError>

Convert BO4E JSON to a complete EDIFACT interchange with envelope segments.

Produces a full interchange including UNA, UNB, UNH, message body, UNT, and UNZ.

§Example
let edifact = mapper.to_edifact_interchange(
    &InterchangeEnvelope {
        sender: EdifactParty::bdew("9900000000003"),
        receiver: EdifactParty::bdew("9900000000001"),
        interchange_ref: "REF001".to_string(),
    },
    &[InterchangeMessage {
        message_ref: "MSG001".to_string(),
        msg_stammdaten: serde_json::json!({"marktteilnehmer": []}),
        tx_stammdaten: vec![serde_json::json!({"prozessdaten": {"pruefidentifikator": "55001"}})],
        fv: "FV2604".to_string(),
        variant: "UTILMD_Strom".to_string(),
        pid: "55001".to_string(),
    }],
)?;
assert!(edifact.starts_with("UNA:+.? '"));
Source

pub fn loaded_format_versions(&self) -> Vec<String>

List all format versions currently loaded in memory.

Source

pub fn variants(&self, fv: &str) -> Result<Vec<String>, MapperError>

List all variants available in a format version’s bundle.

Loads the bundle if not already loaded.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.