Skip to content

Commit

Permalink
Dynamic Media with OpenAPI: Respect Image Dimension from SVG asset me…
Browse files Browse the repository at this point in the history
…tadata (#72)
  • Loading branch information
stefanseifert authored Nov 25, 2024
1 parent e8bbe74 commit 3e461d7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<action type="update" dev="sseifert" issue="71">
Dynamic Media with Open API: Use remote metadata call to validate and get metadata for local assets as well.
</action>
<action type="fix" dev="sseifert" issue="72">
Dynamic Media with OpenAPI: Respect Image Dimension from SVG asset metadata.
</action>
</release>

<release version="2.2.2" date="2024-09-16">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ final class NextGenDynamicMediaRendition implements Rendition {
this.fileExtension = FilenameUtils.getExtension(reference.getFileName());
}

if (isVectorImage() || !isImage() || mediaArgs.isDownload()) {
if (!isImage() || mediaArgs.isDownload()) {
// deliver as binary
this.url = buildBinaryUrl();
}
else if (isVectorImage()) {
// calculate width/height for rendition metadata
calculateWidthHeight();
// deliver as binary
this.url = buildBinaryUrl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaReferenceSample.SAMPLE_REFERENCE;
import static io.wcm.handler.mediasource.ngdm.impl.metadata.MetadataSample.METADATA_JSON_IMAGE;
import static io.wcm.handler.mediasource.ngdm.impl.metadata.MetadataSample.METADATA_JSON_PDF;
import static io.wcm.handler.mediasource.ngdm.impl.metadata.MetadataSample.METADATA_JSON_SVG;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -273,8 +274,32 @@ void testPDFDownload() {
Rendition rendition = media.getRendition();
assertNotNull(rendition);
assertEquals(ContentType.PDF, rendition.getMimeType());
assertEquals(
"https://" + nextGenDynamicMediaConfig.getRepositoryId() + "/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/myfile.pdf",
assertEquals("https://" + nextGenDynamicMediaConfig.getRepositoryId() + "/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/myfile.pdf",
rendition.getUrl());
}

@Test
@SuppressWarnings("null")
void testSVG() {
stubFor(get("/adobe/assets/" + SAMPLE_ASSET_ID + "/metadata")
.willReturn(aResponse()
.withStatus(HttpStatus.SC_OK)
.withHeader("Content-Type", ContentType.JSON)
.withBody(METADATA_JSON_SVG)));

Resource downloadResource = context.create().resource(context.currentPage(), "image",
MediaNameConstants.PN_MEDIA_REF, "/" + SAMPLE_ASSET_ID + "/myfile.svg");

Media media = mediaHandler.get(downloadResource)
.build();
assertTrue(media.isValid());

Rendition rendition = media.getRendition();
assertNotNull(rendition);
assertEquals(ContentType.SVG, rendition.getMimeType());
assertEquals(900, rendition.getWidth());
assertEquals(600, rendition.getHeight());
assertEquals("https://" + nextGenDynamicMediaConfig.getRepositoryId() + "/adobe/assets/" + SAMPLE_ASSET_ID + "/original/as/myfile.svg",
rendition.getUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public final class MetadataSample {
+ " }"
+ "}";

public static final String METADATA_JSON_SVG = "{"
+ " \"assetId\": \"" + SAMPLE_ASSET_ID + "\","
+ " \"repositoryMetadata\": {"
+ " \"repo:name\": \"test.svg\","
+ " \"dc:format\": \"image/svg+xml\""
+ " },"
+ " \"assetMetadata\": {"
+ " \"dam:assetStatus\": \"approved\","
+ " \"dc:description\": \"Test Description\","
+ " \"dc:title\": \"Test Image\","
+ " \"tiff:ImageLength\": 600,"
+ " \"tiff:ImageWidth\": 900"
+ " }"
+ "}";

public static final String METADATA_JSON_PDF = "{"
+ " \"assetId\": \"" + SAMPLE_ASSET_ID + "\","
+ " \"repositoryMetadata\": {"
Expand Down

0 comments on commit 3e461d7

Please sign in to comment.