Skip to content

Commit 203f57b

Browse files
Forms-2896: addition new excludeFromDoRIfHidden property in form container model (#1590)
* FORMS-2896: Adding excludeFromDoRIfHidden in formModel json * FORMS-2896: Test case for excludeFromDoRIfHidden * FORMS-2896: Format the code
1 parent 36afed5 commit 203f57b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private ReservedProperties() {
162162
public static final String FD_ENABLE_AUTO_SAVE = "fd:enableAutoSave";
163163
public static final String FD_AUTO_SAVE_STRATEGY_TYPE = "fd:autoSaveStrategyType";
164164
public static final String FD_AUTO_SAVE_INTERVAL = "fd:autoSaveInterval";
165+
public static final String FD_EXCLUDE_FROM_DOR_IF_HIDDEN = "excludeFromDoRIfHidden";
165166

166167
public static final String FD_XFA_SCRIPTS = "fd:xfaScripts";
167168

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
8383
public static final String FD_ROLE_ATTRIBUTE = "fd:roleAttribute";
8484
private static final String FD_CUSTOM_FUNCTIONS_URL = "fd:customFunctionsUrl";
8585
private static final String FD_DATA_URL = "fd:dataUrl";
86+
private static final String FD_VIEW_PRINT_PATH = "fd:view/print";
87+
private static final String EXCLUDE_FROM_DOR_IF_HIDDEN = "excludeFromDoRIfHidden";
8688

8789
/** Constant representing email submit action type */
8890
private static final String SS_EMAIL = "email";
@@ -140,6 +142,9 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
140142
@Nullable
141143
private String data;
142144

145+
@Nullable
146+
private Boolean excludeFromDoRIfHidden;
147+
143148
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_SPEC_VERSION)
144149
@Default(values = DEFAULT_FORMS_SPEC_VERSION)
145150
private String specVersion;
@@ -173,6 +178,17 @@ protected void initFormContainerModel() {
173178
}
174179
}
175180

181+
@PostConstruct
182+
private void initExcludeFromDoRIfHidden() {
183+
Resource viewPrintResource = resource.getChild(FD_VIEW_PRINT_PATH);
184+
if (viewPrintResource != null) {
185+
ValueMap vm = viewPrintResource.getValueMap();
186+
if (vm.containsKey(EXCLUDE_FROM_DOR_IF_HIDDEN)) {
187+
excludeFromDoRIfHidden = vm.get(EXCLUDE_FROM_DOR_IF_HIDDEN, Boolean.class);
188+
}
189+
}
190+
}
191+
176192
@Override
177193
public void setContextPath(String contextPath) {
178194
this.contextPath = contextPath;
@@ -402,6 +418,9 @@ public Map<String, Object> getDorProperties() {
402418
if (dorTemplateType != null) {
403419
customDorProperties.put(DOR_TEMPLATE_TYPE, dorTemplateType);
404420
}
421+
if (excludeFromDoRIfHidden != null) {
422+
customDorProperties.put(EXCLUDE_FROM_DOR_IF_HIDDEN, excludeFromDoRIfHidden);
423+
}
405424
return customDorProperties;
406425
}
407426

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public class FormContainerImplTest {
115115
private static final String SS_EMAIL = "email";
116116
private static final String SS_SPREADSHEET = "spreadsheet";
117117

118+
private static final String PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN = "/content/forms/af/demo/jcr:content/formcontainerv2-excludeFromDoRIfHidden";
119+
118120
private final AemContext context = FormsCoreComponentTestContext.newAemContext();
119121

120122
@BeforeEach
@@ -785,4 +787,32 @@ public void testActionForCCFormRestSubmission() throws Exception {
785787
!decodedAction.endsWith(".model.json"));
786788
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_CC_FORM_REST_SUBMISSION));
787789
}
790+
791+
@Test
792+
void testExcludeFromDoRIfHiddenFromViewPrint() throws Exception {
793+
// Setup: create a resource structure with fd:view/print child and excludeFromDoRIfHidden property
794+
context.create().resource(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN,
795+
"sling:resourceType", "core/fd/components/form/container/v2/container");
796+
context.create().resource(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN + "/fd:view/print",
797+
"excludeFromDoRIfHidden", true);
798+
799+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN, FormContainer.class, context);
800+
Map<String, Object> dorProperties = ((FormContainerImpl) formContainer).getDorProperties();
801+
assertTrue(dorProperties.containsKey("excludeFromDoRIfHidden"));
802+
assertEquals(true, dorProperties.get("excludeFromDoRIfHidden"));
803+
}
804+
805+
@Test
806+
void testExcludeFromDoRIfHiddenFromViewPrintFalse() throws Exception {
807+
// Setup: create a resource structure with fd:view/print child and excludeFromDoRIfHidden property set to false
808+
context.create().resource(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN,
809+
"sling:resourceType", "core/fd/components/form/container/v2/container");
810+
context.create().resource(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN + "/fd:view/print",
811+
"excludeFromDoRIfHidden", false);
812+
813+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_EXCLUDE_FROM_DOR_IF_HIDDEN, FormContainer.class, context);
814+
Map<String, Object> dorProperties = ((FormContainerImpl) formContainer).getDorProperties();
815+
assertTrue(dorProperties.containsKey("excludeFromDoRIfHidden"));
816+
assertEquals(false, dorProperties.get("excludeFromDoRIfHidden"));
817+
}
788818
}

0 commit comments

Comments
 (0)