Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ private ReservedProperties() {
public static final String PN_EXCLUDE_FROM_DOR = "excludeFromDor";
public static final String PN_MANDATORY = "mandatory";
public static final String PN_HTML_ELEMENT_TYPE_V2 = "fd:htmlelementType";
public static final String FD_AUTO_SAVE_PROPERTY_WRAPPER = "fd:autoSave";
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";
private static final Set<String> reservedProperties = aggregateReservedProperties();

private static Set<String> aggregateReservedProperties() {
Expand Down
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.jetbrains.annotations.NotNull;
Expand All @@ -46,6 +47,7 @@
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.internal.models.v1.form.FormMetaDataImpl;
import com.adobe.cq.forms.core.components.models.form.AutoSaveConfiguration;
import com.adobe.cq.forms.core.components.models.form.Container;
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
import com.adobe.cq.forms.core.components.models.form.FormContainer;
Expand Down Expand Up @@ -119,6 +121,9 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
@Default(values = DEFAULT_FORMS_SPEC_VERSION)
private String specVersion;

@Self(injectionStrategy = InjectionStrategy.OPTIONAL)
private AutoSaveConfiguration autoSaveConfig;

@PostConstruct
protected void initFormContainerModel() {
if (request != null) {
Expand Down Expand Up @@ -314,6 +319,7 @@ public String getLanguageDirection() {
}
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
return properties;
}

Expand Down
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;
}

default AutoSaveStrategyType getAutoSaveStrategyType() {
return AutoSaveStrategyType.TIME;
}

default Integer getAutoSaveInterval() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </p>
*/

@Version("5.5.3") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
@Version("5.5.4") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
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
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"dorType": "generate",
"dorTemplateRef": "xyz"
},
"fd:autoSave": {
"fd:enableAutoSave":false
},
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2",
"fd:schemaType": "BASIC",
"fd:formDataEnabled": true,
Expand Down
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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"FT_FORMS-13209",
"FT_FORMS-11581",
"FT_FORMS-14545",
"FT_SITES-19631"
"FT_SITES-19631",
"FT_FORMS-14255"
]
}
1 change: 1 addition & 0 deletions it/content/src/main/content/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<filter root="/content/experience-fragments" mode="update"/>
<filter root="/content/dam/formsanddocuments/core-components-it" mode="update"/>
<filter root="/conf/global/settings/workflow/models/core-component-it-test" mode="update"/>
<filter root="/conf/global/settings/forms" mode="update"/>
<filter root="/conf/global/settings/cloudconfigs/edge-delivery-service-configuration" mode="update"/>
<filter root="/conf/core-components-it" mode="update"/>
<filter root="/conf/wknd" mode="update"/>
Expand Down
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"/>
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"/>
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"/>
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>
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>
Loading