Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.http.server.resources

public Class CitationsResource

extends Object
Class Inheritance
Annotations
@Path:libraries/{id}/citations
@NullMarked
Imports
java.io.IOException, .StringWriter, java.util.ArrayList, .List, .Optional, org.jabref.http.SrvStateManager, org.jabref.http.dto.UncheckedFetcherException, org.jabref.http.server.services.CitationCacheService, .ServerUtils, org.jabref.logic.UiCommand, .UiMessageHandler, org.jabref.logic.bibtex.BibEntryWriter, .FieldWriter, org.jabref.logic.database.DuplicateCheck, org.jabref.logic.exporter.BibWriter, org.jabref.logic.importer.FetcherException, org.jabref.logic.preferences.CliPreferences, org.jabref.logic.util.strings.StringUtil, org.jabref.model.database.BibDatabaseContext, .BibDatabaseMode, org.jabref.model.entry.BibEntry, .BibEntryTypesManager, com.google.gson.annotations.SerializedName, jakarta.inject.Inject, jakarta.ws.rs.BadRequestException, .ClientErrorException, .Consumes, .InternalServerErrorException, .POST, .Path, .PathParam, .Produces, .QueryParam, jakarta.ws.rs.core.MediaType, .Response, org.jspecify.annotations.NullMarked, .Nullable

Cached plain-citation lookup + later add.

Two endpoints designed for the hover-then-Ctrl+J SumatraPDF flow (the LLM parser is expensive; we don't want to pay twice for "is it already in the library?" and "add it"):

  1. POST /libraries/{id}/citations/lookup — parse plain citation text, run DuplicateCheck against the active library, stash the parsed BibEntry in CitationCacheService, return matches plus the cache token.
  2. POST /libraries/{id}/citations/{parserCacheKey} — look up the cached parsed entry by token, append it to the current library, evict the token. Returns 410 Gone when the token expired so the client can fall back to POST /libraries/current/entries and pay for the parse again.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static record
public static record
CitationsResource.BatchLookupRequest

Wrapper for the batched lookup payload.

public static record
CitationsResource.BatchLookupResponse

Aligned-by-index with the request: results[i] corresponds to citations[i].

public static record
public static record
CitationsResource.LookupResponse

Result of a single plain-citation lookup.

public static enum
CitationsResource.MatchScope

Categorisation of a LookupResponse's matches list.

Field Summary

Modifier and TypeField and Description
pack-priv CitationCacheService
pack-priv BibEntryTypesManager
pack-priv CliPreferences
pack-priv SrvStateManager
pack-priv UiMessageHandler

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Response
addFromCache(String id, String parserCacheKey, @Nullable String group)

private Response
alreadyExistsResponse(String parserCacheKey, BibEntry existingEntry)

Returns a 200 OK {"status":"already-exists","entryId":"…"} body and evicts the cache token so a retry can't double-add the entry.

private Response
appendParsedAndRespond(BibEntry parsed, Optional<Path> targetLibrary, @Nullable String group, String parserCacheKey)

Writes the parsed entry as BibTeX, forwards it to the UI for append, evicts the cache token, and returns 201 Created.

private CitationsResource.LookupResponse
doLookup(String citationText, BibDatabaseContext targetContext, List<BibDatabaseContext> openDatabases, DuplicateCheck duplicateCheck)

Shared body of single + batched lookup.

private static String
libraryIdFor(BibDatabaseContext ctx)

Stable-ish library identifier for response bodies.

public CitationsResource.LookupResponse
lookup(String id, String citationText)

public CitationsResource.BatchLookupResponse
lookupBatch(String id, CitationsResource.BatchLookupRequest request)

Batched variant of lookup for the SumatraPDF page-scan flow: when the reader lands on a new page we extract every citation link's extracted bibliography text in one shot, fire one POST, and paint the returned per-citation matchScope as in-PDF dots.

private BibEntry
parseAndCache(String citationText)

Cache miss → invoke the configured plain-citation parser and stash the result by text-hash.

private BibDatabaseContext
resolveTargetContext(String id)

Resolves the path-segment library id to the library this request operates on.

private Optional<Path>
targetLibrary(String id)

The append target for the resolved library: empty for "current" (append to the active tab without switching), otherwise the open library's on-disk path so the GUI switches to it first.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait