Skip to content

Commit 22e8c75

Browse files
authored
Merge pull request #1229 from adobe/devtomaster-9-May-2024
Devtomaster 9 may 2024
2 parents 2465443 + 3381636 commit 22e8c75

File tree

63 files changed

+1193
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1193
-98
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,31 @@
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1616
package com.adobe.cq.forms.core.components.internal.form;
1717

18+
import java.io.IOException;
19+
import java.io.StringWriter;
20+
import java.io.Writer;
21+
1822
import org.apache.sling.api.SlingHttpServletRequest;
1923
import org.apache.sling.api.resource.Resource;
2024
import org.apache.sling.models.annotations.Model;
2125
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
2226
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
2327
import org.jetbrains.annotations.NotNull;
2428
import org.jetbrains.annotations.Nullable;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2531

2632
import com.adobe.cq.forms.core.components.models.form.FormContainer;
2733
import com.adobe.cq.forms.core.components.models.form.FormStructureParser;
2834
import com.adobe.cq.forms.core.components.util.ComponentUtils;
35+
import com.adobe.cq.forms.core.components.views.Views;
36+
import com.fasterxml.jackson.databind.ObjectMapper;
2937

3038
@Model(
3139
adaptables = { SlingHttpServletRequest.class, Resource.class },
3240
adapters = FormStructureParser.class)
3341
public class FormStructureParserImpl implements FormStructureParser {
34-
42+
private static final Logger logger = LoggerFactory.getLogger(FormStructureParserImpl.class);
3543
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
3644
@Nullable
3745
private SlingHttpServletRequest request;
@@ -104,4 +112,19 @@ private String getFormContainerPath(Resource resource) {
104112

105113
return getFormContainerPath(resource.getParent());
106114
}
115+
116+
public String getFormDefinition() {
117+
String result = null;
118+
FormContainer formContainer = resource.adaptTo(FormContainer.class);
119+
try {
120+
ObjectMapper mapper = new ObjectMapper();
121+
Writer writer = new StringWriter();
122+
// return publish view specific properties only for runtime
123+
mapper.writerWithView(Views.Publish.class).writeValue(writer, formContainer);
124+
result = writer.toString();
125+
} catch (IOException e) {
126+
logger.error("Unable to generate json from resource");
127+
}
128+
return result;
129+
}
107130
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2024 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
package com.adobe.cq.forms.core.components.internal.form;
17+
18+
import org.apache.sling.api.SlingHttpServletRequest;
19+
import org.apache.sling.api.resource.Resource;
20+
import org.apache.sling.models.annotations.Model;
21+
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
22+
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
23+
import org.jetbrains.annotations.Nullable;
24+
25+
import com.adobe.cq.forms.core.components.models.form.HtlUtil;
26+
27+
@Model(
28+
adaptables = { SlingHttpServletRequest.class, Resource.class },
29+
adapters = HtlUtil.class)
30+
public class HtlUtilImpl implements HtlUtil {
31+
@SlingObject(injectionStrategy = InjectionStrategy.OPTIONAL)
32+
@Nullable
33+
private SlingHttpServletRequest request;
34+
35+
public Boolean isEdgeDeliveryRequest() {
36+
if (request != null) {
37+
Object isEdgeDelivery = request.getAttribute("com.adobe.aem.wcm.franklin.internal.servlets.FranklinDeliveryServlet");
38+
return isEdgeDelivery != null && isEdgeDelivery.equals(Boolean.TRUE);
39+
}
40+
return false;
41+
}
42+
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/StaticImageImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package com.adobe.cq.forms.core.components.internal.models.v1.form;
1717

1818
import java.io.IOException;
19+
import java.util.Map;
1920

21+
import javax.annotation.Nonnull;
2022
import javax.annotation.Nullable;
2123
import javax.jcr.RepositoryException;
2224

@@ -45,6 +47,8 @@
4547
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
4648
public class StaticImageImpl extends AbstractFormComponentImpl implements StaticImage {
4749

50+
public static final String DAM_REPO_PATH = "fd:repoPath";
51+
4852
private Image image;
4953

5054
@SlingObject
@@ -62,6 +66,10 @@ public class StaticImageImpl extends AbstractFormComponentImpl implements Static
6266
@org.jetbrains.annotations.Nullable
6367
protected String description; // long description as per current spec
6468

69+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileReference")
70+
@Nullable
71+
protected String fileReference;
72+
6573
/**
6674
* Returns the source where the image is present.
6775
*
@@ -120,4 +128,13 @@ public String getLinkUrl() {
120128
return null;
121129
}
122130
}
131+
132+
@Override
133+
public @Nonnull Map<String, Object> getProperties() {
134+
Map<String, Object> properties = super.getProperties();
135+
if (fileReference != null && fileReference.length() > 0) {
136+
properties.put(DAM_REPO_PATH, fileReference);
137+
}
138+
return properties;
139+
}
123140
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
3333
import org.jetbrains.annotations.NotNull;
3434
import org.jetbrains.annotations.Nullable;
35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3537

3638
import com.adobe.aemds.guide.common.GuideContainer;
3739
import com.adobe.aemds.guide.service.GuideSchemaType;
@@ -63,6 +65,7 @@
6365
public class FormContainerImpl extends AbstractContainerImpl implements FormContainer {
6466
protected static final String RESOURCE_TYPE = "core/fd/components/form/container/v2/container";
6567

68+
private static final Logger logger = LoggerFactory.getLogger(FormContainerImpl.class);
6669
private static final String DOR_TYPE = "dorType";
6770
private static final String DOR_TEMPLATE_REF = "dorTemplateRef";
6871
private static final String DOR_TEMPLATE_TYPE = "dorTemplateType";

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,5 +362,4 @@ default void visit(Consumer<ComponentExporter> callback) throws Exception {}
362362
default String getParentPagePath() {
363363
return null;
364364
}
365-
366365
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormStructureParser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ public interface FormStructureParser {
4343
* @return true if this resource or one of its children is a form container, else false
4444
*/
4545
Boolean containsFormContainer();
46+
47+
/**
48+
* @since com.adobe.cq.forms.core.components.models.form 5.4.1
49+
*
50+
* @return form definition json in Publish view
51+
*/
52+
String getFormDefinition();
4653
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2024 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
package com.adobe.cq.forms.core.components.models.form;
17+
18+
import org.osgi.annotation.versioning.ProviderType;
19+
20+
@ProviderType
21+
public interface HtlUtil {
22+
/**
23+
* Checks whether this request has been originated from edge delivery services
24+
*
25+
* @return {Boolean} true if the request is from edge delivery services, false otherwise
26+
* @since com.adobe.cq.forms.core.components.models.form 5.3.2
27+
*/
28+
Boolean isEdgeDeliveryRequest();
29+
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
* version, is bound to this proxy component resource type.
3535
* </p>
3636
*/
37-
@Version("5.4.0") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
37+
38+
@Version("5.4.1") // aligning this with release/650 since af2-rest-api is compiled with 5.2.0 in release/650
3839
package com.adobe.cq.forms.core.components.models.form;
3940

4041
import org.osgi.annotation.versioning.Version;

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFieldImpl.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import java.util.Arrays;
1919
import java.util.Calendar;
2020
import java.util.Date;
21-
import java.util.LinkedHashMap;
22-
import java.util.Map;
2321

2422
import org.apache.sling.api.resource.Resource;
2523
import org.apache.sling.models.annotations.Default;
@@ -31,7 +29,6 @@
3129
import org.slf4j.LoggerFactory;
3230

3331
import com.adobe.cq.forms.core.components.models.form.Field;
34-
import com.fasterxml.jackson.annotation.JsonIgnore;
3532
import com.fasterxml.jackson.annotation.JsonInclude;
3633
import com.fasterxml.jackson.annotation.JsonProperty;
3734

@@ -80,14 +77,6 @@ public abstract class AbstractFieldImpl extends AbstractBaseImpl implements Fiel
8077
@Nullable
8178
protected Integer maxLength;
8279

83-
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorExclusion")
84-
@Default(booleanValues = false)
85-
protected boolean dorExclusion;
86-
87-
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorColspan")
88-
@Nullable
89-
protected String dorColspan;
90-
9180
/** number and date constraint **/
9281

9382
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "minimumDate")
@@ -116,16 +105,6 @@ public abstract class AbstractFieldImpl extends AbstractBaseImpl implements Fiel
116105

117106
/** number and date constraint **/
118107

119-
/**
120-
* Returns dorBindRef of the form field
121-
*
122-
* @return dorBindRef of the field
123-
* @since com.adobe.cq.forms.core.components.util 2.1.0
124-
*/
125-
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorBindRef")
126-
@Nullable
127-
protected String dorBindRef;
128-
129108
@SlingObject
130109
private Resource resource;
131110

@@ -197,17 +176,4 @@ public String getDataFormat() {
197176
return dataFormat;
198177
}
199178

200-
@Override
201-
@JsonIgnore
202-
public Map<String, Object> getDorProperties() {
203-
Map<String, Object> customDorProperties = new LinkedHashMap<>();
204-
customDorProperties.put("dorExclusion", dorExclusion);
205-
if (dorColspan != null) {
206-
customDorProperties.put("dorColspan", dorColspan);
207-
}
208-
if (dorBindRef != null) {
209-
customDorProperties.put("dorBindRef", dorBindRef);
210-
}
211-
return customDorProperties;
212-
}
213179
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ public class AbstractFormComponentImpl extends AbstractComponentImpl implements
9595
@SlingObject
9696
private Resource resource;
9797

98+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorExclusion")
99+
@Default(booleanValues = false)
100+
protected boolean dorExclusion;
101+
102+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorColspan")
103+
@Nullable
104+
protected String dorColspan;
105+
106+
/**
107+
* Returns dorBindRef of the form field
108+
*
109+
* @return dorBindRef of the field
110+
* @since com.adobe.cq.forms.core.components.util 4.0.0
111+
*/
112+
@JsonIgnore
113+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dorBindRef")
114+
@Nullable
115+
protected String dorBindRef;
116+
98117
/**
99118
* Flag indicating if the data layer is enabled.
100119
*/
@@ -473,4 +492,18 @@ private Map<String, String> getCustomProperties() {
473492
return Collections.emptyMap();
474493
}
475494
}
495+
496+
@Override
497+
@JsonIgnore
498+
public Map<String, Object> getDorProperties() {
499+
Map<String, Object> customDorProperties = new LinkedHashMap<>();
500+
customDorProperties.put("dorExclusion", dorExclusion);
501+
if (dorColspan != null) {
502+
customDorProperties.put("dorColspan", dorColspan);
503+
}
504+
if (dorBindRef != null) {
505+
customDorProperties.put("dorBindRef", dorBindRef);
506+
}
507+
return customDorProperties;
508+
}
476509
}

0 commit comments

Comments
 (0)