public List<String> getCustomDimension(String dimensionName) { if (getRawKvp() != null) { String key = "DIM_" + dimensionName; String value = getRawKvp().get(key); if (value != null) { final ArrayList<String> values = new ArrayList<String>(1); if (value.indexOf(",") > 0) { String[] elements = value.split("\\s*,\\s*"); values.addAll(Arrays.asList(elements)); } else { values.add(value); } return values; } } return null; } }
private boolean filterApplies(Map<String, ParameterFilter> filters, GetMapRequest request, String key, StringBuilder requestMistmatchTarget) { ParameterFilter parameterFilter = filters.get(key); if (parameterFilter == null) { requestMistmatchTarget.append("no parameter filter exists for ").append(key); return false; } String parameter = request.getRawKvp().get(key); boolean applies = parameterFilter.applies(parameter); if (!applies) { requestMistmatchTarget.append(key).append( " does not apply to parameter filter of the same name"); } return applies; }
private boolean filterApplies( Map<String, ParameterFilter> filters, GetMapRequest request, String key, StringBuilder requestMistmatchTarget) { ParameterFilter parameterFilter = filters.get(key); if (parameterFilter == null) { requestMistmatchTarget.append("no parameter filter exists for ").append(key); return false; } String parameter = request.getRawKvp().get(key); boolean applies = parameterFilter.applies(parameter); if (!applies) { requestMistmatchTarget .append(key) .append(" does not apply to parameter filter of the same name"); } return applies; }
/** * Wraps {@link WebMapService#getMap(GetMapRequest)}, called by the {@link Dispatcher} * * @see WebMapService#getMap(GetMapRequest) * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation) */ public WebMap invoke(MethodInvocation invocation) throws Throwable { final Method method = invocation.getMethod(); checkArgument(method.getDeclaringClass().equals(WebMapService.class)); checkArgument("getMap".equals(method.getName())); final Object[] arguments = invocation.getArguments(); checkArgument(arguments.length == 1); checkArgument(arguments[0] instanceof GetMapRequest); final GetMapRequest request = (GetMapRequest) arguments[0]; WebMap map = (WebMap) invocation.proceed(); final Map<String, String> rawKvp = request.getRawKvp(); boolean isSeedingRequest = rawKvp != null && rawKvp.containsKey(GeoServerTileLayer.GWC_SEED_INTERCEPT_TOKEN); if (isSeedingRequest) { GeoServerTileLayer.WEB_MAP.set(map); // returning null makes the Dispatcher ignore further processing the request return null; } return map; }
final Map<String, String> rawKvp = request.getRawKvp(); boolean isSeedingRequest = rawKvp != null && rawKvp.containsKey(GeoServerTileLayer.GWC_SEED_INTERCEPT_TOKEN);
/** * Returns the the kmattr value (either specified in the request, or the default one) * * @param mapContent * @return */ boolean computeKMAttr() { Object kmattr = request.getFormatOptions().get("kmattr"); if (kmattr == null) { kmattr = request.getRawKvp().get("kmattr"); } if (kmattr != null) { return Converters.convert(kmattr, Boolean.class); } else { return wms.getKmlKmAttr(); } }
@Test public void testGetGetMapUrlAllWithDimensions() { GetMapRequest request = initGetMapRequest(MockData.TASMANIA_DEM); request.getRawKvp().put("time", "2017-04-07T19:56:00.000Z"); request.getRawKvp().put("elevation", "1013.2"); request.getRawKvp().put("dim_my_dimension", "010"); String url = getGetMapUrl(request); assertThat(url, containsString("&time=2017-04-07T19:56:00.000Z&")); assertThat(url, containsString("&elevation=1013.2&")); assertThat(url, containsString("&dim_my_dimension=010&")); }
@Test public void testGetGetMapUrlWithDimensions() { GetMapRequest request = initGetMapRequest(MockData.TASMANIA_DEM); request.getRawKvp().put("time", "2017-04-07T19:56:00.000Z"); request.getRawKvp().put("elevation", "1013.2"); request.getRawKvp().put("dim_my_dimension", "010"); List<String> urls = getGetMapUrls(request); assertEquals(1, urls.size()); assertThat(urls.get(0), containsString("&time=2017-04-07T19:56:00.000Z&")); assertThat(urls.get(0), containsString("&elevation=1013.2&")); assertThat(urls.get(0), containsString("&dim_my_dimension=010&")); }
/** * Frame Catalog Constructor. * * @param request * @param wmsConfiguration */ public FrameCatalog(GetMapRequest request, WebMapService wms, WMS wmsConfiguration) { this(); this.getMapRequest = request; this.wms = wms; this.wmsConfiguration = wmsConfiguration; Map<String, String> rawKvp = request.getRawKvp(); String aparam = KvpUtils.caseInsensitiveParam(rawKvp, "aparam", null); String avalues = KvpUtils.caseInsensitiveParam(rawKvp, "avalues", null); if (aparam != null && !aparam.isEmpty() && avalues != null && !avalues.isEmpty()) { this.parameter = aparam; this.values = avalues.split("(?<!\\\\)(,)"); } else { dispose(); throw new RuntimeException( "Missing \"animator\" mandatory params \"aparam\" and \"avalues\"."); } if (this.values.length > this.getWmsConfiguration().getMaxAllowedFrames()) { dispose(); throw new RuntimeException( "Request too long; reached the maximum allowed number of frames."); } }
@SuppressWarnings("unchecked") private GetMapRequest initGetMapRequest(QName... names) { GetMapRequest request = createGetMapRequest(names); request.setRawKvp(new KvpMap(request.getRawKvp())); String layers = request.getLayers() .stream() .map(MapLayerInfo::getName) .collect(Collectors.joining(",")); request.getRawKvp().put("layers", layers); request.setFormat(DefaultWebMapService.FORMAT); DefaultWebMapService.autoSetBoundsAndSize(request); return request; }
@Test public void testGetGetMapUrlWithMultipleLayers() { GetMapRequest request = initGetMapRequest(MockData.LAKES, MockData.TASMANIA_DEM); request.getRawKvp().put("cql_filter", "fid='123';INCLUDE"); request.getRawKvp().put("bgcolor", "0x808080"); request.setStyleFormat("ysld"); request.setSldBody("foo"); List<String> urls = getGetMapUrls(request); assertEquals(2, urls.size()); assertThat(urls.get(0), containsString("&cql_filter=fid='123'&")); assertThat(urls.get(0), containsString("&bgcolor=0x808080&")); assertThat(urls.get(0), containsString("&style_format=ysld&")); assertThat(urls.get(0), containsString("&sld_body=foo")); assertThat(urls.get(1), containsString("&cql_filter=INCLUDE&")); assertThat(urls.get(1), containsString("&bgcolor=0x808080&")); assertThat(urls.get(1), containsString("&style_format=ysld&")); assertThat(urls.get(1), containsString("&sld_body=foo")); }
/** Testing FrameVisitor animation frames setup and production. */ @org.junit.Test public void testFrameVisitor() throws Exception { final WebMapService wms = (WebMapService) applicationContext.getBean("wmsService2"); final String layerName = MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart(); GetMapRequest getMapRequest = createGetMapRequest(new QName(layerName)); FrameCatalog catalog = null; getMapRequest.getRawKvp().put("aparam", "fake_param"); getMapRequest.getRawKvp().put("avalues", "val0,val\\,1,val2\\,\\,,val3"); getMapRequest.getRawKvp().put("format", GIF_ANIMATED_FORMAT); getMapRequest.getRawKvp().put("LAYERS", layerName); catalog = new FrameCatalog(getMapRequest, wms, getWMS()); assertNotNull(catalog); FrameCatalogVisitor visitor = new FrameCatalogVisitor(); catalog.getFrames(visitor); assertEquals(4, visitor.framesNumber); List<RenderedImageMap> frames = visitor.produce(getWMS()); assertNotNull(frames); assertEquals(4, frames.size()); }
initGetMapRequest( MockData.LAKES, MockData.LAKES, MockData.FORESTS, MockData.TASMANIA_DEM); request.getRawKvp() .put( "layers", + ',' + request.getLayers().get(3).getName()); request.getRawKvp().put("cql_filter", "fid='123';name LIKE 'BLUE%';INCLUDE"); request.getRawKvp().put("interpolations", ",,nearest neighbor"); request.getRawKvp().put("sortby", "(fid)(name D)()"); List<String> urls = getGetMapUrls(request); assertEquals(4, urls.size());
@Test public void testGetGetMapUrlWithSingleLayerGroup() throws Exception { GetMapRequest request = initGetMapRequest(MockData.LAKES, MockData.FORESTS); request.getRawKvp().put("layers", NATURE_GROUP); request.getRawKvp().put("cql_filter", "name LIKE 'BLUE%'"); request.getRawKvp().put("sortby", "name A"); request.setStartIndex(25); request.setMaxFeatures(50); request.setStyleVersion("1.1.0"); request.setSld(new URL("http://localhost/test.sld")); request.setValidateSchema(true); List<String> urls = getGetMapUrls(request); assertEquals(2, urls.size()); assertThat(urls.get(0), containsString("&cql_filter=name LIKE 'BLUE%'&")); assertThat(urls.get(0), containsString("&sortby=name A&")); assertThat(urls.get(0), containsString("&startindex=25&")); assertThat(urls.get(0), containsString("&maxfeatures=50&")); assertThat(urls.get(0), containsString("&style_version=1.1.0&")); assertThat(urls.get(0), containsString("&validateschema=true&")); assertThat(urls.get(0), containsString("&sld=http://localhost/test.sld")); assertThat(urls.get(1), containsString("&cql_filter=name LIKE 'BLUE%'&")); assertThat(urls.get(1), containsString("&sortby=name A&")); assertThat(urls.get(1), containsString("&startindex=25&")); assertThat(urls.get(1), containsString("&maxfeatures=50&")); assertThat(urls.get(1), containsString("&style_version=1.1.0&")); assertThat(urls.get(1), containsString("&validateschema=true&")); assertThat(urls.get(1), containsString("&sld=http://localhost/test.sld")); }
@Test public void testGetGetMapUrlWithSingleLayer() throws Exception { GetMapRequest request = initGetMapRequest(MockData.LAKES); request.getRawKvp().put("cql_filter", "fid='123'"); request.setExceptions("INIMAGE"); request.setRemoteOwsType("WFS"); request.setRemoteOwsURL(new URL("https://foo.com/geoserver/wfs")); request.setScaleMethod(ScaleComputationMethod.Accurate); List<String> urls = getGetMapUrls(request); assertEquals(1, urls.size()); assertThat(urls.get(0), containsString("&cql_filter=fid='123'&")); assertThat(urls.get(0), containsString("&remote_ows_type=WFS&")); assertThat(urls.get(0), containsString("&remote_ows_url=https://foo.com/geoserver/wfs&")); assertThat(urls.get(0), containsString("&scalemethod=Accurate")); }
@Override public Feature decorate(Feature feature, KmlEncodingContext context) { Document doc = (Document) feature; // create the screen overlay ScreenOverlay go = doc.createAndAddScreenOverlay(); go.setName("Legend"); go.setOverlayXY(createPixelsVec(0, 0)); go.setScreenXY(createPixelsVec(10, 20)); // build the href Icon icon = go.createAndSetIcon(); String legendOptions = (String) context.getRequest().getRawKvp().get("LEGEND_OPTIONS"); String[] kvpArray = null; if (legendOptions != null) { kvpArray = new String[] { "LEGEND_OPTIONS", legendOptions }; } List<Layer> layerList = context.getMapContent().layers(); Layer[] layers = (Layer[]) layerList.toArray(new Layer[layerList.size()]); icon.setHref(WMSRequests.getGetLegendGraphicUrl(context.getRequest(), layers, kvpArray)); return feature; }
@Test public void testTimeDimension() throws Exception { MapLayerInfo mapLayerInfo = new MapLayerInfo(getCatalog().getLayerByName(WATTEMP_TIME.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, "2001-05-01T00:00:00.000Z, 2001-05-02T00:00:00.000Z"); GeneralParameterValue[] readParam = wms.getWMSReadParameters( req, mapLayerInfo, Filter.INCLUDE, null, null, reader, false); @SuppressWarnings("unchecked") ParameterValue<List<Date>> val = (ParameterValue<List<Date>>) readParam[readParam.length - 1]; assertEquals(2, val.getValue().size()); assertEquals(DF.parse("2001-05-01 00:00:00"), val.getValue().get(0)); 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); } }
/** Testing FrameCatalog constructor from a generic WMS request. */ @org.junit.Test public void testFrameCatalog() throws Exception { final WebMapService wms = (WebMapService) applicationContext.getBean("wmsService2"); final String layerName = MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart(); GetMapRequest getMapRequest = createGetMapRequest(new QName(layerName)); FrameCatalog catalog = null; try { catalog = new FrameCatalog(getMapRequest, wms, getWMS()); } catch (RuntimeException e) { assertEquals( "Missing \"animator\" mandatory params \"aparam\" and \"avalues\".", e.getLocalizedMessage()); } getMapRequest.getRawKvp().put("aparam", "fake_param"); getMapRequest.getRawKvp().put("avalues", "val0,val\\,1,val2\\,\\,,val3"); catalog = new FrameCatalog(getMapRequest, wms, getWMS()); assertNotNull(catalog); assertEquals("fake_param", catalog.getParameter()); assertEquals(4, catalog.getValues().length); assertEquals("val0", catalog.getValues()[0]); assertEquals("val\\,1", catalog.getValues()[1]); assertEquals("val2\\,\\,", catalog.getValues()[2]); assertEquals("val3", catalog.getValues()[3]); }