Skip to content

Commit

Permalink
DEV-36539 Fix UTILMD format (#130)
Browse files Browse the repository at this point in the history
* Fix UTILMD format

* dotnet-format
  • Loading branch information
TobiasNaethLynqtech authored Sep 26, 2023
1 parent 4995044 commit 4733c81
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions EDILibrary/EDIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -319,7 +319,7 @@ public static EDIFileInfo GetEdiFileInfo(string edi)
};
var version = unhParts[2].Split(specialChars.ElementDelimiter.ToCharArray())[4];
var format = Enum.Parse<EdifactFormat>(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;
}
Expand Down
10 changes: 5 additions & 5 deletions EDILibrary/EdiJsonMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<string> ParseToJson(string edi, string packageVersion, string
}
public async Task<JsonResult> ParseToJsonWithTemplates(string edi, EdifactFormatVersion? packageVersion, string ediTemplate, string ediTreeTemplate, string ediJsonTemplate, string includeEmptyValues = null)

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 44 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
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();
Expand Down Expand Up @@ -90,7 +90,7 @@ public async Task<JsonResult> ParseToJsonWithTemplates(string edi, EdifactFormat
}
public async Task<JsonResult> 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<Task> { treeStringTask, templateStringTask });
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task<string> 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)

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 132 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var format = EdifactFormatHelper.FromPruefidentifikator(pid);
var format = EdifactFormatHelper.FromPruefidentifikator(pid, false);

var mappingsBody = ediJsonTemplate;

Expand All @@ -150,7 +150,7 @@ public string CreateFromJsonWithTemplates(string jsonInput, string pid, EdifactF
}
public async Task<string> CreateFromJson(string jsonInput, string pid, EdifactFormatVersion formatPackage, TimeZoneInfo localTime, MAUS.Anwendungshandbuch? ahb, bool convertFromUTC = false)

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (7.0.100)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / unittest (6.0.201)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 151 in EDILibrary/EdiJsonMapper.cs

View workflow job for this annotation

GitHub Actions / coverage

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var format = EdifactFormatHelper.FromPruefidentifikator(pid);
var format = EdifactFormatHelper.FromPruefidentifikator(pid, false);
string jsonBody = null;
try
{
Expand Down Expand Up @@ -214,7 +214,7 @@ public async Task<string> CreateFromJson(string jsonInput, string pid, EdifactFo
}
public async Task<string> 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");

Expand Down
5 changes: 3 additions & 2 deletions EDILibrary/EdifactFormatVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public static class EdifactFormatHelper
/// get fact for a message class ID ("Prüfidentifikator")
/// </summary>
/// <param name="pruefidentifikator">prüfidentifikator, e.g. '11042'</param>
/// <param name="maskUTILMDX">is true, UTILMD is returned instead of UTILMDG bzw. UTILMDS</param>
/// <returns>the EdifactFormat, e.g. <see cref="EdifactFormat.UTILMD"/> or throws a NotImplementedException iff EdiFormat was found</returns>
public static EdifactFormat FromPruefidentifikator(string pruefidentifikator)
public static EdifactFormat FromPruefidentifikator(string pruefidentifikator, bool maskUTILMDX = true)
{
if (string.IsNullOrWhiteSpace(pruefidentifikator))
{
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion EDILibraryTests/EDIHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 12 additions & 2 deletions EDILibraryTests/EdifactFormatVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4733c81

Please sign in to comment.