Skip to content

Commit

Permalink
Merge branch 'dev' into customFunctionTestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
Deep Prakash Dewanji committed May 7, 2024
2 parents c28d102 + 4446d6b commit be8dc79
Show file tree
Hide file tree
Showing 244 changed files with 8,145 additions and 622 deletions.
22 changes: 0 additions & 22 deletions .circleci/config.yml
Expand Up @@ -175,21 +175,6 @@ jobs:
conf: .circleci/codecov.yml
flags: unittests

build-java-8:
executor: forms_executor_java8
working_directory: /home/circleci/build
steps:
- checkout
- *restore_cache
- run:
name: Update permissions
command: sudo chown -R circleci /usr/local/lib/node_modules
- run:
name: Build
command: node .circleci/ci/build.js
- store_artifacts:
path: test-results/junit

cypress-chrome-cloudready-with-addon:
executor: test_executor_cloudready
environment:
Expand Down Expand Up @@ -431,31 +416,24 @@ workflows:
filters:
tags:
only: /.*/
- build-java-8:
filters:
tags:
only: /.*/
- cypress-chrome-cloudready-with-addon:
filters:
tags:
only: /.*/
requires:
- build-java-11
- build-java-8
- cypress-chrome-cloudready-with-latest-addon:
filters:
tags:
only: /.*/
requires:
- build-java-11
- build-java-8
- cypress-chrome-cloudready-with-latest-addon-without-ft:
filters:
tags:
only: /.*/
requires:
- build-java-11
- build-java-8
- jsdocs-deploy:
requires:
- build-java-11
Expand Down
2 changes: 1 addition & 1 deletion .circleci/docker-compose.yml
Expand Up @@ -6,7 +6,7 @@ services:
entrypoint: tail -f /dev/null # Keeps the container running

circleci-aem-cloudready:
image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:7f6c9fff9b-openjdk11
image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:15860-1-openjdk11
depends_on:
- circleci-qp
# Add any additional configurations or environment variables if needed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spec-validate-pr.yml
Expand Up @@ -29,7 +29,7 @@ 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. Please check if your changes are working in visual rule editor"
echo "Commit message contains 'RTC' keyword, and specification files have changed. Build passed. Please check if your changes are working in visual rule editor. Update spec version in form container dialog"
else
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
Expand Down
Expand Up @@ -71,6 +71,9 @@ private FormConstants() {
/** The resource type for check box group v1 */
public static final String RT_FD_FORM_CHECKBOX_GROUP_V1 = RT_FD_FORM_PREFIX + "checkboxgroup/v1/checkboxgroup";

/** The resource type for reCaptcha v1 */
public static final String RT_FD_FORM_HCAPTCHA_V1 = RT_FD_FORM_PREFIX + "hcaptcha/v1/hcaptcha";

/** The resource type for reCaptcha v1 */
public static final String RT_FD_FORM_RECAPTCHA_V1 = RT_FD_FORM_PREFIX + "recaptcha/v1/recaptcha";

Expand Down
@@ -0,0 +1,125 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.LinkedHashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemds.guide.model.HCaptchaConfiguration;
import com.adobe.aemds.guide.service.CloudConfigurationProvider;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.HCaptcha;
import com.adobe.cq.forms.core.components.util.AbstractCaptchaImpl;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = { HCaptcha.class,
ComponentExporter.class },
resourceType = { FormConstants.RT_FD_FORM_HCAPTCHA_V1 })
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class HCaptchaImpl extends AbstractCaptchaImpl implements HCaptcha {

private static final Logger LOGGER = LoggerFactory.getLogger(HCaptchaImpl.class);

@Inject
private ResourceResolver resourceResolver;

private Resource resource;

@Reference
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private HCaptchaConfiguration hCaptchaConfiguration;

@OSGiService
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
private CloudConfigurationProvider cloudConfigurationProvider;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@JsonIgnore
@Named("cloudServicePath")
protected String cloudServicePath;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@JsonIgnore
@Named("size")
protected String size;

private static final String SITE_KEY = "siteKey";
private static final String URI = "uri";
private static final String SIZE = "size";
private static final String THEME = "theme";
private static final String TYPE = "type";

@Override
public String getCloudServicePath() {
return cloudServicePath;
}

@Override
public String getProvider() {
return "hcaptcha";
}

@Override
public Map<String, Object> getCaptchaProperties() throws GuideException {

Map<String, Object> customCaptchaProperties = new LinkedHashMap<>();
String siteKey = null, uri = null;
resource = resourceResolver.getResource(this.getPath());
if (cloudConfigurationProvider == null) {
LOGGER.info("[AF] [Captcha] [HCAPTCHA] Error while fetching cloud configuration, upgrade to latest release to use hCaptcha.");
}
try {
if (resource != null && cloudConfigurationProvider != null) {
hCaptchaConfiguration = cloudConfigurationProvider.getHCaptchaCloudConfiguration(resource);
if (hCaptchaConfiguration != null) {
siteKey = hCaptchaConfiguration.getSiteKey();
uri = hCaptchaConfiguration.getClientSideJsUrl();
}
}
} catch (GuideException e) {
LOGGER.error("[AF] [Captcha] [HCAPTCHA] Error while fetching cloud configuration, upgrade to latest release to use hCaptcha.");
}
customCaptchaProperties.put(SITE_KEY, siteKey);
customCaptchaProperties.put(URI, uri);
customCaptchaProperties.put(SIZE, this.size);
customCaptchaProperties.put(THEME, "light");
customCaptchaProperties.put(TYPE, "image");

return customCaptchaProperties;

}

}
Expand Up @@ -85,6 +85,7 @@ public class FormMetaDataDataSourceServlet extends AbstractDataSourceServlet {
public enum FormMetaDataType {
SUBMIT_ACTION("submitAction"),
PREFILL_ACTION("prefillServiceProvider"),
LANG("lang"),
FORMATTERS("formatters");

private String value;
Expand Down Expand Up @@ -147,6 +148,29 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt
request.setAttribute(DataSource.class.getName(), actionTypeDataSource);
}

/**
* Checks if the type is related to formatters policy and the entry's key starts with the allowedformat.
*
* @param type The type of form meta data.
* @param entry The entry in the form meta data map.
* @return True if the type is related to formatters policy and the entry's key starts with the allowedformat, otherwise false.
*/
private Boolean isFormattersPolicy(FormMetaDataType type, Map.Entry<String, Object> entry) {
return type.equals(FormMetaDataType.FORMATTERS) && entry.getKey().startsWith(ALLOWED_FORMAT);
}

/**
* Checks if the type is related to language policy and the entry's key starts with the value of language metadata.
*
* @param type The type of form meta data.
* @param entry The entry in the form meta data map.
* @return True if the type is related to language policy and the entry's key starts with the value of language metadata, otherwise
* false.
*/
private Boolean isLangPolicy(FormMetaDataType type, Map.Entry<String, Object> entry) {
return type.equals(FormMetaDataType.LANG) && entry.getKey().startsWith(FormMetaDataType.LANG.getValue());
}

private List<Resource> getDataSourceResources(HttpServletRequest request, ResourceResolver resourceResolver, FormMetaDataType type,
String dataModel) {
List<Resource> resources = new ArrayList<>();
Expand All @@ -155,22 +179,25 @@ private List<Resource> getDataSourceResources(HttpServletRequest request, Resour
Iterator<FormsManager.ComponentDescription> metaDataList = null;
switch (type) {
case FORMATTERS:
case LANG:
ContentPolicy policy = ComponentUtils.getPolicy((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE),
resourceResolver);
resources.add(getResourceForDropdownDisplay(resourceResolver, "Select", ""));
if (policy != null) {
ValueMap props = policy.getProperties();
if (props != null) {
for (Map.Entry<String, Object> entry : props.entrySet()) {
if (entry.getKey().startsWith(ALLOWED_FORMAT)) {
if (isFormattersPolicy(type, entry) || isLangPolicy(type, entry)) {
String[] arr = entry.getValue().toString().split("=", 2);
resources.add(getResourceForDropdownDisplay(resourceResolver, arr[0], arr[1]));
}
}
}
Map<String, String> allowedCustomFormattersMap = this.getAllowedCustomFormatters(policy, resourceResolver);
for (Map.Entry<String, String> entry : allowedCustomFormattersMap.entrySet()) {
resources.add(getResourceForDropdownDisplay(resourceResolver, entry.getKey(), entry.getValue()));
if (type.equals(FormMetaDataType.FORMATTERS)) {
Map<String, String> allowedCustomFormattersMap = this.getAllowedCustomFormatters(policy, resourceResolver);
for (Map.Entry<String, String> entry : allowedCustomFormattersMap.entrySet()) {
resources.add(getResourceForDropdownDisplay(resourceResolver, entry.getKey(), entry.getValue()));
}
}
}
resources.add(getResourceForDropdownDisplay(resourceResolver, "Custom", "custom"));
Expand Down
Expand Up @@ -35,6 +35,13 @@
public interface Base extends FormComponent {
public final String DATE_FORMATTER = "yyyy-MM-dd";

/**
* Constant representing the default language used, typically "en-US".
*
* @since com.adobe.cq.forms.core.components.models.form 5.3.1
*/
public final String DEFAULT_LANGUAGE = "en-US";

/**
* Returns label of the form field
*
Expand Down Expand Up @@ -136,4 +143,16 @@ default String getTooltip() {
default boolean isTooltipVisible() {
return false;
}

/**
* Returns the language to use for formatting the field.
*
* @return returns the language to use for formatting the field.
* @since com.adobe.cq.forms.core.components.models.form 5.3.1
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@Nullable
default String getLang() {
return DEFAULT_LANGUAGE;
}
}
Expand Up @@ -23,8 +23,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
* Defines the form {@code Captcha} Sling Model used for the {@code /apps/core/fd/components/form/recaptcha/v1/recaptcha}
* component.
* Defines a base interface to be extended by all the different types of captcha.
*
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
*/
Expand Down
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.12.5";
String DEFAULT_FORMS_SPEC_VERSION = "0.13.0";

/**
* Returns form metadata {@link FormMetaData}
Expand Down Expand Up @@ -294,7 +294,7 @@ default String getDataUrl() {
* @since com.adobe.cq.forms.core.components.models.form 4.0.0
*/
default String getLang() {
return "en-US";
return Base.DEFAULT_LANGUAGE;
}

/**
Expand Down
@@ -0,0 +1,27 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.ConsumerType;

/**
* Defines the form {@code HCaptcha} Sling Model used for the {@code /apps/core/fd/components/form/hcaptcha/v1/hcaptcha}
* component.
*
* @since com.adobe.cq.forms.core.components.models.form 5.4.0
*/
@ConsumerType
public interface HCaptcha extends Captcha {}
Expand Up @@ -34,7 +34,7 @@
* version, is bound to this proxy component resource type.
* </p>
*/
@Version("5.3.0") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
@Version("5.4.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;
Expand Up @@ -117,6 +117,9 @@ public abstract class AbstractBaseImpl extends AbstractFormComponentImpl impleme
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
protected Integer maxItems;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
protected String lang;

/** End **/

@SlingObject
Expand Down Expand Up @@ -155,6 +158,11 @@ public boolean isTooltipVisible() {
return tooltipVisible;
}

@Override
public String getLang() {
return lang;
}

@JsonIgnore
public @NotNull Map<String, Object> getCustomLayoutProperties() {
Map<String, Object> customLayoutProperties = super.getCustomLayoutProperties();
Expand Down

0 comments on commit be8dc79

Please sign in to comment.