Skip to content

Conversation

@prerak09
Copy link
Contributor

@prerak09 prerak09 commented Dec 26, 2025

Closes #14707

Added option in Jabkit CLI to change citation key patterns per entry type , same as available in Jabref GUI

Attached Video show testing of the TestCases.

Steps to test

  1. Create a test file .
    I am attaching the test file i created to test (test.bib)
@Article{,
  author  = {Author1 and Author2},
  title   = {ArticleTitle1},
  journal = {Journal1},
  year    = {2025},
}

@Book{,
  author    = {Author3},
  title     = {BookTitle1},
  publisher = {Publisher1},
  year      = {2026},
}

@InProceedings{,
  author    = {Author4 and Author5},
  title     = {ConferencePaper1},
  booktitle = {Conference1},
  year      = {2027},
}

@Misc{existingKey2024,
  author = {Author6},
  title  = {MiscTitle1},
  year   = {2024},
}

Test 1 -
This Will check Global pattern

./gradlew :jabkit:run --args="citationkeys generate \
  --input=test.bib \
  --pattern=[auth][year]"

Test 2 -
This Will check per entry type changing for article and book

./gradlew :jabkit:run --args="citationkeys generate \
  --input=test.bib \
  --pattern=[auth][year] \
  --entry-type-pattern=article=[auth][year] \
  --entry-type-pattern=book=[auth][year]"

Test 3 -
This Will check invalid entry type
there is no entry like invalid type so it should through an error

./gradlew :jabkit:run --args="citationkeys generate \
  --input=test.bib \
  --entry-type-pattern=invalidtype=[auth][year]"

Test 4 -
This Will check invalid map syntax

./gradlew :jabkit:run --args="citationkeys generate \
  --input=test.bib \
  --entry-type-pattern=article"

Screenshots

Screen.Recording.2025-12-26.at.6.09.41.PM-converted-converted.mp4

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • I checked the user documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request updating file(s) in https://github.com/JabRef/user-documentation/tree/main/en.

@github-actions github-actions bot added the good second issue Issues that involve a tour of two or three interweaved components in JabRef label Dec 26, 2025
@prerak09
Copy link
Contributor Author

@Siedlerchr I created this draft pull request .
Please look at my changes once and let me know if i am doing correct or if any changes are required

@jabref-machine
Copy link
Collaborator

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Source Code Tests / Checkstyle (pull_request)" and click on it.

In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues, commit, and push.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 26, 2025
@subhramit subhramit requested a review from calixtus December 26, 2025 18:43
public class KeySuffixConverter
extends CaseInsensitiveEnumConverter<CitationKeyPatternPreferences.KeySuffix> {

public KeySuffixConverter() {
Copy link
Member

Choose a reason for hiding this comment

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

This class seems to be a bit superfluous to me. Or did i miss something? Can't you just inline CaseInsensitiveEnumConverter<CitationKeyPatternPreferences.KeySuffix> ?

Copy link
Contributor Author

@prerak09 prerak09 Dec 27, 2025

Choose a reason for hiding this comment

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

I tried to inline CaseInsensitiveEnumConverter directly in the @option
here
@option(names = "--suffix", description = "Key suffix strategy: ${COMPLETION-CANDIDATES}", converter = CaseInsensitiveEnumConverter.class)
private CitationKeyPatternPreferences.KeySuffix keySuffix;
but i am facing some errors thats why i created a convertor for that
i will try again

@calixtus
Copy link
Member

What might be helpful would be some hint to a list of allowed entrytypes, if one could not be found. Maybe by hardcoding it or by linking to some online documentation?
Other question is - maybe a user wants to define some citation key pattern for a custom entry type?

Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

It is good that you asked for feedback early, but please note the following comments. Breaking into multiple lines bulks the diff up.
Also, please set up Checkstyle on IntelliJ as it is one of the very first points of our contributing guidelines.

Comment on lines +118 to +119
CitationKeyPatternPreferences existingPreferences =
parentCommand.getParent().cliPreferences.getCitationKeyPatternPreferences();
Copy link
Member

Choose a reason for hiding this comment

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

We currently have limited time and a lot of PRs to review. Please help by not making us repeat the same comments on every PR.
#14620 (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.

Sorry about that , i will fix that before my final PR.
I only created this Draft PR just to get some reviews over my code logic if i am on the right path or not

Copy link
Member

Choose a reason for hiding this comment

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

That is fine, it's just that style and formatting issues get in the way when the person is trying to look through your code and trying to provide feedback on the logic.

Please set up checkstyle so that you don't have to manually format code every time.

Comment on lines +126 to +127
GlobalCitationKeyPatterns patterns =
GlobalCitationKeyPatterns.fromPattern(defaultPattern);
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +5 to +6
public class KeySuffixConverter
extends CaseInsensitiveEnumConverter<CitationKeyPatternPreferences.KeySuffix> {
Copy link
Member

Choose a reason for hiding this comment

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

@prerak09
Copy link
Contributor Author

What might be helpful would be some hint to a list of allowed entrytypes, if one could not be found. Maybe by hardcoding it or by linking to some online documentation? Other question is - maybe a user wants to define some citation key pattern for a custom entry type?

We can add a hint and i guess adding this documentation will be helpful
https://docs.jabref.org/setup/citationkeypatterns

@prerak09
Copy link
Contributor Author

prerak09 commented Dec 27, 2025

What might be helpful would be some hint to a list of allowed entrytypes, if one could not be found. Maybe by hardcoding it or by linking to some online documentation? Other question is - maybe a user wants to define some citation key pattern for a custom entry type?

I will start working on that after fixing this issue
maybe we can create a Sub-Issue for that will that be fine?

@koppor
Copy link
Member

koppor commented Dec 27, 2025

What might be helpful would be some hint to a list of allowed entrytypes, if one could not be found. Maybe by hardcoding it or by linking to some online documentation? Other question is - maybe a user wants to define some citation key pattern for a custom entry type?

I will start working on that after fixing this issue maybe we can create a Sub-Issue for that will that be fine?

No sub issue. We are all in the context here. If there are no long delays in back and forth, this should be solvable.

Use org.jabref.model.entry.types.EntryTypeFactory#parse - you can output all org.jabref.model.entry.types.UnknownEntryType as warning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: citationkey-generator component: JabKit [cli] good second issue Issues that involve a tour of two or three interweaved components in JabRef status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable configuration of citation key patterns at the CLI

5 participants