8000 Fix for note duplication when restoring notes when changing codelist by likp · Pull Request #382 · PxTools/PxWebApi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix for note duplication when restoring notes when changing codelist #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions PxWeb.UnitTests/Data/PaxiomFixUtilTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Notes>();
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()
{
Expand Down
18 changes: 17 additions & 1 deletion PxWeb/Code/Api2/DataSelection/PaxiomFixUtil.cs
43EC
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,28 @@ public static void RestoreNotes(Variable variable, Dictionary<string, Notes> 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<string, Notes> ExtractNotes(Variable variable)
{

Expand Down
0