-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add pseudonymization of groups #14386
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
Open
janbnz
wants to merge
25
commits into
JabRef:main
Choose a base branch
from
janbnz:fix-for-issue-14117
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6cf51d9
Add pseudonymization of groups
janbnz 9fb6d02
Add pseudonymized groups to Chocolate-pseudnomyized.bib
janbnz 93b00c2
Replace var with explicit types
janbnz ade8062
Add test for entries having a group
janbnz 5b3fd57
Merge remote-tracking branch 'upstream/main' into fix-for-issue-14117
janbnz 9f851a3
Apply OpenRewrite cleanup
janbnz 477deb2
Add pseudonymization of groups
janbnz 038a80f
Add pseudonymized groups to Chocolate-pseudnomyized.bib
janbnz 037e21a
Replace var with explicit types
janbnz 2e4d891
Add test for entries having a group
janbnz 2027aab
Apply OpenRewrite cleanup
janbnz 0d7eca5
Merge remote-tracking branch 'origin/fix-for-issue-14117' into fix-fo…
janbnz 7a4b009
Remove duplicate changelog entry
janbnz 88d93f7
Merge branch 'main' into fix-for-issue-14117
janbnz e55286b
Rename "groups" prefix to "group"
janbnz 30a0994
Copy group search syntax version from original file
janbnz 76ee2dc
Fix Chocolate-pseudnomyized.bib
janbnz 57e13a6
Fix group pseudonymization
janbnz fe698bc
Merge branch 'main' into fix-for-issue-14117
calixtus 35e62f7
Merge remote-tracking branch 'origin/main' into fix-for-issue-14117
koppor 7b478a2
Convert JavaDoc to Markdown
koppor 4d3f275
Adapt test
koppor cf35bf7
Improve test
koppor 69cbcc7
Fix typo
koppor c7ce689
Fix test
koppor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| import org.jabref.logic.bibtex.FieldPreferences; | ||
| import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; | ||
|
|
@@ -21,6 +22,10 @@ | |
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.groups.AllEntriesGroup; | ||
| import org.jabref.model.groups.ExplicitGroup; | ||
| import org.jabref.model.groups.GroupHierarchyType; | ||
| import org.jabref.model.groups.GroupTreeNode; | ||
| import org.jabref.model.metadata.SaveOrder; | ||
| import org.jabref.model.util.DummyFileUpdateMonitor; | ||
|
|
||
|
|
@@ -30,6 +35,7 @@ | |
| import org.mockito.Answers; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
|
|
@@ -129,4 +135,93 @@ void pseudonymizeLibraryFile(@TempDir Path tempDir) throws URISyntaxException, I | |
|
|
||
| assertTrue(Files.exists(target)); | ||
| } | ||
|
|
||
| @Test | ||
| void pseudonymizeGroups() { | ||
| // given | ||
| GroupTreeNode root = new GroupTreeNode(new AllEntriesGroup("Root")); | ||
| GroupTreeNode used = root.addSubgroup(new ExplicitGroup("Used", GroupHierarchyType.INDEPENDENT, ',')); | ||
| used.addSubgroup(new ExplicitGroup("Sub", GroupHierarchyType.INDEPENDENT, ',')); | ||
|
|
||
| BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase()); | ||
| databaseContext.getMetaData().setGroups(root); | ||
|
|
||
| Pseudonymization pseudonymization = new Pseudonymization(); | ||
|
|
||
| // when | ||
| Pseudonymization.Result result = pseudonymization.pseudonymizeLibrary(databaseContext); | ||
| GroupTreeNode newRoot = result.bibDatabaseContext().getMetaData().getGroups().orElseThrow(); | ||
|
|
||
| // then | ||
| assertEquals("group-1", newRoot.getName()); | ||
| assertTrue(newRoot.getFirstChild().isPresent()); | ||
|
|
||
| GroupTreeNode newUsed = newRoot.getFirstChild().orElseThrow(); | ||
| assertEquals("group-2", newUsed.getName()); | ||
| assertTrue(newUsed.getFirstChild().isPresent()); | ||
|
|
||
| GroupTreeNode newSub = newUsed.getFirstChild().orElseThrow(); | ||
| assertEquals("group-3", newSub.getName()); | ||
|
|
||
| Map<String, String> mapping = result.valueMapping(); | ||
| assertEquals("Root", mapping.get("group-1")); | ||
| assertEquals("Used", mapping.get("group-2")); | ||
| assertEquals("Sub", mapping.get("group-3")); | ||
| } | ||
|
|
||
| @Test | ||
| void pseudonymizeEntriesWithGroup() { | ||
| // given | ||
| BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(List.of( | ||
| new BibEntry("first").withField(StandardField.GROUPS, "MyGroup"), | ||
| new BibEntry("second").withField(StandardField.GROUPS, "MyGroup, OtherGroup"), | ||
| new BibEntry("third").withField(StandardField.GROUPS, "OtherGroup") | ||
| ))); | ||
|
|
||
| Pseudonymization pseudonymization = new Pseudonymization(); | ||
|
|
||
| // when | ||
| Pseudonymization.Result result = pseudonymization.pseudonymizeLibrary(databaseContext); | ||
|
|
||
| // then | ||
| List<BibEntry> entries = result.bibDatabaseContext().getEntries(); | ||
| assertEquals(3, entries.size()); | ||
|
|
||
| assertEquals(Optional.of("group-1"), entries.getFirst().getField(StandardField.GROUPS)); | ||
| assertEquals(Optional.of("group-1, group-2"), entries.get(1).getField(StandardField.GROUPS)); | ||
| assertEquals(Optional.of("group-2"), entries.get(2).getField(StandardField.GROUPS)); | ||
|
|
||
| Map<String, String> mapping = result.valueMapping(); | ||
| assertEquals("MyGroup", mapping.get("group-1")); | ||
| assertEquals("OtherGroup", mapping.get("group-2")); | ||
| } | ||
|
|
||
| @Test | ||
| void pseudonymizeEntryWithMultipleGroups() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test case missing containing the complete library - I fear the identifiers numbers are not in sync. |
||
| // given | ||
| BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(List.of( | ||
| new BibEntry("first").withField(StandardField.GROUPS, "one, two, three") | ||
| ))); | ||
|
|
||
| Pseudonymization pseudonymization = new Pseudonymization(); | ||
|
|
||
| // when | ||
| Pseudonymization.Result result = pseudonymization.pseudonymizeLibrary(databaseContext); | ||
|
|
||
| // then | ||
| BibEntry pseudonymizedEntry = result.bibDatabaseContext().getEntries().getFirst(); | ||
| String pseudonymizedGroups = pseudonymizedEntry.getField(StandardField.GROUPS).orElseThrow(); | ||
|
|
||
| String[] groups = pseudonymizedGroups.split(", "); | ||
| assertEquals(3, groups.length); | ||
|
|
||
| assertEquals("group-1", groups[0]); | ||
| assertEquals("group-2", groups[1]); | ||
| assertEquals("group-3", groups[2]); | ||
|
|
||
| Map<String, String> mapping = result.valueMapping(); | ||
| assertEquals("one", mapping.get(groups[0])); | ||
| assertEquals("two", mapping.get(groups[1])); | ||
| assertEquals("three", mapping.get(groups[2])); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method name not matching - for groups its NOT the entire field content.