Skip to content
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

eds semantic html without a separate selector #1194

Merged
merged 22 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d1ac8dc
added changes to publish semantic html of form from container[FormCon…
Apr 16, 2024
038043b
added test case to verify formDefinition api....
Apr 16, 2024
3d3bd99
added test case to verify formDefinition api....
Apr 16, 2024
f1063aa
updated the license header of body file...
Apr 22, 2024
ef14c68
added changes to publish semantic html of form from container[FormCon…
Apr 16, 2024
0e872ab
added test case to verify formDefinition api....
Apr 16, 2024
3aac04d
added test case to verify formDefinition api....
Apr 16, 2024
254b89a
updated the license header of body file...
Apr 22, 2024
60a299a
created a new version of page component.....
Apr 25, 2024
a73233c
Merge branch 'FormContainerEds' of https://github.com/adobe/aem-core-…
Apr 25, 2024
9d478c1
added a Utils file to move certain logic out of FormContainer sling m…
Apr 30, 2024
deb1ea7
added test cases for FormUtil class and getFormDef api..
Apr 30, 2024
d7e9474
made changes to remove style elements from container proxy...
May 2, 2024
1c50447
Merge branch 'dev' into FormContainerEds
May 2, 2024
8bd84d7
made changes to remove style elements from container proxy...
May 2, 2024
136b965
removed body html from v1 of page..
May 2, 2024
aca88b9
added README for page comp and bumped up minor version of the package…
May 2, 2024
04527a8
added java doc for the isEdgeDeliveryRequest api...
May 2, 2024
7873513
added test cases for v2 version of page component....
May 3, 2024
331b24e
added test cases for v2 version of page component....
May 3, 2024
c8fd6cb
merged dev branch to FormContainerEds....
May 7, 2024
3847748
made suggested review changes.......
May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@

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");

Check warning on line 126 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormStructureParserImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/FormStructureParserImpl.java#L125-L126

Added lines #L125 - L126 were not covered by tests
}
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) {
deepprakash345 marked this conversation as resolved.
Show resolved Hide resolved
Object isEdgeDelivery = request.getAttribute("com.adobe.aem.wcm.franklin.internal.servlets.FranklinDeliveryServlet");
return isEdgeDelivery != null && isEdgeDelivery.equals(Boolean.TRUE);
}
return false;

Check warning on line 40 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/HtlUtilImpl.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/form/HtlUtilImpl.java#L40

Added line #L40 was not covered by tests
}
}
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();
deepprakash345 marked this conversation as resolved.
Show resolved Hide resolved
}
@@ -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();
deepprakash345 marked this conversation as resolved.
Show resolved Hide resolved
}
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 @@ -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,0 +1,94 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.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.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.adobe.cq.export.json.SlingModelFilter;
import com.adobe.cq.forms.core.components.models.form.HtlUtil;
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.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(AemContextExtension.class)
public class HtlUtilTest {
private static final String BASE = "/form/formutil";
private static final String CONTENT_ROOT = "/content";
private static final String JCR_CONTENT_PATH = CONTENT_ROOT + "/myTestPage/jcr:content";
private static final String FORM_CONTAINER_PATH = JCR_CONTENT_PATH + "/formcontainerv2";
private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
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 testGetIsEdgeDeliveryRequest() throws Exception {
context.currentResource(FORM_CONTAINER_PATH);
MockSlingHttpServletRequest request = context.request();
request.setAttribute("com.adobe.aem.wcm.franklin.internal.servlets.FranklinDeliveryServlet", false);
HtlUtil formUtil = request.adaptTo(HtlUtil.class);
assertFalse(formUtil.isEdgeDeliveryRequest());
}

@Test
void testGetIsEdgeDeliveryRequestTrue() throws Exception {
context.currentResource(FORM_CONTAINER_PATH);
MockSlingHttpServletRequest request = context.request();
request.setAttribute("com.adobe.aem.wcm.franklin.internal.servlets.FranklinDeliveryServlet", true);
HtlUtil formUtil = request.adaptTo(HtlUtil.class);
assertTrue(formUtil.isEdgeDeliveryRequest());
}
}
72 changes: 72 additions & 0 deletions bundles/af-core/src/test/resources/form/formutil/test-content.json
@@ -0,0 +1,72 @@
{
"myTestPage": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"sling:resourceType": "myTest/components/page",
"jcr:title": "Test",
"jcr:description": "Test",
"jcr:primaryType": "cq:PageContent",
"cq:template": "/conf/myTest/settings/wcm/templates/content-page",
"formcontainerv2": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/container/v2/container",
"fieldType" : "form",
"thankyouPage": "/a/b/c",
"thankyouMessage": "message",
"clientLibRef" : "abc",
"datepicker": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/datepicker/v1/datepicker",
"name": "abc",
"jcr:title": "def",
"hideTitle": false,
"description": "dummy",
"visible": false
},
"container1": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "wcm/foundation/components/responsivegrid",
"clientLibRef" : "abc",
"datepicker1": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/datepicker/v1/datepicker",
"name": "abc",
"jcr:title": "def",
"hideTitle": false,
"description": "dummy",
"visible": false
},
"container2": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "wcm/foundation/components/responsivegrid",
"text": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "myTest/components/text",
"text": "abc"
}
}
},
"fragment": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "Fragment",
"name": "fragment-123",
"jcr:lastModified": "Fri Jun 02 2023 12:34:24 GMT+0530",
"sling:resourceType": "core/fd/components/form/fragment/v1/fragment",
"fieldType": "panel",
"fragmentPath": "/content/affragment"
},
"action": "/a/b",
"dataUrl": "/c/d"
},
"container3": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "wcm/foundation/components/responsivegrid",
"text1": {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "myTest/components/text",
"text": "test"
}
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
jcr:mixinTypes="[rep:AccessControllable]"
jcr:primaryType="sling:Folder"
lcFolder="{Long}0"
type="lcFolder"
/>