Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
6d4abb3
Try to have first endpoint
koppor May 19, 2025
82c01d0
Refine ServerCLI
koppor May 19, 2025
4cbe324
Add initial support for "demo"
koppor May 19, 2025
4b344e5
Add JAbSrvLauncher
koppor May 19, 2025
142d29f
Add hint to start.
koppor May 19, 2025
528c588
Merge branch 'main' into jabmap
koppor May 21, 2025
d49c116
Merge remote-tracking branch 'origin/main' into jabmap
koppor May 28, 2025
ea620a5
initial cayw
palukku May 29, 2025
7d57d0e
Merge branch 'main' into cayw
palukku May 30, 2025
0877a93
fix issues mentioned by subhramit
palukku May 30, 2025
546b32a
Merge branch 'JabRef:main' into cayw
palukku May 30, 2025
3cdbc6d
Merge branch 'cayw' into jabmap
koppor May 30, 2025
9b52f2f
Merge branch 'main' into cayw
koppor Jun 2, 2025
7c2826f
Merge branch 'JabRef:main' into cayw
palukku Jun 6, 2025
a673d68
Merge remote-tracking branch 'origin/main' into jabmap
koppor Jun 9, 2025
bf276cb
WIP: for get preview
koppor Jun 9, 2025
3005b75
Finalize endpoint
koppor Jun 9, 2025
4911107
Merge remote-tracking branch 'origin/main' into cayw
koppor Jun 9, 2025
4ae1a03
Merge branch 'cayw' into add-cyaw
koppor Jun 9, 2025
93beea3
Merge branch 'jabmap' into add-cyaw
koppor Jun 9, 2025
3404185
Merge pull request #1 from iloveskittles82/add-cyaw
koppor Jun 9, 2025
57b7ad1
change get mindmap json method
iloveskittles82 Jun 9, 2025
ee66720
add test to rest-api
iloveskittles82 Jun 9, 2025
9faad94
Merge remote-tracking branch 'origin/jabmap' into jabmap
iloveskittles82 Jun 9, 2025
795d229
Merge branch 'JabRef:main' into cayw
palukku Jun 10, 2025
50d4e68
added new formatting for the entry preview get request and another test
iloveskittles82 Jun 17, 2025
1e176fd
added html preview get function
iloveskittles82 Jun 21, 2025
bca73f6
WIP added method which returns list of all pdf files in library
iloveskittles82 Jun 24, 2025
fa06686
Merge branch 'JabRef:main' into cayw
palukku Jun 29, 2025
d96ed1e
Merge branch 'JabRef:main' into cayw
palukku Jul 1, 2025
4931bb5
added method for getting json list of pdf files in library and create…
iloveskittles82 Jul 1, 2025
be6bd38
minor adjustments
iloveskittles82 Jul 1, 2025
700885c
fixed check for online-reference pdf
iloveskittles82 Jul 1, 2025
18e105d
Merge branch 'JabRef:main' into cayw
palukku Jul 1, 2025
91ffba8
initial cayw
palukku May 29, 2025
2e49274
initial cayw
palukku May 29, 2025
d2da505
Merge branch 'main' into cayw
palukku May 30, 2025
b72a1ce
fix issues mentioned by subhramit
palukku May 30, 2025
015d5a3
Merge branch 'JabRef:main' into cayw
palukku May 30, 2025
2f895ec
Merge branch 'main' into cayw
koppor Jun 2, 2025
0626829
Merge branch 'JabRef:main' into cayw
palukku Jun 6, 2025
0a6743b
Merge remote-tracking branch 'origin/main' into cayw
koppor Jun 9, 2025
0825582
Merge branch 'JabRef:main' into cayw
palukku Jun 10, 2025
7e9c94f
Merge branch 'JabRef:main' into cayw
palukku Jun 29, 2025
85ef99e
Merge branch 'main' into cayw
palukku May 30, 2025
04a1fab
fix issues mentioned by subhramit
palukku May 30, 2025
62c7929
Merge branch 'JabRef:main' into cayw
palukku May 30, 2025
c3828cf
Merge branch 'main' into cayw
koppor Jun 2, 2025
edf2b71
Merge branch 'JabRef:main' into cayw
palukku Jun 6, 2025
f516650
Merge remote-tracking branch 'origin/main' into cayw
koppor Jun 9, 2025
54f3937
Merge branch 'JabRef:main' into cayw
palukku Jun 10, 2025
90e4c96
Merge branch 'JabRef:main' into cayw
palukku Jun 29, 2025
6bc30a0
Merge branch 'JabRef:main' into cayw
palukku Jul 1, 2025
22200fc
Merge branch 'JabRef:main' into cayw
palukku Jul 1, 2025
59cece2
fix minor comments and add librarypath (#3)
palukku Jul 1, 2025
99ff753
Merge remote-tracking branch 'origin/cayw' into cayw
palukku Jul 1, 2025
89d09f8
Fix submodules
palukku Jul 1, 2025
f7de70a
fix jabrefHost.py
palukku Jul 1, 2025
a9d66b2
fix jabrefHost.py
palukku Jul 1, 2025
caca932
Discard changes to jabgui/buildres/linux/jabrefHost.py
koppor Jul 1, 2025
f32016f
Discard changes to jabgui/buildres/macos/Resources/jabrefHost.py
koppor Jul 1, 2025
56eabd3
Fix mode
koppor Jul 1, 2025
64ae673
changed port for the http server
palukku Jul 1, 2025
15da4da
fix modifier order
palukku Jul 1, 2025
cd9fb2f
modernize file input
palukku Jul 1, 2025
54eef3d
add changes to CHANGELOG.md
palukku Jul 1, 2025
06a2d5a
fix small things
palukku Jul 1, 2025
70865c1
Add icon for dialog
koppor Jul 1, 2025
92dadba
Merge branch 'cayw' of github.com:palukku/jabref into cayw
koppor Jul 1, 2025
0b17fa0
Apply suggestions from code review
koppor Jul 1, 2025
4f516fc
Fix import
koppor Jul 1, 2025
889bc1b
change paths.get to path.of
palukku Jul 1, 2025
5822b8b
Merge remote-tracking branch 'origin/cayw' into cayw
palukku Jul 1, 2025
5389fdc
Polish strings
koppor Jul 1, 2025
ceebe6d
reuse limit from Stringutil and fix comments
palukku Jul 1, 2025
e3176ee
Merge remote-tracking branch 'origin/cayw' into cayw
palukku Jul 1, 2025
bd88c8a
reuse limit from Stringutil and fix comments
palukku Jul 1, 2025
f018a9a
changed modifier private
palukku Jul 1, 2025
dd2ac4f
use latest library
palukku Jul 1, 2025
d58a196
Apply suggestions from code review
koppor Jul 1, 2025
4986c3f
Merge branch 'main' into cayw
koppor Jul 1, 2025
83d8635
Magic merge commit for PR #13185
koppor Jul 1, 2025
d88ce8d
Merge into cayw
koppor Jul 1, 2025
a669931
Merge branch 'cayw' into jabmap
koppor Jul 1, 2025
845328e
Merge remote-tracking branch 'origin/main' into jabmap
koppor Jul 3, 2025
070f03e
Merge branch 'main' into jabmap
koppor Jul 3, 2025
7225214
Remove remoteThread from HeadlessExecutorService
koppor Jul 3, 2025
efd8435
Initial HttpServerManager
koppor Jul 3, 2025
9621a46
Remove duplicate code
koppor Jul 3, 2025
8fee8b6
Make http server available in the GUI
koppor Jul 3, 2025
6f9ecda
Fix class name
koppor Jul 3, 2025
6bbe5ad
Add to preferences
koppor Jul 3, 2025
36efdb3
Fix JabSrv CLI startup
koppor Jul 3, 2025
55a381b
Fix port in rest-api.http
koppor Jul 3, 2025
679f01b
Merge remote-tracking branch 'origin/main' into http-in-gui
koppor Jul 3, 2025
b6a4f65
Fix CLI start
koppor Jul 3, 2025
e0074e8
Add some debug for shutdown
koppor Jul 3, 2025
f929f68
Fix libraries for GUI
koppor Jul 3, 2025
a43be05
Enable start of http server on JabRef start
koppor Jul 3, 2025
84ffa73
Proper shutdown
koppor Jul 3, 2025
5257c2d
Merge branch 'http-in-gui' into jabmap
koppor Jul 3, 2025
af42217
fix port numbers
koppor Jul 3, 2025
233f6c9
Fix checkstyle
koppor Jul 3, 2025
a461055
Fix tests
koppor Jul 3, 2025
25d0b14
Merge branch 'http-in-gui' into jabmap
koppor Jul 3, 2025
4e09e8a
Merge branch 'main' into http-in-gui
koppor Jul 3, 2025
34b0d79
Merge branch 'http-in-gui' into jabmap
koppor Jul 3, 2025
1864c41
Merge remote-tracking branch 'origin/main' into jabmap
koppor Jul 4, 2025
39aad76
Magic merge commit for PR #13457
koppor Jul 4, 2025
fff413c
Merge into jabmap
koppor Jul 4, 2025
f01526d
add "N/A" when missing parent citationkey in pdfDTO
iloveskittles82 Jul 4, 2025
d7a785c
Merge remote-tracking branch 'origin/jabmap' into jabmap
iloveskittles82 Jul 4, 2025
a184c29
Hotfix for CAYW in GUI
koppor Jul 5, 2025
87f4998
Merge branch 'fix-cayw' into jabmap
koppor Jul 5, 2025
3586448
Merge branch 'main' into fix-cayw
koppor Jul 5, 2025
26c8f00
Add support for library ids in CAYW
koppor Jul 5, 2025
097026f
Merge branch 'fix-cayw' into add-bib-ids-to-cayw
koppor Jul 5, 2025
fa64252
Reformat code
koppor Jul 5, 2025
b50c333
Try to have focus
koppor Jul 5, 2025
560852a
Add demo to cayw.http
koppor Jul 5, 2025
ac05b28
Magic merge commit for PR #13470
koppor Jul 5, 2025
9b9b53c
Merge into add-bib-ids-to-cayw
koppor Jul 5, 2025
3de0cf2
Merge branch 'add-bib-ids-to-cayw' into jabmap
koppor Jul 5, 2025
c3d991d
Adapt LibraryResource to ServerUtils
koppor Jul 5, 2025
ffb65a2
OpenRewrite
koppor Jul 5, 2025
0ff2a73
Merge branch 'add-bib-ids-to-cayw' into jabmap
koppor Jul 5, 2025
2c5f704
Magic merge commit for PR #13470
koppor Jul 5, 2025
82c736b
Merge into jabmap
koppor Jul 5, 2025
d167546
Magic merge commit for PR #13471
koppor Jul 5, 2025
03391b8
Merge into jabmap
koppor Jul 5, 2025
68e4895
Merge branch 'main' into jabmap
koppor Jul 5, 2025
8385a64
Fix JabSrvLauncher
koppor Jul 5, 2025
56efda7
fix internal server issue upon request
iloveskittles82 Jul 5, 2025
10390ed
Merge branch 'main' into jabmap
koppor Jul 6, 2025
22b8524
Merge branch 'main' into jabmap
koppor Jul 7, 2025
6ec24a0
Merge branch 'main' into jabmap
koppor Jul 7, 2025
bbbdae4
add get request method for retrieving all annotations in a library as…
iloveskittles82 Jul 8, 2025
88a6692
removed `//TODO` line and added getters for PDFAnnotationDTO
iloveskittles82 Jul 8, 2025
8cb5d1d
Merge branch 'main' into jabmap
koppor Jul 8, 2025
98f52f8
added endpoint for a list of all pdf annotations in library
iloveskittles82 Jul 8, 2025
426f782
Merge remote-tracking branch 'origin/jabmap' into jabmap
iloveskittles82 Jul 8, 2025
d004ac5
Added Javadoc comments and a new standard mindmap.
iloveskittles82 Jul 8, 2025
b141b8e
added two sources for annotations endpoint
iloveskittles82 Jul 9, 2025
d05d417
updated default mindmap for server
iloveskittles82 Jul 9, 2025
72d6dc4
rename PDFAnnotationDTO to PdfAnnotationDTO to match LinkedPdfFileDTO…
iloveskittles82 Jul 9, 2025
37dc4eb
Unified JavaDoc style
iloveskittles82 Jul 9, 2025
d474bb4
simplify CORS filter
iloveskittles82 Jul 9, 2025
a978973
Merge branch 'main' into jabmap
koppor Jul 10, 2025
9cb47c7
more cleanup
iloveskittles82 Jul 10, 2025
c10f612
did a rewrite run
iloveskittles82 Jul 14, 2025
4eaa897
added more javadoc and paths for requests
iloveskittles82 Jul 14, 2025
51fde13
fixed "put" request error
iloveskittles82 Jul 14, 2025
91e34b8
remove annotation endpoint
iloveskittles82 Jul 14, 2025
a84dd38
Merge branch 'main' into jabmap
iloveskittles82 Jul 14, 2025
0d306f9
Remove unused DTOs
koppor Jul 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jbang/JabSrvLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/cayw/SimpleJson.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/GlobalExceptionMapper.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/GsonFactory.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/dto/LinkedPdfFileDTO.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/JabrefMediaType.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWResource.java
//SOURCES ../jabsrv/src/main/java/org/jabref/http/server/cayw/CAYWQueryParams.java
Expand Down
1 change: 1 addition & 0 deletions jabsrv/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
opens org.jabref.http.server to org.glassfish.hk2.utilities, org.glassfish.hk2.locator;
exports org.jabref.http.server.cayw;
opens org.jabref.http.server.cayw to com.google.gson, org.glassfish.hk2.locator, org.glassfish.hk2.utilities;
opens org.jabref.http.dto to com.google.gson;

requires javafx.base;

Expand Down
28 changes: 28 additions & 0 deletions jabsrv/src/main/java/org/jabref/http/dto/LinkedPdfFileDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jabref.http.dto;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;

public class LinkedPdfFileDTO {
private final String fileName;
private final String parentCitationKey;
private final String path;

public LinkedPdfFileDTO(BibEntry parentEntry, LinkedFile file) {
this.parentCitationKey = parentEntry.getCitationKey().orElse("N/A");
this.path = file.getLink();
this.fileName = path.substring(path.lastIndexOf('/') + 1);
}

public String getFileName() {
return fileName;
}

public String getParentCitationKey() {
return parentCitationKey;
}

public String getPath() {
return path;
}
}
8 changes: 1 addition & 7 deletions jabsrv/src/main/java/org/jabref/http/server/CORSFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
public class CORSFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
String requestOrigin = requestContext.getHeaderString("Origin");
if (requestOrigin == null) {
// IntelliJ's rest client is calling
responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
} else if (requestOrigin.contains("://localhost")) {
responseContext.getHeaders().add("Access-Control-Allow-Origin", requestOrigin);
}
responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
responseContext.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
responseContext.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept");
responseContext.getHeaders().add("Access-Control-Allow-Credentials", "false");
Expand Down
248 changes: 240 additions & 8 deletions jabsrv/src/main/java/org/jabref/http/server/LibraryResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.jabref.http.JabrefMediaType;
import org.jabref.http.dto.BibEntryDTO;
import org.jabref.http.dto.LinkedPdfFileDTO;
import org.jabref.http.server.services.ContextsToServe;
import org.jabref.http.server.services.FilesToServe;
import org.jabref.http.server.services.ServerUtils;
import org.jabref.logic.citationstyle.JabRefItemDataProvider;
import org.jabref.logic.preferences.CliPreferences;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.field.StandardField;

import com.airhacks.afterburner.injection.Injector;
import com.google.gson.Gson;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
Expand All @@ -48,18 +56,94 @@ public class LibraryResource {
@Inject
Gson gson;

/**
* At http://localhost:23119/libraries/{id}
*
* @param id The specified library
* @return specified library in JSON format
* @throws IOException
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getJson(@PathParam("id") String id) throws IOException {
BibDatabaseContext databaseContext = getDatabaseContext(id);
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);
List<BibEntryDTO> list = databaseContext.getDatabase().getEntries().stream()
.peek(bibEntry -> bibEntry.getSharedBibEntryData().setSharedID(Objects.hash(bibEntry)))
.map(entry -> new BibEntryDTO(entry, databaseContext.getMode(), preferences.getFieldPreferences(), entryTypesManager))
.toList();
.peek(bibEntry -> bibEntry.getSharedBibEntryData().setSharedID(Objects.hash(bibEntry)))
.map(entry -> new BibEntryDTO(entry, databaseContext.getMode(), preferences.getFieldPreferences(), entryTypesManager))
.toList();
return gson.toJson(list);
}

/**
* At http://localhost:23119/libraries/{id}/map <br><br>
*
* Looks for the .jmp file in the directory of the given library ({id}.bib file).
*
* @param id The given library
* @return A JSON String containing the mindmap data. If no {id}.jmp file was found, returns the standard mindmap
* @throws IOException
*/
@GET
@Path("map")
@Produces(MediaType.APPLICATION_JSON)
public String getJabMapJson(@PathParam("id") String id) throws IOException {
boolean isDemo = "demo".equals(id);
java.nio.file.Path jabMapPath;
if (isDemo) {
jabMapPath = getJabMapDemoPath();
} else {
jabMapPath = getJabMapPath(id);
}
// if no file is found, return the default mindmap
if (!Files.exists(jabMapPath)) {
return """
{
"map": {
"meta": {
"name": "JabMap",
"author": "JabMap",
"version": "1.0"
},
"format": "node_tree",
"data": {
"id": "root",
"topic": "JabMap",
"expanded": true,
"icons": [],
"highlight": null,
"type": "Text"
}
}
}
""";
}
return Files.readString(jabMapPath);
}

/**
* At http://localhost:23119/libraries/{id}/map <br><br>
*
* Saves the mindmap next to its associated library.
*
* @param id The given library
*
* @throws IOException
*/
@PUT
@Path("map")
@Consumes(MediaType.APPLICATION_JSON)
public void updateJabMapJson(@PathParam("id") String id, String fileContent) throws IOException {
boolean isDemo = "demo".equals(id);
java.nio.file.Path targetPath;
if (isDemo) {
targetPath = getJabMapDemoPath();
} else {
targetPath = getJabMapPath(id);
}
Files.writeString(targetPath, fileContent);
}

@GET
@Produces(JabrefMediaType.JSON_CSL_ITEM)
public String getClsItemJson(@PathParam("id") String id) throws IOException {
Expand Down Expand Up @@ -94,17 +178,165 @@ public Response getBibtex(@PathParam("id") String id) {
throw new InternalServerErrorException("Could not read library " + library, e);
}
return Response.ok()
.header("Content-Disposition", "attachment; filename=\"" + library.getFileName() + "\"")
.entity(libraryAsString)
.build();
.header("Content-Disposition", "attachment; filename=\"" + library.getFileName() + "\"")
.entity(libraryAsString)
.build();
}

private java.nio.file.Path getJabMapPath(String id) {
java.nio.file.Path libraryPath = ServerUtils.getLibraryPath(id, filesToServe, contextsToServe);
String newName = libraryPath.getFileName().toString().replaceFirst("\\.bib$", ".jmp");
return libraryPath.getParent().resolve(newName);
}

private java.nio.file.Path getJabMapDemoPath() {
java.nio.file.Path result = java.nio.file.Path.of(System.getProperty("java.io.tmpdir")).resolve("demo.jmp");
LOGGER.debug("Using temporary file for demo jmp: {}", result);
return result;
}

/// @param id - also "demo" for the Chocolate.bib file
/**
* @param id - also "demo" for the Chocolate.bib file
*/
private BibDatabaseContext getDatabaseContext(String id) throws IOException {
return ServerUtils.getBibDatabaseContext(id, filesToServe, contextsToServe, preferences.getImportFormatPreferences());
}

/// @return a stream to the Chocolate.bib file in the classpath (is null only if the file was moved or there are issues with the classpath)
/**
* At http://localhost:23119/libraries/{id}/entries/{entryId} <br><br>
*
* Combines attributes of a given BibEntry into a basic entry preview for as plain text.
*
* @param id The name of the library
* @param entryId The CitationKey of the BibEntry
* @return a basic entry preview as plain text
* @throws IOException
* @throws NotFoundException
*/
@GET
@Path("entries/{entryId}")
@Produces(MediaType.TEXT_PLAIN + ";charset=UTF-8")
public String getPlainRepresentation(@PathParam("id") String id, @PathParam("entryId") String entryId) throws IOException {
BibDatabaseContext databaseContext = getDatabaseContext(id);
List<BibEntry> entriesByCitationKey = databaseContext.getDatabase().getEntriesByCitationKey(entryId);
if (entriesByCitationKey.isEmpty()) {
throw new NotFoundException("Entry with citation key '" + entryId + "' not found in library " + id);
}
if (entriesByCitationKey.size() > 1) {
LOGGER.warn("Multiple entries found with citation key '{}'. Using the first one.", entryId);
}

// TODO: Currently, the preview preferences are in GUI package, which is not accessible here.
// build the preview
BibEntry entry = entriesByCitationKey.getFirst();

String author = entry.getField(StandardField.AUTHOR).orElse("(N/A)");
String title = entry.getField(StandardField.TITLE).orElse("(N/A)");
String journal = entry.getField(StandardField.JOURNAL).orElse("(N/A)");
String volume = entry.getField(StandardField.VOLUME).orElse("(N/A)");
String number = entry.getField(StandardField.NUMBER).orElse("(N/A)");
String pages = entry.getField(StandardField.PAGES).orElse("(N/A)");
String releaseDate = entry.getField(StandardField.DATE).orElse("(N/A)");

// the only difference to the HTML version of this method is the format of the output:
String preview =
"Author: " + author
+ "\nTitle: " + title
+ "\nJournal: " + journal
+ "\nVolume: " + volume
+ "\nNumber: " + number
+ "\nPages: " + pages
+ "\nReleased on: " + releaseDate;

return preview;
}

/**
* At http://localhost:23119/libraries/{id}/entries/{entryId} <br><br>
*
* Combines attributes of a given BibEntry into a basic entry preview for as HTML text.
*
* @param id The name of the library
* @param entryId The CitationKey of the BibEntry
* @return a basic entry preview as HTML text
* @throws IOException
*/
@GET
@Path("entries/{entryId}")
@Produces(MediaType.TEXT_HTML + ";charset=UTF-8")
public String getHTMLRepresentation(@PathParam("id") String id, @PathParam("entryId") String entryId) throws IOException {
List<BibEntry> entriesByCitationKey = getDatabaseContext(id).getDatabase().getEntriesByCitationKey(entryId);
if (entriesByCitationKey.isEmpty()) {
throw new NotFoundException("Entry with citation key '" + entryId + "' not found in library " + id);
}
if (entriesByCitationKey.size() > 1) {
LOGGER.warn("Multiple entries found with citation key '{}'. Using the first one.", entryId);
}

// TODO: Currently, the preview preferences are in GUI package, which is not accessible here.
// build the preview
BibEntry entry = entriesByCitationKey.getFirst();

String author = entry.getField(StandardField.AUTHOR).orElse("(N/A)");
String title = entry.getField(StandardField.TITLE).orElse("(N/A)");
String journal = entry.getField(StandardField.JOURNAL).orElse("(N/A)");
String volume = entry.getField(StandardField.VOLUME).orElse("(N/A)");
String number = entry.getField(StandardField.NUMBER).orElse("(N/A)");
String pages = entry.getField(StandardField.PAGES).orElse("(N/A)");
String releaseDate = entry.getField(StandardField.DATE).orElse("(N/A)");

// the only difference to the plain text version of this method is the format of the output:
String preview =
"<strong>Author:</strong> " + author + "<br>" +
"<strong>Title:</strong> " + title + "<br>" +
"<strong>Journal:</strong> " + journal + "<br>" +
"<strong>Volume:</strong> " + volume + "<br>" +
"<strong>Number:</strong> " + number + "<br>" +
"<strong>Pages:</strong> " + pages + "<br>" +
"<strong>Released on:</strong> " + releaseDate;

return preview;
}

/**
* At http://localhost:23119/libraries/{id}/entries/pdffiles <br><br>
*
* Loops through all entries in the specified library and adds attached files of type "PDF" to
* a list and JSON serialises it.
*/
@GET
@Path("entries/pdffiles")
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
public String getPDFFilesAsList(@PathParam("id") String id) throws IOException {
// get a list of all entries in library (specified by "id")
BibDatabaseContext databaseContext = getDatabaseContext(id);
List<LinkedPdfFileDTO> response = new ArrayList<>();
List<BibEntry> entries = databaseContext.getDatabase().getEntries();
if (entries.isEmpty()) {
throw new NotFoundException("No entries found for library: " + id);
}

// loop through all entries to extract pdfs and paths
for (BibEntry entry : entries) {
List<LinkedFile> pathsToFiles = entry.getFiles();
if (!pathsToFiles.isEmpty()) {
for (LinkedFile file : pathsToFiles) {
// ignore all non pdf files and online references
if (!"PDF".equals(file.getFileType()) || LinkedFile.isOnlineLink(file.getLink())) {
continue;
}
// add file to response body
LinkedPdfFileDTO localPdfFile = new LinkedPdfFileDTO(entry, file);
response.add(localPdfFile);
}
}
}
return gson.toJson(response);
}

/**
* @return a stream to the Chocolate.bib file in the classpath (is null only if the file was moved or there are issues with the classpath)
*/
private @Nullable InputStream getChocolateBibAsStream() {
return BibDatabase.class.getResourceAsStream("/Chocolate.bib");
}
Expand Down
1 change: 1 addition & 0 deletions jabsrv/src/main/java/org/jabref/http/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private HttpServer startServer(ServiceLocator serviceLocator, URI uri) {

// see https://stackoverflow.com/a/33794265/873282
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.property("jersey.config.server.wadl.disableWadl", true);
// TODO: Add SSL
resourceConfig.register(RootResource.class);
resourceConfig.register(LibrariesResource.class);
Expand Down
Loading