Skip to content

Commit 633484a

Browse files
authored
Merge pull request #1516 from adobe/master65027Jan
Master65027 jan
2 parents 0bfda99 + c6a9ff3 commit 633484a

File tree

27 files changed

+355
-86
lines changed

27 files changed

+355
-86
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ frontend-maven-plugin
5858
yarn-error.log
5959
.env
6060
.npmrc
61+
**/npm-debug.log
62+
6163

6264
# UI Tests
6365
node/

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
@@ -162,6 +162,8 @@ 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+
166+
public static final String FD_DRAFT_ID = "fd:draftId";
165167
private static final Set<String> reservedProperties = aggregateReservedProperties();
166168

167169
private static Set<String> aggregateReservedProperties() {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ public String getAltText() {
110110
return translate("altText", altText);
111111
}
112112

113-
@Override
114-
public String getDataRef() {
115-
return null;
116-
}
117-
118113
@Override
119114
@JsonIgnore
120115
public String getDescription() {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
8383
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
8484
private CoreComponentCustomPropertiesProvider coreComponentCustomPropertiesProvider;
8585

86+
private static final String DRAFT_PREFILL_SERVICE = "service://FP/draft/";
87+
8688
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
8789
@Nullable
8890
private SlingHttpServletRequest request;
@@ -352,9 +354,19 @@ public String getLanguageDirection() {
352354
(request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF)))) {
353355
formDataEnabled = true;
354356
}
357+
358+
// set draftId in properties in case of forms portal prefill
359+
if (request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF))) {
360+
final String dataRef = request.getParameter(GuideConstants.AF_DATA_REF);
361+
if (dataRef.startsWith(DRAFT_PREFILL_SERVICE)) {
362+
properties.put(ReservedProperties.FD_DRAFT_ID, StringUtils.substringAfter(dataRef, DRAFT_PREFILL_SERVICE));
363+
}
364+
}
355365
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
356366
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
357-
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
367+
if (this.autoSaveConfig != null && this.autoSaveConfig.isEnableAutoSave()) {
368+
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
369+
}
358370
properties.put(FD_CUSTOM_FUNCTIONS_URL, getCustomFunctionUrl());
359371
properties.put(FD_DATA_URL, getDataUrl());
360372

@@ -416,4 +428,10 @@ public String getCustomFunctionUrl() {
416428
return getContextPath() + ADOBE_GLOBAL_API_ROOT + FORMS_RUNTIME_API_GLOBAL_ROOT + "/customfunctions/" + getId();
417429
}
418430

431+
@JsonIgnore
432+
@Override
433+
public AutoSaveConfiguration getAutoSaveConfig() {
434+
return autoSaveConfig;
435+
}
436+
419437
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,15 @@ default String getCustomFunctionUrl() {
391391
return null;
392392
}
393393

394+
/**
395+
* Returns the auto save configuration
396+
*
397+
* @return auto save configuration
398+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
399+
*/
400+
@JsonIgnore
401+
default AutoSaveConfiguration getAutoSaveConfig() {
402+
return null;
403+
}
404+
394405
}

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.10.0")
38+
@Version("5.11.0")
3939
package com.adobe.cq.forms.core.components.models.form;
4040

4141
import org.osgi.annotation.versioning.Version;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void testGetName() {
9595
@Test
9696
void testGetDataRef() {
9797
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_CUSTOMIZED, StaticImage.class, context);
98-
assertEquals(null, staticImage.getDataRef());
98+
assertEquals("a.b", staticImage.getDataRef());
9999
StaticImage staticImageMock = Mockito.mock(StaticImage.class);
100100
Mockito.when(staticImageMock.getDataRef()).thenCallRealMethod();
101101
assertEquals(null, staticImageMock.getDataRef());

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

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@
4747
import com.adobe.cq.export.json.SlingModelFilter;
4848
import com.adobe.cq.forms.core.Utils;
4949
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
50-
import com.adobe.cq.forms.core.components.models.form.FieldType;
51-
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
52-
import com.adobe.cq.forms.core.components.models.form.FormContainer;
53-
import com.adobe.cq.forms.core.components.models.form.TextInput;
54-
import com.adobe.cq.forms.core.components.models.form.ThankYouOption;
50+
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
51+
import com.adobe.cq.forms.core.components.models.form.*;
5552
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
5653
import com.day.cq.i18n.I18n;
5754
import com.day.cq.wcm.api.NameConstants;
5855
import com.day.cq.wcm.api.Page;
5956
import com.day.cq.wcm.api.PageManager;
57+
import com.day.cq.wcm.foundation.model.export.AllowedComponentsExporter;
6058
import com.day.cq.wcm.msm.api.MSMNameConstants;
6159
import io.wcm.testing.mock.aem.junit5.AemContext;
6260
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
@@ -79,6 +77,8 @@ public class FormContainerImplTest {
7977
private static final String CONTENT_DAM_ROOT = "/content/dam/formsanddocuments/demo";
8078
private static final String PATH_FORM_1 = CONTENT_ROOT + "/formcontainerv2";
8179
private static final String PATH_FORM_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/formcontainerv2-without-fieldtype";
80+
81+
private static final String PATH_FORM_WITH_AUTO_SAVE = CONTENT_ROOT + "/formcontainerv2WithAutoSave";
8282
private static final String PATH_FORM_1_WITHOUT_REDIRECT = CONTENT_ROOT + "/formcontainerv2WithoutRedirect";
8383
private static final String CONTENT_FORM_WITHOUT_PREFILL_ROOT = "/content/forms/af/formWithoutPrefill";
8484
private static final String PATH_FORM_WITHOUT_PREFILL = CONTENT_FORM_WITHOUT_PREFILL_ROOT + "/formcontainerv2WithoutPrefill";
@@ -244,6 +244,14 @@ void testJSONExport() throws Exception {
244244
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_1));
245245
}
246246

247+
@Ignore
248+
void testJSONExportWithAutoSaveEnable() throws Exception {
249+
context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
250+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
251+
FormContainer.class, context);
252+
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_WITH_AUTO_SAVE));
253+
}
254+
247255
@Test
248256
void testGetThankYouMessage() throws Exception {
249257
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
@@ -456,6 +464,30 @@ void testGetFormDataEnabledWhenDataRefIsSet() throws Exception {
456464
request.setParameterMap(new HashMap<>());
457465
}
458466

467+
@Test
468+
void testDraftIdPropertyWhenDataRefIsSet() throws Exception {
469+
MockSlingHttpServletRequest request = context.request();
470+
Map<String, Object> tempMap = new HashMap<>();
471+
tempMap.put(GuideConstants.AF_DATA_REF, "service://FP/draft/KH5DOFY2RMWVOOVREE324MRXIY");
472+
request.setParameterMap(tempMap);
473+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
474+
assertEquals("KH5DOFY2RMWVOOVREE324MRXIY", formContainer.getProperties().get(ReservedProperties.FD_DRAFT_ID));
475+
// reset the parameter map
476+
request.setParameterMap(new HashMap<>());
477+
}
478+
479+
@Test
480+
void testDraftIdPropertyWhenDraftIdIsNotPresentInDataRef() throws Exception {
481+
MockSlingHttpServletRequest request = context.request();
482+
Map<String, Object> tempMap = new HashMap<>();
483+
tempMap.put(GuideConstants.AF_DATA_REF, "service://FP/draft");
484+
request.setParameterMap(tempMap);
485+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
486+
assertNull(formContainer.getProperties().get(ReservedProperties.FD_DRAFT_ID));
487+
// reset the parameter map
488+
request.setParameterMap(new HashMap<>());
489+
}
490+
459491
@Test
460492
void testGetFormDataDisabled() throws Exception {
461493
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
@@ -531,4 +563,63 @@ void testCustomFunctionUrl() throws Exception {
531563
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
532564
assertEquals("/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==", formContainer.getCustomFunctionUrl());
533565
}
566+
567+
@Test
568+
public void testGetAutoSaveProperties() throws Exception {
569+
context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
570+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
571+
FormContainer.class, context);
572+
assertNotNull(formContainer.getAutoSaveConfig());
573+
assertTrue(formContainer.getAutoSaveConfig().isEnableAutoSave());
574+
assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, formContainer.getAutoSaveConfig().getAutoSaveStrategyType());
575+
}
576+
577+
@Test
578+
public void testDefaultGetAutoSaveConfig() throws Exception {
579+
FormContainer formContainer1 = new FormContainer() {
580+
581+
@Override
582+
public FormMetaData getMetaData() {
583+
return null;
584+
}
585+
586+
@Override
587+
public String getEncodedCurrentPagePath() {
588+
return null;
589+
}
590+
591+
@Override
592+
public String getThankYouMessage() {
593+
return null;
594+
}
595+
596+
@Override
597+
public List<? extends ComponentExporter> getItems() {
598+
return null;
599+
}
600+
601+
@Override
602+
public String getGridClassNames() {
603+
return null;
604+
}
605+
606+
@Override
607+
public Map<String, String> getColumnClassNames() {
608+
return null;
609+
}
610+
611+
@Override
612+
public int getColumnCount() {
613+
return 0;
614+
}
615+
616+
@Override
617+
public AllowedComponentsExporter getExportedAllowedComponents() {
618+
return null;
619+
}
620+
};
621+
;
622+
assertNull(formContainer1.getAutoSaveConfig());
623+
}
624+
534625
}

bundles/af-core/src/test/resources/form/formcontainer/exporter-formcontainerv2.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"dorType": "generate",
99
"dorTemplateRef": "xyz"
1010
},
11-
"fd:autoSave": {
12-
"fd:enableAutoSave":false
13-
},
1411
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2",
1512
"fd:isHamburgerMenuEnabled": false,
1613
"fd:schemaType": "BASIC",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"id": "L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
3+
"fieldType": "form",
4+
"lang": "en",
5+
"properties": {
6+
"thankyouPage": "/a/b/c",
7+
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave",
8+
"fd:schemaType": "BASIC",
9+
"fd:isHamburgerMenuEnabled": false,
10+
"fd:roleAttribute": null,
11+
"fd:formDataEnabled": true,
12+
"fd:autoSave": {
13+
"fd:enableAutoSave": true,
14+
"fd:autoSaveStrategyType": "time",
15+
"fd:autoSaveInterval": 2
16+
},
17+
"fd:customFunctionsUrl": "/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
18+
"fd:dataUrl": "/adobe/forms/af/data/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw=="
19+
},
20+
"action": "/adobe/forms/af/submit/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
21+
"events": {
22+
"custom:setProperty": [
23+
"$event.payload"
24+
]
25+
},
26+
":itemsOrder": [
27+
"textinput"
28+
],
29+
"adaptiveform": "0.14.2",
30+
"metadata": {
31+
"grammar": "json-formula-1.0.0",
32+
"version": "1.0.0"
33+
},
34+
":type": "core/fd/components/form/container/v2/container",
35+
":items": {
36+
"textinput": {
37+
"id": "textinput-2ddda8d6f9",
38+
"fieldType": "text-input",
39+
"name": "abc",
40+
"visible": false,
41+
"description": "dummy",
42+
"type": "string",
43+
"label": {
44+
"value": "def",
45+
"visible": true
46+
},
47+
"properties": {
48+
"customProp": "customPropValue",
49+
"fd:dor": {
50+
"dorExclusion": false
51+
},
52+
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave/textinput"
53+
},
54+
"events": {
55+
"custom:setProperty": [
56+
"$event.payload"
57+
]
58+
},
59+
":type": "core/fd/components/form/textinput/v1/textinput"
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)