Skip to content

Commit

Permalink
UE: Binding each core component's fieldType to its respective sling m…
Browse files Browse the repository at this point in the history
…odel (#1409)

* FORMS-16011 - Binding each core component's fieldType to its respective sling model.

* fixing import

* Fixing test collateral

* fixing import order

* Fixing star imports

* Refactoring getFieldType to super class

* Updating import

* sorting import

* Spec update to 0.14.1 | RTC approved

* updating classpath with schema folder

* fixing paths

* updating schema with buttonType

* incorporating review comments
  • Loading branch information
TalmizAhmed committed Sep 24, 2024
1 parent c3eef5a commit b154b88
Show file tree
Hide file tree
Showing 83 changed files with 3,758 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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.models.form.Button;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.util.AbstractBaseImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;

Expand Down Expand Up @@ -87,6 +88,11 @@ public String getButtonType() {
return buttonType;
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.BUTTON);
}

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_DOR_EXCLUSION)
@Default(booleanValues = false)
protected boolean dorExclusion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.models.form.CheckBox;
import com.adobe.cq.forms.core.components.models.form.CheckBoxGroup;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.util.AbstractOptionsFieldImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;

Expand Down Expand Up @@ -83,4 +84,9 @@ public Integer getMaxItems() {
public Type getType() {
return super.getType(); // check box group always has type array // we always return boolean[], string[] or number[]
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.CHECKBOX_GROUP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.models.form.ConstraintType;
import com.adobe.cq.forms.core.components.models.form.DatePicker;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;

Expand Down Expand Up @@ -83,6 +84,11 @@ public Date getExclusiveMinimumDate() {
return ComponentUtils.clone(exclusiveMinimumVaue);
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.DATE_INPUT);
}

public @NotNull Map<ConstraintType, String> getConstraintMessages() {
Map<ConstraintType, String> res = super.getConstraintMessages();
String msg = getConstraintMessage(ConstraintType.MINIMUM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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.models.form.DropDown;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.util.AbstractOptionsFieldImpl;

@Model(
Expand Down Expand Up @@ -56,4 +57,9 @@ public Integer getMaxItems() {
public Boolean isMultiSelect() {
return multiSelect;
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.DROP_DOWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.FileInput;
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;

Expand Down Expand Up @@ -79,6 +80,11 @@ public Type getType() {
}
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.FILE_INPUT);
}

@Override
public Boolean isMultiple() {
return multiSelection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.NumberInput;
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
Expand Down Expand Up @@ -129,6 +130,11 @@ public Type getType() {
}
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.NUMBER_INPUT);
}

@PostConstruct
private void initNumberInput() {
Object tempExclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximumAsStr != null ? maximumAsStr : maximum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Panel;
import com.adobe.cq.forms.core.components.util.AbstractContainerImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -107,6 +108,11 @@ public Type getType() {
return null;
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.PANEL);
}

@Override
@JsonInclude(JsonInclude.Include.NON_NULL)
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.RadioButton;
import com.adobe.cq.forms.core.components.util.AbstractOptionsFieldImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -68,4 +69,9 @@ private void initRadioButtonModel() {
public Orientation getOrientation() {
return orientation;
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.RADIO_GROUP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.StaticImage;
import com.adobe.cq.forms.core.components.util.AbstractFormComponentImpl;
import com.day.cq.wcm.foundation.Image;
Expand Down Expand Up @@ -138,4 +139,9 @@ public String getLinkUrl() {
}
return properties;
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.IMAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.adobe.cq.export.json.ExporterConstants;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Text;
import com.adobe.cq.forms.core.components.util.AbstractFormComponentImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -69,4 +70,9 @@ public boolean isRichText() {
public String getText() {
return getValue();
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.PLAIN_TEXT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ public boolean isMultiLine() {
public String getFieldType() {
if (isMultiLine()) {
return FieldType.MULTILINE_INPUT.getValue();
} else {
return super.getFieldType();
}
return super.getFieldType(FieldType.TEXT_INPUT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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.FieldType;
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
import com.adobe.cq.forms.core.components.models.form.FormContainer;
import com.adobe.cq.forms.core.components.models.form.FormMetaData;
Expand Down Expand Up @@ -124,6 +125,11 @@ public class FormContainerImpl extends AbstractContainerImpl implements FormCont
@Self(injectionStrategy = InjectionStrategy.OPTIONAL)
private AutoSaveConfiguration autoSaveConfig;

@Override
public String getFieldType() {
return super.getFieldType(FieldType.FORM);
}

@PostConstruct
protected void initFormContainerModel() {
if (request != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.adobe.cq.forms.core.components.internal.Heading;
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.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.FormTitle;
import com.adobe.cq.forms.core.components.util.AbstractFormComponentImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
Expand Down Expand Up @@ -69,6 +70,11 @@ public class TitleImplV2 extends AbstractFormComponentImpl implements FormTitle

private Heading heading;

@Override
public String getFieldType() {
return super.getFieldType(FieldType.PLAIN_TEXT);
}

/**
* Translation of the title property
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public enum FieldType {
PANEL("panel"),
FORM("form"),
CHECKBOX_GROUP("checkbox-group"),
IMAGE("image");
IMAGE("image"),
TELEPHONE("tel"),
PASSWORD("password"),
RANGE("range");

private String value;

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.0";
String DEFAULT_FORMS_SPEC_VERSION = "0.14.1";

/**
* Returns form metadata {@link FormMetaData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.adobe.aemds.guide.service.GuideException;
import com.adobe.cq.forms.core.components.models.form.Captcha;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
Expand All @@ -31,6 +32,11 @@ public abstract class AbstractCaptchaImpl extends AbstractFieldImpl implements C
@JsonIgnore
public abstract String getProvider();

@Override
public String getFieldType() {
return super.getFieldType(FieldType.CAPTCHA);
}

public abstract Map<String, Object> getCaptchaProperties();

public Map<String, Object> getProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.models.form.Base;
import com.adobe.cq.forms.core.components.models.form.FieldType;

/**
* Abstract class which can be used as base class for {@link Base} implementations.
Expand Down Expand Up @@ -57,4 +58,9 @@ public Object[] getEnums() {
return ComponentUtils.coerce(type, enums);
}
}

@Override
public String getFieldType() {
return super.getFieldType(FieldType.CHECKBOX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements
protected String dataRef;

// mandatory property else adapt should fail for adaptive form components
@ValueMapValue(name = ReservedProperties.PN_FIELDTYPE)
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_FIELDTYPE)
protected String fieldTypeJcr;
private FieldType fieldType;

Expand Down Expand Up @@ -148,7 +148,9 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements
@PostConstruct
protected void initBaseModel() {
// first check if this is in the supported list of field type
fieldType = FieldType.fromString(fieldTypeJcr);
if (StringUtils.isNotEmpty(fieldTypeJcr)) {
fieldType = FieldType.fromString(fieldTypeJcr);
}
if (request != null && i18n == null) {
i18n = GuideUtils.getI18n(request, resource);
}
Expand Down Expand Up @@ -216,6 +218,13 @@ public String getFieldType() {
return fieldType.getValue();
}

protected String getFieldType(@Nonnull FieldType defaultFieldType) {
if (fieldType == null) {
return defaultFieldType.getValue();
}
return fieldType.getValue();
}

/**
* Returns {@code true} if form field should be visible, otherwise {@code false}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,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.0/adaptive-form.schema.json");
InputStream schemaStream = Utils.class.getResourceAsStream("/schema/0.14.1/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.0/form.json");
InputStream formContainerTemplate = Utils.class.getResourceAsStream("/schema/0.14.1/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 @@ -35,6 +35,7 @@ public class ButtonImplTest {
private static final String CONTENT_ROOT = "/content";
private static final String PATH_BUTTON_1 = CONTENT_ROOT + "/button";
private static final String PATH_BUTTON_CUSTOMIZED = CONTENT_ROOT + "/button-customized";
private static final String PATH_BUTTON_NO_FIELDTYPE = CONTENT_ROOT + "/button-without-fieldtype";
private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
Expand Down Expand Up @@ -141,4 +142,10 @@ void testGetProperties() {
Button button = Utils.getComponentUnderTest(PATH_BUTTON_1, Button.class, context);
assertEquals("button", button.getProperties().get("fd:buttonType"));
}

@Test
void testNoFieldType() {
Button button = Utils.getComponentUnderTest(PATH_BUTTON_NO_FIELDTYPE, Button.class, context);
assertEquals(FieldType.BUTTON.getValue(), button.getFieldType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class CheckBoxGroupImplTest {

private static final String PATH_CHECKBOX_GROUP_WITH_DUPLICATE_ENUMS = CONTENT_ROOT + "/checkboxgroup-duplicate-enum";
private static final String PATH_CHECKBOX_GROUP_FOR_INSERTION_ORDER = CONTENT_ROOT + "/checkboxgroup-insertion-order";

private static final String PATH_CHECKBOX_GROUP_FOR_BOOLEAN = CONTENT_ROOT + "/checkboxgroup-boolean";
private static final String PATH_CHECKBOX_GROUP_NO_FIELDTYPE = CONTENT_ROOT + "/checkboxgroup-without-fieldtype";

private final AemContext context = FormsCoreComponentTestContext.newAemContext();

Expand Down Expand Up @@ -387,4 +387,10 @@ void testInsertionOrderForEnumNames() {
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"));
assertArrayEquals(set.toArray(new String[0]), checkboxGroup.getEnumNames());
}

@Test
void testNoFieldType() {
CheckBoxGroup checkboxGroup = getCheckBoxGroupUnderTest(PATH_CHECKBOX_GROUP_NO_FIELDTYPE);
Utils.testJSONExport(checkboxGroup, Utils.getTestExporterJSONPath(BASE, PATH_CHECKBOX_GROUP_NO_FIELDTYPE));
}
}
Loading

0 comments on commit b154b88

Please sign in to comment.