class GetRasterTilesCommand implements CommandHasRequest<GetRasterTilesRequest, GetRasterTilesResponse> {

	@Override
	public void execute(GetRasterTilesRequest request, GetRasterTilesResponse response) throws Exception {
		log.debug("request start layer {}, crs {}", request.getLayerId(), request.getCrs());
		String layerId = request.getLayerId();
		if (null == layerId) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "layer");
		}
		if (null == request.getCrs()) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "crs");
		}
		if (!securityContext.isLayerVisible(layerId)) {
			throw new GeomajasSecurityException(ExceptionCode.LAYER_NOT_VISIBLE, layerId, securityContext.getUserId());
		}

		log.debug("execute() : bbox {}", request.getBbox());
		List<RasterTile> images = layerService.getTiles(layerId, geoService.getCrs2(request.getCrs()),
				converterService.toInternal(request.getBbox()),	request.getScale());
		log.debug("execute() : returning {} images", images.size());

		response.setRasterData(images);
		if (images.size() > 0) {
			response.setNodeId(layerId + "." + images.get(0).getCode().getTileLevel());
		}
	}

}