diff --git a/PxWeb.UnitTests/Data/PaxiomFixUtilTests.cs b/PxWeb.UnitTests/Data/PaxiomFixUtilTests.cs index 10b4ac9f..80ff200f 100644 --- a/PxWeb.UnitTests/Data/PaxiomFixUtilTests.cs +++ b/PxWeb.UnitTests/Data/PaxiomFixUtilTests.cs @@ -67,6 +67,33 @@ public void RestoreNotes_WhenNotesExist_ReturnsNotes() Assert.AreEqual(1, variable.Values[0].Notes.Count); } + [TestMethod] + public void RestoreNotes_WhenSameNoteExist_DoesNotAddNote() + { + // Arrange + var variable = new Variable("VAR1", "VAR1", PlacementType.Heading, 1); + var value = new Value("v1"); + value.AddNote(new Note("My note", NoteType.Value, true)); + PaxiomUtil.SetCode(value, "v1"); + variable.Values.Add(value); + value = new Value("v2"); + PaxiomUtil.SetCode(value, "v2"); + variable.Values.Add(value); + value = new Value("v3"); + PaxiomUtil.SetCode(value, "v3"); + variable.Values.Add(value); + var notes = new Dictionary(); + var list = new Notes(); + list.Add(new Note("My note", NoteType.Value, true)); + notes.Add("v1", list); + + // Act + PaxiomFixUtil.RestoreNotes(variable, notes); + + // Assert + Assert.AreEqual(1, variable.Values[0].Notes.Count); + } + [TestMethod] public void RestoreNotes_WhenNotesNotApplicable_ReturnsNotes() { diff --git a/PxWeb/Code/Api2/DataSelection/PaxiomFixUtil.cs b/PxWeb/Code/Api2/DataSelection/PaxiomFixUtil.cs index 8fb01e04..f9db3ecf 100644 --- a/PxWeb/Code/Api2/DataSelection/PaxiomFixUtil.cs +++ b/PxWeb/Code/Api2/DataSelection/PaxiomFixUtil.cs @@ -31,12 +31,28 @@ public static void RestoreNotes(Variable variable, Dictionary not { foreach (var note in notes[valueCode]) { - value.AddNote(note); + RetoreNote(value, note); } } } } + private static void RetoreNote(Value value, Note note) + { + if (value.Notes is null) + { + value.AddNote(note); + } + else + { + if (value.Notes.Any(n => n.Text == note.Text && n.Type == note.Type && n.Mandantory == note.Mandantory)) + { + return; // Note already exists + } + value.AddNote(note); + } + } + public static Dictionary ExtractNotes(Variable variable) {