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

Detect and remove ?doi= tag before passing to DOI.parse #9848

Merged
merged 5 commits into from
May 8, 2023

Conversation

sean-leichtle
Copy link
Contributor

@sean-leichtle sean-leichtle commented May 7, 2023

Fixes #9821

Modify org/jabref/logic/importer/CompositeIdFetcher.java to detect and remove ?doi= tag before passing to DOI.parse

Add unit tests to org/jabref/model/entry/identifier/DOITest.java

Update CHANGELOG.md

Compulsory checks

Preview Give feedback

Optional<DOI> doi = DOI.parse(identifier);
Optional<DOI> doi = DOI.parse(filterForDOITag(identifier));
Copy link
Member

Choose a reason for hiding this comment

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

Please no new method if not needed.

Please to

Optional<DOI> doi = DOI.findInText(identifier);

and report back if this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That certainly works. Sorry, I misunderstood the requirements you originally outlined:

Test-enabling: Heuristics as own method. This method needs to be tested. Method can be "package private".

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Sorry for having a discussion with you without updating the main text. I thought, it was clear.

4 days ago, we discussed the usage of that method: #9821 (comment)

(And you even acknowledged 4 days ago - #9821 (comment))

Sorry again that I did not update the main text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok. No worries, my misunderstanding. It's really quite a small fix - I would have been quicker except it didn't occur to me for most of yesterday that the reason it wasn't working was the copy-paste issue.

Copy link
Member

Choose a reason for hiding this comment

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

The copy and paste thing is a hard one to work on. This involves understanding JavaFX behavior on macOS, which is different than on Windows. Therefore, we have some "hacks" included, which might not work as expected (which you encountered).

Nevertheless, the issue at hand requires some GUI (!) tests, which could be hard. See https://github.com/JabRef/jabref/blob/main/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java for an example test.

Side story: It is hard to craft "medium-sized" issues. Mostly, the issues involve much code understanding, but little code changes. -- You can look at https://github.com/orgs/JabRef/projects/3/views/3 for a curated list of issues...

@@ -121,4 +121,16 @@ void performSearchByIdReturnsEmptyForInvalidId(String groundInvalidArXivId) thro
void performSearchByIdReturnsCorrectEntryForIdentifier(String name, BibEntry bibEntry, String identifier) throws FetcherException {
assertEquals(Optional.of(bibEntry), compositeIdFetcher.performSearchById(identifier));
}

@ParameterizedTest
@ValueSource(strings = "https://www.scitepress.org/Link.aspx?doi=10.5220/0010404301780189")
Copy link
Member

Choose a reason for hiding this comment

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

The "secret" sauce for parameterized tests is to pass both the expected result and the input.

Try

@CsvSource({"10.5220/0010404301780189,"https://www.scitepress.org/Link.aspx?doi=10.5220/0010404301780189", 
"10.5220/0010404301780189,10.5220/0010404301780189"})
 void filterForDOITagReturnsDOI(String expected, String DOIString) throws FetcherException {

Oh, the test seems to be go after https://github.com/koppor/jabref/blob/main/src/test/java/org/jabref/model/entry/identifier/DOITest.java#L203-L203

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've read up a bit on CsvSource-parameterized tests, but I don't understand why this doesn't work:

    @CsvSource({"https://www.scitepress.org/Link.aspx?doi=10.5220/0010404301780189, 10.5220/0010404301780189",
                "10.5220/0010404301780189, 10.5220/0010404301780189"})
    void performSearchByIdRemovesDOITag(String input, String expectedResult) throws FetcherException {
        assertEquals(expectedResult, compositeIdFetcher.performSearchById(input));
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I didn't read closely enough....

Copy link
Contributor Author

@sean-leichtle sean-leichtle May 7, 2023

Choose a reason for hiding this comment

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

Nope. It seems to me this should work, though of course it doesn't:

    @ParameterizedTest
    @CsvSource({"10.5220/0010404301780189, https://www.scitepress.org/Link.aspx?doi=10.5220/0010404301780189",
                "10.5220/0010404301780189, 10.5220/0010404301780189"})
    void performSearchByIdRemovesDOITag(String expectedResult, String input) throws FetcherException {
        assertEquals(expectedResult, compositeIdFetcher.performSearchById(input));
    }

Copy link
Member

Choose a reason for hiding this comment

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

"it doesn't" is too unspecific for me.

I was about to write follwing

  • If you set a breakpoint at assertEquals and press the debug button. Which values do input and expectedResult take?
  • Then highlight compositeIdFetcher.performSearchById(input)
  • Then press Alt+F8 to evaluate

While writing, it is clear: ´compositeIdFetcher.performSearchById(input)` performs a search on the string. You just want to test the parsing of the ID there.

I am so sorry, I was not clear what I meant with "Oh, the test seems to be go"

I meant: Forget my eduacation about CSV source. Just add two lines after https://github.com/koppor/jabref/blob/main/src/test/java/org/jabref/model/entry/identifier/DOITest.java#L203-L203

I write them for you:

 Arguments.of("10.5220/0010404301780189", DOI.findInText("https://www.scitepress.org/Link.aspx?doi=10.5220/0010404301780189").get().getDOI()),
 Arguments.of("10.5220/0010404301780189", DOI.findInText("10.5220/0010404301780189").get().getDOI()),

Education:

I know, these tests are not an example for good tests. They should be rewritten so that only pairs of expected/input-doi-string are passed. For that, however, the tests need to split up. Needs concentration.

Copy link
Contributor Author

@sean-leichtle sean-leichtle May 7, 2023

Choose a reason for hiding this comment

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

If you set a breakpoint at assertEquals and press the debug button. Which values do input and expectedResult take?
Then highlight compositeIdFetcher.performSearchById(input)
Then press Alt+F8 to evaluate

Well, that was certainly idiotic of me since DOI.findInText returns an Optional and therefore the assertEquals comparing strings will fail. In any case, I'm pleased to have learned about CsvSource. Thanks for the patient explanation!

@sean-leichtle sean-leichtle changed the title Add method to detect and remove ?doi= tag before passing to DOI.parse Detect and remove ?doi= tag before passing to DOI.parse May 7, 2023
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Small comment. I assume you won't to a GUI test in this PR.

CHANGELOG.md Outdated
@@ -71,6 +71,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed the citation key generation for (`[authors]`, `[authshort]`, `[authorsAlpha]`, `authIniN`, `authEtAl`, `auth.etal`)[https://docs.jabref.org/setup/citationkeypatterns#special-field-markers] to handle `and others` properly. [koppor#626](https://github.com/koppor/jabref/issues/626)
- We fixed the Save/save as file type shows BIBTEX_DB instead of "Bibtex library" [#9372](https://github.com/JabRef/jabref/issues/9372)
- We fixed an issue regarding recording redundant prefixes in search history. [#9685](https://github.com/JabRef/jabref/issues/9685)
- We fixed an issue where passing a valid URL containing a "?doi=" tag to DOI.parse yielded a "No entry found" notification. [#9821](https://github.com/JabRef/jabref/issues/9821)
Copy link
Member

Choose a reason for hiding this comment

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

It's more than ?doi=. Moreover, end users are not interested in implementation details. Here a suggestion:

Suggested change
- We fixed an issue where passing a valid URL containing a "?doi=" tag to DOI.parse yielded a "No entry found" notification. [#9821](https://github.com/JabRef/jabref/issues/9821)
- We fixed an issue where passing a URL containing a DOI lead to a "No entry found" notification. [#9821](https://github.com/JabRef/jabref/issues/9821)

Copy link
Contributor Author

@sean-leichtle sean-leichtle May 7, 2023

Choose a reason for hiding this comment

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

Small comment. I assume you won't to a GUI test in this PR.

I'd certainly like to try. I assume I should follow this comment and in particular look at src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java.

Edit: Right, you mentioned GlobalSearchBarTest above.

@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 7, 2023
@calixtus
Copy link
Member

calixtus commented May 8, 2023

Looks good. Thanks for you interest in JabRef!
Failing test is not related to you addition.

@calixtus calixtus merged commit 99ab75a into JabRef:main May 8, 2023
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.

Quick import should work if DOI is included
3 participants