class SearchFeatureCommand implements CommandHasRequest<SearchFeatureRequest, SearchFeatureResponse> {

	@Override
	public void execute(SearchFeatureRequest request, SearchFeatureResponse response) throws Exception {
		String layerId = request.getLayerId();
		if (null == layerId) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "layer");
		}
		String crs = request.getCrs();
		if (null == crs) {
			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "crs");
		}

		Filter filter = createFilter(request, layerId);
		log.debug("filter to apply : {}", filter);

		List<InternalFeature> features = layerService.getFeatures(layerId, geoService.getCrs(request.getCrs()), filter,
				null, request.getFeatureIncludes(), request.getOffSet(), request.getMax());
		response.setLayerId(layerId);
		int max = request.getMax();
		if (max == SearchFeatureRequest.MAX_UNLIMITED) {
			max = features.size();
		}
		if (max > features.size()) {
			max = features.size();
		}
		Feature[] maxList = new Feature[max];
		for (int i = 0; i < max; i++) {
			Feature feature = converter.toDto(features.get(i));
			feature.setCrs(crs);
			maxList[i] = feature;
		}
		response.setFeatures(maxList);
	}

}