-
Notifications
You must be signed in to change notification settings - Fork 165
#5777 - Allow fetching resource metadata from the backend #5780
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
#5777 - Allow fetching resource metadata from the backend #5780
Conversation
- Ability to fetch image metadata via ImageIO - Also embed width/height on img tags we render from the backend
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.
Pull request overview
This PR adds the ability to fetch image metadata (width and height) from the backend and automatically embed these dimensions on <img> tags during HTML rendering. This feature is particularly useful for MHTML archives that contain images without declared dimensions.
Key Changes:
- Added a new REST endpoint (
/meta) to fetch image metadata as JSON - Implemented automatic embedding of width/height attributes on img tags during document rendering
- Fixed a typo in
NamespaceDecodingContentHandlerAdapterclass name
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Added imageio-tiff version property (3.10.0) for enhanced image format support |
| inception-dependencies/pom.xml | Added imageio-tiff dependency declaration for TIFF image support |
| inception-external-editor/pom.xml | Added imageio-tiff dependency and configured maven-dependency-plugin to ignore it (SPI-based) |
| NamespaceDecodingContentHandlerAdapter.java | Fixed class name typo from 'Namspace' to 'Namespace' |
| ImageMetaData.java | New record class to represent image dimensions (width/height) with builder pattern |
| XHtmlXmlDocumentViewController.java | Added getResourceMetadata method signature to interface |
| XHtmlXmlDocumentViewControllerImpl.java | Core implementation: added metadata endpoint, image dimension extraction via ImageIO, and automatic dimension embedding handler |
| XmlDocumentViewControllerImplBase.java | Removed applyHtmlResourceUrlFilter method (moved to subclass) |
| MatrixWorkloadManagementPage.java | Reformatted method call for better readability |
| WicketApplicationBase.java | Reformatted CSP value initialization for consistency |
| InceptionSecurityWebUIApiAutoConfiguration.java | Reformatted CSP value initialization for consistency |
| PdfJsViewerPage.java | Reformatted comments and method calls for better readability |
Comments suppressed due to low confidence (2)
inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/xml/NamespaceDecodingContentHandlerAdapter.java:35
- Fixed typo in class name: 'Namspace' corrected to 'Namespace'.
inception/inception-support/src/main/java/de/tudarmstadt/ukp/inception/support/xml/NamespaceDecodingContentHandlerAdapter.java:45 - Fixed typo in constructor name: 'Namspace' corrected to 'Namespace'.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @PreAuthorize("@documentAccess.canViewAnnotationDocument(#aProjectId, #aDocumentId, #principal.name)") | ||
| @Override | ||
| @GetMapping(path = GET_METADATA_PATH) | ||
| public ResponseEntity<String> getResourceMetadata( // | ||
| @PathVariable("projectId") long aProjectId, // | ||
| @PathVariable("documentId") long aDocumentId, // | ||
| @RequestParam("resId") String aResourceId, // | ||
| Principal principal) | ||
| throws Exception | ||
| { | ||
| var srcDoc = documentService.getSourceDocument(aProjectId, aDocumentId); | ||
|
|
||
| var maybeFormatSupport = formatRegistry.getFormatById(srcDoc.getFormat()); | ||
| if (maybeFormatSupport.isEmpty()) { | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
|
|
||
| var srcDocFile = documentStorageService.getSourceDocumentFile(srcDoc); | ||
|
|
||
| var formatSupport = maybeFormatSupport.get(); | ||
|
|
||
| if (!formatSupport.hasResources() | ||
| || !formatSupport.isAccessibleResource(srcDocFile, aResourceId)) { | ||
| LOG.debug("Resource [{}] for document {} not found", aResourceId, srcDoc); | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
|
|
||
| try { | ||
| var inputStream = formatSupport.openResourceStream(srcDocFile, aResourceId); | ||
|
|
||
| var httpHeaders = new HttpHeaders(); | ||
| httpHeaders.setContentType(APPLICATION_JSON); | ||
|
|
||
| var imageMetaData = getImageDimensions(inputStream); | ||
| if (imageMetaData.isPresent()) { | ||
| return new ResponseEntity<>(toJsonString(imageMetaData.get()), httpHeaders, OK); | ||
| } | ||
|
|
||
| return new ResponseEntity<>("{}", httpHeaders, NOT_FOUND); | ||
| } | ||
| catch (FileNotFoundException e) { | ||
| LOG.debug("Resource [{}] for document {} not found", aResourceId, srcDoc); | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
| catch (Exception e) { | ||
| LOG.debug("Unable to load resource [{}] for document {}", aResourceId, srcDoc, e); | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
| } |
Copilot
AI
Dec 10, 2025
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.
The new getResourceMetadata endpoint lacks test coverage. Consider adding tests to verify:
- Successful metadata retrieval for valid image resources
- Proper 404 responses for non-existent resources
- Proper 404 responses for non-image resources
- Access control enforcement
- JSON response format correctness
This is a new public API endpoint that should have comprehensive test coverage.
What's in the PR
How to test manually
Automatic testing
Documentation