class SearchFeatureCommand implements CommandHasRequest<SearchFeatureRequest, SearchFeatureResponse> {

	Filter createFilter(SearchFeatureRequest request, String layerId) throws GeomajasException {
		Filter f = null;
		VectorLayer layer = configurationService.getVectorLayer(layerId);
		if (layer == null) {
			throw new  GeomajasException(ExceptionCode.LAYER_NOT_FOUND, layerId);
		}
		String idName = layer.getLayerInfo().getFeatureInfo().getIdentifier().getName();
		if (null != request.getCriteria()) {
			for (SearchCriterion criterion : request.getCriteria()) {
				Filter temp;
				String attributeName = criterion.getAttributeName();
				String operator = criterion.getOperator();
				if ((SearchFeatureRequest.ID_ATTRIBUTE.equals(attributeName) || attributeName.equals(idName)) &&
						(null == operator || "=".equals(operator))) {
					temp = filterService.createFidFilter(new String[]{criterion.getValue()});
				} else {
					String c = criterion.toString().replace('*', '%').replace('?', '_');
					temp = filterService.parseFilter(c);
				}
				if (f == null) {
					f = temp;
				} else {
					f = filterService.createLogicFilter(f, request.getBooleanOperator(), temp);
				}
			}
		}

		// AND the layer filter
		String filter = request.getFilter();
		if (filter != null) {
			if (f == null) {
				f = filterService.parseFilter(filter);
			} else {
				f = filterService.createAndFilter(filterService.parseFilter(filter), f);
			}
		}

		// If f is still null:
		if (f == null) {
			f = filterService.createTrueFilter();
		}

		return f;
	}

}