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
impl Mapper
Sourcepub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>
pub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>
Sourcepub fn conversion_service(
&self,
fv: &str,
variant: &str,
) -> Result<ConversionService, MapperError>
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.
Sourcepub fn engine(
&self,
fv: &str,
variant: &str,
pid: &str,
) -> Result<MappingEngine, MapperError>
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.
Sourcepub fn validate_pid(
&self,
json: &Value,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
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).
Sourcepub fn validate_pid_struct(
&self,
value: &impl Serialize,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
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));Sourcepub fn validate_pid_with_conditions(
&self,
json: &Value,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
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.
Sourcepub fn to_edifact(
&self,
msg_stammdaten: &Value,
tx_stammdaten: &[Value],
fv: &str,
variant: &str,
pid: &str,
) -> Result<String, MapperError>
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",
)?;Sourcepub fn to_edifact_struct(
&self,
nachricht: &impl Serialize,
fv: &str,
variant: &str,
pid: &str,
) -> Result<String, MapperError>
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": [{...}] }
Sourcepub fn association_code(
&self,
fv: &str,
variant: &str,
) -> Result<String, MapperError>
pub fn association_code( &self, fv: &str, variant: &str, ) -> Result<String, MapperError>
Sourcepub fn message_metadata(
&self,
fv: &str,
variant: &str,
) -> Result<MessageMetadata, MapperError>
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.
Sourcepub fn to_edifact_interchange(
&self,
envelope: &InterchangeEnvelope,
messages: &[InterchangeMessage],
) -> Result<String, MapperError>
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:+.? '"));Sourcepub fn loaded_format_versions(&self) -> Vec<String>
pub fn loaded_format_versions(&self) -> Vec<String>
List all format versions currently loaded in memory.