Skip to content

Commit c791fca

Browse files
Adding scribble signature support. (#1651)
* Adding scribble signature support. * Adding scribble signature support. * Adding scribble signature support. * Moving the test logic to then post click. * Moving the test logic to then post click. * Moving the test logic to then post click. * Moving the test logic to then post click. * Moving the test logic to then post click. * Addressing review comments. * Moving the test logic to then post click. * Addressing review comments. * Addressing review comments. * Moving the test logic to then post click.
1 parent 42077bb commit c791fca

File tree

49 files changed

+2390
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2390
-38
lines changed

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/ReservedProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private ReservedProperties() {
165165
public static final String FD_AUTO_SAVE_STRATEGY_TYPE = "fd:autoSaveStrategyType";
166166
public static final String FD_AUTO_SAVE_INTERVAL = "fd:autoSaveInterval";
167167
public static final String FD_EXCLUDE_FROM_DOR_IF_HIDDEN = "fd:excludeFromDoRIfHidden";
168-
168+
public static final String FD_DIALOG_LABEL = "fd:dialogLabel";
169169
public static final String FD_XFA_SCRIPTS = "fd:xfaScripts";
170170

171171
public static final String FD_DRAFT_ID = "fd:draftId";
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
17+
package com.adobe.cq.forms.core.components.internal.models.v1.form;
18+
19+
import java.util.Map;
20+
21+
import org.apache.sling.api.SlingHttpServletRequest;
22+
import org.apache.sling.api.resource.Resource;
23+
import org.apache.sling.models.annotations.Default;
24+
import org.apache.sling.models.annotations.Exporter;
25+
import org.apache.sling.models.annotations.Model;
26+
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
27+
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
28+
import org.jetbrains.annotations.NotNull;
29+
30+
import com.adobe.cq.export.json.ComponentExporter;
31+
import com.adobe.cq.export.json.ExporterConstants;
32+
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
33+
import com.adobe.cq.forms.core.components.models.form.FieldType;
34+
import com.adobe.cq.forms.core.components.models.form.Scribble;
35+
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
36+
import com.fasterxml.jackson.annotation.JsonIgnore;
37+
import com.fasterxml.jackson.annotation.JsonInclude;
38+
39+
@Model(
40+
adaptables = { SlingHttpServletRequest.class, Resource.class },
41+
adapters = { Scribble.class, ComponentExporter.class },
42+
resourceType = "core/fd/components/form/scribble/v1/scribble")
43+
@Exporter(
44+
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
45+
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
46+
public class ScribbleImpl extends AbstractFieldImpl implements Scribble {
47+
48+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
49+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
50+
private String value;
51+
52+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.FD_DIALOG_LABEL)
53+
@Default(values = Scribble.DEFAULT_DIALOG_LABEL)
54+
protected String dialogLabel;
55+
56+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_FORMAT)
57+
@JsonInclude(JsonInclude.Include.NON_NULL)
58+
protected String format;
59+
60+
@Override
61+
public String getValue() {
62+
return value;
63+
}
64+
65+
@JsonIgnore
66+
public String getDialogLabel() {
67+
return dialogLabel;
68+
}
69+
70+
@Override
71+
public String getFormat() {
72+
return format;
73+
}
74+
75+
@Override
76+
public String getFieldType() {
77+
return super.getFieldType(FieldType.FILE_INPUT);
78+
}
79+
80+
@Override
81+
public @NotNull Map<String, Object> getProperties() {
82+
Map<String, Object> customProperties = super.getProperties();
83+
customProperties.put(ReservedProperties.PN_VIEWTYPE, "signature");
84+
if (getDialogLabel() != null)
85+
customProperties.put(ReservedProperties.FD_DIALOG_LABEL, getDialogLabel());
86+
return customProperties;
87+
}
88+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2024 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
17+
package com.adobe.cq.forms.core.components.models.form;
18+
19+
import org.osgi.annotation.versioning.ConsumerType;
20+
21+
/**
22+
* Defines the form Scribble Sling Model used for the Scribble component.
23+
*
24+
* @since com.adobe.cq.forms.core.components.models.form 5.12.0
25+
*/
26+
@ConsumerType
27+
public interface Scribble extends Field {
28+
29+
String DEFAULT_DIALOG_LABEL = "Please sign here";
30+
31+
/**
32+
* Returns the data-url string of the scribble.
33+
*
34+
* @return data-url string representing the scribble
35+
* @since com.adobe.cq.forms.core.components.models.form 5.12.0
36+
*/
37+
String getValue();
38+
39+
/**
40+
* Returns the format of the scribble.
41+
*
42+
* @return the format of the scribble, e.g., data-url
43+
* @since com.adobe.cq.forms.core.components.models.form 5.12.0
44+
*/
45+
String getFormat();
46+
47+
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* </p>
3636
*/
3737

38-
@Version("5.11.0")
38+
@Version("5.12.0")
3939
package com.adobe.cq.forms.core.components.models.form;
4040

4141
import org.osgi.annotation.versioning.Version;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
package com.adobe.cq.forms.core.components.internal.models.v1.form;
17+
18+
import java.util.Map;
19+
20+
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.mockito.Mockito;
25+
26+
import com.adobe.cq.forms.core.Utils;
27+
import com.adobe.cq.forms.core.components.models.form.FieldType;
28+
import com.adobe.cq.forms.core.components.models.form.Scribble;
29+
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
30+
import io.wcm.testing.mock.aem.junit5.AemContext;
31+
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
32+
33+
import static org.junit.Assert.assertEquals;
34+
import static org.junit.Assert.assertNotNull;
35+
import static org.junit.Assert.assertTrue;
36+
37+
@ExtendWith(AemContextExtension.class)
38+
public class ScribbleImplTest {
39+
private static final String BASE = "/form/scribble";
40+
private static final String CONTENT_ROOT = "/content";
41+
private static final String PATH_SCRIBBLE = CONTENT_ROOT + "/scribble";
42+
private final AemContext context = FormsCoreComponentTestContext.newAemContext();
43+
44+
@BeforeEach
45+
void setUp() {
46+
context.load().json(BASE + "/test_content.json", CONTENT_ROOT);
47+
}
48+
49+
@Test
50+
void testExportedType() {
51+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
52+
assertEquals("core/fd/components/form/scribble/v1/scribble", scribble.getExportedType());
53+
Scribble scribbleMock = Mockito.mock(Scribble.class);
54+
Mockito.when(scribbleMock.getExportedType()).thenCallRealMethod();
55+
assertEquals("", scribbleMock.getExportedType());
56+
}
57+
58+
@Test
59+
void testFieldType() {
60+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
61+
assertEquals(FieldType.FILE_INPUT.getValue(), scribble.getFieldType());
62+
}
63+
64+
@Test
65+
void testGetValue() {
66+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
67+
assertEquals("", scribble.getValue());
68+
}
69+
70+
@Test
71+
void testGetLabel() {
72+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
73+
assertEquals("Scribble", scribble.getLabel().getValue());
74+
}
75+
76+
@Test
77+
void testGetProperties() {
78+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
79+
Map<String, Object> properties = scribble.getProperties();
80+
assertNotNull(properties);
81+
assertTrue(properties.containsKey("fd:viewType"));
82+
assertEquals("signature", properties.get("fd:viewType"));
83+
assertTrue(properties.containsKey("fd:dialogLabel"));
84+
assertEquals("Scribble", properties.get("fd:dialogLabel"));
85+
}
86+
87+
@Test
88+
void testJSONExport() throws Exception {
89+
Scribble scribble = getScribbleUnderTest(PATH_SCRIBBLE);
90+
Utils.testJSONExport(scribble, BASE + "/exporter-scribble.json");
91+
}
92+
93+
private Scribble getScribbleUnderTest(String resourcePath) {
94+
context.currentResource(resourcePath);
95+
MockSlingHttpServletRequest request = context.request();
96+
return request.adaptTo(Scribble.class);
97+
}
98+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": "scribble-ca4ee66cea",
3+
"fieldType": "file-input",
4+
"name": "scribble1710484027357",
5+
"type": "string",
6+
"properties": {
7+
"fd:dor": {
8+
"dorExclusion": false
9+
},
10+
"fd:path": "/content/scribble",
11+
"fd:viewType": "signature",
12+
"fd:dialogLabel": "Scribble"
13+
},
14+
"label": {
15+
"value": "Scribble"
16+
},
17+
"events": {
18+
"custom:setProperty": [
19+
"$event.payload"
20+
]
21+
},
22+
":type": "core/fd/components/form/scribble/v1/scribble"
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"scribble": {
3+
"jcr:primaryType": "nt:unstructured",
4+
"jcr:title": "Scribble",
5+
"name": "scribble1710484027357",
6+
"fieldType": "file-input",
7+
"value": "",
8+
"type": "string",
9+
"fd:dialogLabel": "Scribble",
10+
"properties": {
11+
"fd:dor": {
12+
"dorExclusion": false
13+
},
14+
"fd:path": "/content/scribble"
15+
},
16+
"sling:resourceType": "core/fd/components/form/scribble/v1/scribble"
17+
}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="cq:Component"
4+
jcr:title="Adaptive Form Scribble"
5+
jcr:description="Add a field to capture scribble signature."
6+
sling:resourceSuperType="core/fd/components/form/scribble/v1/scribble"
7+
componentGroup="Core Components Examples - Adaptive Form"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
3+
jcr:primaryType="nt:unstructured"
4+
jcr:title="Scribble"
5+
fieldType="file-input"
6+
fd:viewType="signature"
7+
fd:dialogLabel="Please sign here"
8+
placeholder="Type Your Signature Here"
9+
type="string"
10+
format="data-url"/>

0 commit comments

Comments
 (0)