Skip to content

Commit

Permalink
Merge pull request #1516 from adobe/master65027Jan
Browse files Browse the repository at this point in the history
Master65027 jan
  • Loading branch information
rismehta authored Jan 27, 2025
2 parents 0bfda99 + c6a9ff3 commit 633484a
Show file tree
Hide file tree
Showing 27 changed files with 355 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ frontend-maven-plugin
yarn-error.log
.env
.npmrc
**/npm-debug.log


# UI Tests
node/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ private ReservedProperties() {
public static final String FD_ENABLE_AUTO_SAVE = "fd:enableAutoSave";
public static final String FD_AUTO_SAVE_STRATEGY_TYPE = "fd:autoSaveStrategyType";
public static final String FD_AUTO_SAVE_INTERVAL = "fd:autoSaveInterval";

public static final String FD_DRAFT_ID = "fd:draftId";
private static final Set<String> reservedProperties = aggregateReservedProperties();

private static Set<String> aggregateReservedProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ public String getAltText() {
return translate("altText", altText);
}

@Override
public String getDataRef() {
return null;
}

@Override
@JsonIgnore
public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
private CoreComponentCustomPropertiesProvider coreComponentCustomPropertiesProvider;

private static final String DRAFT_PREFILL_SERVICE = "service://FP/draft/";

@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private SlingHttpServletRequest request;
Expand Down Expand Up @@ -352,9 +354,19 @@ public String getLanguageDirection() {
(request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF)))) {
formDataEnabled = true;
}

// set draftId in properties in case of forms portal prefill
if (request != null && StringUtils.isNotBlank(request.getParameter(GuideConstants.AF_DATA_REF))) {
final String dataRef = request.getParameter(GuideConstants.AF_DATA_REF);
if (dataRef.startsWith(DRAFT_PREFILL_SERVICE)) {
properties.put(ReservedProperties.FD_DRAFT_ID, StringUtils.substringAfter(dataRef, DRAFT_PREFILL_SERVICE));
}
}
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
if (this.autoSaveConfig != null && this.autoSaveConfig.isEnableAutoSave()) {
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
}
properties.put(FD_CUSTOM_FUNCTIONS_URL, getCustomFunctionUrl());
properties.put(FD_DATA_URL, getDataUrl());

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

@JsonIgnore
@Override
public AutoSaveConfiguration getAutoSaveConfig() {
return autoSaveConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,15 @@ default String getCustomFunctionUrl() {
return null;
}

/**
* Returns the auto save configuration
*
* @return auto save configuration
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
*/
@JsonIgnore
default AutoSaveConfiguration getAutoSaveConfig() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </p>
*/

@Version("5.10.0")
@Version("5.11.0")
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void testGetName() {
@Test
void testGetDataRef() {
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_CUSTOMIZED, StaticImage.class, context);
assertEquals(null, staticImage.getDataRef());
assertEquals("a.b", staticImage.getDataRef());
StaticImage staticImageMock = Mockito.mock(StaticImage.class);
Mockito.when(staticImageMock.getDataRef()).thenCallRealMethod();
assertEquals(null, staticImageMock.getDataRef());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@
import com.adobe.cq.export.json.SlingModelFilter;
import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
import com.adobe.cq.forms.core.components.models.form.FormContainer;
import com.adobe.cq.forms.core.components.models.form.TextInput;
import com.adobe.cq.forms.core.components.models.form.ThankYouOption;
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.models.form.*;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.NameConstants;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.foundation.model.export.AllowedComponentsExporter;
import com.day.cq.wcm.msm.api.MSMNameConstants;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
Expand All @@ -79,6 +77,8 @@ public class FormContainerImplTest {
private static final String CONTENT_DAM_ROOT = "/content/dam/formsanddocuments/demo";
private static final String PATH_FORM_1 = CONTENT_ROOT + "/formcontainerv2";
private static final String PATH_FORM_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/formcontainerv2-without-fieldtype";

private static final String PATH_FORM_WITH_AUTO_SAVE = CONTENT_ROOT + "/formcontainerv2WithAutoSave";
private static final String PATH_FORM_1_WITHOUT_REDIRECT = CONTENT_ROOT + "/formcontainerv2WithoutRedirect";
private static final String CONTENT_FORM_WITHOUT_PREFILL_ROOT = "/content/forms/af/formWithoutPrefill";
private static final String PATH_FORM_WITHOUT_PREFILL = CONTENT_FORM_WITHOUT_PREFILL_ROOT + "/formcontainerv2WithoutPrefill";
Expand Down Expand Up @@ -244,6 +244,14 @@ void testJSONExport() throws Exception {
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_1));
}

@Ignore
void testJSONExportWithAutoSaveEnable() throws Exception {
context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
FormContainer.class, context);
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_WITH_AUTO_SAVE));
}

@Test
void testGetThankYouMessage() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
Expand Down Expand Up @@ -456,6 +464,30 @@ void testGetFormDataEnabledWhenDataRefIsSet() throws Exception {
request.setParameterMap(new HashMap<>());
}

@Test
void testDraftIdPropertyWhenDataRefIsSet() throws Exception {
MockSlingHttpServletRequest request = context.request();
Map<String, Object> tempMap = new HashMap<>();
tempMap.put(GuideConstants.AF_DATA_REF, "service://FP/draft/KH5DOFY2RMWVOOVREE324MRXIY");
request.setParameterMap(tempMap);
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
assertEquals("KH5DOFY2RMWVOOVREE324MRXIY", formContainer.getProperties().get(ReservedProperties.FD_DRAFT_ID));
// reset the parameter map
request.setParameterMap(new HashMap<>());
}

@Test
void testDraftIdPropertyWhenDraftIdIsNotPresentInDataRef() throws Exception {
MockSlingHttpServletRequest request = context.request();
Map<String, Object> tempMap = new HashMap<>();
tempMap.put(GuideConstants.AF_DATA_REF, "service://FP/draft");
request.setParameterMap(tempMap);
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
assertNull(formContainer.getProperties().get(ReservedProperties.FD_DRAFT_ID));
// reset the parameter map
request.setParameterMap(new HashMap<>());
}

@Test
void testGetFormDataDisabled() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITHOUT_PREFILL, FormContainer.class, context);
Expand Down Expand Up @@ -531,4 +563,63 @@ void testCustomFunctionUrl() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
assertEquals("/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==", formContainer.getCustomFunctionUrl());
}

@Test
public void testGetAutoSaveProperties() throws Exception {
context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
FormContainer.class, context);
assertNotNull(formContainer.getAutoSaveConfig());
assertTrue(formContainer.getAutoSaveConfig().isEnableAutoSave());
assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, formContainer.getAutoSaveConfig().getAutoSaveStrategyType());
}

@Test
public void testDefaultGetAutoSaveConfig() throws Exception {
FormContainer formContainer1 = new FormContainer() {

@Override
public FormMetaData getMetaData() {
return null;
}

@Override
public String getEncodedCurrentPagePath() {
return null;
}

@Override
public String getThankYouMessage() {
return null;
}

@Override
public List<? extends ComponentExporter> getItems() {
return null;
}

@Override
public String getGridClassNames() {
return null;
}

@Override
public Map<String, String> getColumnClassNames() {
return null;
}

@Override
public int getColumnCount() {
return 0;
}

@Override
public AllowedComponentsExporter getExportedAllowedComponents() {
return null;
}
};
;
assertNull(formContainer1.getAutoSaveConfig());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"dorType": "generate",
"dorTemplateRef": "xyz"
},
"fd:autoSave": {
"fd:enableAutoSave":false
},
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2",
"fd:isHamburgerMenuEnabled": false,
"fd:schemaType": "BASIC",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"id": "L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"fieldType": "form",
"lang": "en",
"properties": {
"thankyouPage": "/a/b/c",
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave",
"fd:schemaType": "BASIC",
"fd:isHamburgerMenuEnabled": false,
"fd:roleAttribute": null,
"fd:formDataEnabled": true,
"fd:autoSave": {
"fd:enableAutoSave": true,
"fd:autoSaveStrategyType": "time",
"fd:autoSaveInterval": 2
},
"fd:customFunctionsUrl": "/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"fd:dataUrl": "/adobe/forms/af/data/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw=="
},
"action": "/adobe/forms/af/submit/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":itemsOrder": [
"textinput"
],
"adaptiveform": "0.14.2",
"metadata": {
"grammar": "json-formula-1.0.0",
"version": "1.0.0"
},
":type": "core/fd/components/form/container/v2/container",
":items": {
"textinput": {
"id": "textinput-2ddda8d6f9",
"fieldType": "text-input",
"name": "abc",
"visible": false,
"description": "dummy",
"type": "string",
"label": {
"value": "def",
"visible": true
},
"properties": {
"customProp": "customPropValue",
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave/textinput"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":type": "core/fd/components/form/textinput/v1/textinput"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@
"prefillService" : "abc",
"fd:enableAutoSave": "true",
"fd:autoSaveInterval": "2",
"fd:autoSaveStrategyType": "time"
"fd:autoSaveStrategyType": "time",
"textinput" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "core/fd/components/form/textinput/v1/textinput",
"name" : "abc",
"jcr:title" : "def",
"hideTitle" : false,
"description" : "dummy",
"fd:translationIds" : "{\"jcr:title\":\"guideContainer##textinput##jcr:title##5598\",\"placeholder\":\"guideContainer##textinput##description##5648\"}",
"visible" : false,
"customProp": "customPropValue"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "image-ad1e095fba",
"dataRef" : "a.b",
"fieldType": "image",
"name": "abc",
"value": "/content/image-customized.img.png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jcr:title" : "def",
"hideTitle" : false,
"visible" : false,
"dataRef" : "a.b",
"altText": "abc",
"file": {
"jcr:content": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ function testTextImportData(globals)
globals.functions.importData({'a' : {'b' : 'prefilled'}});
}

/**
* Tests static image import data
* @name testImageImportData
* @param {scope} globals
*/
function testImageImportData(globals)
{
globals.functions.importData({'a' : {'b' : '/content/dam/reference-fragments/visa%402x.png'}})
}

/**
* Tests set focus
* @name testSetFocus
Expand Down
Loading

0 comments on commit 633484a

Please sign in to comment.