UserMaximumExtentCommand implements CommandHasRequest<UserMaximumExtentRequest, UserMaximumExtentResponse> { @Override public void execute(UserMaximumExtentRequest request, UserMaximumExtentResponse response) throws Exception { String[] layers; ArrayList<String> tempLayers = new ArrayList<String>(); String[] includeLayers = request.getLayerIds(); boolean excludeRasterLayers = request.isExcludeRasterLayers(); if (includeLayers != null && includeLayers.length > 0) { for (String layerId : includeLayers) { if (!securityContext.isLayerVisible(layerId)) { throw new GeomajasSecurityException(ExceptionCode.LAYER_NOT_VISIBLE, layerId); } Layer<?> l = configurationService.getLayer(layerId); if (null == l) { throw new GeomajasException(ExceptionCode.LAYER_NOT_FOUND, layerId); } if (!excludeRasterLayers || l.getLayerInfo().getLayerType() != LayerType.RASTER) { tempLayers.add(l.getId()); } } } layers = tempLayers.toArray(new String[tempLayers.size()]); Layer<?> layer; Crs targetCrs = geoService.getCrs2(request.getCrs()); if (layers.length == 0) { response.setBounds(new Bbox()); } else { Envelope extent = new Envelope(); for (String layerId : layers) { layer = configurationService.getLayer(layerId); if (layer != null) { Envelope bounds; if (layer.getLayerInfo().getLayerType() == LayerType.RASTER) { bounds = securityContext.getVisibleArea(layerId).getEnvelopeInternal(); CrsTransform transform = geoService.getCrsTransform(layer.getCrs(), targetCrs); bounds = geoService.transform(bounds, transform); } else { bounds = layerService.getBounds(layerId, targetCrs, null); } extent.expandToInclude(bounds); } else { log.warn("layer not found ?! " + layerId); } } response.setBounds(converterService.toDto(extent)); } }  @Override UserMaximumExtentRequest getEmptyCommandRequest(); @Override UserMaximumExtentResponse getEmptyCommandResponse(); @Override void execute(UserMaximumExtentRequest request, UserMaximumExtentResponse response);  }
@Test public void testUserMaximumExtent() throws Exception { UserMaximumExtentRequest request = new UserMaximumExtentRequest(); request.setCrs(CRS); request.setLayerIds(new String[] { LAYER_ID }); UserMaximumExtentResponse response = (UserMaximumExtentResponse) dispatcher.execute( UserMaximumExtentRequest.COMMAND, request, null, "en"); if (response.isError()) { response.getErrors().get(0).printStackTrace(); } Assert.assertFalse(response.isError()); Bbox bounds = response.getBounds(); Assert.assertNotNull(bounds); Assert.assertEquals(-1.0, bounds.getX(), DOUBLE_TOLERANCE); Assert.assertEquals(-1.0, bounds.getY(), DOUBLE_TOLERANCE); Assert.assertEquals(1.0, bounds.getMaxX(), DOUBLE_TOLERANCE); Assert.assertEquals(1.0, bounds.getMaxY(), DOUBLE_TOLERANCE); }