Skip to content

Conversation

josephyim
Copy link
Contributor

Closes #13578

Added formatters mentioned in the issue and http tests on org.jabref.http.server.CAYWResource

Steps to test

Follow the guideline on https://devdocs.jabref.org/code-howtos/http-server.html#start-http-server to start the server.
Examples of command to run are:

curl http://localhost:23119/better-bibtex/cayw?format=natbib
curl http://localhost:23119/better-bibtex/cayw?format=pandoc
curl "http://localhost:23119/better-bibtex/cayw?format=citet&command=abc"
image image image

Mandatory checks

@josephyim josephyim changed the title Fix issue 13578 add: CAYW endpoint formats Aug 29, 2025
@subhramit subhramit requested a review from palukku August 29, 2025 17:36
@josephyim
Copy link
Contributor Author

@palukku Hi Philip, I made a mess in commit history on my remote branch, so asked AI what to do. At the end, the commit history looks good now, I pushed with force and the test failed. What can I do to resolve this?
Thank you.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason on why you switched from the map and registry approach to the new switch/case approach?

I'm fine with both but I'm curious what your thoughts behind this were

Copy link
Contributor Author

Choose a reason for hiding this comment

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

latex, cite, citep and citet are alias of natbib, so they share the same output format. However, if command is not specified, the default value of each format is:

Format Default command
latex cite natbib cite
citep citep
citet citet

At first, I tried to keep the registry approach by doing below in, for example, NatbibFormatter:

// Replace CAYWFormatter#getFormatName by below method
@Override
public List<String> getFormatNames() {
    return List.of("natbib", "latex", "cite", "citep", "citet");
}

@Override
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) {
    String command = queryParams.getCommand().orElseGet(() -> {
        String format = queryParams.getFormat();
        switch (format) {
            case "natbib":
            case "latex":
            case "cite":
                return "cite";
            case "citep":
                return "citep";
            case "citet":
                return "citet";
            default:
                return "cite";
        }
    });
    ...
}

In this way, I have 2 concerns:

  1. queryParams.getFormat() in theory will not be null, but I can't 100% feel safe about this. Just in case it is null, I don't have a nice way of handling it.
  2. If we have a new format using the same Formatter, then we need to add the new format in both getFormatNames and format.
    Because of above, I put the the new switch/case approach in the FormatterService.java class. I am happy to edit if this is not a good approach. Thanks.

@palukku
Copy link
Member

palukku commented Aug 30, 2025

@palukku Hi Philip, I made a mess in commit history on my remote branch, so asked AI what to do. At the end, the commit history looks good now, I pushed with force and the test failed. What can I do to resolve this? Thank you.

No need to worry, next time just add new commits it does not matter if you have changes later on on things you also have in an earlier commit because as the bot already wrote will get squashed anyway.

@subhramit subhramit requested a review from palukku September 1, 2025 20:36
@palukku
Copy link
Member

palukku commented Sep 2, 2025

Currently I have very limited time, I will do a full review on thursday evening.

.toList();

return bibEntries.stream()
.map(entry -> entry.getCitationKey().map("@%s"::formatted))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should use the full cite command (example there: #cite(<arrgh>)) also think about:
If your source name contains certain characters such as slashes, which are not recognized by the <> syntax, you can explicitly call label instead.

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 the review. I updated the code to use #cite(label("arrgh")), just in case slash is used.

image

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 like it to only add the label thing when there is a slash present, so it is only used when necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified such that when there are multiple keys, only the ones containing slash will be formatted with the label thing, and the other keys will use the @ thing. Please see whether this is what you intend. Thanks.

void mmd() {
MMDFormatter formatter = new MMDFormatter();
String actual = formatter.format(queryParams(null), caywEntries("key1", "key2"));
// Whatever your MMD formatter currently emits; adjust expected accordingly.
Copy link
Member

Choose a reason for hiding this comment

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

This comment and the othere smells like ai? Also please remove, adds nothing meaningful to the code.

Copy link
Contributor Author

@josephyim josephyim Sep 5, 2025

Choose a reason for hiding this comment

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

Yes, I did use AI to generate the tests, then I checked the code. Sorry that I overlooked this.

Copy link
Member

@palukku palukku Sep 5, 2025

Choose a reason for hiding this comment

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

For this it's okay, but don't rely too much on ai when coding and always double check what the ai suggests.

Also delete the comments here: https://github.com/JabRef/jabref/pull/13785/files#diff-d3db9dc636031d931c6fe5cdfe69aff341619cda38fa586964c3b3bf6bc1d674R53-R56

palukku
palukku previously approved these changes Sep 7, 2025
Copy link
Member

@palukku palukku left a comment

Choose a reason for hiding this comment

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

Looks good to me

palukku
palukku previously approved these changes Sep 7, 2025
palukku
palukku previously approved these changes Sep 7, 2025
Copy link
Member

@palukku palukku left a comment

Choose a reason for hiding this comment

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

Now it should work and looks good

Copy link
Member

@palukku palukku left a comment

Choose a reason for hiding this comment

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

I should avoid committing things on my phone next time

Copy link

trag-bot bot commented Sep 7, 2025

@trag-bot didn't find any issues in the code! ✅✨

@palukku palukku added this pull request to the merge queue Sep 7, 2025
Merged via the queue into JabRef:main with commit ce5cd12 Sep 7, 2025
35 checks passed
@github-actions github-actions bot mentioned this pull request Sep 7, 2025
6 tasks
Siedlerchr added a commit that referenced this pull request Sep 8, 2025
* upstream/main: (54 commits)
  Split relativizeSymlinks parameterized tests in separate tests (#13782)
  Update the search syntax highlight for web search (#13801)
  Chore(deps): Bump ai.djl:bom from 0.33.0 to 0.34.0 in /versions (#13833)
  Fix typos in CHANGELOG.md (#13826)
  Chore(deps): Bump com.konghq:unirest-modules-gson in /versions (#13831)
  Chore(deps): Bump org.gradlex:extra-java-module-info in /build-logic (#13830)
  Chore(deps): Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (#13832)
  Chore(deps): Bump io.zonky.test.postgres:embedded-postgres-binaries-bom (#13834)
  Chore(deps): Bump jablib/src/main/resources/csl-locales (#13829)
  Chore(deps): Bump jablib/src/main/resources/csl-styles (#13827)
  Chore(deps): Bump jablib/src/main/abbrv.jabref.org (#13828)
  add: CAYW endpoint formats (#13785)
  New Crowdin updates (#13823)
  chore(deps): update dependency org.kohsuke:github-api to v2.0-rc.5 (#13822)
  Add support for automatic ICORE conference ranking lookup [#13476] (#13699)
  New Crowdin updates (#13820)
  Initialize search bar auto-completion with real database context (no tab switch needed) (#13816)
  Fixes #13274: Allow cygwin-paths on Windows (#13297)
  Refine "REDACTED" replacement of API key value in web fetcher search URL (#13814)
  changed ISSNCleanup into NormalizeIssn, refactored respective tests #13748 (#13767)
  ...
@josephyim josephyim deleted the fix-issue-13578 branch September 29, 2025 13:11
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.

Add additional CAYW Formatters
3 participants