-
Notifications
You must be signed in to change notification settings - Fork 64
Forms-14212 Implemented time based auto save #1337
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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
79 changes: 79 additions & 0 deletions
79
...com/adobe/cq/forms/core/components/internal/models/v2/form/AutoSaveConfigurationImpl.java
This file contains hidden or 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,79 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2024 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.v2.form; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
|
|
||
| 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 com.adobe.cq.export.json.ExporterConstants; | ||
| import com.adobe.cq.forms.core.components.internal.form.ReservedProperties; | ||
| import com.adobe.cq.forms.core.components.models.form.AutoSaveConfiguration; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| @Model( | ||
| adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
| adapters = AutoSaveConfiguration.class) | ||
| @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
| public class AutoSaveConfigurationImpl implements AutoSaveConfiguration { | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.FD_ENABLE_AUTO_SAVE) | ||
| @Default(booleanValues = false) | ||
| @JsonProperty(ReservedProperties.FD_ENABLE_AUTO_SAVE) | ||
| private boolean enableAutoSave; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.FD_AUTO_SAVE_STRATEGY_TYPE) | ||
| @JsonIgnore | ||
| private String autoSaveStrategyJcr; | ||
|
|
||
| @JsonProperty(ReservedProperties.FD_AUTO_SAVE_STRATEGY_TYPE) | ||
| private AutoSaveStrategyType autoSaveStrategyType; | ||
|
|
||
| @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.FD_AUTO_SAVE_INTERVAL) | ||
| @JsonProperty(ReservedProperties.FD_AUTO_SAVE_INTERVAL) | ||
| private Integer autoSaveInterval; | ||
|
|
||
| @Override | ||
| public boolean isEnableAutoSave() { | ||
| return enableAutoSave; | ||
| } | ||
|
|
||
| @Override | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public AutoSaveStrategyType getAutoSaveStrategyType() { | ||
| return autoSaveStrategyType; | ||
| } | ||
|
|
||
| @Override | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public Integer getAutoSaveInterval() { | ||
| return autoSaveInterval; | ||
| } | ||
|
|
||
| @PostConstruct | ||
| protected void initAutoSaveConfiguration() { | ||
| autoSaveStrategyType = AutoSaveStrategyType.fromString(autoSaveStrategyJcr); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
79 changes: 79 additions & 0 deletions
79
...e/src/main/java/com/adobe/cq/forms/core/components/models/form/AutoSaveConfiguration.java
This file contains hidden or 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,79 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2024 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.apache.commons.lang3.StringUtils; | ||
| import org.osgi.annotation.versioning.ProviderType; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
|
|
||
| /** | ||
| * Defines the auto save configuration {@code AutoSaveConfiguration} | ||
| * | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.5.4 | ||
| */ | ||
| @ProviderType | ||
| public interface AutoSaveConfiguration { | ||
|
|
||
| enum AutoSaveStrategyType { | ||
| TIME("time"); | ||
|
|
||
| private String strategyType; | ||
|
|
||
| AutoSaveStrategyType(String strategyType) { | ||
| this.strategyType = strategyType; | ||
| } | ||
|
|
||
| public String getStrategyType() { | ||
| return strategyType; | ||
| } | ||
|
|
||
| /** | ||
| * Given a {@link String} <code>strategyType</code>, this method returns the enum's value that corresponds to the provided string | ||
| * representation | ||
| * | ||
| * @param strategyType the string representation for which an enum value should be returned | ||
| * @return the corresponding enum value, if one was found | ||
| * @since com.adobe.cq.forms.core.components.models.form 5.5.4 | ||
| */ | ||
| public static AutoSaveStrategyType fromString(String strategyType) { | ||
| for (AutoSaveStrategyType type : AutoSaveStrategyType.values()) { | ||
| if (StringUtils.equals(strategyType, type.strategyType)) { | ||
| return type; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| @JsonValue | ||
| public String toString() { | ||
| return getStrategyType(); | ||
| } | ||
| } | ||
|
|
||
| default boolean isEnableAutoSave() { | ||
| return false; | ||
girotraapankaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| default AutoSaveStrategyType getAutoSaveStrategyType() { | ||
| return AutoSaveStrategyType.TIME; | ||
| } | ||
|
|
||
| default Integer getAutoSaveInterval() { | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or 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
72 changes: 72 additions & 0 deletions
72
...com/adobe/cq/forms/core/components/internal/models/v2/form/AutoSaveConfigurationTest.java
This file contains hidden or 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,72 @@ | ||
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| ~ Copyright 2024 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.v2.form; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| import com.adobe.cq.forms.core.components.models.form.AutoSaveConfiguration; | ||
| import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext; | ||
| 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 AutoSaveConfigurationTest { | ||
|
|
||
| private static final String BASE = "/form/formcontainer"; | ||
| private static final String TEST_CONTENT = BASE + "/test-content-auto-save.json"; | ||
| private static final String GUIDE_CONTAINER_ROOT = "/content/forms/af/testform/jcr:content/guideContainer"; | ||
|
|
||
| private final AemContext context = FormsCoreComponentTestContext.newAemContext(); | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| context.load().json(TEST_CONTENT, GUIDE_CONTAINER_ROOT); | ||
| context.request().setResource(context.currentResource(GUIDE_CONTAINER_ROOT)); | ||
| } | ||
|
|
||
| @Test | ||
| void testAutoSaveConfigurationForDefaultImplementation() { | ||
| final AutoSaveConfiguration autoSaveConfiguration = new AutoSaveConfiguration() { | ||
|
|
||
| }; | ||
| assertEquals(false, autoSaveConfiguration.isEnableAutoSave()); | ||
| assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, autoSaveConfiguration.getAutoSaveStrategyType()); | ||
| assertEquals((Integer) 0, autoSaveConfiguration.getAutoSaveInterval()); | ||
| } | ||
|
|
||
| @Test | ||
| void testAutoSaveConfigurationForResourceAdaptation() { | ||
|
|
||
| final AutoSaveConfiguration autoSaveConfiguration = context.currentResource(GUIDE_CONTAINER_ROOT).adaptTo( | ||
| AutoSaveConfiguration.class); | ||
| assertEquals(true, autoSaveConfiguration.isEnableAutoSave()); | ||
| assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, autoSaveConfiguration.getAutoSaveStrategyType()); | ||
| assertEquals((Integer) 2, autoSaveConfiguration.getAutoSaveInterval()); | ||
| } | ||
|
|
||
| @Test | ||
| void testAutoSaveConfigurationForRequestAdaptation() { | ||
| final AutoSaveConfiguration autoSaveConfiguration = context.request().adaptTo(AutoSaveConfiguration.class); | ||
| assertEquals(true, autoSaveConfiguration.isEnableAutoSave()); | ||
| assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, autoSaveConfiguration.getAutoSaveStrategyType()); | ||
| assertEquals((Integer) 2, autoSaveConfiguration.getAutoSaveInterval()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
bundles/af-core/src/test/resources/form/formcontainer/test-content-auto-save.json
This file contains hidden or 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,11 @@ | ||
| { | ||
| "jcr:primaryType": "nt:unstructured", | ||
| "sling:resourceType" : "core/fd/components/form/container/v2/container", | ||
| "thankyouPage": "/a/b/c", | ||
| "thankyouMessage": "message", | ||
| "fieldType" : "form", | ||
| "prefillService" : "abc", | ||
| "fd:enableAutoSave": "true", | ||
| "fd:autoSaveInterval": "2", | ||
| "fd:autoSaveStrategyType": "time" | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| "FT_FORMS-13209", | ||
| "FT_FORMS-11581", | ||
| "FT_FORMS-14545", | ||
| "FT_SITES-19631" | ||
| "FT_SITES-19631", | ||
| "FT_FORMS-14255" | ||
| ] | ||
| } | ||
This file contains hidden or 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
3 changes: 3 additions & 0 deletions
3
it/content/src/main/content/jcr_root/conf/global/settings/forms/.content.xml
This file contains hidden or 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,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" | ||
| jcr:primaryType="sling:Folder"/> |
3 changes: 3 additions & 0 deletions
3
it/content/src/main/content/jcr_root/conf/global/settings/forms/usc/.content.xml
This file contains hidden or 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,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" | ||
| jcr:primaryType="sling:Folder"/> |
3 changes: 3 additions & 0 deletions
3
it/content/src/main/content/jcr_root/conf/global/settings/forms/usc/portal/.content.xml
This file contains hidden or 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,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" | ||
| jcr:primaryType="sling:Folder"/> |
10 changes: 10 additions & 0 deletions
10
...ntent/src/main/content/jcr_root/conf/global/settings/forms/usc/portal/portal/.content.xml
This file contains hidden or 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,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" | ||
| jcr:primaryType="cq:Page"> | ||
| <jcr:content | ||
| cq:lastModified="{Date}2024-06-11T19:20:44.087+05:30" | ||
| cq:lastModifiedBy="admin" | ||
| jcr:primaryType="cq:PageContent" | ||
| cloud-config-path="/conf/global/settings/cloudconfigs/azurestorage/AzureConfig" | ||
| storage="azure"/> | ||
| </jcr:root> |
23 changes: 23 additions & 0 deletions
23
...t/jcr_root/content/dam/formsanddocuments/core-components-it/samples/autosave/.content.xml
This file contains hidden or 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,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:dam="http://www.day.com/dam/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0" | ||
| jcr:primaryType="dam:Asset"> | ||
| <jcr:content | ||
| cq:conf="\0" | ||
| jcr:lastModified="{Date}2024-04-12T09:13:49.646Z" | ||
| jcr:primaryType="dam:AssetContent" | ||
| sling:resourceType="fd/fm/af/render" | ||
| guide="1" | ||
| type="guide"> | ||
| <metadata | ||
| fd:version="2.1" | ||
| jcr:language="en" | ||
| jcr:primaryType="nt:unstructured" | ||
| xmp:CreatorTool="AEM Forms AF Wizard" | ||
| allowedRenderFormat="HTML" | ||
| author="admin" | ||
| dorType="none" | ||
| formmodel="none" | ||
| themeRef="/libs/fd/af/themes/canvas" | ||
| title="autosaveruntime"/> | ||
| </jcr:content> | ||
| </jcr:root> |
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.
Uh oh!
There was an error while loading. Please reload this page.