Skip to content
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

Fix clear year and month field when converting to biblatex #6434

Merged
merged 25 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
788f395
ISSUE :: 6224 - allow merging of year and date if identical
catarinagomespt May 6, 2020
05518d2
fix comment
catarinagomespt May 6, 2020
e1cfa25
Merge branch 'master' of github.com:JabRef/jabref into fix-for-issue-…
catarinagomespt May 7, 2020
93de4bc
Updated Changelog.md file with fixed issue
catarinagomespt May 7, 2020
29ae438
Fix changelog.md file
catarinagomespt May 7, 2020
559e749
Check If date field is filled and is equal to year it should be remov…
catarinagomespt May 8, 2020
c4a4b15
Added unit test: Cleanup With Date Already Present And Equals To Year…
catarinagomespt May 8, 2020
e810e1e
ISSUE :: 6224 - Removed Unused import - java.util.Optional
catarinagomespt May 8, 2020
8750df7
ISSUE :: 6224 - Separated org.jabref.model.FieldChange from previous …
catarinagomespt May 8, 2020
433e800
Merge branch 'master' of github.com:JabRef/jabref into fix-for-issue-…
catarinagomespt May 8, 2020
bf16459
remove checkstyle warning
catarinagomespt May 8, 2020
0eb5906
Change variable newYear name
catarinagomespt May 8, 2020
1628f21
Merge branch 'master' of github.com:JabRef/jabref into fix-for-issue-…
catarinagomespt May 9, 2020
5b1c852
Update Changelog.md
catarinagomespt May 9, 2020
05c86c2
ISSUE :: 6224 - Added month validation and tests
catarinagomespt May 10, 2020
fb75aa5
ISSUE :: 6224 - For inconsistent data: Do not overwrite/move
catarinagomespt May 12, 2020
3541c2f
ISSUE :: 6224 - Fix Test
catarinagomespt May 12, 2020
23b9878
Merge branch 'master' of github.com:JabRef/jabref into fix-for-issue-…
catarinagomespt May 12, 2020
935f656
ISSUE :: 6224 - Added month checking Test
catarinagomespt May 12, 2020
c2b1950
ISSUE :: 6224 - Fix Test
catarinagomespt May 12, 2020
5604f3c
ISSUE :: 6224 - Change Date.parse
catarinagomespt May 13, 2020
28e9c6d
ISSUE :: 6224 - Update Date class
catarinagomespt May 13, 2020
3c0d2a4
ISSUE :: 6224 - Fix Date
catarinagomespt May 13, 2020
3b910f6
ISSUE :: 6224 - Added new test
catarinagomespt May 13, 2020
440db88
Merge branch 'master' of github.com:JabRef/jabref into fix-for-issue-…
catarinagomespt May 13, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the Preferences entry preview will be unexpected modified leads to Value too long exception [#6198](https://github.com/JabRef/jabref/issues/6198)
- We fixed an issue where custom jstyles for Open/LibreOffice would only be valid if a layout line for the entry type `default` was at the end of the layout section [#6303](https://github.com/JabRef/jabref/issues/6303)
- We fixed an issue where sort on numeric cases was broken. [#6349](https://github.com/JabRef/jabref/issues/6349)
- We fixed an issue where year and month fields were not cleared when converting to biblatex [#6224](https://github.com/JabRef/jabref/issues/6224)
- We fixed an issue where an "Not on FX thread" exception occured when saving on linux [#6453](https://github.com/JabRef/jabref/issues/6453)
- We fixed an issue where the library sort order was lost. [#6091](https://github.com/JabRef/jabref/issues/6091)
- We fixed an issue where brackets in regular expressions were not working. [6469](https://github.com/JabRef/jabref/pull/6469)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.jabref.model.FieldChange;
import org.jabref.model.cleanup.CleanupJob;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.Date;
import org.jabref.model.entry.EntryConverter;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
Expand Down Expand Up @@ -39,8 +41,19 @@ public List<FieldChange> cleanup(BibEntry entry) {
entry.clearField(StandardField.YEAR).ifPresent(changes::add);
entry.clearField(StandardField.MONTH).ifPresent(changes::add);
});
} else {
// If the year from date field is filled and equal to year it should be removed the year field
entry.getFieldOrAlias(StandardField.DATE).ifPresent(date -> {
Optional<Date> newDate = Date.parse(date);
Optional<Date> checkDate = Date.parse(entry.getFieldOrAlias(StandardField.YEAR),
entry.getFieldOrAlias(StandardField.MONTH), Optional.empty());

catarinagomespt marked this conversation as resolved.
Show resolved Hide resolved
if (checkDate.equals(newDate)) {
entry.clearField(StandardField.YEAR).ifPresent(changes::add);
entry.clearField(StandardField.MONTH).ifPresent(changes::add);
}
});
}
return changes;
}

}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/model/entry/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public Date(TemporalAccessor date) {
* - "dd-MM-yyyy" (covers 15-1-2009)
* - "d.M.uuuu" (covers 15.1.2015)
* - "uuuu.M.d" (covers 2015.1.15)
* - "MMM, uuuu" (covers Jan, 2020)
* The code is essentially taken from http://stackoverflow.com/questions/4024544/how-to-parse-dates-in-multiple-formats-using-simpledateformat.
*/
public static Optional<Date> parse(String dateString) {
Expand All @@ -54,7 +55,8 @@ public static Optional<Date> parse(String dateString) {
"MMMM d, uuuu",
"MMMM, uuuu",
"d.M.uuuu",
"uuuu.M.d", "uuuu");
"uuuu.M.d", "uuuu",
"MMM, uuuu");
catarinagomespt marked this conversation as resolved.
Show resolved Hide resolved

for (String formatString : formatStrings) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,45 @@ public void cleanupMovesYearMonthToDate() {
}

@Test
public void cleanupWithDateAlreadyPresentDoesNothing() {
public void cleanupWithDateAlreadyPresentAndDifferentFromYearDoesNothing() {
BibEntry entry = new BibEntry();
entry.setField(StandardField.YEAR, "2011");
entry.setField(StandardField.MONTH, "#jan#");
entry.setField(StandardField.DATE, "2012");
entry.setField(StandardField.DATE, "2012-01");

worker.cleanup(entry);

assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR));
assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH));
assertEquals(Optional.of("2012"), entry.getField(StandardField.DATE));
assertEquals(Optional.of("2012-01"), entry.getField(StandardField.DATE));
}

@Test
public void cleanupWithDateAlreadyPresentAndDifferentFromMonthDoesNothing() {
BibEntry entry = new BibEntry();
entry.setField(StandardField.YEAR, "2011");
entry.setField(StandardField.MONTH, "#jan#");
entry.setField(StandardField.DATE, "2011-02");

worker.cleanup(entry);

assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR));
assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH));
assertEquals(Optional.of("2011-02"), entry.getField(StandardField.DATE));
}

@Test
public void cleanupWithDateAlreadyPresentAndEqualsToYearAndMonth() {
BibEntry entry = new BibEntry();
entry.setField(StandardField.YEAR, "2011");
entry.setField(StandardField.MONTH, "#jan#");
entry.setField(StandardField.DATE, "2011-01");

worker.cleanup(entry);

assertEquals(Optional.empty(), entry.getField(StandardField.YEAR));
assertEquals(Optional.empty(), entry.getField(StandardField.MONTH));
assertEquals(Optional.of("2011-01"), entry.getField(StandardField.DATE));
}

@Test
Expand All @@ -55,4 +83,5 @@ public void cleanupMovesJournalToJournaltitle() {
assertEquals(Optional.empty(), entry.getField(StandardField.JOURNAL));
assertEquals(Optional.of("Best of JabRef"), entry.getField(StandardField.JOURNALTITLE));
}

}