Skip to content

Commit 58264b8

Browse files
FORMS-17068 Fetch custom properties from CoreComponentCustomPropertiesProvider which are behind FT and make part of FormContainer get properties. (#1467)
Also updated FOrms SDK version
1 parent 6bbccfc commit 58264b8

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
import org.apache.sling.models.annotations.Default;
2828
import org.apache.sling.models.annotations.Exporter;
2929
import org.apache.sling.models.annotations.Model;
30-
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
31-
import org.apache.sling.models.annotations.injectorspecific.Self;
32-
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
33-
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
30+
import org.apache.sling.models.annotations.injectorspecific.*;
3431
import org.jetbrains.annotations.NotNull;
3532
import org.jetbrains.annotations.Nullable;
3633
import org.slf4j.Logger;
3734
import org.slf4j.LoggerFactory;
3835

3936
import com.adobe.aemds.guide.common.GuideContainer;
37+
import com.adobe.aemds.guide.service.CoreComponentCustomPropertiesProvider;
4038
import com.adobe.aemds.guide.service.GuideSchemaType;
4139
import com.adobe.aemds.guide.utils.GuideConstants;
4240
import com.adobe.aemds.guide.utils.GuideUtils;
@@ -80,6 +78,9 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
8078
public static final String FD_FORM_DATA_ENABLED = "fd:formDataEnabled";
8179
public static final String FD_ROLE_ATTRIBUTE = "fd:roleAttribute";
8280

81+
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
82+
private CoreComponentCustomPropertiesProvider coreComponentCustomPropertiesProvider;
83+
8384
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
8485
@Nullable
8586
private SlingHttpServletRequest request;
@@ -318,7 +319,14 @@ public String getLanguageDirection() {
318319

319320
@Override
320321
public @NotNull Map<String, Object> getProperties() {
321-
Map<String, Object> properties = super.getProperties();
322+
Map<String, Object> properties = new LinkedHashMap<>();
323+
if (coreComponentCustomPropertiesProvider != null) {
324+
Map<String, Object> customProperties = coreComponentCustomPropertiesProvider.getProperties();
325+
if (customProperties != null) {
326+
properties.putAll(customProperties);
327+
}
328+
}
329+
properties.putAll(super.getProperties());
322330
if (getSchemaType() != null) {
323331
properties.put(FD_SCHEMA_TYPE, getSchemaType());
324332
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.adobe.aemds.guide.model.HCaptchaConfiguration;
2525
import com.adobe.aemds.guide.model.ReCaptchaConfigurationModel;
26+
import com.adobe.aemds.guide.model.TurnstileConfiguration;
2627
import com.adobe.aemds.guide.service.CloudConfigurationProvider;
2728
import com.adobe.aemds.guide.service.GuideException;
2829
import com.adobe.cq.forms.core.Utils;
@@ -54,10 +55,20 @@ public ReCaptchaConfigurationModel getRecaptchaCloudConfiguration(Resource resou
5455
return null;
5556
}
5657

58+
@Override
59+
public String getCustomFunctionUrl(Resource resource) {
60+
return null;
61+
}
62+
5763
@Override
5864
public HCaptchaConfiguration getHCaptchaCloudConfiguration(Resource resource) throws GuideException {
5965
return hCaptchaConfiguration;
6066
}
67+
68+
@Override
69+
public TurnstileConfiguration getTurnstileCloudConfiguration(Resource resource) throws GuideException {
70+
return null;
71+
}
6172
};
6273

6374
@BeforeEach

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.adobe.aemds.guide.model.HCaptchaConfiguration;
2727
import com.adobe.aemds.guide.model.ReCaptchaConfigurationModel;
28+
import com.adobe.aemds.guide.model.TurnstileConfiguration;
2829
import com.adobe.aemds.guide.service.CloudConfigurationProvider;
2930
import com.adobe.aemds.guide.service.GuideException;
3031
import com.adobe.cq.forms.core.Utils;
@@ -55,10 +56,20 @@ public ReCaptchaConfigurationModel getRecaptchaCloudConfiguration(Resource resou
5556
return reCaptchaConfiguration;
5657
}
5758

59+
@Override
60+
public String getCustomFunctionUrl(Resource resource) {
61+
return null;
62+
}
63+
5864
@Override
5965
public HCaptchaConfiguration getHCaptchaCloudConfiguration(Resource resource) throws GuideException {
6066
return null;
6167
}
68+
69+
@Override
70+
public TurnstileConfiguration getTurnstileCloudConfiguration(Resource resource) throws GuideException {
71+
return null;
72+
}
6273
};
6374

6475
@BeforeEach

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.mockito.ArgumentCaptor;
4040
import org.mockito.Mockito;
4141

42+
import com.adobe.aemds.guide.service.CoreComponentCustomPropertiesProvider;
4243
import com.adobe.aemds.guide.service.GuideLocalizationService;
4344
import com.adobe.aemds.guide.utils.GuideConstants;
4445
import com.adobe.cq.export.json.ComponentExporter;
@@ -490,4 +491,37 @@ public void testGetIsHamburgerMenuEnabled() {
490491
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
491492
assertFalse(Boolean.valueOf(formContainer.getIsHamburgerMenuEnabled().toString()));
492493
}
494+
495+
/**
496+
* Test to check if the properties are fetched from the CoreComponentCustomPropertiesProvider are part of form container properties or
497+
* not
498+
* Also, if same properties is set in form container, then it should override the properties from CoreComponentCustomPropertiesProvider
499+
*
500+
* @throws Exception
501+
*/
502+
@Test
503+
void testGetPropertiesForCoreComponentCustomPropertiesProvider() throws Exception {
504+
CoreComponentCustomPropertiesProvider coreComponentCustomPropertiesProvider = Mockito.mock(
505+
CoreComponentCustomPropertiesProvider.class);
506+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
507+
Utils.setInternalState(formContainer, "coreComponentCustomPropertiesProvider", coreComponentCustomPropertiesProvider);
508+
Mockito.when(coreComponentCustomPropertiesProvider.getProperties()).thenReturn(new HashMap<String, Object>() {
509+
{
510+
put("fd:changeEventBehaviour", "deps");
511+
put("customProp", "customValue");
512+
}
513+
});
514+
assertEquals("deps", formContainer.getProperties().get("fd:changeEventBehaviour"));
515+
assertEquals("customPropValue", formContainer.getProperties().get("customProp"));
516+
}
517+
518+
@Test
519+
void testGetPropertiesForCoreComponentCustomPropertiesProviderForNull() throws Exception {
520+
CoreComponentCustomPropertiesProvider coreComponentCustomPropertiesProvider = Mockito.mock(
521+
CoreComponentCustomPropertiesProvider.class);
522+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
523+
Utils.setInternalState(formContainer, "coreComponentCustomPropertiesProvider", coreComponentCustomPropertiesProvider);
524+
Mockito.when(coreComponentCustomPropertiesProvider.getProperties()).thenReturn(null);
525+
assertEquals("customPropValue", formContainer.getProperties().get("customProp"));
526+
}
493527
}

parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@
11281128
<dependency>
11291129
<groupId>com.adobe.aem</groupId>
11301130
<artifactId>aem-forms-sdk-api</artifactId>
1131-
<version>2024.04.18.00-240300</version>
1131+
<version>2024.09.08.00-240800</version>
11321132
</dependency>
11331133

11341134
<dependency>

0 commit comments

Comments
 (0)