-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terms and Conditions Component #889
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...va/com/adobe/cq/forms/core/components/internal/models/v1/form/TermsAndConditionsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2023 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
|
||
package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Default; | ||
import org.apache.sling.models.annotations.Exporter; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.adobe.cq.export.json.ComponentExporter; | ||
import com.adobe.cq.export.json.ExporterConstants; | ||
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.TermsAndConditions; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
@Model( | ||
adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
adapters = { TermsAndConditions.class, | ||
ComponentExporter.class }, | ||
resourceType = { FormConstants.RT_FD_FORM_TERMS_AND_CONDITIONS_V1 }) | ||
|
||
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
public class TermsAndConditionsImpl extends PanelImpl implements TermsAndConditions { | ||
|
||
private static final String CUSTOM_TNC_PROPERTY = "fd:tnc"; | ||
|
||
private static final String FIELD_TYPE = "fieldType"; | ||
|
||
@JsonIgnore | ||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = true) | ||
private boolean showApprovalOption; | ||
|
||
@JsonIgnore | ||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = false) | ||
private boolean showLink; | ||
|
||
@JsonIgnore | ||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = false) | ||
private boolean showAsPopup; | ||
|
||
@Override | ||
public boolean isShowApprovalOption() { | ||
return showApprovalOption; | ||
} | ||
|
||
@Override | ||
public boolean isShowLink() { | ||
return showLink; | ||
} | ||
|
||
@Override | ||
public boolean isShowAsPopup() { | ||
return showAsPopup; | ||
} | ||
|
||
@Override | ||
public @NotNull String getId() { | ||
return super.getId(); | ||
} | ||
|
||
@Override | ||
public @NotNull Map<String, Object> getProperties() { | ||
Map<String, Object> properties = super.getProperties(); | ||
if (resource.getValueMap().containsKey(CUSTOM_TNC_PROPERTY)) { | ||
properties.put(CUSTOM_TNC_PROPERTY, true); | ||
} | ||
return properties; | ||
} | ||
|
||
@Override | ||
protected List<Resource> getFilteredChildrenResources() { | ||
List<Resource> childResources = getFilteredChildrenResources(resource); | ||
// the tnc component will either have links or consent text based upon showLink value | ||
if (showLink) { | ||
childResources.removeIf(child -> FieldType.PLAIN_TEXT.getValue().equals(child.getValueMap().get(FIELD_TYPE))); | ||
|
||
} else { | ||
childResources.removeIf(child -> FieldType.CHECKBOX_GROUP.getValue().equals(child.getValueMap().get(FIELD_TYPE))); | ||
} | ||
return childResources; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...core/src/main/java/com/adobe/cq/forms/core/components/models/form/TermsAndConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2023 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
|
||
package com.adobe.cq.forms.core.components.models.form; | ||
|
||
import org.osgi.annotation.versioning.ConsumerType; | ||
|
||
/** | ||
* Defines the form {@code TermsAndConditions} Sling Model used for the | ||
* {@code /apps/core/fd/components/form/termsandconditions/v1/termsandconditions} component. | ||
* | ||
* @since com.adobe.cq.forms.core.components.models.form 4.7.0 | ||
*/ | ||
@ConsumerType | ||
public interface TermsAndConditions extends Container, ContainerConstraint { | ||
|
||
String FD_TERMS_AND_CONDITIONS = "fd:tnc"; | ||
|
||
/** | ||
* | ||
* @return {@code true} if approval checkbox should be shown, otherwise {@code false} | ||
*/ | ||
boolean isShowApprovalOption(); | ||
|
||
/** | ||
* | ||
* @return {@code true} if links to external Terms & Conditions pages are to be shown, otherwise | ||
* {@code false if consent text is to be shown} | ||
*/ | ||
boolean isShowLink(); | ||
|
||
/** | ||
* | ||
* @return @return {@code true} if the content is to be shown as pop-up , otherwise {@code false} | ||
*/ | ||
boolean isShowAsPopup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...om/adobe/cq/forms/core/components/internal/models/v1/form/TermsAndConditionsImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2023 Adobe | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
package com.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.apache.sling.api.resource.Resource; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mockito; | ||
|
||
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.TermsAndConditions; | ||
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext; | ||
import com.day.cq.wcm.api.NameConstants; | ||
import com.day.cq.wcm.msm.api.MSMNameConstants; | ||
import io.wcm.testing.mock.aem.junit5.AemContext; | ||
import io.wcm.testing.mock.aem.junit5.AemContextExtension; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@ExtendWith(AemContextExtension.class) | ||
public class TermsAndConditionsImplTest { | ||
|
||
private static final String BASE = "/form/termsandconditions"; | ||
private static final String CONTENT_ROOT = "/content"; | ||
|
||
private static final String PATH_TNC = CONTENT_ROOT + "/termsandconditions"; | ||
|
||
private static final String PATH_NOWRAP_TNC = CONTENT_ROOT + "/termsandconditionsNoWrapData"; | ||
|
||
private final AemContext context = FormsCoreComponentTestContext.newAemContext(); | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT); | ||
context.registerService(SlingModelFilter.class, new SlingModelFilter() { | ||
|
||
private final Set<String> IGNORED_NODE_NAMES = new HashSet<String>() { | ||
{ | ||
add(NameConstants.NN_RESPONSIVE_CONFIG); | ||
add(MSMNameConstants.NT_LIVE_SYNC_CONFIG); | ||
add("cq:annotations"); | ||
} | ||
}; | ||
|
||
@Override | ||
public Map<String, Object> filterProperties(Map<String, Object> map) { | ||
return map; | ||
} | ||
|
||
@Override | ||
public Iterable<Resource> filterChildResources(Iterable<Resource> childResources) { | ||
return StreamSupport | ||
.stream(childResources.spliterator(), false) | ||
.filter(r -> !IGNORED_NODE_NAMES.contains(r.getName())) | ||
.collect(Collectors.toList()); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
void testExportedType() throws Exception { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); | ||
assertEquals(FormConstants.RT_FD_FORM_TERMS_AND_CONDITIONS_V1, tnc.getExportedType()); | ||
TermsAndConditions tncMock = Mockito.mock(TermsAndConditions.class); | ||
Mockito.when(tncMock.getExportedType()).thenCallRealMethod(); | ||
assertEquals("", tncMock.getExportedType()); | ||
} | ||
|
||
@Test | ||
public void testGetProperties() { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); | ||
Assert.assertTrue(tnc.isShowApprovalOption()); | ||
Assert.assertTrue(tnc.isShowAsPopup()); | ||
Assert.assertFalse(tnc.isShowLink()); | ||
} | ||
|
||
@Test | ||
public void testCustomFDProperty() { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); | ||
Map<String, Object> props = tnc.getProperties(); | ||
Assert.assertTrue(props.containsKey("fd:tnc")); | ||
Assert.assertTrue((Boolean) props.get("fd:tnc")); | ||
|
||
} | ||
|
||
@Test | ||
void testJSONExport() throws Exception { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_TNC, TermsAndConditions.class, context); | ||
Utils.testJSONExport(tnc, Utils.getTestExporterJSONPath(BASE, PATH_TNC)); | ||
} | ||
|
||
@Test | ||
void testJSONExport_showLink() throws Exception { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_NOWRAP_TNC, TermsAndConditions.class, context); | ||
Utils.testJSONExport(tnc, Utils.getTestExporterJSONPath(BASE, PATH_NOWRAP_TNC)); | ||
} | ||
|
||
@Test | ||
void testNoWrap() { | ||
TermsAndConditions tnc = Utils.getComponentUnderTest(PATH_NOWRAP_TNC, TermsAndConditions.class, context); | ||
Assert.assertNull(tnc.getType()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
bundles/af-core/src/test/resources/form/termsandconditions/exporter-termsandconditions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"id": "termsandconditions-dac51d5ed9", | ||
"fieldType": "panel", | ||
"name": "termsandconditions1694159302516", | ||
"type": "object", | ||
"properties": { | ||
"fd:dor": { | ||
"dorExclusion": false, | ||
"dorExcludeTitle": false, | ||
"dorExcludeDescription": false | ||
}, | ||
"fd:path": "/content/termsandconditions", | ||
"fd:tnc": true | ||
}, | ||
"label": { | ||
"value": "Terms And Conditions" | ||
}, | ||
"events": { | ||
"custom:setProperty": [ | ||
"$event.payload" | ||
] | ||
}, | ||
":itemsOrder": [ | ||
"text", | ||
"approvalcheckbox" | ||
], | ||
":items": { | ||
"text": { | ||
"id": "text-37c101fc2b", | ||
"fieldType": "plain-text", | ||
"name": "consenttext", | ||
"value": "Text related to the terms and conditions come here", | ||
"richText": false, | ||
"events": { | ||
"custom:setProperty": [ | ||
"$event.payload" | ||
] | ||
}, | ||
"properties": { | ||
"fd:path": "/content/termsandconditions/text" | ||
}, | ||
":type": "core/fd/components/form/text/v1/text" | ||
}, | ||
"approvalcheckbox": { | ||
"id": "checkbox-150eb94d3e", | ||
"fieldType": "checkbox", | ||
"name": "approvalcheckbox", | ||
"type": "string", | ||
"enabled": false, | ||
"enforceEnum": true, | ||
"label": { | ||
"value": "I agree to the terms & conditions" | ||
}, | ||
"events": { | ||
"custom:setProperty": [ | ||
"$event.payload" | ||
] | ||
}, | ||
"properties": { | ||
"afs:layout": { | ||
"orientation": "horizontal" | ||
}, | ||
"fd:dor": { | ||
"dorExclusion": false | ||
}, | ||
"fd:path": "/content/termsandconditions/approvalcheckbox" | ||
}, | ||
"enum": [ | ||
"true" | ||
], | ||
":type": "core/fd/components/form/checkbox/v1/checkbox" | ||
} | ||
}, | ||
":type": "core/fd/components/form/termsandconditions/v1/termsandconditions" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add java doc for all API's and also update package-info