Skip to content

FORMS-19758: Addition of fragmentPath to the CRISPR JSON in Author View #1593

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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 @@ -43,7 +43,9 @@
import com.adobe.cq.forms.core.components.models.form.FormContainer;
import com.adobe.cq.forms.core.components.models.form.Fragment;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
import com.adobe.cq.forms.core.components.views.Views;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
Expand Down Expand Up @@ -80,7 +82,7 @@ private void initFragmentModel() {
}
}

@JsonIgnore
@JsonView(Views.Author.class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case to check the presence of this property in the json ? You can refer existing test case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case added.

public String getFragmentPath() {
return fragmentPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface FormContainer extends Container {
*/
String PN_CLIENT_LIB_REF = GuideConstants.CLIENT_LIB_REF;

String DEFAULT_FORMS_SPEC_VERSION = "0.14.2";
String DEFAULT_FORMS_SPEC_VERSION = "0.15.2";

/**
* Returns form metadata {@link FormMetaData}
Expand Down
28 changes: 21 additions & 7 deletions bundles/af-core/src/test/java/com/adobe/cq/forms/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
*/
public class Utils {

public static InputStream getJson(Object model) {
public static InputStream getJson(Object model, Class<? extends Views.Publish> viewType) {
Writer writer = new StringWriter();
ObjectMapper mapper = new ObjectMapper();
PageModuleProvider pageModuleProvider = new PageModuleProvider();
mapper.registerModule(pageModuleProvider.getModule());
DefaultMethodSkippingModuleProvider defaultMethodSkippingModuleProvider = new DefaultMethodSkippingModuleProvider();
mapper.registerModule(defaultMethodSkippingModuleProvider.getModule());
try {
mapper.writerWithView(Views.Publish.class).writeValue(writer, model);
mapper.writerWithView(viewType).writeValue(writer, model);
} catch (IOException e) {
fail(String.format("Unable to generate JSON export for model %s: %s", model.getClass().getName(),
e.getMessage()));
Expand All @@ -77,7 +77,7 @@ public static InputStream getCompleteJson(Object model) {
DefaultMethodSkippingModuleProvider defaultMethodSkippingModuleProvider = new DefaultMethodSkippingModuleProvider();
mapper.registerModule(defaultMethodSkippingModuleProvider.getModule());
try {
mapper.writer().writeValue(writer, model);
mapper.writerWithView(Views.Author.class).writeValue(writer, model);
} catch (IOException e) {
fail(String.format("Unable to generate JSON export for model %s: %s", model.getClass().getName(),
e.getMessage()));
Expand All @@ -95,8 +95,8 @@ public static InputStream getCompleteJson(Object model) {
* @param expectedJsonResource
* the class path resource providing the expected JSON object
*/
public static void testJSONExport(Object model, String expectedJsonResource) {
InputStream modeInputStream = getJson(model);
public static void testJSONExport(Object model, String expectedJsonResource, Class<? extends Views.Publish> viewType) {
InputStream modeInputStream = getJson(model, viewType);
JsonReader outputReader = Json.createReader(modeInputStream);
InputStream is = Utils.class.getResourceAsStream(expectedJsonResource);
if (is != null) {
Expand All @@ -113,6 +113,20 @@ public static void testJSONExport(Object model, String expectedJsonResource) {
}
}

/**
* Provided a {@code model} object and an {@code expectedJsonResource} identifying a JSON file in the class path,
* this method will test the JSON export of the model and compare it to the JSON object provided by the
* {@code expectedJsonResource}.
*
* @param model
* the Sling Model
* @param expectedJsonResource
* the class path resource providing the expected JSON object
*/
public static void testJSONExport(Object model, String expectedJsonResource) {
testJSONExport(model, expectedJsonResource, Views.Publish.class);
}

/**
* The given model is validated against adaptive form specification
*
Expand All @@ -126,14 +140,14 @@ public static void testSchemaValidation(@NotNull Object model) {
// create an instance of the JsonSchemaFactory using version flag
JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
try {
InputStream schemaStream = Utils.class.getResourceAsStream("/schema/0.14.2/adaptive-form.schema.json");
InputStream schemaStream = Utils.class.getResourceAsStream("/schema/0.15.2/adaptive-form.schema.json");
JsonSchema schema = schemaFactory.getSchema(schemaStream);
// read data from the stream and store it into JsonNode
JsonNode json = objectMapper.readTree(jsonStream);
// if there is a version bump of schema, then it needs to be validated against its corresponding sling model here
// by explicitly checking the model implementation
if (!(model instanceof FormContainerImpl)) {
InputStream formContainerTemplate = Utils.class.getResourceAsStream("/schema/0.14.2/form.json");
InputStream formContainerTemplate = Utils.class.getResourceAsStream("/schema/0.15.2/form.json");
JsonNode formContainerTemplateNode = objectMapper.readTree(formContainerTemplate);
((ObjectNode) formContainerTemplateNode).putArray("items").add(json);
json = formContainerTemplateNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
import com.adobe.cq.forms.core.components.models.form.Fragment;
import com.adobe.cq.forms.core.components.models.form.TextInput;
import com.adobe.cq.forms.core.components.views.Views;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.wcm.api.NameConstants;
import com.day.cq.wcm.msm.api.MSMNameConstants;
Expand All @@ -55,6 +56,7 @@ public class FragmentImplTest {
private static final String PATH_FRAGMENT = CONTENT_ROOT + "/fragment";
private static final String PATH_FRAGMENT_DAMPATH = CONTENT_ROOT + "/fragment-dampath";
private static final String PATH_FRAGMENT_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/fragment-without-fieldtype";
private static final String PATH_FRAGMENT_WITH_FRAGMENT_PATH = CONTENT_ROOT + "/fragment-with-fragment-path";
private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
Expand Down Expand Up @@ -133,6 +135,12 @@ void testJSONExportWithDamPath() throws Exception {
Utils.testJSONExport(fragment, Utils.getTestExporterJSONPath(BASE, PATH_FRAGMENT_DAMPATH));
}

@Test
void testJSONExportWithFragmentPath() throws Exception {
Fragment fragment = Utils.getComponentUnderTest(PATH_FRAGMENT_WITH_FRAGMENT_PATH, Fragment.class, context);
Utils.testJSONExport(fragment, Utils.getTestExporterJSONPath(BASE, PATH_FRAGMENT_WITH_FRAGMENT_PATH), Views.Author.class);
}

@Test
void testGetChildrenModels() {
Fragment fragment = Utils.getComponentUnderTest(PATH_FRAGMENT, Fragment.class, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"id": "fragment-c83f64bf1d",
"fieldType": "panel",
"name": "fragment-123",
"type": "object",
"repeatable": true,
"minOccur": 0,
"maxOccur": 4,
"fragmentPath": "/content/affragment",
"properties": {
"customProp": "customPropValue",
"fd:dor": {
"dorExclusion": false,
"dorExcludeTitle": false,
"dorExcludeDescription": false
},
"fd:path": "/content/fragment-with-fragment-path",
"fd:fragment": true,
"fd:viewType": "fragment"
},
"label": {
"value": "Fragment"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":itemsOrder": [
"textinput"
],
":items": {
"textinput": {
"id": "textinput-233cc688ba",
"fieldType": "text-input",
"name": "fragmenttextinput",
"type": "string",
"label": {
"value": "Text Input"
},
"properties": {
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/affragment/jcr:content/guideContainer/textinput"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":type": "core/fd/components/form/textinput/v1/textinput"
}
},
":type": "core/fd/components/form/fragment/v1/fragment"
}
15 changes: 15 additions & 0 deletions bundles/af-core/src/test/resources/form/fragment/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@
"sling:resourceType": "core/fd/components/form/fragment/v1/fragment",
"fragmentPath": "/content/affragment"
},
"fragment-with-fragment-path": {
"jcr:primaryType": "nt:unstructured",
"wrapData": true,
"jcr:title": "Fragment",
"minOccur": "0",
"jcr:lastModifiedBy": "admin",
"name": "fragment-123",
"maxOccur": "4",
"jcr:lastModified": "Fri Jun 02 2023 12:34:24 GMT+0530",
"repeatable": true,
"sling:resourceType": "core/fd/components/form/fragment/v1/fragment",
"fieldType": "panel",
"fragmentPath": "/content/affragment",
"customProp": "customPropValue"
},
"affragment": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "AF Fragment (v2)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$id": "classpath:/schema/0.15.2/adaptive-form-aem-allowed-components.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "Allowed Components object for the current panel.",
"description": "This is applicable only if the panel's layout is grid system. This property is useful if needs to show list of allowed components in the client while authoring the panel.",
"properties": {
"components": {
"type": "array",
"title": "List of simple objects representing all Allowed Components for the given panel"
},
"applicable": {
"type": "boolean",
"title": "Is the given panel contained by a page, with authored template structure and is the given panel set as editable (unlocked)",
"description": "true if the template has structure support and the panel is editable, false otherwise"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$id": "classpath:/schema/0.15.2/adaptive-form-aem-responsive-grid-properties.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"allowedComponents": {
"$ref": "./adaptive-form-aem-allowed-components.schema.json"
},
"appliedCssClassNames": {
"title": "CSS classes delimited using a SPACE character",
"description": "Describes the style system information associated with the current form element",
"type": "string",
"examples": [
{
"appliedCssClassNames": "outlined red-border"
}
]
},
"gridClassNames": {
"title": "The CSS class names to be applied to the current panel delimited using a SPACE character",
"description": "This is applicable only if the panel's layout is grid system.",
"type": "string",
"examples": [
{
"gridClassNames": "aem-Grid aem-Grid--12 aem-Grid--default--12"
}
]
},
"columnClassNames": {
"title": "The CSS class names associated with each responsive grid column and listed by column name",
"description": "This is applicable only if the panel's layout is grid system.",
"type": "object",
"examples": [
{
"columnClassNames": {
"title_v3": "aem-GridColumn aem-GridColumn--default--12"
}
}
]
},
"columnCount": {
"title": "The number of columns available for direct children in the panel.",
"description": "This is applicable only if the panel's layout is grid system.",
"type": "number",
"examples": [
{
"columnCount": 12
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$id": "classpath:/schema/0.15.2/adaptive-form-container-dor-properties.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"dorType": {
"title": "DOR Type",
"description": "Describes the type of Document of Record (DOR)",
"type": "string",
"enum": [
"generate",
"select"
],
"examples": [
{
"dorType": "generate"
}
]
},
"dorTemplateRef": {
"title": "DOR Template Reference",
"description": "Reference to the template for the Document of Record (DOR).",
"type": "string",
"examples": [
{
"dorTemplateRef": "/content/dam/formsanddocuments/acro form conversion.pdf"
}
]
},
"dorTemplateType": {
"title": "DOR Template Type",
"description": "Type of the template for the Document of Record (DOR).",
"enum": [
"acroform",
"xfa"
],
"type": "string"
},
"pageTemplate": {
"$ref": "./print/adaptive-form-page-template-properties.schema.json"
}
}
}
Loading