Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatkhurana-adobe committed Dec 17, 2023
2 parents 67976d8 + 3907187 commit 64f6699
Show file tree
Hide file tree
Showing 112 changed files with 922 additions and 2,626 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ executors:
docker:
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-qp:6.4.6-openjdk11
<<: *docker_auth
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:1209202301-openjdk11
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:13804-openjdk11
<<: *docker_auth

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/spec-validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
# Check if any commit message contains a specific keyword or pattern (e.g., "RTC")
if echo "$commit_messages" | grep -q 'RTC' && echo "$changed_files" | grep -E 'resources/schema/.*\.json$'; then
echo "Commit message contains 'RTC' keyword, and specification files have changed. Build passed."
echo "Commit message contains 'RTC' keyword, and specification files have changed. Build passed. Please check if your changes are working in visual rule editor"
else
echo "Either commit message doesn't contain 'RTC' keyword or specification files haven't changed. Build failed."
echo "Either commit message doesn't contain 'RTC' keyword or specification files haven't changed. Build failed. Please check if your changes are working in visual rule editor"
exit 1
fi
shell: bash
1 change: 0 additions & 1 deletion bundles/af-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.4.1</version>
<configuration>
<groups>java, javax, org</groups>
<staticGroups>*</staticGroups>
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.models.form.ThankYouOption;
import com.adobe.cq.forms.core.components.util.AbstractContainerImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;
import com.day.cq.commons.LanguageUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -259,6 +260,26 @@ public String getLang() {
}
}

@Override
public String getContainingPageLang() {
// todo: right now it is copy of aem form because app is part of far, and af-apps is not pare of far
if (request != null) {
Page currentPage = getCurrentPage();
if (!GuideWCMUtils.isForms(currentPage.getPath())) {
String pagePath = currentPage.getPath(), pageLocaleRoot = LanguageUtil.getLanguageRoot(pagePath), locale = "";
if (StringUtils.isNotBlank(pageLocaleRoot)) {
int localeStartIndex = StringUtils.lastIndexOf(pageLocaleRoot, '/');
locale = StringUtils.substring(pageLocaleRoot, localeStartIndex + 1);
}
return locale;
} else {
return FormContainer.super.getContainingPageLang();
}
} else {
return FormContainer.super.getContainingPageLang();
}
}

@Override
public String getLanguageDirection() {
return GuideUtils.getLanguageDirection(getLang());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ default String getLang() {
return "en-US";
}

/**
* Returns the language of the containing page
*
* @return the language of the containing page
* @since com.adobe.cq.forms.core.components.models.form 4.7.1
*/
@JsonIgnore
default String getContainingPageLang() {
return getLang();
}

/**
* API to give direction of content in HTML for a given language.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@
/**
* Interface for a label
*
* @since com.adobe.cq.forms.core.components.models.form 4.6.0
* @since com.adobe.cq.forms.core.components.models.form 0.0.1
*/
@ConsumerType
public interface Label extends TextContent {
public interface Label {

/**
* Returns {@code true} if label is rich text, otherwise {@code false}.
*
* @return {@code true} if label is rich text, otherwise {@code false}
* @since com.adobe.cq.forms.core.components.models.form 0.0.1
*/
@Nullable
default Boolean isRichText() {
return null;
}

/**
* Returns {@code true} if label should be visible, otherwise {@code false}.
Expand All @@ -37,4 +48,15 @@ default Boolean isVisible() {
return null;
}

/**
* Returns the value of this label.
*
* @return the value of this label
* @since com.adobe.cq.forms.core.components.models.form 0.0.1
*/
@Nullable
default String getValue() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.osgi.annotation.versioning.ProviderType;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
Expand Down Expand Up @@ -58,17 +57,5 @@ default boolean isEnforceEnum() {
* @return the list of enum names
* @since com.adobe.cq.forms.core.components.models.form 0.0.1
*/
@Deprecated
@JsonIgnore
String[] getEnumNames();

/**
* Returns a list of RichText to be displayed to the end user.
* The length of enum and enumNames array must match
*
* @return the list of enum names
* @since com.adobe.cq.forms.core.components.models.form 4.6.0
*/
@JsonProperty("enumNames")
TextContent[] getEnumNamesAsTextContent();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* version, is bound to this proxy component resource type.
* </p>
*/
@Version("4.7.0")
@Version("5.2.0") // 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
Expand Up @@ -29,9 +29,6 @@

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

/**
* Abstract class which can be used as base class for options {@link Field} implementations.
Expand All @@ -52,10 +49,6 @@ public abstract class AbstractOptionsFieldImpl extends AbstractFieldImpl impleme
@Nullable
protected String[] enumNames;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "areOptionsRichText")
@Nullable
private Boolean areOptionsRichText;

@Override
public boolean isEnforceEnum() {
return enforceEnum;
Expand Down Expand Up @@ -102,8 +95,6 @@ public Object[] getEnums() {
}

@Override
@Deprecated
@JsonIgnore
public String[] getEnumNames() {
if (enumNames != null) {
Map<Object, String> map = removeDuplicates();
Expand All @@ -117,29 +108,6 @@ public String[] getEnumNames() {
return null;
}

@Override
public TextContent[] getEnumNamesAsTextContent() {
if (enumNames != null) {
Map<Object, String> map = removeDuplicates();
String[] enumName = map.values().toArray(new String[0]);
return Arrays.stream(enumName)
.map(p -> new TextContent() {
@Override
@JsonInclude(JsonInclude.Include.NON_NULL)
public @Nullable Boolean isRichText() {
return areOptionsRichText;
}

@Override
public @Nullable String getValue() {
return translate("enumNames", p);
}
})
.toArray(TextContent[]::new);
}
return null;
}

@Override
public Object[] getDefault() {
Object[] typedDefaultValue = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -297,44 +296,6 @@ void testGetType() {
void testGetEnumNames() {
CheckBoxGroup checkboxGroup = getCheckBoxGroupUnderTest(PATH_CHECKBOX_GROUP);
assertArrayEquals(new String[] { "m", "f", "o" }, checkboxGroup.getEnumNames());
TextContent textContent1 = new TextContent() {
@Override
public @Nullable Boolean isRichText() {
return null;
}

@Override
public @Nullable String getValue() {
return "m";
}
};
TextContent textContent2 = new TextContent() {
@Override
public @Nullable Boolean isRichText() {
return null;
}

@Override
public @Nullable String getValue() {
return "f";
}
};
TextContent textContent3 = new TextContent() {
@Override
public @Nullable Boolean isRichText() {
return null;
}

@Override
public @Nullable String getValue() {
return "o";
}
};
TextContent[] textContent = new TextContent[] { textContent1, textContent2, textContent3 };
for (int i = 0; i < checkboxGroup.getEnumNamesAsTextContent().length; i++) {
assertEquals(textContent[i].getValue(), checkboxGroup.getEnumNamesAsTextContent()[i].getValue());
assertEquals(textContent[i].isRichText(), checkboxGroup.getEnumNamesAsTextContent()[i].isRichText());
}
}

@Test
Expand All @@ -345,9 +306,6 @@ void testGetEnumNamesWithDuplicateEnumValues() {
map.put("1", "Item 2");
map.put("0", "Item 3");
assertArrayEquals(map.values().toArray(new String[0]), checkboxGroup.getEnumNames());
String[] checkboxGroupValues = Arrays.stream(checkboxGroup.getEnumNamesAsTextContent()).map(d -> d.getValue()).toArray(
size -> new String[checkboxGroup.getEnumNamesAsTextContent().length]);
assertArrayEquals(map.values().toArray(new String[0]), checkboxGroupValues);
}

@Test
Expand Down Expand Up @@ -428,8 +386,5 @@ void testInsertionOrderForEnumNames() {
Set<String> set = new LinkedHashSet<>(Arrays.asList("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"));
assertArrayEquals(set.toArray(new String[0]), checkboxGroup.getEnumNames());
String[] checkboxGroupValues = Arrays.stream(checkboxGroup.getEnumNamesAsTextContent()).map(d -> d.getValue()).toArray(
size -> new String[checkboxGroup.getEnumNamesAsTextContent().length]);
assertArrayEquals(set.toArray(new String[0]), checkboxGroupValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@

import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.*;
import com.adobe.cq.forms.core.components.models.form.Base;
import com.adobe.cq.forms.core.components.models.form.CheckBox;
import com.adobe.cq.forms.core.components.models.form.CheckBox.Orientation;
import com.adobe.cq.forms.core.components.models.form.ConstraintType;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Label;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.adobe.cq.wcm.style.ComponentStyleInfo;
import io.wcm.testing.mock.aem.junit5.AemContext;
Expand Down Expand Up @@ -305,16 +309,6 @@ void testGetEnum() {

}

@Test
void testGetNullEnumNames() {
CheckBox checkbox = getCheckBoxUnderTest(PATH_CHECKBOX);
assertNull(checkbox.getEnumNamesAsTextContent());
assertNull(checkbox.getEnumNames());
CheckBox noEnumCheckbox = getCheckBoxUnderTest(PATH_CHECKBOX_NOENUM);
assertNull(noEnumCheckbox.getEnumNamesAsTextContent());
assertNull(noEnumCheckbox.getEnumNames());
}

@Test
void testGetNullEnum() {
CheckBox noEnumCheckbox = getCheckBoxUnderTest(PATH_CHECKBOX_NOENUM);
Expand Down
Loading

0 comments on commit 64f6699

Please sign in to comment.