diff --git a/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaAsset.java b/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaAsset.java index 60a9a143..6c2a5f57 100644 --- a/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaAsset.java +++ b/src/main/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMediaAsset.java @@ -19,6 +19,9 @@ */ package io.wcm.handler.mediasource.ngdm; +import static com.day.cq.dam.api.DamConstants.DC_DESCRIPTION; +import static com.day.cq.dam.api.DamConstants.DC_TITLE; + import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.sling.api.resource.Resource; @@ -32,6 +35,7 @@ import io.wcm.handler.media.UriTemplate; import io.wcm.handler.media.UriTemplateType; import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaContext; +import io.wcm.handler.mediasource.ngdm.impl.metadata.NextGenDynamicMediaMetadata; /** * {@link Asset} implementation for Next Gen. Dynamic Media remote assets. @@ -39,30 +43,42 @@ final class NextGenDynamicMediaAsset implements Asset { private final NextGenDynamicMediaContext context; + private final MediaArgs defaultMediaArgs; + private final ValueMap properties; NextGenDynamicMediaAsset(@NotNull NextGenDynamicMediaContext context) { this.context = context; + this.defaultMediaArgs = context.getDefaultMediaArgs(); + + NextGenDynamicMediaMetadata metadata = context.getMetadata(); + if (metadata != null) { + this.properties = metadata.getProperties(); + } + else { + this.properties = ValueMap.EMPTY; + } } @Override public @Nullable String getTitle() { - return context.getReference().getFileName(); + return StringUtils.defaultString(properties.get(DC_TITLE, String.class), + context.getReference().getFileName()); } @Override public @Nullable String getAltText() { - if (context.getDefaultMediaArgs().isDecorative()) { + if (defaultMediaArgs.isDecorative()) { return ""; } - else { - return context.getDefaultMediaArgs().getAltText(); + if (!defaultMediaArgs.isForceAltValueFromAsset() && StringUtils.isNotEmpty(defaultMediaArgs.getAltText())) { + return defaultMediaArgs.getAltText(); } + return StringUtils.defaultString(getDescription(), getTitle()); } @Override public @Nullable String getDescription() { - // not supported - return null; + return properties.get(DC_DESCRIPTION, String.class); } @Override @@ -77,7 +93,7 @@ final class NextGenDynamicMediaAsset implements Asset { @Override public @Nullable Rendition getDefaultRendition() { - return getRendition(this.context.getDefaultMediaArgs()); + return getRendition(defaultMediaArgs); } @Override diff --git a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithMetadataTest.java b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithMetadataTest.java index 46aa3cd1..2356f305 100644 --- a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithMetadataTest.java +++ b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithMetadataTest.java @@ -103,7 +103,8 @@ void testAsset() { Asset asset = media.getAsset(); assertNotNull(asset); assertEquals(SAMPLE_FILENAME, asset.getTitle()); - assertNull(asset.getAltText()); + assertNull(asset.getDescription()); + assertEquals("my-image.jpg", asset.getAltText()); assertNull(asset.getDescription()); assertEquals(SAMPLE_REFERENCE, asset.getPath()); assertEquals(ValueMap.EMPTY, asset.getProperties()); diff --git a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithoutMetadataTest.java b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithoutMetadataTest.java index 3176cf29..c3825877 100644 --- a/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithoutMetadataTest.java +++ b/src/test/java/io/wcm/handler/mediasource/ngdm/NextGenDynamicMedia_RemoteAssetWithoutMetadataTest.java @@ -84,7 +84,7 @@ void testAsset() { Asset asset = media.getAsset(); assertNotNull(asset); assertEquals(SAMPLE_FILENAME, asset.getTitle()); - assertNull(asset.getAltText()); + assertEquals("my-image.jpg", asset.getAltText()); assertNull(asset.getDescription()); assertEquals(SAMPLE_REFERENCE, asset.getPath()); assertEquals(ValueMap.EMPTY, asset.getProperties()); diff --git a/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataServiceImpl_ImsAccessTokenTest.java b/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataServiceImpl_ImsAccessTokenTest.java index d932fae8..0064023e 100644 --- a/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataServiceImpl_ImsAccessTokenTest.java +++ b/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataServiceImpl_ImsAccessTokenTest.java @@ -19,6 +19,8 @@ */ package io.wcm.handler.mediasource.ngdm.impl.metadata; +import static com.day.cq.dam.api.DamConstants.DC_DESCRIPTION; +import static com.day.cq.dam.api.DamConstants.DC_TITLE; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -118,8 +120,8 @@ void testValidToken() { assertEquals(1500, dimension.getWidth()); assertEquals(900, dimension.getHeight()); assertEquals("image/jpeg", metadata.getMimeType()); - assertEquals("Test Image", metadata.getProperties().get("dc:title", String.class)); - assertEquals("Test Description", metadata.getProperties().get("dc:description", String.class)); + assertEquals("Test Image", metadata.getProperties().get(DC_TITLE, String.class)); + assertEquals("Test Description", metadata.getProperties().get(DC_DESCRIPTION, String.class)); } @Test @@ -139,8 +141,8 @@ void testInvalidToken_FallbackNoAuth() { assertEquals(1200, dimension.getWidth()); assertEquals(800, dimension.getHeight()); assertEquals("image/jpeg", metadata.getMimeType()); - assertNull(metadata.getProperties().get("dc:title", String.class)); - assertNull(metadata.getProperties().get("dc:description", String.class)); + assertNull(metadata.getProperties().get(DC_TITLE, String.class)); + assertNull(metadata.getProperties().get(DC_DESCRIPTION, String.class)); } } diff --git a/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataTest.java b/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataTest.java index 7129167a..21fea558 100644 --- a/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataTest.java +++ b/src/test/java/io/wcm/handler/mediasource/ngdm/impl/metadata/NextGenDynamicMediaMetadataTest.java @@ -20,6 +20,8 @@ package io.wcm.handler.mediasource.ngdm.impl.metadata; import static com.day.cq.dam.api.DamConstants.ASSET_STATUS_APPROVED; +import static com.day.cq.dam.api.DamConstants.DC_DESCRIPTION; +import static com.day.cq.dam.api.DamConstants.DC_TITLE; 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_IMAGE_FULL; import static io.wcm.handler.mediasource.ngdm.impl.metadata.MetadataSample.METADATA_JSON_PDF; @@ -71,8 +73,8 @@ void testSampleJson_Image_Full() throws JsonProcessingException { assertEquals(1500, dimension.getWidth()); assertEquals(900, dimension.getHeight()); assertEquals(ASSET_STATUS_APPROVED, metadata.getAssetStatus()); - assertEquals("Test Image", metadata.getProperties().get("dc:title", String.class)); - assertEquals("Test Description", metadata.getProperties().get("dc:description", String.class)); + assertEquals("Test Image", metadata.getProperties().get(DC_TITLE, String.class)); + assertEquals("Test Description", metadata.getProperties().get(DC_DESCRIPTION, String.class)); assertEquals(0, metadata.getSmartCrops().size()); assertTrue(metadata.isValid()); }