diff --git a/EDILibrary/EDIHelper.cs b/EDILibrary/EDIHelper.cs index 96c999e..0be5edc 100644 --- a/EDILibrary/EDIHelper.cs +++ b/EDILibrary/EDIHelper.cs @@ -277,7 +277,7 @@ public static string NormalizeEDIHeader(string edi) return $"UNA{DefaultElementDelimiter}{DefaultGroupDelimiter}{DefaultDecimalChar}{DefaultEscapeChar} {DefaultSegmentDelimiter}{message}"; } - public static EDIFileInfo GetEdiFileInfo(string edi) + public static EDIFileInfo GetEdiFileInfo(string edi, bool maskUTILMDX = true) { if (edi == null) { @@ -319,7 +319,7 @@ public static EDIFileInfo GetEdiFileInfo(string edi) }; var version = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[4]; var format = Enum.Parse(unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[0]); - if (format == EdifactFormat.UTILMD) + if (!maskUTILMDX && format == EdifactFormat.UTILMD) { format = version.StartsWith("G") ? EdifactFormat.UTILMDG : version.StartsWith("S") ? EdifactFormat.UTILMDS : format; } diff --git a/EDILibrary/EdiJsonMapper.cs b/EDILibrary/EdiJsonMapper.cs index 4599507..713502a 100644 --- a/EDILibrary/EdiJsonMapper.cs +++ b/EDILibrary/EdiJsonMapper.cs @@ -43,7 +43,7 @@ public async Task ParseToJson(string edi, string packageVersion, string } public async Task ParseToJsonWithTemplates(string edi, EdifactFormatVersion? packageVersion, string ediTemplate, string ediTreeTemplate, string ediJsonTemplate, string includeEmptyValues = null) { - var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length))); + var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length)), false); var ediString = EDIHelper.NormalizeEDIHeader(edi); var templateString = ediTemplate; var loader = new GenericEDILoader(); @@ -90,7 +90,7 @@ public async Task ParseToJsonWithTemplates(string edi, EdifactFormat } public async Task ParseToJsonWithVersion(string edi, EdifactFormatVersion? packageVersion, string includeEmptyValues = null) { - var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length))); + var ediInfo = EDIHelper.GetEdiFileInfo(edi.Substring(0, Math.Min(1000, edi.Length)), false); var treeStringTask = _loader.LoadEDITemplate(ediInfo, "tree"); var templateStringTask = _loader.LoadEDITemplate(ediInfo, "template"); await Task.WhenAll(new List { treeStringTask, templateStringTask }); @@ -131,7 +131,7 @@ public async Task CreateFromJson(string jsonInput, string pid, string fo } public string CreateFromJsonWithTemplates(string jsonInput, string pid, EdifactFormatVersion formatPackage, string ediJsonTemplate, string createTemplate, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false) { - var format = EdifactFormatHelper.FromPruefidentifikator(pid); + var format = EdifactFormatHelper.FromPruefidentifikator(pid, false); var mappingsBody = ediJsonTemplate; @@ -150,7 +150,7 @@ public string CreateFromJsonWithTemplates(string jsonInput, string pid, EdifactF } public async Task CreateFromJson(string jsonInput, string pid, EdifactFormatVersion formatPackage, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false) { - var format = EdifactFormatHelper.FromPruefidentifikator(pid); + var format = EdifactFormatHelper.FromPruefidentifikator(pid, false); string jsonBody = null; try { @@ -214,7 +214,7 @@ public async Task CreateFromJson(string jsonInput, string pid, EdifactFo } public async Task CreateFromEdiJson(string jsonInput, string pid, EdifactFormatVersion formatPackage, TimeZoneInfo localTime, bool convertFromUTC = false) { - var format = EdifactFormatHelper.FromPruefidentifikator(pid); + var format = EdifactFormatHelper.FromPruefidentifikator(pid, false); var mappingsBody = await _loader.LoadJSONTemplate(format, formatPackage.ToLegacyVersionString(), format + ".json"); diff --git a/EDILibrary/EdifactFormatVersion.cs b/EDILibrary/EdifactFormatVersion.cs index 20c4acc..6665c43 100644 --- a/EDILibrary/EdifactFormatVersion.cs +++ b/EDILibrary/EdifactFormatVersion.cs @@ -121,8 +121,9 @@ public static class EdifactFormatHelper /// get fact for a message class ID ("Prüfidentifikator") /// /// prüfidentifikator, e.g. '11042' + /// is true, UTILMD is returned instead of UTILMDG bzw. UTILMDS /// the EdifactFormat, e.g. or throws a NotImplementedException iff EdiFormat was found - public static EdifactFormat FromPruefidentifikator(string pruefidentifikator) + public static EdifactFormat FromPruefidentifikator(string pruefidentifikator, bool maskUTILMDX = true) { if (string.IsNullOrWhiteSpace(pruefidentifikator)) { @@ -133,7 +134,7 @@ public static EdifactFormat FromPruefidentifikator(string pruefidentifikator) { if (pruefidentifikator.StartsWith(((int)ef).ToString())) { - return ef; + return maskUTILMDX && ef is EdifactFormat.UTILMDG or EdifactFormat.UTILMDS ? EdifactFormat.UTILMD : ef; } } diff --git a/EDILibraryTests/EDIHelperTests.cs b/EDILibraryTests/EDIHelperTests.cs index 82f7558..a546431 100644 --- a/EDILibraryTests/EDIHelperTests.cs +++ b/EDILibraryTests/EDIHelperTests.cs @@ -72,7 +72,7 @@ public void TestNormalizeEdiHeader(string input, string expectedResult) "{\"Format\":null}")] // wegen "UNA:+.?" ohne space vor "?" [DataRow( "UNA:+.? 'UNB+UNOC:3+123456789012345:500+123456789:500+210326:1553+WIM00000000901'UNH+WIM00000000901+UTILMD:D:11A:UN:S1.1'BGM+E03+WIM00000000901'DTM+137:202103261553:203'NAD+MS+123456789012345::293'CTA+IC+:Max Mustermann'COM+max@mustermann.de:EM'NAD+MR+123456789::293'IDE+24+WIMP0000000459'DTM+92:20210401:102'DTM+157:20210401:102'STS+7++ZE8'LOC+172+41234567896'RFF+Z13:11116'SEQ+Z01'CCI+Z30++Z06'", - "{\"Format\":\"UTILMDS\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] + "{\"Format\":\"UTILMD\", \"Nachrichtenversion\":\"D\",\"Version\":\"S1.1\", \"Sender\":{\"CodeList\":\"500\",\"ID\":\"123456789012345\"}, \"Freigabenummer\":\"11A\", \"Empfänger\":{\"CodeList\":\"500\",\"ID\":\"123456789\"}, \"ID\":\"WIM00000000901\"}")] public void TestGetEdiFileInfo(string input, string expectedOutput) { diff --git a/EDILibraryTests/EdifactFormatVersionTests.cs b/EDILibraryTests/EdifactFormatVersionTests.cs index fa5c7d6..2bd576d 100644 --- a/EDILibraryTests/EdifactFormatVersionTests.cs +++ b/EDILibraryTests/EdifactFormatVersionTests.cs @@ -26,13 +26,23 @@ public class EdifactFormatVersionTests [DataRow("35002", EdifactFormat.REQOTE)] [DataRow("33001", EdifactFormat.REMADV)] [DataRow("11042", EdifactFormat.UTILMD)] - [DataRow("44001", EdifactFormat.UTILMDG)] - [DataRow("55001", EdifactFormat.UTILMDS)] + [DataRow("44001", EdifactFormat.UTILMD)] + [DataRow("55001", EdifactFormat.UTILMD)] public void TestPruefiToFormat(string pruefi, EdifactFormat expectedFormat) { var actualFormat = EdifactFormatHelper.FromPruefidentifikator(pruefi); Assert.AreEqual(expectedFormat, actualFormat); } + + [TestMethod] + [DataRow("44001", EdifactFormat.UTILMDG)] + [DataRow("55001", EdifactFormat.UTILMDS)] + public void TestPruefiToFormatUnMaskUTILMDX(string pruefi, EdifactFormat expectedFormat) + { + var actualFormat = EdifactFormatHelper.FromPruefidentifikator(pruefi, false); + Assert.AreEqual(expectedFormat, actualFormat); + } + [TestMethod] [Obsolete] public void TestCompare()