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

Time dimension daterange fix #8128

Closed
wants to merge 4 commits into from
Closed
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 @@ -4,10 +4,6 @@
*/
package org.geoserver.web.data.resource;

import static org.junit.Assert.assertEquals;

import java.util.Date;
import javax.xml.namespace.QName;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.tester.FormTester;
import org.geoserver.catalog.DimensionInfo;
Expand All @@ -21,6 +17,11 @@
import org.junit.Before;
import org.junit.Test;

import javax.xml.namespace.QName;
import java.util.Date;

import static org.junit.Assert.assertEquals;

public class DimensionEditorTest extends GeoServerWicketTestSupport {

private static final QName V_TIME_ELEVATION =
Expand Down Expand Up @@ -120,4 +121,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