Skip to content

Commit

Permalink
return max with/height for uri template, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 16, 2024
1 parent fb890ec commit fec06ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaContext;
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaImageDeliveryParams;
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaImageUrlBuilder;
import io.wcm.handler.mediasource.ngdm.impl.metadata.NextGenDynamicMediaMetadata;

/**
* {@link UriTemplate} implementation for Next Gen. Dynamic Media remote assets.
Expand All @@ -38,11 +39,20 @@ final class NextGenDynamicMediaUriTemplate implements UriTemplate {

private final UriTemplateType type;
private final String uriTemplate;
private final Dimension dimension;

NextGenDynamicMediaUriTemplate(@NotNull NextGenDynamicMediaContext context,
@NotNull UriTemplateType type) {
this.type = type;

NextGenDynamicMediaMetadata metadata = context.getMetadata();
if (metadata != null) {
dimension = metadata.getDimension();
}
else {
dimension = null;
}

if (type == UriTemplateType.SCALE_HEIGHT) {
throw new IllegalArgumentException("URI template type not supported: " + type);
}
Expand Down Expand Up @@ -72,11 +82,17 @@ final class NextGenDynamicMediaUriTemplate implements UriTemplate {

@Override
public long getMaxWidth() {
if (dimension != null) {
return dimension.getWidth();
}
return 0; // unknown
}

@Override
public long getMaxHeight() {
if (dimension != null) {
return dimension.getHeight();
}
return 0; // unknown
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void testLocalAsset() {
setupNGDM(true);
MediaHandler mediaHandler = AdaptTo.notNull(context.request(), MediaHandler.class);

com.day.cq.dam.api.Asset asset = context.create().asset("/content/dam/my-image.jpg", 10, 10, ContentType.JPEG,
com.day.cq.dam.api.Asset asset = context.create().asset("/content/dam/my-image.jpg", 20, 10, ContentType.JPEG,
ASSET_STATUS_PROPERTY, ASSET_STATUS_APPROVED);
ModifiableValueMap props = AdaptTo.notNull(asset, ModifiableValueMap.class);
props.put(JcrConstants.JCR_UUID, SAMPLE_UUID);
Expand All @@ -283,6 +283,15 @@ void testLocalAsset() {
.build();
assertTrue(media.isValid());
assertUrl(media, "preferwebp=true&quality=85", "jpg");

// validate URI template
Rendition rendition = media.getRendition();
UriTemplate uriTemplate = rendition.getUriTemplate(UriTemplateType.SCALE_WIDTH);
assertEquals("https://repo1/adobe/assets/" + SAMPLE_ASSET_ID + "/as/my-image.jpg?preferwebp=true&quality=85&width={width}",
uriTemplate.getUriTemplate());
assertEquals(UriTemplateType.SCALE_WIDTH, uriTemplate.getType());
assertEquals(20, uriTemplate.getMaxWidth());
assertEquals(10, uriTemplate.getMaxHeight());
}

@Test
Expand Down

0 comments on commit fec06ed

Please sign in to comment.