Skip to content

Commit

Permalink
GEOS-7989 -part2: WMS/WCS custom dimensions with Number
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Jul 24, 2017
1 parent 47b20ac commit 2889316
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ public Collection<Object> convertDimensionValue(String name, String value) {
Class<?> type = Class.forName(typeName); Class<?> type = Class.forName(typeName);
if (type == java.util.Date.class) { if (type == java.util.Date.class) {
result.addAll(new TimeParser().parse(value)); result.addAll(new TimeParser().parse(value));
} else if (Number.class.isAssignableFrom(type) && !value.contains(",")) {
result.add(parseNumberOrRange(value));
} else { } else {
for (String element : value.split(",")) { for (String element : value.split(",")) {
result.add(Converters.convert(element, type)); result.add(Converters.convert(element, type));
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testMixedElevationExtraction() throws IOException {
} }


@Test @Test
public void testCustomDimensionConvertion() throws IOException, ParseException { public void testCustomTimeDimensionConvertion() throws IOException, ParseException {
MockDimensionReader reader = new MockDimensionReader(); MockDimensionReader reader = new MockDimensionReader();
reader.metadata.put("HAS_MYDIM_DOMAIN", "true"); reader.metadata.put("HAS_MYDIM_DOMAIN", "true");
reader.metadata.put("MYDIM_DOMAIN_DATATYPE", "java.util.Date"); reader.metadata.put("MYDIM_DOMAIN_DATATYPE", "java.util.Date");
Expand All @@ -119,4 +119,31 @@ public void testCustomDimensionConvertion() throws IOException, ParseException {
assertEquals(DF.parse("2001-05-02 00:00:00"), converted.get(1)); assertEquals(DF.parse("2001-05-02 00:00:00"), converted.get(1));
assertEquals(DF.parse("2001-05-03 00:00:00"), converted.get(2)); assertEquals(DF.parse("2001-05-03 00:00:00"), converted.get(2));
} }

@Test
public void testCustomDepthDimensionConvertion() throws IOException, ParseException {
MockDimensionReader reader = new MockDimensionReader();
reader.metadata.put("HAS_MYDIM_DOMAIN", "true");
reader.metadata.put("MYDIM_DOMAIN_DATATYPE", "java.lang.Double");
ReaderDimensionsAccessor accessor = new ReaderDimensionsAccessor(reader);
List<Object> converted = accessor.convertDimensionValue("MYDIM",
Arrays.asList("10/20"));
assertEquals(1, converted.size());
NumberRange<Double> expected = new NumberRange<Double>(Double.class, 10d, 20d);
assertEquals(expected, converted.get(0));
}

@Test
public void testCustomCloudCoverDimensionConvertion() throws IOException, ParseException {
MockDimensionReader reader = new MockDimensionReader();
reader.metadata.put("HAS_MYDIM_DOMAIN", "true");
reader.metadata.put("MYDIM_DOMAIN_DATATYPE", "java.lang.Integer");
ReaderDimensionsAccessor accessor = new ReaderDimensionsAccessor(reader);
List<Object> converted = accessor.convertDimensionValue("MYDIM",
Arrays.asList("75/100"));
assertEquals(1, converted.size());
NumberRange<Double> expected = new NumberRange<Double>(Double.class, 75d, 100d);
assertEquals(expected, converted.get(0));
}

} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.geoserver.wms.WMS; import org.geoserver.wms.WMS;
import org.geoserver.wms.WMSTestSupport; import org.geoserver.wms.WMSTestSupport;
import org.geotools.coverage.grid.io.GridCoverage2DReader; import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.util.NumberRange;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.opengis.filter.Filter; import org.opengis.filter.Filter;
Expand All @@ -33,12 +34,16 @@
/** /**
* Tests the WMS default value support for a custom dimension * Tests the WMS default value support for a custom dimension
* that uses the java.util.Date class rather than Strings * that uses the java.util.Date class rather than Strings
* and java.lang.Double class rather than Strings
*/ */
public class CustomDimensionTimeTest extends WMSTestSupport { public class CustomDimensionTimeAndNumberTest extends WMSTestSupport {


private static final QName WATTEMP_TIME = new QName(MockData.SF_URI, "watertemp_time", private static final QName WATTEMP_TIME = new QName(MockData.SF_URI, "watertemp_time",
MockData.SF_PREFIX); MockData.SF_PREFIX);


private static final QName WATTEMP_DEPTH = new QName(MockData.SF_URI, "watertemp_depth",
MockData.SF_PREFIX);

private static SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); private static SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");


static { static {
Expand All @@ -58,6 +63,9 @@ public void setup() throws Exception {
((SystemTestData)testData).addRasterLayer(WATTEMP_TIME, "custwatertemp_time.zip", null, ((SystemTestData)testData).addRasterLayer(WATTEMP_TIME, "custwatertemp_time.zip", null,
Collections.emptyMap(), Collections.emptyMap(),
getClass(), getCatalog()); getClass(), getCatalog());
((SystemTestData)testData).addRasterLayer(WATTEMP_DEPTH, "custwatertemp_depth.zip", null,
Collections.emptyMap(),
getClass(), getCatalog());
} }


@Test @Test
Expand All @@ -77,5 +85,33 @@ public void testTimeDimension() throws Exception {
assertEquals(DF.parse("2001-05-02 00:00:00"), val.getValue().get(1)); assertEquals(DF.parse("2001-05-02 00:00:00"), val.getValue().get(1));
} }



@Test
public void testCustomDepthIntervalDimension() throws Exception {
MapLayerInfo mapLayerInfo = new MapLayerInfo(getCatalog().getLayerByName(WATTEMP_DEPTH.getLocalPart()));
final GridCoverage2DReader reader = (GridCoverage2DReader) mapLayerInfo.getCoverageReader();
GetMapRequest req = new GetMapRequest();
req.setRawKvp(new HashMap<String, String>());
req.getRawKvp().put("DIM_" + CustomFormat.CUSTOM_DIMENSION_NAME, "10/50");

GeneralParameterValue[] readParam = wms.getWMSReadParameters(req, mapLayerInfo, Filter.INCLUDE, null, null, reader, false);
@SuppressWarnings("unchecked")
ParameterValue<List<NumberRange>> val = (ParameterValue<List<NumberRange>>) readParam[readParam.length - 1];
assertEquals(new NumberRange<Double>(Double.class, 10d, 50d), val.getValue().get(0));
}

@Test
public void testCustomDepthListDimension() throws Exception {
MapLayerInfo mapLayerInfo = new MapLayerInfo(getCatalog().getLayerByName(WATTEMP_DEPTH.getLocalPart()));
final GridCoverage2DReader reader = (GridCoverage2DReader) mapLayerInfo.getCoverageReader();
GetMapRequest req = new GetMapRequest();
req.setRawKvp(new HashMap<String, String>());
req.getRawKvp().put("DIM_" + CustomFormat.CUSTOM_DIMENSION_NAME, "10,50");

GeneralParameterValue[] readParam = wms.getWMSReadParameters(req, mapLayerInfo, Filter.INCLUDE, null, null, reader, false);
@SuppressWarnings("unchecked")
ParameterValue<List<Double>> val = (ParameterValue<List<Double>>) readParam[readParam.length - 1];
assertEquals(10, (Double)val.getValue().get(0), 1E-6);
assertEquals(50, (Double)val.getValue().get(1), 1E-6);
}

} }
Binary file not shown.

0 comments on commit 2889316

Please sign in to comment.