Skip to content

Commit

Permalink
Merge pull request #1229 from adobe/devtomaster-9-May-2024
Browse files Browse the repository at this point in the history
Devtomaster 9 may 2024
  • Loading branch information
barshat7 committed May 9, 2024
2 parents 2465443 + 3381636 commit 22e8c75
Show file tree
Hide file tree
Showing 63 changed files with 1,193 additions and 98 deletions.
Expand Up @@ -15,23 +15,31 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.forms.core.components.internal.form;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.cq.forms.core.components.models.form.FormContainer;
import com.adobe.cq.forms.core.components.models.form.FormStructureParser;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
import com.adobe.cq.forms.core.components.views.Views;
import com.fasterxml.jackson.databind.ObjectMapper;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = FormStructureParser.class)
public class FormStructureParserImpl implements FormStructureParser {

private static final Logger logger = LoggerFactory.getLogger(FormStructureParserImpl.class);
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private SlingHttpServletRequest request;
Expand Down Expand Up @@ -104,4 +112,19 @@ private String getFormContainerPath(Resource resource) {

return getFormContainerPath(resource.getParent());
}

public String getFormDefinition() {
String result = null;
FormContainer formContainer = resource.adaptTo(FormContainer.class);
try {
ObjectMapper mapper = new ObjectMapper();
Writer writer = new StringWriter();
// return publish view specific properties only for runtime
mapper.writerWithView(Views.Publish.class).writeValue(writer, formContainer);
result = writer.toString();
} catch (IOException e) {
logger.error("Unable to generate json from resource");
}
return result;
}
}
@@ -0,0 +1,42 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.form;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.jetbrains.annotations.Nullable;

import com.adobe.cq.forms.core.components.models.form.HtlUtil;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = HtlUtil.class)
public class HtlUtilImpl implements HtlUtil {
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private SlingHttpServletRequest request;

public Boolean isEdgeDeliveryRequest() {
if (request != null) {
Object isEdgeDelivery = request.getAttribute("com.adobe.aem.wcm.franklin.internal.servlets.FranklinDeliveryServlet");
return isEdgeDelivery != null && isEdgeDelivery.equals(Boolean.TRUE);
}
return false;
}
}
Expand Up @@ -16,7 +16,9 @@
package com.adobe.cq.forms.core.components.internal.models.v1.form;

import java.io.IOException;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.RepositoryException;

Expand Down Expand Up @@ -45,6 +47,8 @@
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class StaticImageImpl extends AbstractFormComponentImpl implements StaticImage {

public static final String DAM_REPO_PATH = "fd:repoPath";

private Image image;

@SlingObject
Expand All @@ -62,6 +66,10 @@ public class StaticImageImpl extends AbstractFormComponentImpl implements Static
@org.jetbrains.annotations.Nullable
protected String description; // long description as per current spec

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileReference")
@Nullable
protected String fileReference;

/**
* Returns the source where the image is present.
*
Expand Down Expand Up @@ -120,4 +128,13 @@ public String getLinkUrl() {
return null;
}
}

@Override
public @Nonnull Map<String, Object> getProperties() {
Map<String, Object> properties = super.getProperties();
if (fileReference != null && fileReference.length() > 0) {
properties.put(DAM_REPO_PATH, fileReference);
}
return properties;
}
}
Expand Up @@ -32,6 +32,8 @@
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemds.guide.common.GuideContainer;
import com.adobe.aemds.guide.service.GuideSchemaType;
Expand Down Expand Up @@ -63,6 +65,7 @@
public class FormContainerImpl extends AbstractContainerImpl implements FormContainer {
protected static final String RESOURCE_TYPE = "core/fd/components/form/container/v2/container";

private static final Logger logger = LoggerFactory.getLogger(FormContainerImpl.class);
private static final String DOR_TYPE = "dorType";
private static final String DOR_TEMPLATE_REF = "dorTemplateRef";
private static final String DOR_TEMPLATE_TYPE = "dorTemplateType";
Expand Down
Expand Up @@ -362,5 +362,4 @@ default void visit(Consumer<ComponentExporter> callback) throws Exception {}
default String getParentPagePath() {
return null;
}

}
Expand Up @@ -43,4 +43,11 @@ public interface FormStructureParser {
* @return true if this resource or one of its children is a form container, else false
*/
Boolean containsFormContainer();

/**
* @since com.adobe.cq.forms.core.components.models.form 5.4.1
*
* @return form definition json in Publish view
*/
String getFormDefinition();
}
@@ -0,0 +1,29 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.osgi.annotation.versioning.ProviderType;

@ProviderType
public interface HtlUtil {
/**
* Checks whether this request has been originated from edge delivery services
*
* @return {Boolean} true if the request is from edge delivery services, false otherwise
* @since com.adobe.cq.forms.core.components.models.form 5.3.2
*/
Boolean isEdgeDeliveryRequest();
}
Expand Up @@ -34,7 +34,8 @@
* version, is bound to this proxy component resource type.
* </p>
*/
@Version("5.4.0") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650

@Version("5.4.1") // 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;
Expand Up @@ -18,8 +18,6 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
Expand All @@ -31,7 +29,6 @@
import org.slf4j.LoggerFactory;

import com.adobe.cq.forms.core.components.models.form.Field;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -80,14 +77,6 @@ public abstract class AbstractFieldImpl extends AbstractBaseImpl implements Fiel
@Nullable
protected Integer maxLength;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorExclusion")
@Default(booleanValues = false)
protected boolean dorExclusion;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorColspan")
@Nullable
protected String dorColspan;

/** number and date constraint **/

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "minimumDate")
Expand Down Expand Up @@ -116,16 +105,6 @@ public abstract class AbstractFieldImpl extends AbstractBaseImpl implements Fiel

/** number and date constraint **/

/**
* Returns dorBindRef of the form field
*
* @return dorBindRef of the field
* @since com.adobe.cq.forms.core.components.util 2.1.0
*/
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorBindRef")
@Nullable
protected String dorBindRef;

@SlingObject
private Resource resource;

Expand Down Expand Up @@ -197,17 +176,4 @@ public String getDataFormat() {
return dataFormat;
}

@Override
@JsonIgnore
public Map<String, Object> getDorProperties() {
Map<String, Object> customDorProperties = new LinkedHashMap<>();
customDorProperties.put("dorExclusion", dorExclusion);
if (dorColspan != null) {
customDorProperties.put("dorColspan", dorColspan);
}
if (dorBindRef != null) {
customDorProperties.put("dorBindRef", dorBindRef);
}
return customDorProperties;
}
}
Expand Up @@ -95,6 +95,25 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements
@SlingObject
private Resource resource;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorExclusion")
@Default(booleanValues = false)
protected boolean dorExclusion;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorColspan")
@Nullable
protected String dorColspan;

/**
* Returns dorBindRef of the form field
*
* @return dorBindRef of the field
* @since com.adobe.cq.forms.core.components.util 4.0.0
*/
@JsonIgnore
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorBindRef")
@Nullable
protected String dorBindRef;

/**
* Flag indicating if the data layer is enabled.
*/
Expand Down Expand Up @@ -473,4 +492,18 @@ private Map<String, String> getCustomProperties() {
return Collections.emptyMap();
}
}

@Override
@JsonIgnore
public Map<String, Object> getDorProperties() {
Map<String, Object> customDorProperties = new LinkedHashMap<>();
customDorProperties.put("dorExclusion", dorExclusion);
if (dorColspan != null) {
customDorProperties.put("dorColspan", dorColspan);
}
if (dorBindRef != null) {
customDorProperties.put("dorBindRef", dorBindRef);
}
return customDorProperties;
}
}
Expand Up @@ -15,6 +15,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.forms.core.components.internal.models.v1.form;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -34,6 +35,9 @@
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.wcm.api.NameConstants;
import com.day.cq.wcm.msm.api.MSMNameConstants;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

Expand Down Expand Up @@ -85,6 +89,17 @@ void testFormContainerPath() {
assertEquals(FORM_CONTAINER_PATH, formStructureParser.getFormContainerPath());
}

@Test
void testFormDefinition() throws JsonProcessingException {
String path = FORM_CONTAINER_PATH;
FormStructureParser formStructureParser = getFormStructureParserUnderTest(path);
String formDef = formStructureParser.getFormDefinition();
HashMap<String, Object> formJson = (HashMap<String, Object>) new ObjectMapper().readValue(formDef,
new TypeReference<Map<String, Object>>() {});
assertNotNull(formStructureParser.getFormDefinition());
assertEquals(formJson.get("fieldType"), "form");
}

@Test
void testFormContainerPathEmbedWithoutIframe() {
FormStructureParser formStructureParser = getFormStructureParserUnderTest(JCR_CONTENT_PATH, FORM_CONTAINER_PATH);
Expand Down

0 comments on commit 22e8c75

Please sign in to comment.