test_class.declarator: LAYER_ID = "countries"
test_class.modifier: private static final
test_class.original_string: private static final String LAYER_ID = "countries";
test_class.type: String
test_class.var_name: LAYER_ID
test_class.declarator: dispatcher
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private CommandDispatcher dispatcher;
test_class.type: CommandDispatcher
test_class.var_name: dispatcher
test_class.declarator: converter
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private DtoConverterService converter;
test_class.type: DtoConverterService
test_class.var_name: converter
test_class.file: command/src/test/java/org/geomajas/command/feature/SearchByLocationCommandTest.java
test_class.identifier: SearchByLocationCommandTest
test_case.body: @Test
  	public void intersectCountriesOnEquator() throws Exception {
  		// prepare command
  		SearchByLocationRequest request = new SearchByLocationRequest();
  		request.setCrs("EPSG:4326");
  		request.setQueryType(SearchByLocationRequest.QUERY_INTERSECTS);
  		request.setSearchType(SearchByLocationRequest.SEARCH_ALL_LAYERS);
  		request.setLayerIds(new String[] {LAYER_ID});
  
  		GeometryFactory factory = new GeometryFactory();
  		LineString equator = factory.createLineString(new Coordinate[] {new Coordinate(0, 0),
  				new Coordinate(-180, 180)});
  		request.setLocation(converter.toDto(equator));
  
  		// execute
  		SearchByLocationResponse response = (SearchByLocationResponse) dispatcher.execute(
  				SearchByLocationRequest.COMMAND, request, null, "en");
  
  		// test
  		Assert.assertFalse(response.isError());
  		List<Feature> features = response.getFeatureMap().get(LAYER_ID);
  		Assert.assertNotNull(features);
  		Assert.assertEquals(4, features.size());
  		List<String> actual = new ArrayList<String>();
  		for (Feature feature : features) {
  			actual.add(feature.getLabel());
  		}
  		Assert.assertTrue(actual.contains("Country 4"));
  		Assert.assertTrue(actual.contains("Country 3"));
  		Assert.assertTrue(actual.contains("Country 2"));
  		Assert.assertTrue(actual.contains("Country 1"));
  	}
test_case.class_method_signature: SearchByLocationCommandTest.intersectCountriesOnEquator()
test_case.full_signature: @Test public void intersectCountriesOnEquator()
test_case.identifier: intersectCountriesOnEquator
test_case.invocations: setCrs setQueryType setSearchType setLayerIds createLineString setLocation toDto execute assertFalse isError get getFeatureMap assertNotNull assertEquals size add getLabel assertTrue contains assertTrue contains assertTrue contains assertTrue contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void intersectCountriesOnEquator()
focal_class.declarator: log = LoggerFactory.getLogger(SearchByLocationCommand.class)
focal_class.modifier: private final
focal_class.original_string: private final Logger log = LoggerFactory.getLogger(SearchByLocationCommand.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: configurationService
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private ConfigurationService configurationService;
focal_class.type: ConfigurationService
focal_class.var_name: configurationService
focal_class.declarator: geoService
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private GeoService geoService;
focal_class.type: GeoService
focal_class.var_name: geoService
focal_class.declarator: converter
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private DtoConverterService converter;
focal_class.type: DtoConverterService
focal_class.var_name: converter
focal_class.declarator: filterCreator
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private FilterService filterCreator;
focal_class.type: FilterService
focal_class.var_name: filterCreator
focal_class.declarator: layerService
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private VectorLayerService layerService;
focal_class.type: VectorLayerService
focal_class.var_name: layerService
focal_class.declarator: securityContext
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private SecurityContext securityContext;
focal_class.type: SecurityContext
focal_class.var_name: securityContext
focal_class.file: command/src/main/java/org/geomajas/command/feature/SearchByLocationCommand.java
focal_class.identifier: SearchByLocationCommand
focal_class.interfaces: implements CommandHasRequest<SearchByLocationRequest, SearchByLocationResponse>
focal_class.class_method_signature: SearchByLocationCommand.getEmptyCommandRequest()
focal_class.full_signature: @Override public SearchByLocationRequest getEmptyCommandRequest()
focal_class.identifier: getEmptyCommandRequest
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: SearchByLocationRequest
focal_class.signature: SearchByLocationRequest getEmptyCommandRequest()
focal_class.class_method_signature: SearchByLocationCommand.getEmptyCommandResponse()
focal_class.full_signature: @Override public SearchByLocationResponse getEmptyCommandResponse()
focal_class.identifier: getEmptyCommandResponse
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: SearchByLocationResponse
focal_class.signature: SearchByLocationResponse getEmptyCommandResponse()
focal_class.class_method_signature: SearchByLocationCommand.execute(SearchByLocationRequest request, SearchByLocationResponse response)
focal_class.full_signature: @Override public void execute(SearchByLocationRequest request, SearchByLocationResponse response)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (SearchByLocationRequest request, SearchByLocationResponse response)
focal_class.return: void
focal_class.signature: void execute(SearchByLocationRequest request, SearchByLocationResponse response)
focal_method.body: @Override
  	public void execute(SearchByLocationRequest request, SearchByLocationResponse response) throws Exception {
  		if (null == request.getLayerIds()) {
  			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "layerIds");
  		}
  		String crsCode = request.getCrs();
  		if (null == crsCode) {
  			throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "crs");
  		}
  		Geometry location = converter.toInternal(request.getLocation());
  		int queryType = request.getQueryType();
  		double ratio = request.getRatio();
  		int searchType = request.getSearchType();
  		Crs crs = geoService.getCrs2(request.getCrs());
  
  		// Check if a buffer should be added around the location:
  		Geometry geometry = location;
  		if (request.getBuffer() > 0) {
  			geometry = location.buffer(request.getBuffer());
  		}
  		log.debug("search by location " + geometry);
  
  		for (String clientLayerId : request.getLayerIds()) {
  			String serverLayerId = request.getServerLayerId(clientLayerId);
  			if (null == serverLayerId) {
  				throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, 
  								"serverLayerId for clientLayerId " + clientLayerId);
  			}
  			if (securityContext.isLayerVisible(serverLayerId)) {
  				VectorLayer vectorLayer = configurationService.getVectorLayer(serverLayerId);
  				if (vectorLayer != null) {
  					String geomName = vectorLayer.getLayerInfo().getFeatureInfo().getGeometryType().getName();
  
  					// Transform geometry to layer CRS:
  					Geometry layerGeometry = geoService.transform(geometry, crs, layerService.getCrs(vectorLayer));
  					log.trace("on layer " + serverLayerId + " use " + layerGeometry);
  
  					// Create the correct Filter object:
  					Filter f = null;
  					switch (queryType) {
  						case SearchByLocationRequest.QUERY_INTERSECTS:
  							f = filterCreator.createIntersectsFilter(layerGeometry, geomName);
  							break;
  						case SearchByLocationRequest.QUERY_CONTAINS:
  							f = filterCreator.createContainsFilter(layerGeometry, geomName);
  							break;
  						case SearchByLocationRequest.QUERY_TOUCHES:
  							f = filterCreator.createTouchesFilter(layerGeometry, geomName);
  							break;
  						case SearchByLocationRequest.QUERY_WITHIN:
  							f = filterCreator.createWithinFilter(layerGeometry, geomName);
  							break;
  						default:
  							throw new IllegalArgumentException("Unknown query type " + queryType);
  					}
  					//Set the per layer filter
  					if (null != request.getFilter(clientLayerId)) {
  						if (null == f) {
  							f = filterCreator.parseFilter(request.getFilter(clientLayerId));
  						} else {
  							f = filterCreator.createAndFilter(
  									filterCreator.parseFilter(request.getFilter(clientLayerId)), f);
  						}
  					}
  					//Set the global filter
  					if (null != request.getFilter()) {
  						if (null == f) {
  							f = filterCreator.parseFilter(request.getFilter());
  						} else {
  							f = filterCreator.createAndFilter(filterCreator.parseFilter(request.getFilter()), f);
  						}
  					}
  
  					// Get the features:
  					List<InternalFeature> temp = layerService.getFeatures(serverLayerId, crs, f, null, request
  							.getFeatureIncludes());
  					if (temp.size() > 0) {
  						List<Feature> features = new ArrayList<Feature>();
  
  						// Calculate overlap ratio in case of intersects:
  						if (queryType == SearchByLocationRequest.QUERY_INTERSECTS && ratio >= 0 && ratio < 1) {
  							for (InternalFeature feature : temp) {
  								double minimalOverlap = feature.getGeometry().getArea() * ratio;
  								Geometry overlap = geometry.intersection(feature.getGeometry());
  								double effectiveOverlap = overlap.getArea();
  								if (minimalOverlap <= effectiveOverlap) {
  									log.trace("found " + feature);
  									Feature dto = converter.toDto(feature);
  									dto.setCrs(crsCode);
  									features.add(dto);
  								}
  							}
  						} else {
  							for (InternalFeature feature : temp) {
  								log.trace("found " + feature);
  								Feature dto = converter.toDto(feature);
  								dto.setCrs(crsCode);
  								features.add(dto);
  							}
  						}
  
  						// features.size can again be 0... so check:
  						if (features.size() > 0) {
  							// We have a response for this layer!
  							response.addLayer(clientLayerId, features);
  
  							// If searchType == SEARCH_FIRST_LAYER, we should search no further:
  							if (searchType == SearchByLocationRequest.SEARCH_FIRST_LAYER) {
  								break;
  							}
  						}
  					}
  				}
  			}
  		}
  	}
focal_method.class_method_signature: SearchByLocationCommand.execute(SearchByLocationRequest request, SearchByLocationResponse response)
focal_method.full_signature: @Override public void execute(SearchByLocationRequest request, SearchByLocationResponse response)
focal_method.identifier: execute
focal_method.invocations: getLayerIds getCrs toInternal getLocation getQueryType getRatio getSearchType getCrs2 getCrs getBuffer buffer getBuffer debug getLayerIds getServerLayerId isLayerVisible getVectorLayer getName getGeometryType getFeatureInfo getLayerInfo transform getCrs trace createIntersectsFilter createContainsFilter createTouchesFilter createWithinFilter getFilter parseFilter getFilter createAndFilter parseFilter getFilter getFilter parseFilter getFilter createAndFilter parseFilter getFilter getFeatures getFeatureIncludes size getArea getGeometry intersection getGeometry getArea trace toDto setCrs add trace toDto setCrs add size addLayer
focal_method.modifiers: @Override public
focal_method.parameters: (SearchByLocationRequest request, SearchByLocationResponse response)
focal_method.return: void
focal_method.signature: void execute(SearchByLocationRequest request, SearchByLocationResponse response)