Skip to content

Commit db4d39b

Browse files
author
Sandra Thieme
committed
Extend address query api with static addresses even if no hashkey is given
1 parent 4e91bbc commit db4d39b

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/main/java/net/contargo/iris/address/service/AddressServiceWrapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.slf4j.LoggerFactory;
1515

1616
import java.util.ArrayList;
17+
import java.util.Collection;
1718
import java.util.Collections;
1819
import java.util.List;
1920
import java.util.Map;
@@ -25,6 +26,7 @@
2526
import static net.contargo.iris.address.nominatim.service.AddressDetailKey.STREET;
2627

2728
import static java.util.Collections.singletonList;
29+
import static java.util.stream.Collectors.toList;
2830

2931

3032
/**
@@ -203,6 +205,16 @@ public List<Address> getAddressesByQuery(String query) {
203205

204206
if (addresses.isEmpty()) {
205207
addresses.addAll(addressService.getAddressesByQuery(query));
208+
209+
List<Address> matchingStaticAddresses = addresses.stream()
210+
.map(a ->
211+
staticAddressService.findAddresses(a.getPostcode(), a.getCity(), a.getCountryCode())
212+
.getAddresses())
213+
.flatMap(Collection::stream)
214+
.distinct()
215+
.collect(toList());
216+
217+
addresses.addAll(matchingStaticAddresses);
206218
}
207219

208220
return addresses;

src/test/java/net/contargo/iris/address/service/AddressServiceWrapperUnitTest.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,31 @@ public void getAddressesByQuery() {
420420

421421
Address address = new Address();
422422
address.setDisplayName("Gartenstr. 67, Karlsruhe (Südweststadt)");
423+
address.getAddress().put("city", "Karlsruhe");
424+
address.getAddress().put("postcode", "76135");
425+
address.getAddress().put("country_code", "de");
426+
address.getAddress().put("street", "Gartenstr.");
423427

424428
when(addressServiceMock.getAddressesByQuery("Gartenstraße 67, Karlsruhe")).thenReturn(singletonList(address));
425429

426-
List<Address> addresses = sut.getAddressesByQuery("Gartenstraße 67, Karlsruhe");
430+
StaticAddress staticAddress1 = new StaticAddress();
431+
staticAddress1.setCity("Karlsruhe");
432+
staticAddress1.setPostalcode("76135");
427433

428-
assertThat(addresses, hasSize(1));
429-
assertThat(addresses.get(0), is(address));
434+
StaticAddress staticAddress2 = new StaticAddress();
435+
staticAddress2.setCity("Karlsruhe");
436+
staticAddress2.setPostalcode("76135");
437+
staticAddress2.setSuburb("Südweststadt");
430438

431-
verifyZeroInteractions(staticAddressServiceMock);
439+
when(staticAddressServiceMock.findAddresses("76135", "Karlsruhe", "de")).thenReturn(new AddressList("",
440+
asList(staticAddress1.toAddress(), staticAddress2.toAddress())));
441+
442+
List<Address> addresses = sut.getAddressesByQuery("Gartenstraße 67, Karlsruhe");
443+
444+
assertThat(addresses, hasSize(3));
445+
assertThat(addresses.get(0).getDisplayName(), is("Gartenstr. 67, Karlsruhe (Südweststadt)"));
446+
assertThat(addresses.get(1).getDisplayName(), is("76135 Karlsruhe"));
447+
assertThat(addresses.get(2).getDisplayName(), is("76135 Karlsruhe (Südweststadt)"));
432448
}
433449

434450

0 commit comments

Comments
 (0)