Skip to content

Commit

Permalink
adding source property in sling model of image component to get dam a…
Browse files Browse the repository at this point in the history
…sset path in headless json (#1198)

* [eds adding source property in sling model of image component to get the path in crx of the image.......]

* [eds adding source property in sling model of image component to get the path in crx of the image.......]

* [FORMS-13952] changed the dam repo path property to fd:repoPath

* [FORMS-13952] changed the dam repo path property to fd:repoPath

* fixed some test cases ........

* FORMS-13952 removed unused api of getSource...

* [FORMS-13952] formatter change added in StaticImage......

---------

Co-authored-by: Deep Prakash Dewanji <deepprakashdewanji@labusers-mbp-5.macromedia.com>
Co-authored-by: Deep Prakash Dewanji <deepprakashdewanji@labusers-mbp-9.corp.adobe.com>
  • Loading branch information
3 people committed May 7, 2024
1 parent e9b4d42 commit e23a818
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.adobe.cq.forms.core.components.internal.models.v1.form;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.RepositoryException;

Expand Down Expand Up @@ -45,6 +47,8 @@
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class StaticImageImpl extends AbstractFormComponentImpl implements StaticImage {

public static final String DAM_REPO_PATH = "fd:repoPath";

private Image image;

@SlingObject
Expand All @@ -62,6 +66,10 @@ public class StaticImageImpl extends AbstractFormComponentImpl implements Static
@org.jetbrains.annotations.Nullable
protected String description; // long description as per current spec

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileReference")
@Nullable
protected String fileReference;

/**
* Returns the source where the image is present.
*
Expand Down Expand Up @@ -120,4 +128,13 @@ public String getLinkUrl() {
return null;
}
}

@Override
public @Nonnull Map<String, Object> getProperties() {
Map<String, Object> properties = super.getProperties();
if (fileReference != null && fileReference.length() > 0) {
properties.put(DAM_REPO_PATH, fileReference);
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class StaticImageImplTest {
private static final String BASE = "/form/image";
private static final String CONTENT_ROOT = "/content";
private static final String PATH_IMAGE_CUSTOMIZED = CONTENT_ROOT + "/image-customized";

private static final String PATH_IMAGE_PARSED = CONTENT_ROOT + "/image-parsedSrc";
private static final String PATH_IMAGE = CONTENT_ROOT + "/image";
private static final String PATH_IMAGE_DATALAYER = CONTENT_ROOT + "/image-datalayer";

Expand All @@ -67,6 +69,13 @@ void testExportedType() {
assertEquals("", staticImageMock.getExportedType());
}

@Test
void testExportedTypeForParsedImage() {
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_PARSED, StaticImage.class, context);
assertEquals(FormConstants.RT_FD_FORM_IMAGE_V1, staticImage.getExportedType());
assertEquals("/content/dam/formsanddocuments/abc.jpeg", staticImage.getProperties().get("fd:repoPath"));
}

@Test
void testFieldType() {
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_CUSTOMIZED, StaticImage.class, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "image-7cfd7f1fe4",
"fieldType": "image",
"name": "abcd",
"visible": false,
"altText": "abc",
"value": "/content/image-customized.img.png",
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:path": "/content/image",
"fd:repoPath": "/content/dam/formsanddocuments/abc.jpeg"
},
":type": "core/fd/components/form/image/v1/image"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
]
},
"properties": {
"fd:path": "/content/image"
"fd:path": "/content/image",
"fd:repoPath": "/content/dam/formsanddocuments/abc.jpeg"
},
":type": "core/fd/components/form/image/v1/image"
}
13 changes: 13 additions & 0 deletions bundles/af-core/src/test/resources/form/image/test-content.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"image-parsedSrc" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/image/v1/image",
"name" : "abcd",
"jcr:title" : "def",
"hideTitle" : false,
"visible" : false,
"altText": "abc",
"fileReference": "/content/dam/formsanddocuments/abc.jpeg",
"excludeFromDor": false,
"fieldType": "image"
},
"image-customized" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/image/v1/image",
Expand All @@ -21,6 +33,7 @@
"jcr:createdBy": "admin",
"jcr:title": "Image",
"name": "emptyImage",
"fileReference": "/content/dam/formsanddocuments/abc.jpeg",
"sling:resourceType": "core/fd/components/form/image/v1/image",
"fieldType": "image"
},
Expand Down

0 comments on commit e23a818

Please sign in to comment.