Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.backend into SI-381_get_adresses
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/AddressController.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/AddressController.java
index 5be2f77..b804b79 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/AddressController.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/controller/AddressController.java
@@ -19,11 +19,15 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.AddressService;
+import org.eclipse.openk.gridfailureinformation.viewmodel.AddressDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.HousenumberUuidDto;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
@Log4j2
@RestController
@@ -33,6 +37,16 @@
@Autowired
private AddressService addressService;
+ @GetMapping("/{uuid}")
+ @ApiOperation(value = "Anzeigen einer bestimmten Adresse")
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
+ @ApiResponse(code = 404, message = "Adresse wurde nicht gefunden")})
+ @ResponseStatus(HttpStatus.OK)
+ public AddressDto readAddress(
+ @PathVariable UUID uuid) {
+ return addressService.getAdressByUuid(uuid);
+ }
+
//@Secured({"ROLE_GRID-FAILURE-ADMIN", "ROLE_GRID-FAILURE-CREATOR", "ROLE_GRID-FAILURE-QUALIFIER", "ROLE_GRID-FAILURE-PUBLISHER"})
@ApiOperation(value = "Anzeige aller PLZs")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@@ -77,7 +91,7 @@
@ApiOperation(value = "Anzeige Strassen nach Postleitzahl und Ort und Strasse")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping("/housenumbers")
- public List<String> findHousenumbers(
+ public List<HousenumberUuidDto> findHousenumbers(
@RequestParam ("postcode") String postcode,
@RequestParam ("community") String community,
@RequestParam ("street") String street
@@ -86,8 +100,4 @@
}
-
-
-
-
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/AddressRepository.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/AddressRepository.java
index 6377faf..720d093 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/AddressRepository.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/repository/AddressRepository.java
@@ -47,7 +47,6 @@
@Query("select distinct a.street from TblAddress a where postcode = :postcode and community = :community and district = :district")
List<String> findStreetsByPostcodeAndCommunityAndDistrict(@Param("postcode") String postcode, @Param("community") String community, @Param("district") String district);
- @Query("select distinct a.housenumber from TblAddress a where postcode = :postcode and community = :community and street = :street")
- List<String> findHousenumbersByPostcodeAndCommunityAndStreet(@Param("postcode") String postcode, @Param("community") String community, @Param("street") String street);
+ List<TblAddress> findByPostcodeAndCommunityAndStreet(String postcode, String community, String street);
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/AddressService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/AddressService.java
index 86073a4..30bd331 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/AddressService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/AddressService.java
@@ -14,16 +14,21 @@
*/
package org.eclipse.openk.gridfailureinformation.service;
+import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.mapper.AddressMapper;
+import org.eclipse.openk.gridfailureinformation.model.TblAddress;
import org.eclipse.openk.gridfailureinformation.repository.AddressRepository;
import org.eclipse.openk.gridfailureinformation.viewmodel.AddressDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.HousenumberUuidDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import java.util.stream.Collectors;
+import static java.util.stream.Collectors.collectingAndThen;
+import static java.util.stream.Collectors.toCollection;
+
@Service
public class AddressService {
@@ -33,6 +38,13 @@
@Autowired
private AddressMapper addressMapper;
+ private static HousenumberUuidDto toHousenumberUuid(TblAddress tblAddress) {
+ HousenumberUuidDto housenumberUuidDto = new HousenumberUuidDto();
+ housenumberUuidDto.setHousenumber(tblAddress.getHousenumber());
+ housenumberUuidDto.setUuid(tblAddress.getUuid());
+ return housenumberUuidDto;
+ }
+
public List<AddressDto> getAddresses() {
return addressRepository.findAll().stream()
@@ -40,6 +52,12 @@
.collect(Collectors.toList());
}
+ public AddressDto getAdressByUuid(UUID uuid) {
+ TblAddress tblAddress = addressRepository.findByUuid(uuid)
+ .orElseThrow(NotFoundException::new);
+ return addressMapper.toAddressDto(tblAddress);
+ }
+
public List<String> getPostcodes(){
return addressRepository.findAllPostcodes();
}
@@ -62,11 +80,15 @@
}
}
- public List<String> getHousenumbers(String postcode, String community, String street) {
- return addressRepository.findHousenumbersByPostcodeAndCommunityAndStreet(postcode, community, street);
+ public List<HousenumberUuidDto> getHousenumbers(String postcode, String community, String street) {
+
+ return addressRepository.findByPostcodeAndCommunityAndStreet(postcode, community, street)
+ .stream()
+ .map(AddressService::toHousenumberUuid)
+ .collect(collectingAndThen(toCollection(() -> new TreeSet<>(Comparator.comparing(HousenumberUuidDto::getHousenumber))),
+ ArrayList::new));
+
}
-
-
}
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/HousenumberUuidDto.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/HousenumberUuidDto.java
new file mode 100644
index 0000000..51e8777
--- /dev/null
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/viewmodel/HousenumberUuidDto.java
@@ -0,0 +1,26 @@
+/**
+******************************************************************************
+* Copyright © 2017-2018 PTA GmbH.
+* All rights reserved. This program and the accompanying materials
+* are made available under the terms of the Eclipse Public License v1.0
+* which accompanies this distribution, and is available at
+*
+* http://www.eclipse.org/legal/epl-v10.html
+*
+******************************************************************************
+*/
+package org.eclipse.openk.gridfailureinformation.viewmodel;
+
+import lombok.Data;
+import lombok.RequiredArgsConstructor;
+
+import java.util.UUID;
+
+@Data
+@RequiredArgsConstructor
+public class HousenumberUuidDto {
+
+ private UUID uuid;
+ private String housenumber;
+
+}
\ No newline at end of file
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/AddressControllerTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/AddressControllerTest.java
index e7e2e24..75a8287 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/AddressControllerTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/controller/AddressControllerTest.java
@@ -17,6 +17,7 @@
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.service.AddressService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
+import org.eclipse.openk.gridfailureinformation.viewmodel.HousenumberUuidDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -114,8 +115,8 @@
String postcode = "71111";
String community = "com1";
String street = "street1";
- List<String> strings = MockDataHelper.mockStringList();
- when(addressService.getHousenumbers(postcode, community, street)).thenReturn(strings);
+ List<HousenumberUuidDto> housenumberUuidDtos = MockDataHelper.mockHousnumberUuidList();
+ when(addressService.getHousenumbers(postcode, community, street)).thenReturn(housenumberUuidDtos);
mockMvc.perform(
get("/addresses/housenumbers")
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/AddressServiceTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/AddressServiceTest.java
index f2f0fd6..7cdd870 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/AddressServiceTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/AddressServiceTest.java
@@ -19,6 +19,7 @@
import org.eclipse.openk.gridfailureinformation.repository.AddressRepository;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.AddressDto;
+import org.eclipse.openk.gridfailureinformation.viewmodel.HousenumberUuidDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -95,13 +96,16 @@
String postcode = "12345";
String community = "com1";
String street = "street1";
- List<String> strings = MockDataHelper.mockStringList();
- when(addressRepository.findHousenumbersByPostcodeAndCommunityAndStreet(postcode, community, street)).thenReturn(strings);
- List<String> housenumbers = addressService.getHousenumbers(postcode, community, street);
+ List<HousenumberUuidDto> housenumberUuids = MockDataHelper.mockHousnumberUuidList();
+ List<TblAddress> tblAddresses = MockDataHelper.mockAddressList();
- assertEquals(housenumbers.size(), strings.size());
+ when(addressRepository.findByPostcodeAndCommunityAndStreet(postcode, community, street)).thenReturn(tblAddresses);
+
+ List<HousenumberUuidDto> housenumbers = addressService.getHousenumbers(postcode, community, street);
+
+ assertEquals(housenumbers.size(), housenumberUuids.size());
assertEquals(2, housenumbers.size());
- assertEquals(housenumbers.get(1), strings.get(1));
+ assertEquals(housenumbers.get(1).getHousenumber(), housenumberUuids.get(1).getHousenumber());
}
@Test
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/support/MockDataHelper.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/support/MockDataHelper.java
index 34b1c86..9707030 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/support/MockDataHelper.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/support/MockDataHelper.java
@@ -890,16 +890,34 @@
address1.setUuid(UUID.randomUUID());
address1.setStreet("stree1");
address1.setPostcode("23443");
+ address1.setHousenumber("44");
address1.setLongitude(BigDecimal.valueOf(443443));
TblAddress address2 = new TblAddress();
address2.setUuid(UUID.randomUUID());
address2.setStreet("stree1");
address2.setPostcode("45465");
+ address2.setHousenumber("93g");
address2.setLongitude(BigDecimal.valueOf(546765));
addressList.add(address1);
addressList.add(address2);
return addressList;
}
+
+ public static List<HousenumberUuidDto> mockHousnumberUuidList() {
+ List<HousenumberUuidDto> housenumberUuidDtoList = new ArrayList<>();
+
+ HousenumberUuidDto housenumberUuidDto1 = new HousenumberUuidDto();
+ housenumberUuidDto1.setHousenumber("44");
+ housenumberUuidDto1.setUuid(UUID.randomUUID());
+
+ HousenumberUuidDto housenumberUuidDto2 = new HousenumberUuidDto();
+ housenumberUuidDto2.setHousenumber("93g");
+ housenumberUuidDto2.setUuid(UUID.randomUUID());
+
+ housenumberUuidDtoList.add(housenumberUuidDto1);
+ housenumberUuidDtoList.add(housenumberUuidDto2);
+ return housenumberUuidDtoList;
+ }
}