Skip to content

Commit 3b715a4

Browse files
author
dgurjar
committed
date time fixes
1 parent b1743af commit 3b715a4

File tree

54 files changed

+3481
-241
lines changed

Some content is hidden

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

54 files changed

+3481
-241
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ private FormConstants() {
137137

138138
public static final String PROP_FRAGMENT_PATH = "fragmentPath";
139139

140-
<<<<<<< HEAD
141140
/** The resource type for review v1 */
142141
public static final String RT_FD_FORM_REVIEW_V1 = RT_FD_FORM_PREFIX + "review/v1/review";
143142

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private ReservedProperties() {
8383
public static final String PN_MAX_LENGTH = "maxLength";
8484
public static final String PN_MINIMUM_DATE = "minimumDate";
8585
public static final String PN_MAXIMUM_DATE = "maximumDate";
86+
public static final String PN_MINIMUM_DATE_TIME = "minimumDateTime";
87+
public static final String PN_DEFAULT_DATE_TIME = "defaultDateTime";
88+
public static final String PN_MAXIMUM_DATE_TIME = "maximumDateTime";
8689
public static final String PN_MAXIMUM = "maximum";
8790
public static final String PN_MINIMUM = "minimum";
8891
public static final String PN_EXCLUSIVE_MINIMUM = "exclusiveMinimum";
Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2-
~ Copyright 2024 Adobe
2+
~ Copyright 2025 Adobe
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
55
~ you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
1616

1717
package com.adobe.cq.forms.core.components.internal.models.v1.form;
1818

19+
import java.time.OffsetDateTime;
20+
import java.time.format.DateTimeFormatter;
21+
import java.util.Map;
22+
1923
import javax.annotation.Nullable;
2024
import javax.annotation.PostConstruct;
2125

@@ -25,13 +29,15 @@
2529
import org.apache.sling.models.annotations.Model;
2630
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
2731
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
32+
import org.jetbrains.annotations.NotNull;
2833

2934
import com.adobe.cq.export.json.ComponentExporter;
3035
import com.adobe.cq.export.json.ExporterConstants;
3136
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
32-
import com.adobe.cq.forms.core.components.models.form.DateTime;
37+
import com.adobe.cq.forms.core.components.models.form.*;
3338
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
34-
import com.adobe.cq.forms.core.components.util.ComponentUtils;
39+
import com.adobe.xfa.ut.StringUtils;
40+
import com.fasterxml.jackson.annotation.JsonFormat;
3541

3642
@Model(
3743
adaptables = { SlingHttpServletRequest.class, Resource.class },
@@ -41,70 +47,60 @@
4147
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
4248
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
4349
public class DateTimeImpl extends AbstractFieldImpl implements DateTime {
44-
45-
private Object exclusiveMinimumVaue;
46-
private Object exclusiveMaximumValue;
47-
4850
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
4951
@Nullable
5052
private String pattern;
5153

5254
@Override
5355
public String getFieldType() {
54-
return super.getFieldType();
56+
return super.getFieldType(FieldType.DATETIME_INPUT);
5557
}
5658

57-
@Override
58-
public Integer getMinLength() {
59-
return minLength;
60-
}
59+
@PostConstruct
60+
private void initTextInput() {}
6161

6262
@Override
63-
public Integer getMaxLength() {
64-
return maxLength;
63+
public String getMinimumDateTime() {
64+
return getFormattedDate(minimumDateTime);
6565
}
6666

6767
@Override
68-
public Long getMinimum() {
69-
return minimum;
68+
public String getMaximumDateTime() {
69+
return getFormattedDate(maximumDateTime);
7070
}
7171

72-
@Override
73-
public Long getMaximum() {
74-
return maximum;
75-
}
72+
private String getFormattedDate(String dateTime) {
73+
if (!StringUtils.isEmpty(dateTime)) {
74+
OffsetDateTime formattedTime = OffsetDateTime.parse(dateTime);
75+
return formattedTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"));
76+
}
77+
return dateTime;
7678

77-
@Override
78-
public String getFormat() {
79-
return displayFormat;
8079
}
8180

82-
@Override
83-
public String getPattern() {
84-
return pattern;
81+
public @NotNull Map<ConstraintType, String> getConstraintMessages() {
82+
Map<ConstraintType, String> res = super.getConstraintMessages();
83+
String msg = getConstraintMessage(ConstraintType.MINIMUM);
84+
if (msg != null) {
85+
res.put(ConstraintType.MINIMUM, msg);
86+
}
87+
msg = getConstraintMessage(ConstraintType.MAXIMUM);
88+
if (msg != null) {
89+
res.put(ConstraintType.MAXIMUM, msg);
90+
}
91+
return res;
8592
}
8693

8794
@Override
88-
public Long getExclusiveMaximum() {
89-
return (Long) exclusiveMaximumValue;
95+
@Nullable
96+
public String getFormat() {
97+
return "date-time";
9098
}
9199

100+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
92101
@Override
93-
public Long getExclusiveMinimum() {
94-
return (Long) exclusiveMinimumVaue;
95-
}
96-
97-
@PostConstruct
98-
private void initTextInput() {
99-
exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximum, null);
100-
exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimum, null);
101-
// in json either, exclusiveMaximum or maximum should be present
102-
if (exclusiveMaximumValue != null) {
103-
maximum = null;
104-
}
105-
if (exclusiveMinimumVaue != null) {
106-
minimum = null;
107-
}
102+
public Object[] getDefault() {
103+
return defaultValue;
108104
}
109105

110106
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
public interface Base extends FormComponent {
3636
public final String DATE_FORMATTER = "yyyy-MM-dd";
3737

38+
public final String DATE_TIME_FORMATTER = "yyyy-MM-dd'T'HH:mm:ss";
39+
3840
/**
3941
* Constant representing the default language used, typically "en-US".
4042
*

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3-
~ Copyright 2024 Adobe
3+
~ Copyright 2025 Adobe
44
~
55
~ Licensed under the Apache License, Version 2.0 (the "License");
66
~ you may not use this file except in compliance with the License.
@@ -22,17 +22,9 @@
2222
/**
2323
* Interface for {@code Password} Sling Model used for the {@code /apps/core/fd/components/form/password/v1/password} component.
2424
*
25-
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
25+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
2626
*/
2727
@ConsumerType
28-
public interface DateTime extends Field, StringConstraint, NumberConstraint {
28+
public interface DateTime extends Field, DateTimeConstraint {
2929

30-
/**
31-
* Returns the validation pattern (regex) for the password field.
32-
*
33-
* @return the validation pattern
34-
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
35-
*/
36-
String getPattern();
37-
38-
}
30+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 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+
17+
package com.adobe.cq.forms.core.components.models.form;
18+
19+
import com.fasterxml.jackson.annotation.JsonFormat;
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
23+
public interface DateTimeConstraint extends FormatConstraint {
24+
/**
25+
* Returns the minimum value for the date. The constraint is applicable only for field with type date
26+
*
27+
* @return minimum date
28+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
29+
*/
30+
@JsonInclude(JsonInclude.Include.NON_NULL)
31+
@JsonProperty("minimum")
32+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
33+
String getMinimumDateTime();
34+
35+
/**
36+
* Returns the maximum value for the date. The constraint is applicable only for field with type date
37+
*
38+
* @return maximum date
39+
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
40+
*/
41+
@JsonInclude(JsonInclude.Include.NON_NULL)
42+
@JsonProperty("maximum")
43+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Base.DATE_TIME_FORMATTER, timezone = "UTC")
44+
String getMaximumDateTime();
45+
46+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum FieldType {
3838
IMAGE("image"),
3939
TELEPHONE("tel"),
4040
PASSWORD("password"),
41-
DATETIME("date-time"),
41+
DATETIME_INPUT("datetime-input"),
4242
RANGE("range"),
4343
COLOR("color"),
4444
URL("url"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public interface FormContainer extends Container {
6464
*/
6565
String PN_CLIENT_LIB_REF = GuideConstants.CLIENT_LIB_REF;
6666

67-
String DEFAULT_FORMS_SPEC_VERSION = "0.14.2";
67+
String DEFAULT_FORMS_SPEC_VERSION = "0.15.0";
6868

6969
/**
7070
* Returns form metadata {@link FormMetaData}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public abstract class AbstractFieldImpl extends AbstractBaseImpl implements Fiel
8787
@Nullable
8888
protected Date maximumDate;
8989

90+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MINIMUM_DATE_TIME)
91+
@Nullable
92+
protected String minimumDateTime;
93+
94+
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MAXIMUM_DATE_TIME)
95+
@Nullable
96+
protected String maximumDateTime;
97+
9098
/** Do not do any changes, this is just present for backward compatibility **/
9199
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MAXIMUM)
92100
@Nullable

bundles/af-core/src/test/java/com/adobe/cq/forms/core/Utils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ public static void testSchemaValidation(@NotNull Object model) {
126126
// create an instance of the JsonSchemaFactory using version flag
127127
JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
128128
try {
129-
InputStream schemaStream = Utils.class.getResourceAsStream("/schema/0.14.2/adaptive-form.schema.json");
129+
InputStream schemaStream = Utils.class.getResourceAsStream("/schema/0.15.0/adaptive-form.schema.json");
130130
JsonSchema schema = schemaFactory.getSchema(schemaStream);
131131
// read data from the stream and store it into JsonNode
132132
JsonNode json = objectMapper.readTree(jsonStream);
133133
// if there is a version bump of schema, then it needs to be validated against its corresponding sling model here
134134
// by explicitly checking the model implementation
135135
if (!(model instanceof FormContainerImpl)) {
136-
InputStream formContainerTemplate = Utils.class.getResourceAsStream("/schema/0.14.2/form.json");
136+
InputStream formContainerTemplate = Utils.class.getResourceAsStream("/schema/0.15.0/form.json");
137137
JsonNode formContainerTemplateNode = objectMapper.readTree(formContainerTemplate);
138138
((ObjectNode) formContainerTemplateNode).putArray("items").add(json);
139139
json = formContainerTemplateNode;
140140
}
141-
// create set of validation message and store result in it
141+
// create set of validation message and st ore result in it
142142
Set<ValidationMessage> validationResult = schema.validate(json);
143143
// show the validation errors
144144
if (!validationResult.isEmpty()) {

0 commit comments

Comments
 (0)