Skip to content

Commit 9b1eb2a

Browse files
rismehtaShivam Agarwal
andauthored
FORMS-18986 XFA to AF (#1532)
* XFA web pack refactoring * FORMS-16342 adding xfa data model in CC * XFA changes to master * XFA changes to master * Adding support for xfa page component * Adding test and few fixes * Adding xfa client lib to .gitignore * Stop tracking auto-generated client libs * Language resources would always be part of runtime-all library * Adding xfa test * Fixing xfa test * Fixing test * Fixing XFA data model code --------- Co-authored-by: Shivam Agarwal <shivama@adobe.com>
1 parent 0e467d3 commit 9b1eb2a

File tree

55 files changed

+1312
-101
lines changed

Some content is hidden

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

55 files changed

+1312
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# auto-generated clientlib
1111
ui.af.apps/src/main/content/jcr_root/apps/core/fd/af-clientlibs/core-forms-components-runtime-base/**
12+
ui.af.apps/src/main/content/jcr_root/apps/core/fd/af-clientlibs/core-forms-components-runtime-base-xfa/**
1213

1314
# Ignore Maven stuff
1415
target/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ private ReservedProperties() {
163163
public static final String FD_AUTO_SAVE_STRATEGY_TYPE = "fd:autoSaveStrategyType";
164164
public static final String FD_AUTO_SAVE_INTERVAL = "fd:autoSaveInterval";
165165

166+
public static final String FD_XFA_SCRIPTS = "fd:xfaScripts";
167+
166168
public static final String FD_DRAFT_ID = "fd:draftId";
167169
private static final Set<String> reservedProperties = aggregateReservedProperties();
168170

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.math.BigDecimal;
20-
import java.util.AbstractMap;
21-
import java.util.Arrays;
22-
import java.util.Calendar;
23-
import java.util.Collections;
24-
import java.util.HashMap;
25-
import java.util.HashSet;
26-
import java.util.LinkedHashMap;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Optional;
30-
import java.util.Set;
20+
import java.util.*;
3121
import java.util.function.Predicate;
3222
import java.util.regex.Pattern;
3323
import java.util.stream.Collectors;
@@ -68,9 +58,12 @@
6858
import com.fasterxml.jackson.annotation.JsonInclude;
6959
import com.fasterxml.jackson.annotation.JsonProperty;
7060
import com.fasterxml.jackson.core.JsonGenerator;
61+
import com.fasterxml.jackson.databind.JsonNode;
7162
import com.fasterxml.jackson.databind.JsonSerializer;
63+
import com.fasterxml.jackson.databind.ObjectMapper;
7264
import com.fasterxml.jackson.databind.SerializerProvider;
7365
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
66+
import com.fasterxml.jackson.databind.node.ArrayNode;
7467

7568
public class AbstractFormComponentImpl extends AbstractComponentImpl implements FormComponent {
7669
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_DATAREF)
@@ -298,6 +291,10 @@ protected boolean getEditMode() {
298291
if (rulesProperties.size() > 0) {
299292
properties.put(CUSTOM_RULE_PROPERTY_WRAPPER, rulesProperties);
300293
}
294+
List<String> disabledScripts = getDisabledXFAScripts();
295+
if (!disabledScripts.isEmpty()) {
296+
properties.put("fd:disabledXfaScripts", disabledScripts);
297+
}
301298
return properties;
302299
}
303300

@@ -550,4 +547,24 @@ public Map<String, Object> getDorProperties() {
550547
return customDorProperties;
551548
}
552549

550+
private List<String> getDisabledXFAScripts() {
551+
Set<String> disabledScripts = new HashSet<>();
552+
String xfaScripts = resource.getValueMap().get(ReservedProperties.FD_XFA_SCRIPTS, "");
553+
if (StringUtils.isNotEmpty(xfaScripts)) {
554+
// read string xfaScripts to jsonNode
555+
ObjectMapper mapper = new ObjectMapper();
556+
try {
557+
ArrayNode node = (ArrayNode) mapper.readTree(xfaScripts);
558+
// iterate through the array node and add the elements which have disabled property set to true
559+
for (JsonNode jsonNode : node) {
560+
if (jsonNode.has("disabled") && jsonNode.get("disabled").asBoolean()) {
561+
disabledScripts.add(jsonNode.get("activity").asText());
562+
}
563+
}
564+
} catch (IOException e) {
565+
logger.error("Error while parsing xfaScripts {} {}", e, resource.getPath());
566+
}
567+
}
568+
return new ArrayList<>(disabledScripts);
569+
}
553570
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractOptionsFieldImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
21+
import java.util.Optional;
2122
import java.util.stream.IntStream;
2223

2324
import org.apache.sling.models.annotations.Default;
@@ -106,9 +107,7 @@ public String[] getEnumNames() {
106107
Map<Object, String> map = getEnumPairs();
107108
String[] enumName = map.values().toArray(new String[0]);
108109
return Arrays.stream(enumName)
109-
.map(p -> {
110-
return this.translate(ReservedProperties.PN_ENUM_NAMES, p);
111-
})
110+
.map(p -> Optional.ofNullable(translate(ReservedProperties.PN_ENUM_NAMES, p)).orElse(""))
112111
.toArray(String[]::new);
113112
}
114113
return null;

bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/CheckBoxGroupImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class CheckBoxGroupImplTest {
5757
private static final String PATH_CHECKBOX_GROUP_FOR_INSERTION_ORDER = CONTENT_ROOT + "/checkboxgroup-insertion-order";
5858
private static final String PATH_CHECKBOX_GROUP_FOR_BOOLEAN = CONTENT_ROOT + "/checkboxgroup-boolean";
5959
private static final String PATH_CHECKBOX_GROUP_NO_FIELDTYPE = CONTENT_ROOT + "/checkboxgroup-without-fieldtype";
60+
private static final String PATH_CHECKBOX_GROUP_WITH_NULL_VALUES = CONTENT_ROOT + "/checkboxgroup-with-null-values";
6061

6162
private final AemContext context = FormsCoreComponentTestContext.newAemContext();
6263

@@ -298,6 +299,18 @@ void testGetEnumNames() {
298299
assertArrayEquals(new String[] { "m", "f", "o" }, checkboxGroup.getEnumNames());
299300
}
300301

302+
@Test
303+
void testGetEnumNamesWithNullValues() throws Exception {
304+
// Get the checkbox group under test
305+
CheckBoxGroup checkboxGroup = getCheckBoxGroupUnderTest(PATH_CHECKBOX_GROUP);
306+
String[] modifiedEnumNames = new String[] { null, "", "value3" };
307+
FieldUtils.writeField(checkboxGroup, "enumNames", modifiedEnumNames, true);
308+
// Now call getEnumNames() which should handle the null value by converting it to an empty string
309+
String[] result = checkboxGroup.getEnumNames();
310+
// Verify that nulls are converted to empty strings
311+
assertArrayEquals(new String[] { "", "", "value3" }, result);
312+
}
313+
301314
@Test
302315
void testGetEnumNamesWithDuplicateEnumValues() {
303316
CheckBoxGroup checkboxGroup = getCheckBoxGroupUnderTest(PATH_CHECKBOX_GROUP_WITH_DUPLICATE_ENUMS);

bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImplTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.adobe.cq.forms.core.components.util;
1818

1919
import java.lang.reflect.Method;
20+
import java.util.List;
2021
import java.util.Map;
2122

2223
import org.apache.sling.api.resource.Resource;
@@ -48,6 +49,9 @@ public class AbstractFormComponentImplTest {
4849
private static final String PATH_COMPONENT_WITH_NO_VALIDATION_STATUS = CONTENT_ROOT + "/datepicker2";
4950
private static final String PATH_COMPONENT_WITH_INVALID_VALIDATION_STATUS = CONTENT_ROOT + "/datepicker3";
5051
private static final String PATH_COMPONENT_WITH_NO_RULE = CONTENT_ROOT + "/numberinput";
52+
private static final String PATH_COMPONENT_WITH_DISABLED_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponent";
53+
private static final String PATH_COMPONENT_WITH_INVALID_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponentinvalid";
54+
private static final String PATH_COMPONENT_WITH_NO_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponentnone";
5155
private static final String AF_PATH = "/content/forms/af/testAf";
5256
private static final String PAGE_PATH = "/content/testPage";
5357

@@ -101,6 +105,34 @@ public void testInvalidValidationStatusRule() {
101105
assertEquals("invalid", rulesProperties.get("validationStatus"));
102106
}
103107

108+
@Test
109+
public void testDisabledXFAScripts() {
110+
AbstractFormComponentImpl abstractFormComponentImpl = prepareTestClass(PATH_COMPONENT_WITH_DISABLED_XFA_SCRIPTS);
111+
Map<String, Object> properties = abstractFormComponentImpl.getProperties();
112+
List<String> disabledScripts = (List<String>) properties.get("fd:disabledXfaScripts");
113+
assertNotNull(disabledScripts);
114+
assertEquals(2, disabledScripts.size());
115+
assertTrue(disabledScripts.contains("click"));
116+
assertTrue(disabledScripts.contains("change"));
117+
}
118+
119+
@Test
120+
public void testInvalidXFAScripts() {
121+
AbstractFormComponentImpl abstractFormComponentImpl = prepareTestClass(PATH_COMPONENT_WITH_INVALID_XFA_SCRIPTS);
122+
Map<String, Object> properties = abstractFormComponentImpl.getProperties();
123+
Object disabledScripts = properties.get("fd:disabledXfaScripts");
124+
// Even with invalid JSON, we should get an empty list, not null
125+
assertNull(disabledScripts);
126+
}
127+
128+
@Test
129+
public void testNoXFAScripts() {
130+
AbstractFormComponentImpl abstractFormComponentImpl = prepareTestClass(PATH_COMPONENT_WITH_NO_XFA_SCRIPTS);
131+
Map<String, Object> properties = abstractFormComponentImpl.getProperties();
132+
Object disabledScripts = properties.get("fd:disabledXfaScripts");
133+
assertNull(disabledScripts);
134+
}
135+
104136
@Test
105137
public void testEmbedWithIframe() {
106138
Resource resource = Mockito.mock(Resource.class);
@@ -147,7 +179,6 @@ public Page getCurrentPageToTest() {
147179
}
148180
}
149181

150-
@Test
151182
private AbstractFormComponentImpl prepareTestClass(String path) {
152183
Resource resource = context.resourceResolver().getResource(path);
153184
AbstractFormComponentImpl abstractFormComponentImpl = new AbstractFormComponentImpl();

bundles/af-core/src/test/resources/form/checkboxgroup/test-content.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,25 @@
269269
],
270270
"jcr:lastModified": "Tue Jul 30 2024 15:16:00 GMT+0530",
271271
"sling:resourceType": "forms-components-examples/components/form/checkboxgroup"
272+
},
273+
"checkboxgroup-with-null-values": {
274+
"id": "checkboxgroup-with-null-values",
275+
"jcr:primaryType": "nt:unstructured",
276+
"sling:resourceType": "core/fd/components/form/checkboxgroup/v1/checkboxgroup",
277+
"name": "nullValues",
278+
"jcr:title": "Null Values Test",
279+
"fieldType": "checkbox-group",
280+
"type": "number[]",
281+
"enum": [
282+
0,
283+
1,
284+
2
285+
],
286+
"enforceEnum": true,
287+
"enumNames": [
288+
"",
289+
"",
290+
"value3"
291+
]
272292
}
273293
}

bundles/af-core/src/test/resources/form/componentswithrule/test-content.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,16 @@
4343
"jcr:primaryType": "nt:unstructured",
4444
"validationStatus" : "someInvalidStatus"
4545
}
46+
},
47+
"xfacomponent": {
48+
"jcr:primaryType": "nt:unstructured",
49+
"fd:xfaScripts": "[{\"activity\":\"click\",\"disabled\":true},{\"activity\":\"change\",\"disabled\":true},{\"activity\":\"initialize\",\"disabled\":false}]"
50+
},
51+
"xfacomponentinvalid": {
52+
"jcr:primaryType": "nt:unstructured",
53+
"fd:xfaScripts": "invalid json"
54+
},
55+
"xfacomponentnone": {
56+
"jcr:primaryType": "nt:unstructured"
4657
}
4758
}

it/config/src/main/content/jcr_root/apps/system/config/com.adobe.granite.toggle.impl.dev.DynamicToggleProviderImpl.cfg.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"FT_SITES-19631",
2222
"FT_FORMS-14255",
2323
"FT_FORMS-14068",
24-
"FT_FORMS-16351"
24+
"FT_FORMS-16351",
25+
"FT_FORMS-14518"
2526
]
2627
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:dam="http://www.day.com/dam/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
3+
jcr:mixinTypes="[mix:referenceable]"
4+
jcr:primaryType="dam:Asset"
5+
jcr:uuid="9430dcf2-cfb7-4ae8-80ae-84a3675547b7">
6+
<jcr:content
7+
dam:assetState="processed"
8+
jcr:lastModified="{Date}2025-02-28T12:13:46.966+05:30"
9+
jcr:lastModifiedBy="admin"
10+
jcr:primaryType="dam:AssetContent"
11+
sling:resourceType="fd/fm/xfaforms/render"
12+
type="xfaForm"
13+
xfaForm="{Long}1">
14+
<metadata
15+
dam:extracted="{Date}2025-02-28T12:13:42.704+05:30"
16+
dam:sha1="5a33541a37987b9ef052a4e64a56fa3502dbcfe1"
17+
dam:size="{Long}10015"
18+
dc:format="application/vnd.adobe.xdp+xml"
19+
jcr:lastModified="{Date}2025-02-28T12:13:42.643+05:30"
20+
jcr:lastModifiedBy="admin"
21+
jcr:mixinTypes="[mix:created,mix:lastModified]"
22+
jcr:primaryType="nt:unstructured"
23+
allowedRenderFormat="BOTH"
24+
availableInMobileApp="false"
25+
name="showHideRule.xdp"
26+
profile="/libs/xfaforms/profiles/default"/>
27+
</jcr:content>
28+
</jcr:root>

0 commit comments

Comments
 (0)