Skip to content

Commit 4e714b3

Browse files
authored
FORMS-19721 Addition of rules to the CRISPR JSON for print channel (#1594)
* Added rule events and passed chanel information to child * Added rule events and passed chanel information to child * Removed unnecessary imports * Removed rule editor uber changes * mergedchanges and added missing one * mergedchanges and added missing one * Added test cases * modified null check
1 parent ca9443d commit 4e714b3

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ private FormConstants() {
151151

152152
/** The channel for print */
153153
public static final String CHANNEL_PRINT = "print";
154-
}
154+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,4 @@ protected String translate(@NotNull String propertyName, @Nullable String proper
224224
return com.adobe.cq.forms.core.components.util.ComponentUtils.translate(propertyValue, propertyName, resource, i18n);
225225
}
226226

227-
}
227+
}

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,35 @@ public Map<String, String> getRules() {
342342
private Map<String, Object> getRulesProperties() {
343343
Resource ruleNode = resource.getChild(CUSTOM_RULE_PROPERTY_WRAPPER);
344344
Map<String, Object> customRulesProperties = new LinkedHashMap<>();
345+
if (ruleNode == null) {
346+
logger.debug("No rules node found for resource: {}", resource.getPath());
347+
return customRulesProperties;
348+
}
349+
addValidationStatus(ruleNode, customRulesProperties);
350+
if (FormConstants.CHANNEL_PRINT.equals(this.channel)) {
351+
populateAdditionalRulesProperties(ruleNode, customRulesProperties);
352+
}
353+
return customRulesProperties;
354+
}
355+
356+
private void addValidationStatus(Resource ruleNode, Map<String, Object> customRulesProperties) {
345357
String status = getRulesStatus(ruleNode);
346358
if (!STATUS_NONE.equals(status)) {
347-
customRulesProperties.put(RULES_STATUS_PROP_NAME, getRulesStatus(ruleNode));
359+
customRulesProperties.put(RULES_STATUS_PROP_NAME, status);
348360
}
349-
return customRulesProperties;
361+
}
362+
363+
private void populateAdditionalRulesProperties(@NotNull Resource ruleNode, Map<String, Object> customRulesProperties) {
364+
String[] RULES = { "fd:formReady", "fd:layoutReady", "fd:docReady", "fd:calc", "fd:init", "fd:validate", "fd:indexChange" };
365+
ValueMap props = ruleNode.adaptTo(ValueMap.class);
366+
if (props != null) {
367+
Arrays.stream(RULES).forEach(rule -> addRuleProperty(props, customRulesProperties, rule));
368+
}
369+
}
370+
371+
private void addRuleProperty(@NotNull ValueMap props, Map<String, Object> customRulesProperties, String rule) {
372+
Optional<String[]> propertyValue = Optional.ofNullable(props.get(rule, String[].class));
373+
propertyValue.ifPresent(value -> customRulesProperties.put(rule, value));
350374
}
351375

352376
/***

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class AbstractFormComponentImplTest {
5353
private static final String PATH_COMPONENT_WITH_DISABLED_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponent";
5454
private static final String PATH_COMPONENT_WITH_INVALID_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponentinvalid";
5555
private static final String PATH_COMPONENT_WITH_NO_XFA_SCRIPTS = CONTENT_ROOT + "/xfacomponentnone";
56+
private static final String PATH_COMPONENT_WITH_RULES = CONTENT_ROOT + "/textinputWithPrintRule";
5657
private static final String AF_PATH = "/content/forms/af/testAf";
5758
private static final String PAGE_PATH = "/content/testPage";
5859

@@ -203,4 +204,15 @@ public void testGetDorContainer() {
203204
assertThrows(java.lang.IllegalArgumentException.class, () -> abstractFormComponentImpl.getDorContainer());
204205

205206
}
207+
208+
@Test
209+
public void testPrintChannelRule() {
210+
AbstractFormComponentImpl abstractFormComponentImpl = prepareTestClass(PATH_COMPONENT_WITH_RULES);
211+
Utils.setInternalState(abstractFormComponentImpl, "channel", "print");
212+
Map<String, Object> properties = abstractFormComponentImpl.getProperties();
213+
Object rulesProperties = properties.get("fd:rules");
214+
assertNotNull(rulesProperties);
215+
Object formReadyRule = ((Map<String, Object>) rulesProperties).get("fd:formReady");
216+
assertNotNull(formReadyRule);
217+
}
206218
}

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
@@ -54,5 +54,16 @@
5454
},
5555
"xfacomponentnone": {
5656
"jcr:primaryType": "nt:unstructured"
57+
},
58+
"textinputWithPrintRule": {
59+
"jcr:primaryType": "nt:unstructured",
60+
"name": "name",
61+
"sling:resourceType": "forms-components-examples/components/form/textinput",
62+
"fieldType": "text-input",
63+
"fd:channel": "print",
64+
"fd:rules": {
65+
"jcr:primaryType": "nt:unstructured",
66+
"fd:formReady": ["form Ready"]
67+
}
5768
}
5869
}

0 commit comments

Comments
 (0)