-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Rename the Review Tab into Comments Tab #3658
Changes from 8 commits
289c2d2
351b1db
ac341e4
07a8965
6a75c6a
af9022a
afe5476
995b965
056ef9d
9d9c5a6
4a6886e
a5a2994
37a247c
1e0d56e
e949025
c93b490
e405f67
6cca4ab
b7ca150
38750e8
2d2bb7e
dfeda8d
4828955
5962710
4c1905d
38e6139
b246cfe
303ed4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jabref.logic.importer.util; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jabref.logic.importer.ParserResult; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.FieldName; | ||
|
||
public class RenameReviewToComment implements PostOpenAction { | ||
|
||
@Override | ||
public void performAction(ParserResult parserResult) { | ||
Objects.requireNonNull(parserResult); | ||
|
||
for (BibEntry entry : parserResult.getDatabase().getEntries()) { | ||
if (entry.getField(FieldName.REVIEW).isPresent()) { | ||
String review = entry.getField(FieldName.REVIEW).get(); | ||
review = concatCommentFieldIfPresent(entry, review); | ||
updateFields(entry, review); | ||
} | ||
} | ||
} | ||
|
||
private String concatCommentFieldIfPresent(BibEntry entry, String review) { | ||
if (entry.getField(FieldName.COMMENT).isPresent()) { | ||
String comment = entry.getField(FieldName.COMMENT).get().trim(); | ||
if (!comment.isEmpty()) { | ||
review = String.format("%s\nReview:\n%s", comment, review.trim()); | ||
} | ||
} | ||
|
||
return review; | ||
} | ||
|
||
private void updateFields(BibEntry entry, String review) { | ||
entry.setField(FieldName.COMMENT, review); | ||
entry.clearField(FieldName.REVIEW); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.jabref.logic.importer.util; | ||
|
||
import java.util.Collections; | ||
|
||
import org.jabref.logic.importer.ParserResult; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.FieldName; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class RenameReviewToCommentTest { | ||
|
||
private RenameReviewToComment action; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
action = new RenameReviewToComment(); | ||
} | ||
|
||
@Test | ||
void noFields() { | ||
BibEntry entry = createMinimalBibEntry(); | ||
ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); | ||
|
||
action.performAction(actualParserResult); | ||
|
||
assertEquals(new ParserResult(Collections.singletonList(entry)).getDatabase().getEntryByKey("Entry1"), | ||
actualParserResult.getDatabase().getEntryByKey("Entry1")); | ||
} | ||
|
||
@Test | ||
void reviewField() { | ||
BibEntry actualEntry = createMinimalBibEntry(); | ||
actualEntry.setField(FieldName.REVIEW, "My Review"); | ||
ParserResult actualParserResult = new ParserResult(Collections.singletonList(actualEntry)); | ||
|
||
BibEntry expectedEntry = createMinimalBibEntry(); | ||
expectedEntry.setField(FieldName.COMMENT, "My Review"); | ||
|
||
action.performAction(actualParserResult); | ||
|
||
assertEquals(new ParserResult(Collections.singletonList(expectedEntry)).getDatabase().getEntryByKey("Entry1"), | ||
actualParserResult.getDatabase().getEntryByKey("Entry1")); | ||
} | ||
|
||
@Test | ||
void commentField() { | ||
BibEntry entry = createMinimalBibEntry(); | ||
entry.setField(FieldName.COMMENT, "My Comment"); | ||
ParserResult actualParserResult = new ParserResult(Collections.singletonList(entry)); | ||
|
||
action.performAction(actualParserResult); | ||
|
||
assertEquals(new ParserResult(Collections.singletonList(entry)).getDatabase().getEntryByKey("Entry1"), | ||
actualParserResult.getDatabase().getEntryByKey("Entry1")); | ||
} | ||
|
||
|
||
@Test | ||
void reviewAndCommentField() { | ||
BibEntry actualEntry = createMinimalBibEntry(); | ||
actualEntry.setField(FieldName.REVIEW, "My Review"); | ||
actualEntry.setField(FieldName.COMMENT, "My Comment"); | ||
|
||
ParserResult actualParserResult = new ParserResult(Collections.singletonList(actualEntry)); | ||
|
||
BibEntry expectedEntry = createMinimalBibEntry(); | ||
expectedEntry.setField(FieldName.COMMENT, "My Comment\nReview:\nMy Review"); | ||
|
||
action.performAction(actualParserResult); | ||
|
||
assertEquals(new ParserResult(Collections.singletonList(expectedEntry)).getDatabase().getEntryByKey("Entry1"), | ||
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. why not just Same remark applies also to some other tests here. 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. good remark! (: |
||
actualParserResult.getDatabase().getEntryByKey("Entry1")); | ||
} | ||
|
||
private BibEntry createMinimalBibEntry() { | ||
BibEntry entry = new BibEntry(); | ||
entry.setCiteKey("Entry1"); | ||
entry.setField(FieldName.TITLE, "A random entry!"); | ||
entry.setField(FieldName.AUTHOR, "JabRef DEVELOPERS"); | ||
return entry; | ||
} | ||
} |
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.
Could you move the complete class into
org.jabref.migrations
? Because that's what it actually does, it migrates an opened bib file to a newer version of JabRef. I think it makes sense to bundle all this stuff in a dedicated package, because then it gets easier for us to see what sort of conversions are performed on open.While you're doing that, could you also move the
ConvertLegacyExplicitGroups
?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.
Done. I also renamed these actions to what they are: migrations