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 biblatex cleanup for date field #2339

Merged
merged 13 commits into from
Dec 8, 2016
Merged

Fix biblatex cleanup for date field #2339

merged 13 commits into from
Dec 8, 2016

Conversation

Siedlerchr
Copy link
Member

@Siedlerchr Siedlerchr commented Dec 4, 2016

This fixes #2335
Moved biblatex Cleanup to new test

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 4, 2016
@Siedlerchr
Copy link
Member Author

Failing test is something from Medline, not related

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM but I have a few remarks.

if (entry.getField(FieldName.DATE).isPresent()) {
date = entry.getField(FieldName.DATE).get();
}
if (date.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if (StringUtils.isBlank (entry.getField(FieldName.DATE))) is cleaner (not sure about the naming)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this approach, because it captures 2 purposes and checks the optonal
a) If the field is not present the date is empty
b) if the field is present, we assign the value, however, it still might be empty

Optional<String> oldYear = entry.getField(FieldName.YEAR);
Optional<String> oldMonth = entry.getField(FieldName.MONTH);

entry.setField(FieldName.DATE, newDate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, then set/clearField already return the right FieldChange

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was part of the code I didn't touch


@Before
public void setUp() throws IOException {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line

public void setUp() throws IOException {

MetaData metaData = new MetaData();
BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(), metaData, bibFolder.newFile("test.bib"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a create a file?

BibEntry entry = new BibEntry();
entry.setField(FieldName.JOURNAL, "test");

worker.cleanup(preset, entry);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directly use the BiblatexCleanup.cleanup method instead of using the worker (makes tests and initialization more transparent)

@@ -308,17 +308,6 @@ public void cleanupLatexMergesTwoLatexMathEnvironments() {
}

@Test
public void convertToBiblatexMovesJournalToJournalTitle() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this test here to make sure that the CleanupWorker works correctly wrt to the "Convert to BibLatex" option; the other test class for the BibLatexCleanupJob then only tests this class directly.


entry.clearField(oldFieldName);
changes.add(new FieldChange(entry, oldFieldName, oldValue, null));
changes.add(entry.setField(newFieldName, oldValue).orElse(null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry.setField(...).ifPresent(changes::add), otherwise you add null values to the list which is not so nice.

// Dates: create date out of year and month, save it and delete old fields
// If there already exists a value for the field date, it is not overwritten
String date = "";
if (entry.getField(FieldName.DATE).isPresent()) {
date = entry.getField(FieldName.DATE).get();
}
if (date.isEmpty()) {
if (StringUtils.isBlank(date)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBlank also accepts an optional I think (if not, please add a corresponding overload), hence Optional<String> date = entry.getField(FieldName.DATE) should work.

@Siedlerchr
Copy link
Member Author

Siedlerchr commented Dec 5, 2016 via email

* upstream/master:
  builds.jabref.org: Keep html files and just remove *.exe, *.dmg, *.jar during upload of a new build
  Fix comment typo
  Fix typos in comments in .travis.yml
  Switch to LGoodDatePicker (#2340)
  Gradle build scans should only run on TravisCI, not on the other CI services
  Try scans.gradle.com
  Remove reference to GPL - we are MIT now
  fix date changes in medline fetcher results
  Fix #2336: shutdown is working again (#2338)
@Siedlerchr
Copy link
Member Author

Failing Snap CI is due to HTTP error 502 in AstrophysicsDataSystemTest

@koppor
Copy link
Member

koppor commented Dec 5, 2016

Could you please merge master again - I merged #2333 and thus SnapCI only does the basic tests as described at https://github.com/JabRef/jabref/wiki/CI#snapci 😇

* upstream/master:
  Update com.github.johnrengelman.shadow from 1.2.3 to 1.2.4
  Introduce categories: DatabseTests, FetcherTests, GUITests
  Place oracle stub into src/main/java
  Move all tests into src/test/java
@tobiasdiez
Copy link
Member

tobiasdiez commented Dec 5, 2016

@Siedlerchr: sorry I don't understand you comment.
Lets go through this case by case with the following code:

Optional<String> date = entry.getField(FieldName.DATE);
Boolean isBlank = StringUtils.isBlank(date);
case date isBlank
no date at all Optional.empty true
empty string Optional.of("") true
something else Optional.of("something") false

You want to move year and month to the date field exactly in the first two cases, i.e., if and only if isBlank == true. What do I miss?

@Siedlerchr
Copy link
Member Author

Ah now I understand your comment, the first case was not obvious for me, that an empty should return true.

* upstream/master:
  Remove obsolete variable
  Translate new messages (#2341)
  Update gradle from 3.2 to 3.2.1
* upstream/master:
  Move files to subfolders in file directory (#1899)

# Conflicts:
#	src/test/java/net/sf/jabref/logic/cleanup/CleanupWorkerTest.java
@Siedlerchr
Copy link
Member Author

@tobiasdiez The confusion came from the naming stuff. I previously had the apache.commons StringUtil class and not the jabref specific one. Changed that.

public class BiblatexCleanupTest {

@Rule
public TemporaryFolder bibFolder = new TemporaryFolder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable ever used?

@koppor
Copy link
Member

koppor commented Dec 7, 2016

Besides the micro comment: LGTM 👍

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment, otherwise can be merged.

@@ -307,11 +308,11 @@ public void cleanupLatexMergesTwoLatexMathEnvironments() {
public void convertToBiblatexMovesJournalToJournalTitle() {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX);
BibEntry entry = new BibEntry();
entry.setField("journal", "test");
entry.setField(FieldName.JOURNAL, "test");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert these changes, as hard-coded strings in tests are actually desirable. The logic for the conversation moves FieldName.JOURNAL to FieldName,JOURNALTITLE. Hence if somebody changes FieldName.JOURNAL = "stupid" the test still passes but the functionality is broken.

Siedlerchr and others added 4 commits December 8, 2016 09:17
* upstream/master:
  Some more formatting
  Keeping shared database changes together and remove duplicate
  Add missing newline
  Update mockito-core from 2.2.26 to 2.2.28
  Fix comments
  Add comment where to find documentation why swingx is broken

# Conflicts:
#	CHANGELOG.md
@tobiasdiez tobiasdiez merged commit 123f2e6 into master Dec 8, 2016
@tobiasdiez tobiasdiez deleted the biblatexDateCleanup branch December 8, 2016 08:59
tobiasdiez pushed a commit to tobiasdiez/jabref that referenced this pull request Dec 10, 2016
* Fix biblatex cleanup for date field
Moved biblatex Cleanup to new test

* Add changelog entry

* Directly use returend fieldChanges from set/Clear entry
Minimize test

* Use ifPresent with changes add

* Use jabref StringUtil with Optional checker

* Change field constants to strings in tests

* Replace remaining field names with string

* Remove unnecessary import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Biblatex Cleanup for moving year+ month to Date field not working
3 participants