Skip to content

Conversation

muigor
Copy link

@muigor muigor commented Aug 21, 2025

Closes #13588

Steps to test

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [/] Screenshots added in PR description (if change is visible to the user)
  • [/] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [/] Checked 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 to the documentation repository.

@muigor muigor changed the title Add biby entry ressource endpoint test Extract BibEntry endpoints into BibEntryResource and add tests Aug 21, 2025

JsonNode root = mapper.readTree(response);

assertTrue(root.isArray(), "CSL JSON must be a JSON array");
Copy link
Member

Choose a reason for hiding this comment

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

We normally check the complete content at once. Then, its easier to know whats going wrong, because IntellIj displays the diff

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback , i work on it , it is ready

Copy link
Author

@muigor muigor Aug 25, 2025

Choose a reason for hiding this comment

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

Hello @koppor, @calixtus , the change has been implemented and everything should be fine. I would appreciate it if you could review it when you have time

@muigor muigor force-pushed the add-bibyEntryRessource-endpoint-test(#13588) branch from 79168dd to 0b17f24 Compare August 22, 2025 11:44
Copy link

trag-bot bot commented Aug 22, 2025

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

@Siedlerchr Siedlerchr requested a review from palukku August 25, 2025 17:49
Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

codewise looks good to me, but I have no clue if this is correct otherwise

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 25, 2025
@muigor
Copy link
Author

muigor commented Aug 25, 2025

codewise looks good to me, but I have no clue if this is correct otherwise

Hello @Siedlerchr Thanks for the Feedback, I made changes regarding the tasks on this issue #13588

@palukku
Copy link
Member

palukku commented Aug 26, 2025

Did you manually tested the changes you made?
For me the api requests in rest-api.http don't work anymore:
This is what I expected:
image

But I received:
image

@palukku
Copy link
Member

palukku commented Aug 26, 2025

Also looks like you added the json ones (which for itself looks on first sight good and can be kept) but you removed the html and plain string representation for the responses. If I understand the task correct they are the ones that should be moved to the new resource.

Comment on lines -205 to -252
/**
* 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;
}
Copy link
Member

Choose a reason for hiding this comment

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

Those are the ones that should be moved to the new resource.

Comment on lines -254 to -299
/**
* 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;
}
Copy link
Member

Choose a reason for hiding this comment

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

those too

Comment on lines +97 to +99

###
GET http://localhost:23119/libraries/demo/entries/Corti_2009
Copy link
Member

Choose a reason for hiding this comment

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

Please add a heading like on the others and move it up to the other cases which handle the entries itself, the end is for error cases. Also add that it only accepts the according mediatype

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 8, 2025
@koppor koppor marked this pull request as draft September 8, 2025 20:18
@koppor koppor added the status: changes-required Pull requests that are not yet complete label Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes-required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create BibEntryResource
4 participants