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

Support RFC links in Quick Import functionality (#11949) #12043

Merged
merged 19 commits into from
Oct 23, 2024

Conversation

AU0430
Copy link
Contributor

@AU0430 AU0430 commented Oct 20, 2024

Purpose

See #11949
This PR addresses Issue #11949, which requested support for importing RFC using url links in the quick import feature of JabRef.

Changes Made

  1. Enhanced CompositeIdFetcher to Recognize Rfc URL Links:

    • Updated the CompositeIdFetcher class to support RFC document URLs.
    • Added RfcId.java to parse RFC URLs (e.g., https://www.rfc-editor.org/rfc/rfc7276.html) and extract the RFC ID correctly, even if the URL contains a section fragment (e.g., #section-2.2.2).
  2. Updated Identifier Handling:

    • Added RFC-specific parsing logic directly in the CompositeIdFetcher to detect URLs containing "rfc" and extract relevant RFC identifiers.
    • This change allows the performSearchById method to correctly identify and handle RFC URLs without needing a separate importer.

How the Issue is Solved

  • Problem: Users were unable to import RFC documents directly using their full URLs, especially when these URLs included section references.
  • Solution: Modified the CompositeIdFetcher class to include logic that can extract RFC identifiers from URLs and proceed with the import. This allows users to directly paste RFC URLs into the quick import field, and JabRef will successfully parse and import the relevant RFC entry.

Notes

  • This PR only supports URLs from https://www.rfc-editor.org. If users encounter other RFC sources, further enhancement might be needed.
  • Users can now easily use the quick import feature with full RFC URLs, which will enhance the usability of JabRef for RFC references.

Please review these changes, and let me know if there are any adjustments or additional enhancements required. Feedback is highly appreciated to ensure the solution meets user expectations effectively.

return Optional.empty();
}

public boolean isValid() {
Copy link
Member

Choose a reason for hiding this comment

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

Why only plain and not with URL?

Add JavaDoc comment!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, maybe I understand something wrong, so I don't need to match plain in this part, but only need to match URLs in this format("https://www.rfc-editor.org/rfc/" + rfc7276.html#section-2.2.2)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can the modified part meet your requirements?

Copy link
Member

Choose a reason for hiding this comment

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

Hi, maybe I understand something wrong, so I don't need to match plain in this part, but only need to match URLs in this format("https://www.rfc-editor.org/rfc/" + rfc7276.html#section-2.2.2)?

You do nlt match the URL at all there. therefore I wondered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I was worried that there might be other formats of URLs, I considered just matching the format of rfc****.
My mistake. I am really sorry for causing you trouble.

Copy link
Member

Choose a reason for hiding this comment

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

The method is nowhere used. REmove.

If you would implement it correctly, you need to have to check both the URL and just the ID.

}
}

@Override
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, neither equals nor hashCode need to be overriden.

Just remove that code.

There is also a logic error, because Id is stored lower case and the equals also converts loeer case (unnecessarily)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out! I have removed the overridden equals and hashCode methods as suggested. Please let me know if there's anything else you'd like me to adjust.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

Add JavaDoc comments
Remove unnecessary lowercase
Add JavaDoc comments
Remove unnecessary lowercase
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

@AU0430
Copy link
Contributor Author

AU0430 commented Oct 20, 2024

Hello, I have modified my code style, I think there should be no problem, can you test my PR again?

ChengPuPu and others added 4 commits October 21, 2024 10:50
- Removed RFC entry from identifier list(StandardField.java)
- Modified RfcId class to extend EprintIdentifier
…link' into Issue11949-quick-import-for-RFC-link
@AU0430
Copy link
Contributor Author

AU0430 commented Oct 21, 2024

According to CI test feedback:

  1. I changed the code style according to the checkstyle.xml.
  2. Removed the entry RFC("rfc", "RFC", FieldProperty.IDENTIFIER) from the codebase, thereby reducing the total number of entries from 126 to 125.
  3. Modified the RfcId class to extend EprintIdentifier, enhancing its functionality to integrate better with existing identifier logic.

@AU0430 AU0430 requested a review from koppor October 21, 2024 09:09
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.

Tests for RfcId class missing.

Both rfc7276 and URLs ´https://www.rfc-editor.org/rfc/rfc7276.html` need to be supported

* Represents an RFC identifier, which can be used to fetch bibliographic information about the RFC document.
* This class supports both plain RFC IDs (e.g., "rfc7276") and full URLs (e.g., "https://www.rfc-editor.org/rfc/" + rfc****.html).
*/
public class RfcId extends EprintIdentifier {
Copy link
Member

Choose a reason for hiding this comment

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

Name this class RFC - to be consistent with the other classes in that package.

Copy link
Contributor Author

@AU0430 AU0430 Oct 21, 2024

Choose a reason for hiding this comment

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

  1. Thank you for the feedback. I have renamed the class to RFC for consistency with the other classes in the package. The class now follows the naming conventions as requested.

  2. I have removed the unused method(isValid) as suggested.

  3. I have implemented additional test cases in RFCTest.java to verify that the new RFC class handles both plain RFC IDs (e.g., rfc7276) and URLs (e.g., https://www.rfc-editor.org/rfc/rfc7276.html).

return Optional.empty();
}

public boolean isValid() {
Copy link
Member

Choose a reason for hiding this comment

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

The method is nowhere used. REmove.

If you would implement it correctly, you need to have to check both the URL and just the ID.

- Replaced RfcId name with RFC class for consistency and clarity.
- Updated RFC parsing logic to support both plain RFC IDs (e.g., "rfc7276") and full URLs (e.g., "https://www.rfc-editor.org/rfc/rfc7276.html").
- Added tests in RFCTest to validate proper parsing of RFC identifiers from both formats.
- Removed unnecessary method (isValid) improved code clarity.
- Adjusted the CompositeIdFetcher to integrate the new RFC class functionalities.
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.

Some small comments on the test.

class RFCTest {

@Test
void testParsePlainRfcId() {
Copy link
Member

Choose a reason for hiding this comment

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

Convert to @ParameterizedTest.You can use @CsvSource. Left: excpected, right: input.

Use assertEquals(expected, new RFC(input).getNormlized().

Also the next test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted testParsePlainRfcId to a @ParameterizedTest using @CsvSource(done)

  • Updated testGetExternalUri to verify the URI using Optional.of() for consistent checks.

@Test
void testInvalidRfc() {
Optional<RFC> rfc = RFC.parse("invalidRfc");
assertFalse(rfc.isPresent());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertFalse(rfc.isPresent());
assertEquals(Optional.empty, rfc);

If something is wrong, the diff can be investigated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted testInvalidRfc to use assertEquals(Optional.empty(), rfc).(done)

Comment on lines 35 to 37
Optional<URI> uri = rfc.getExternalURI();
assertTrue(uri.isPresent());
assertEquals("https://www.rfc-editor.org/rfc/rfc7276", uri.get().toString());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Optional<URI> uri = rfc.getExternalURI();
assertTrue(uri.isPresent());
assertEquals("https://www.rfc-editor.org/rfc/rfc7276", uri.get().toString());
assertEquals(Optional.of("https://www.rfc-editor.org/rfc/rfc7276"), rfc.getExternalURI());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated testGetExternalUri to verify the URI using Optional.of() for consistent checks.(done)

- Converted `testParsePlainRfcId` to a `@ParameterizedTest` using `@CsvSource`.
- Adjusted `testInvalidRfc` to use `assertEquals(Optional.empty(), rfc)`.
- Updated `testGetExternalUri` to verify the URI using `Optional.of()` for consistent checks.
@AU0430 AU0430 requested a review from koppor October 21, 2024 19:51
Siedlerchr
Siedlerchr previously approved these changes Oct 22, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

Comment on lines 17 to 20
"rfc7276, rfc7276",
"https://www.rfc-editor.org/rfc/rfc7276.html, rfc7276"
})
void testParseValidRfcIdAndUrl(String input, String expected) {
Copy link
Member

Choose a reason for hiding this comment

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

Please be consistent.

assertEquals first gets expected, thus please, first expected then input

I fix it for myself. Too much context switches.

koppor
koppor previously approved these changes Oct 23, 2024
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.

OK for me now.

@koppor koppor enabled auto-merge October 23, 2024 18:28
@AU0430 AU0430 disabled auto-merge October 23, 2024 18:37
@koppor
Copy link
Member

koppor commented Oct 23, 2024

@ChengPuPu Thank you for the follow up. I was about to open the PR in my IDE and fix it for myself.

@koppor
Copy link
Member

koppor commented Oct 23, 2024

BTW: No need to disable automerge. Automerge happens if the required workflows run successfully.

@koppor koppor enabled auto-merge October 23, 2024 18:40
@AU0430
Copy link
Contributor Author

AU0430 commented Oct 23, 2024

@koppor Thank you very much for your patience and guidance. I have learned a lot about code management through this experience. Thank you very much.

@koppor koppor added this pull request to the merge queue Oct 23, 2024
Merged via the queue into JabRef:main with commit b90ef75 Oct 23, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants