Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEOS-11658] Time editor dumps stack trace in UI if the start or end time values are intervals #8151

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.geotools.api.coverage.grid.GridCoverageReader;
import org.geotools.api.feature.type.PropertyDescriptor;
import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.util.DateRange;
import org.geotools.util.DateTimeParser;
import org.geotools.util.Range;
import org.geotools.util.logging.Logging;
Expand Down Expand Up @@ -947,12 +948,16 @@ public StartEndValueValidator(String dimensionId) {
public void validate(IValidatable<String> value) {
boolean valid = false;
String errorKey = "invalidStartOrEndDate";
DateTimeParser dateTimeParser = new DateTimeParser();
DateTimeParser dateTimeParser = new DateTimeParser(-1, 1);
Date date = null;
if (dimension.equals("time")) {
String timeValue = value.getValue();
try {
date = (Date) ((List) dateTimeParser.parse(timeValue)).get(0);
Object dateObject = ((List) dateTimeParser.parse(timeValue)).get(0);
if (dateObject instanceof DateRange) {
throw new ParseException("Invalid date: " + dateObject, 0);
}
date = (Date) dateObject;
} catch (ParseException e) {
LOGGER.log(
Level.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,27 @@ public void testEditVectorElevation() throws Exception {
// should not be visible
tester.assertInvisible(prefix + "nearestMatchContainer");
}

@Test
public void testStartValueErrorMessageWithDateRange() throws Exception {
FeatureTypeInfo ft = getCatalog().getFeatureTypeByName(getLayerId(V_TIME_ELEVATION));
DimensionInfo time = ft.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
Model<DimensionInfo> timeModel = new Model<>(time);

tester.startPage(
new FormTestPage(
id -> new DimensionEditor(id, timeModel, ft, Date.class, true, false)));
print(tester.getLastRenderedPage(), true, true);

FormTester form = tester.newFormTester("form");
String formPrefix = "panel:configContainer:configs:";

// Set an invalid value for startValue (for example, an incorrect date format)
form.setValue(formPrefix + "startEndContainer:startValue", "invalid-date-format");
form.submit();

// Check if an error message is displayed for startValue
tester.assertErrorMessages(
"Start data range value must be an ISO8601 DateTime or a construct like 'PRESENT'");
}
}
Loading