-
-
Notifications
You must be signed in to change notification settings - Fork 3k
add: CAYW endpoint formats #13785
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
Merged
Merged
add: CAYW endpoint formats #13785
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fbbb325
add new formatters and cayw resource tests
jinchat-joseph-yim b4606c2
update changelog
jinchat-joseph-yim 213bf25
correct method name and expected result in tests
jinchat-joseph-yim 49a740c
add sources of new formatter
jinchat-joseph-yim cf113a2
use bib entry constructor that takes citation key in test case
jinchat-joseph-yim e77d5e0
use builder of BibEntry with citation key
josephyim 26a011c
Merge remote-tracking branch 'upstream/main' into fix-issue-13578
josephyim a89cfee
Update the format of typst to consider special character in key, and …
josephyim 6db81bf
Merge remote-tracking branch 'upstream/main' into fix-issue-13578
josephyim d6fe81e
Remove unnecessary constructor code for consistency
josephyim 0e9fcdb
Ue cite in typst format only when key contains slash
josephyim ab18130
Remove meaningless comment
josephyim 70ce1b9
Update jabsrv/src/main/java/org/jabref/http/server/cayw/format/TypstF…
palukku 21d82a9
Update jabsrv/src/test/java/org/jabref/http/server/cayw/format/CAYWFo…
palukku 9cadf5f
Fix test
palukku 68ee3bb
Update jabsrv/src/test/java/org/jabref/http/server/cayw/format/CAYWFo…
palukku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
jabsrv/src/main/java/org/jabref/http/server/cayw/format/MMDFormatter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
import org.jabref.http.server.cayw.gui.CAYWEntry; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
public class MMDFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public MediaType getMediaType() { | ||
return MediaType.TEXT_PLAIN_TYPE; | ||
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return bibEntries.stream() | ||
.map(entry -> entry.getCitationKey().map("[#%s][]"::formatted)) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.joining("")); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
jabsrv/src/main/java/org/jabref/http/server/cayw/format/NatbibFormatter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
import org.jabref.http.server.cayw.gui.CAYWEntry; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import org.jvnet.hk2.annotations.Service; | ||
|
||
@Service | ||
public class NatbibFormatter implements CAYWFormatter { | ||
|
||
private final String defaultCommand; | ||
|
||
public NatbibFormatter(String defaultCommand) { | ||
this.defaultCommand = defaultCommand; | ||
} | ||
|
||
@Override | ||
public MediaType getMediaType() { | ||
return MediaType.TEXT_PLAIN_TYPE; | ||
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
String command = queryParams.getCommand().orElse(defaultCommand); | ||
|
||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return "\\%s{%s}".formatted(command, | ||
bibEntries.stream() | ||
.map(BibEntry::getCitationKey) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.joining(","))); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
jabsrv/src/main/java/org/jabref/http/server/cayw/format/PandocFormatter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
import org.jabref.http.server.cayw.gui.CAYWEntry; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
public class PandocFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public MediaType getMediaType() { | ||
return MediaType.TEXT_PLAIN_TYPE; | ||
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return "[%s]".formatted(bibEntries.stream() | ||
.map(entry -> entry.getCitationKey().map("@%s"::formatted)) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.joining("; "))); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
jabsrv/src/main/java/org/jabref/http/server/cayw/format/TypstFormatter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.jabref.http.server.cayw.format; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.http.server.cayw.CAYWQueryParams; | ||
import org.jabref.http.server.cayw.gui.CAYWEntry; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
public class TypstFormatter implements CAYWFormatter { | ||
|
||
@Override | ||
public MediaType getMediaType() { | ||
return MediaType.TEXT_PLAIN_TYPE; | ||
} | ||
|
||
@Override | ||
public String format(CAYWQueryParams queryParams, List<CAYWEntry> caywEntries) { | ||
List<BibEntry> bibEntries = caywEntries.stream() | ||
.map(CAYWEntry::bibEntry) | ||
.toList(); | ||
|
||
return bibEntries.stream() | ||
.map(entry -> entry.getCitationKey().map(key -> { | ||
if (key.contains("/")) { | ||
return "#cite(label(\"%s\"))".formatted(key); | ||
} else { | ||
return "#cite(<%s>)".formatted(key); | ||
} | ||
})) | ||
.flatMap(Optional::stream) | ||
.collect(Collectors.joining(" ")); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
latex
,cite
,citep
andcitet
are alias ofnatbib
, so they share the same output format. However, ifcommand
is not specified, the default value of each format is:latex
cite
natbib
cite
citep
citep
citet
citet
At first, I tried to keep the registry approach by doing below in, for example,
NatbibFormatter
:In this way, I have 2 concerns:
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.getFormatNames
andformat
.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.