Skip to content

Commit 10fd0f6

Browse files
authored
ASSETS-44583 - [DM OpenAPI Integration] Image modifier support in site editor page (#2887)
* add Image modifier support in site editor page * add tests
1 parent 77dd95c commit 10fd0f6

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/ImageImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ private void initNextGenerationDynamicMedia() {
331331
properties = resource.getValueMap();
332332
String fileReference = properties.get("fileReference", String.class);
333333
String smartCrop = properties.get("smartCropRendition", String.class);
334+
String modifiers = properties.get("imageModifiers", String.class);
334335
if (isNgdmImageReference(fileReference)) {
335336
int width = currentStyle.get(PN_DESIGN_RESIZE_WIDTH, DEFAULT_NGDM_ASSET_WIDTH);
336337
NextGenDMImageURIBuilder builder = new NextGenDMImageURIBuilder(nextGenDynamicMediaConfig, fileReference)
@@ -339,6 +340,9 @@ private void initNextGenerationDynamicMedia() {
339340
if(StringUtils.isNotEmpty(smartCrop) && !StringUtils.equals(smartCrop, SMART_CROP_AUTO)) {
340341
builder.withSmartCrop(smartCrop);
341342
}
343+
if (StringUtils.isNotEmpty(modifiers)) {
344+
builder.withImageModifiers(modifiers);
345+
}
342346
src = builder.build();
343347
ngdmImage = true;
344348
hasContent = true;

bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v3/NextGenDMImageURIBuilder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class NextGenDMImageURIBuilder {
4242
private int height;
4343
private boolean preferWebp = true;
4444

45+
private String modifiers;
46+
4547
public NextGenDMImageURIBuilder(NextGenDynamicMediaConfig config, String fileReference) {
4648
this.config = config;
4749
this.fileReference = fileReference;
@@ -84,6 +86,15 @@ public NextGenDMImageURIBuilder withPreferWebp(boolean preferWebp) {
8486
return this;
8587
}
8688

89+
/**
90+
* Set extra image modifiers.
91+
* @param modifiersStr
92+
*/
93+
public NextGenDMImageURIBuilder withImageModifiers(String modifiersStr) {
94+
this.modifiers = modifiersStr;
95+
return this;
96+
}
97+
8798
/**
8899
* Use this to create a NextGen Dynamic Media Image URI.
89100
* @return a uri.
@@ -124,6 +135,13 @@ public String build() {
124135
}
125136
uriBuilder.deleteCharAt(uriBuilder.length() - 1);
126137
}
138+
if(StringUtils.isNotEmpty(this.modifiers)) {
139+
if (this.modifiers.startsWith("&")) {
140+
uriBuilder.append(this.modifiers);
141+
} else {
142+
uriBuilder.append("&" + this.modifiers);
143+
}
144+
}
127145
return uriBuilder.toString();
128146
}
129147
LOGGER.info("Invalid fileReference or NGDMConfig. fileReference = {}", this.fileReference);

bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v3/ImageImplTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class ImageImplTest extends com.adobe.cq.wcm.core.components.internal.models.v2.
9696
private static final String PAGE3_IMAGE0_PATH = PAGE3 + "/jcr:content/root/page3_image0";
9797
private static final String NGDM_IMAGE1_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_image1";
9898
private static final String NGDM_SMARTCROP_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image";
99+
100+
private static final String NGDM_MODIFIERS_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_modifiers_image";
99101
private static final String NGDM_SMARTCROP_AUTO_IMAGE_PATH = "/content/ngdm_test_page/jcr:content/root/ngdm_test_page_smartcrop_image_auto";
100102

101103

@@ -731,6 +733,19 @@ void testNgdmImageWithSmartCropRendition() {
731733
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_SMARTCROP_IMAGE_PATH));
732734
}
733735

736+
@Test
737+
void testNgdmImageWithModifiers() {
738+
MockNextGenDynamicMediaConfig config = new MockNextGenDynamicMediaConfig();
739+
config.setEnabled(true);
740+
config.setRepositoryId("testrepo");
741+
config.setAssetMetadataPath("/adobe/assets/{asset-id}/metadata");
742+
context.registerInjectActivateService(config);
743+
744+
Image image = getImageUnderTest(NGDM_MODIFIERS_IMAGE_PATH);
745+
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, NGDM_MODIFIERS_IMAGE_PATH));
746+
assertTrue(image.getSrc().contains("&width=100&height=200"));
747+
}
748+
734749
@Test
735750
void testNgdmImageWithAutoSmartCropRendition() throws Exception {
736751
String expectedMetadataAPIResponseJSON = "{\"assetId\":\"urn:aaid:aem:33b6255d-a978-43ad-8e2e-ef5677c64715\",\"repositoryMetadata\":{\"smartcrops\":{\"Large\":{\"height\":\"1200\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"800\",\"top\":\"0.16\"},\"Medium\":{\"height\":\"800\",\"left\":\"0.0\",\"manualCrop\":\"false\",\"width\":\"600\",\"top\":\"0.0\"}}}}";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "image-06acc3dd21",
3+
"src": "https://testrepo/adobe/dynamicmedia/deliver/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png?width=640&preferwebp=true&width=100&height=200",
4+
"lazyEnabled": true,
5+
"sizes": "",
6+
"dataLayer": {
7+
"image-06acc3dd21": {
8+
"@type": "core/wcm/components/image/v3/image"
9+
}
10+
},
11+
":type": "core/wcm/components/image/v3/image"
12+
}

bundles/core/src/test/resources/image/v3/test-content.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@
965965
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
966966
"smartCropRendition": "Medium"
967967
},
968+
"ngdm_test_page_modifiers_image": {
969+
"jcr:primaryType": "nt:unstructured",
970+
"jcr:createdBy": "admin",
971+
"sling:resourceType": "core/wcm/components/image/v3/image",
972+
"fileReference": "/urn:aaid:aem:e82c3c87-1453-48f5-844b-1822fb610911/cutfruits.png",
973+
"imageModifiers": "&width=100&height=200"
974+
},
968975
"ngdm_test_page_smartcrop_image_auto": {
969976
"jcr:primaryType": "nt:unstructured",
970977
"jcr:createdBy": "admin",

0 commit comments

Comments
 (0)